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

Android 10.0适配须知

如果厂商车机ROM是Android 10.0版本,在进行无线连接之前,应进行蓝牙和Wi-Fi适配修改。其中蓝牙适配修改可参考蓝牙,Wi-Fi适配可参考以下操作进行。

说明

以下修改方案参考及代码供厂商参考,具体修改内容还需厂商根据自身系统情况独立完成适配。

修改framework下的文件:

“/service/java/com/android/server/wifi/SoftApManager.java”

“/service/java/com/android/server/wifi/WifiNative.java”

“/service/java/com/android/server/wifi/WificondControl.java”

收起
自动换行
深色代码主题
复制
  1. diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java
  2. index b92dab7..f88c98c 100644
  3. --- a/service/java/com/android/server/wifi/SoftApManager.java
  4. +++ b/service/java/com/android/server/wifi/SoftApManager.java
  5. @@ -64,6 +64,9 @@ public class SoftApManager implements ActiveModeManager {
  6. public static final String SOFT_AP_SEND_MESSAGE_TIMEOUT_TAG = TAG
  7. + " Soft AP Send Message Timeout";
  8. + private static final String ACTION_WIFI_AP_STA_JOIN = "android.net.wifi.WIFI_AP_STA_JOIN";
  9. + private static final String ACTION_WIFI_AP_STA_LEAVE = "android.net.wifi.WIFI_AP_STA_LEAVE";
  10. +
  11. private final Context mContext;
  12. private final FrameworkFacade mFrameworkFacade;
  13. private final WifiNative mWifiNative;
  14. @@ -112,6 +115,18 @@ public class SoftApManager implements ActiveModeManager {
  15. }
  16. @Override
  17. + public void onStationAssociated(String macAddress) {
  18. + Log.i(TAG, "onStationAssociated macAddress: " + macAddress);
  19. + mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_ASSOCIATED, macAddress);
  20. + }
  21. +
  22. + @Override
  23. + public void onStationDisassociated(String macAddress) {
  24. + Log.i(TAG, "onStationDisassociated macAddress: " + macAddress);
  25. + mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_DISASSOCIATED, macAddress);
  26. + }
  27. +
  28. + @Override
  29. public void onSoftApChannelSwitched(int frequency, int bandwidth) {
  30. mStateMachine.sendMessage(
  31. SoftApStateMachine.CMD_SOFT_AP_CHANNEL_SWITCHED, frequency, bandwidth);
  32. @@ -237,6 +252,15 @@ public class SoftApManager implements ActiveModeManager {
  33. mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
  34. }
  35. + private void notifyStationChanged(String action, String macAddress) {
  36. + if (action != null && mContext != null) {
  37. + Intent apStaChangedIt = new Intent(action);
  38. + apStaChangedIt.putExtra("macInfo", macAddress);
  39. + Log.i(TAG, "notifyStationChanged macAddress=" + macAddress);
  40. + mContext.sendBroadcastAsUser(apStaChangedIt, UserHandle.ALL, android.Manifest.permission.ACCESS_WIFI_STATE);
  41. + }
  42. + }
  43. +
  44. /**
  45. * Start a soft AP instance with the given configuration.
  46. * @param config AP configuration
  47. @@ -312,6 +336,8 @@ public class SoftApManager implements ActiveModeManager {
  48. public static final int CMD_INTERFACE_DESTROYED = 7;
  49. public static final int CMD_INTERFACE_DOWN = 8;
  50. public static final int CMD_SOFT_AP_CHANNEL_SWITCHED = 9;
  51. + public static final int CMD_NOTIFY_STATION_ASSOCIATED = 10;
  52. + public static final int CMD_NOTIFY_STATION_DISASSOCIATED = 11;
  53. private final State mIdleState = new IdleState();
  54. private final State mStartedState = new StartedState();
  55. @@ -645,6 +671,12 @@ public class SoftApManager implements ActiveModeManager {
  56. WifiManager.WIFI_AP_STATE_FAILED, 0);
  57. transitionTo(mIdleState);
  58. break;
  59. + case CMD_NOTIFY_STATION_ASSOCIATED:
  60. + notifyStationChanged(ACTION_WIFI_AP_STA_JOIN, (String) message.obj);
  61. + break;
  62. + case CMD_NOTIFY_STATION_DISASSOCIATED:
  63. + notifyStationChanged(ACTION_WIFI_AP_STA_LEAVE, (String) message.obj);
  64. + break;
  65. default:
  66. return NOT_HANDLED;
  67. }
  68. diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
  69. index 3e5dc3c..44f9c42 100644
  70. --- a/service/java/com/android/server/wifi/WifiNative.java
  71. +++ b/service/java/com/android/server/wifi/WifiNative.java
  72. @@ -1527,6 +1527,16 @@ public class WifiNative {
  73. void onNumAssociatedStationsChanged(int numStations);
  74. /**
  75. + * Notify station associated
  76. + */
  77. + void onStationAssociated(String macAddress);
  78. +
  79. + /**
  80. + * Notify station disassociated
  81. + */
  82. + void onStationDisassociated(String macAddress);
  83. +
  84. + /**
  85. * Invoked when the channel switch event happens.
  86. */
  87. void onSoftApChannelSwitched(int frequency, int bandwidth);
  88. diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java
  89. index bd756f6..4cd8975 100644
  90. --- a/service/java/com/android/server/wifi/WificondControl.java
  91. +++ b/service/java/com/android/server/wifi/WificondControl.java
  92. @@ -188,6 +188,16 @@ public class WificondControl implements IBinder.DeathRecipient {
  93. }
  94. @Override
  95. + public void onStationAssociated(String macAddress) {
  96. + mSoftApListener.onStationAssociated(macAddress);
  97. + }
  98. +
  99. + @Override
  100. + public void onStationDisassociated(String macAddress) {
  101. + mSoftApListener.onStationDisassociated(macAddress);
  102. + }
  103. +
  104. + @Override
  105. public void onSoftApChannelSwitched(int frequency, int bandwidth) {
  106. mSoftApListener.onSoftApChannelSwitched(frequency, bandwidth);
  107. }
  108. --
  109. 2.7.4

修改如下文件:

“system/connectivity/wificond/aidl/android/net/wifi/IApInterfaceEventCallback.aidl”

“system/connectivity/wificond/ap_interface_binder.cpp”

“system/connectivity/wificond/ap_interface_binder.h”

“system/connectivity/wificond/ap_interface_impl.cpp”

收起
自动换行
深色代码主题
复制
  1. diff --git a/aidl/android/net/wifi/IApInterfaceEventCallback.aidl b/aidl/android/net/wifi/IApInterfaceEventCallback.aidl
  2. index d23da91..f2b4b60 100644
  3. --- a/aidl/android/net/wifi/IApInterfaceEventCallback.aidl
  4. +++ b/aidl/android/net/wifi/IApInterfaceEventCallback.aidl
  5. @@ -33,6 +33,16 @@ interface IApInterfaceEventCallback {
  6. // @param numStations Number of associated stations after change
  7. oneway void onNumAssociatedStationsChanged(int numStations);
  8. + // Notify station associated
  9. + //
  10. + // @param macAddress mac address of this station
  11. + oneway void onStationAssociated(String macAddress);
  12. +
  13. + // Notify station disassociated
  14. + //
  15. + // @param macAddress mac address of this station
  16. + oneway void onStationDisassociated(String macAddress);
  17. +
  18. // Signals a channel switch event for this soft Ap.
  19. //
  20. // @param frequency Represents the frequency of the channel in MHz
  21. diff --git a/ap_interface_binder.cpp b/ap_interface_binder.cpp
  22. index 56e779f..b59f67e 100644
  23. --- a/ap_interface_binder.cpp
  24. +++ b/ap_interface_binder.cpp
  25. @@ -37,6 +37,18 @@ void ApInterfaceBinder::NotifyNumAssociatedStationsChanged(int num_stations) {
  26. }
  27. }
  28. + void ApInterfaceBinder::NotifyStationAssociated(const String16& mac_address) {
  29. + if (ap_interface_event_callback_ != nullptr) {
  30. + ap_interface_event_callback_->onStationAssociated(mac_address);
  31. + }
  32. +}
  33. +
  34. + void ApInterfaceBinder::NotifyStationDisassociated(const String16& mac_address) {
  35. + if (ap_interface_event_callback_ != nullptr) {
  36. + ap_interface_event_callback_->onStationDisassociated(mac_address);
  37. + }
  38. +}
  39. +
  40. void ApInterfaceBinder::NotifySoftApChannelSwitched(
  41. int frequency, ChannelBandwidth channel_bandwidth) {
  42. if (ap_interface_event_callback_ == nullptr) {
  43. diff --git a/ap_interface_binder.h b/ap_interface_binder.h
  44. index 7e332f5..0b5fae1 100644
  45. --- a/ap_interface_binder.h
  46. +++ b/ap_interface_binder.h
  47. @@ -41,6 +41,8 @@ class ApInterfaceBinder : public android::net::wifi::BnApInterface {
  48. // Called by |impl_| everytime number of associated stations changes.
  49. void NotifyNumAssociatedStationsChanged(int num_stations);
  50. + void NotifyStationAssociated(const String16& mac_address);
  51. + void NotifyStationDisassociated(const String16& mac_address);
  52. // Called by |impl_| on every channel switch event.
  53. void NotifySoftApChannelSwitched(int frequency,
  54. diff --git a/ap_interface_impl.cpp b/ap_interface_impl.cpp
  55. index f39e9c1..80a8d42 100644
  56. --- a/ap_interface_impl.cpp
  57. +++ b/ap_interface_impl.cpp
  58. @@ -88,6 +88,8 @@ void ApInterfaceImpl::OnStationEvent(
  59. << LoggingUtils::GetMacString(mac_address)
  60. << " associated with hotspot";
  61. number_of_associated_stations_++;
  62. + binder_->NotifyStationAssociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
  63. + binder_->NotifyNumAssociatedStationsChanged(number_of_associated_stations_);
  64. } else if (event == DEL_STATION) {
  65. LOG(INFO) << "Station "
  66. << LoggingUtils::GetMacString(mac_address)
  67. @@ -99,9 +101,8 @@ void ApInterfaceImpl::OnStationEvent(
  68. } else {
  69. number_of_associated_stations_--;
  70. }
  71. - }
  72. - if (event == NEW_STATION || event == DEL_STATION) {
  73. + binder_->NotifyStationDisassociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
  74. binder_->NotifyNumAssociatedStationsChanged(number_of_associated_stations_);
  75. }
  76. }

修改如下文件:

“core/res/AndroidManifest.xml”

收起
自动换行
深色代码主题
复制
  1. diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
  2. index 825d198..1c9c9d9 100644
  3. --- a/core/res/AndroidManifest.xml
  4. +++ b/core/res/AndroidManifest.xml
  5. @@ -635,6 +635,10 @@
  6. <!-- For tether entitlement recheck-->
  7. <protected-broadcast
  8. android:name="com.android.server.connectivity.tethering.PROVISIONING_RECHECK_ALARM" />
  9. +
  10. + <!-- For HiCar SDK OS -->
  11. + <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_JOIN" />
  12. + <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_LEAVE" />
  13. <!-- ====================================================================== -->
  14. <!-- RUNTIME PERMISSIONS -->
  15. <!-- ====================================================================== -->
在 指南 中进行搜索
请输入您想要搜索的关键词