文档管理中心
HiCar Guides集成开发Android设备接入附录Android 11.0适配须知

Android 11.0适配须知

此处对Android 11车机适配过程中涉及的修改进行说明,适配修改主要涉及蓝牙和Wi-Fi两个模块。其中蓝牙模块的适配主要用于HiCar的连接和设备发现, 蓝牙模块的修改适配可参考3.1.2.2-蓝牙。Wi-Fi模块的适配主要用于HiCar的连接和视频流传输等功能,具体修改点可参考以下方案:

说明

以下修改方案及代码实现仅供厂商参考,具体修改的内容需厂商根据车机系统情况进行适配。

对Wi-Fi模块的修改主要是为感知Wi-Fi网络的状态变化,具体要修改的文件路径及增加的内容如下:

frameworks/opt/net/wifi/service/java/com/android/server/wifi/SoftApManager.java

收起
自动换行
深色代码主题
复制
  1. public class SoftApManager implements ActiveModeManager {
  2. //此处省略原有代码
  3. private static final String ACTION_WIFI_AP_STA_JOIN = "android.net.wifi.WIFI_AP_STA_JOIN";
  4. private static final String ACTION_WIFI_AP_STA_LEAVE = "android.net.wifi.WIFI_AP_STA_LEAVE";
  5. /**
  6. * Listener for soft AP events.
  7. */
  8. private final SoftApListener mSoftApListener = new SoftApListener() {
  9. //此处省略原有代码
  10. @Override
  11. public void onStationAssociated(String macAddress) {
  12. Log.i(TAG, "onStationAssociated macAddress: " + macAddress);
  13. mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_ASSOCIATED, macAddress);
  14. }
  15. @Override
  16. public void onStationDisassociated(String macAddress) {
  17. Log.i(TAG, "onStationDisassociated macAddress: " + macAddress);
  18. mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_DISASSOCIATED, macAddress);
  19. }
  20. }
  21. private void notifyStationChanged(String action, String macAddress) {
  22. if (action != null && mContext != null) {
  23. Intent apStaChangedIt = new Intent(action);
  24. apStaChangedIt.putExtra("macInfo", macAddress);
  25. Log.i(TAG, "notifyStationChanged macAddress=" + macAddress);
  26. mContext.sendBroadcastAsUser(apStaChangedIt, UserHandle.ALL, android.Manifest.permission.ACCESS_WIFI_STATE);
  27. }
  28. }
  29. private class SoftApStateMachine extends StateMachine {
  30. // 此处省略原有代码
  31. public static final int CMD_NOTIFY_STATION_ASSOCIATED = 12;
  32. public static final int CMD_NOTIFY_STATION_DISASSOCIATED = 13;
  33. // 此处省略原有代码
  34. @Override
  35. public boolean processMessage(Message message) {
  36. switch (message.what) {
  37. // 此处省略原有代码
  38. case CMD_NOTIFY_STATION_ASSOCIATED:
  39. notifyStationChanged(ACTION_WIFI_AP_STA_JOIN, (String) message.obj);
  40. break;
  41. case CMD_NOTIFY_STATION_DISASSOCIATED:
  42. notifyStationChanged(ACTION_WIFI_AP_STA_LEAVE, (String) message.obj);
  43. break;
  44. default:
  45. return NOT_HANDLED;
  46. }
  47. }
  48. }
  49. }

frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java

收起
自动换行
深色代码主题
复制
  1. public class WifiNative {
  2. // 此处省略原有部分代码
  3. public interface SoftApListener extends WifiNl80211Manager.SoftApCallback {
  4. // 此处省略原有部分代码
  5. /**
  6. * Notify station associated
  7. */
  8. void onStationAssociated(String macAddress);
  9. /**
  10. * Notify station disassociated
  11. */
  12. void onStationDisassociated(String macAddress);
  13. }
  14. }

frameworks/base/wifi/java/android/net/wifi/nl80211/WifiNl80211Manager.java

收起
自动换行
深色代码主题
复制
  1. public class WifiNl80211Manager {
  2. // 此处省略原有部分代码
  3. public interface SoftApCallback {
  4. // 此处省略原有部分代码
  5. /**
  6. * Notify station associated
  7. */
  8. void onStationAssociated(String macAddress);
  9. /**
  10. * Notify station disassociated
  11. */
  12. void onStationDisassociated(String macAddress);
  13. }
  14. // 此处省略原有部分代码
  15. private class ApInterfaceEventCallback extends IApInterfaceEventCallback.Stub {
  16. // 此处省略原有部分代码
  17. @Override
  18. public void onStationAssociated(String macAddress) {
  19. mExecutor.execute(() -> mSoftApListener.onStationAssociated(macAddress));
  20. }
  21. @Override
  22. public void onStationDisassociated(String macAddress) {
  23. mExecutor.execute(() -> mSoftApListener.onStationDisassociated(macAddress));
  24. }
  25. }
  26. }

Native层需要修改的文件如下:

system/connectivity/wificond/aidl/android/net/wifi/nl80211/IApInterfaceEventCallback.aidl

收起
自动换行
深色代码主题
复制
  1. oneway interface IApInterfaceEventCallback {
  2. // 此处省略原有代码
  3. // Notify station associated
  4. //
  5. // @param macAddress mac address of this station
  6. oneway void onStationAssociated(String macAddress);
  7. // Notify station disassociated
  8. //
  9. // @param macAddress mac address of this station
  10. oneway void onStationDisassociated(String macAddress);
  11. }

system/connectivity/wificond/ap_interface_binder.h

收起
自动换行
深色代码主题
复制
  1. class ApInterfaceBinder : public android::net::wifi::nl80211::BnApInterface {
  2. // 省略原有代码
  3. void NotifyStationAssociated(const String16& mac_address);
  4. void NotifyStationDisassociated(const String16& mac_address);
  5. }

system/connectivity/wificond/ap_interface_impl.cpp

收起
自动换行
深色代码主题
复制
  1. void ApInterfaceImpl::OnStationEvent(
  2. StationEvent event,
  3. const array<uint8_t, ETH_ALEN>& mac_address) {
  4. if (event == NEW_STATION) {
  5. // 省略原有代码
  6. binder_->NotifyStationAssociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
  7. } else if (event == DEL_STATION) {
  8. // 省略原有代码
  9. binder_->NotifyStationDisassociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
  10. }
  11. }

system/connectivity/wificond/ap_interface_binder.cpp

收起
自动换行
深色代码主题
复制
  1. // 此处省略原有代码
  2. void ApInterfaceBinder::NotifyStationAssociated(const String16& mac_address) {
  3. if (ap_interface_event_callback_ != nullptr) {
  4. ap_interface_event_callback_->onStationAssociated(mac_address);
  5. }
  6. }
  7. void ApInterfaceBinder::NotifyStationDisassociated(const String16& mac_address) {
  8. if (ap_interface_event_callback_ != nullptr) {
  9. ap_interface_event_callback_->onStationDisassociated(mac_address);
  10. }
  11. }

frameworks/base/core/res/AndroidManifest.xml

收起
自动换行
深色代码主题
复制
  1. // 省略原有代码
  2. <!-- For HiCar SDK OS -->
  3. <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_JOIN" />
  4. <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_LEAVE" />
在 指南 中进行搜索
请输入您想要搜索的关键词