智能客服
你问我答,随时在线为你解决问题
此处对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
- public class SoftApManager implements ActiveModeManager {
-
- //此处省略原有代码
- private static final String ACTION_WIFI_AP_STA_JOIN = "android.net.wifi.WIFI_AP_STA_JOIN";
-
- private static final String ACTION_WIFI_AP_STA_LEAVE = "android.net.wifi.WIFI_AP_STA_LEAVE";
-
- /**
- * Listener for soft AP events.
- */
- private final SoftApListener mSoftApListener = new SoftApListener() {
- //此处省略原有代码
- @Override
- public void onStationAssociated(String macAddress) {
- Log.i(TAG, "onStationAssociated macAddress: " + macAddress);
- mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_ASSOCIATED, macAddress);
- }
-
- @Override
- public void onStationDisassociated(String macAddress) {
- Log.i(TAG, "onStationDisassociated macAddress: " + macAddress);
- mStateMachine.sendMessage(SoftApStateMachine.CMD_NOTIFY_STATION_DISASSOCIATED, macAddress);
- }
- }
-
- private void notifyStationChanged(String action, String macAddress) {
- if (action != null && mContext != null) {
- Intent apStaChangedIt = new Intent(action);
- apStaChangedIt.putExtra("macInfo", macAddress);
- Log.i(TAG, "notifyStationChanged macAddress=" + macAddress);
- mContext.sendBroadcastAsUser(apStaChangedIt, UserHandle.ALL, android.Manifest.permission.ACCESS_WIFI_STATE);
- }
- }
-
- private class SoftApStateMachine extends StateMachine {
- // 此处省略原有代码
- public static final int CMD_NOTIFY_STATION_ASSOCIATED = 12;
- public static final int CMD_NOTIFY_STATION_DISASSOCIATED = 13;
-
- // 此处省略原有代码
- @Override
- public boolean processMessage(Message message) {
- switch (message.what) {
- // 此处省略原有代码
- case CMD_NOTIFY_STATION_ASSOCIATED:
- notifyStationChanged(ACTION_WIFI_AP_STA_JOIN, (String) message.obj);
- break;
- case CMD_NOTIFY_STATION_DISASSOCIATED:
- notifyStationChanged(ACTION_WIFI_AP_STA_LEAVE, (String) message.obj);
- break;
- default:
- return NOT_HANDLED;
- }
- }
- }
- }
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java
- public class WifiNative {
- // 此处省略原有部分代码
- public interface SoftApListener extends WifiNl80211Manager.SoftApCallback {
-
- // 此处省略原有部分代码
- /**
- * Notify station associated
- */
- void onStationAssociated(String macAddress);
-
- /**
- * Notify station disassociated
- */
- void onStationDisassociated(String macAddress);
- }
- }
frameworks/base/wifi/java/android/net/wifi/nl80211/WifiNl80211Manager.java
- public class WifiNl80211Manager {
-
- // 此处省略原有部分代码
- public interface SoftApCallback {
-
- // 此处省略原有部分代码
- /**
- * Notify station associated
- */
- void onStationAssociated(String macAddress);
-
- /**
- * Notify station disassociated
- */
- void onStationDisassociated(String macAddress);
- }
-
- // 此处省略原有部分代码
- private class ApInterfaceEventCallback extends IApInterfaceEventCallback.Stub {
-
- // 此处省略原有部分代码
- @Override
- public void onStationAssociated(String macAddress) {
- mExecutor.execute(() -> mSoftApListener.onStationAssociated(macAddress));
- }
- @Override
- public void onStationDisassociated(String macAddress) {
- mExecutor.execute(() -> mSoftApListener.onStationDisassociated(macAddress));
- }
- }
- }
Native层需要修改的文件如下:
system/connectivity/wificond/aidl/android/net/wifi/nl80211/IApInterfaceEventCallback.aidl
- oneway interface IApInterfaceEventCallback {
-
- // 此处省略原有代码
- // Notify station associated
- //
- // @param macAddress mac address of this station
- oneway void onStationAssociated(String macAddress);
-
- // Notify station disassociated
- //
- // @param macAddress mac address of this station
- oneway void onStationDisassociated(String macAddress);
- }
system/connectivity/wificond/ap_interface_binder.h
- class ApInterfaceBinder : public android::net::wifi::nl80211::BnApInterface {
- // 省略原有代码
- void NotifyStationAssociated(const String16& mac_address);
- void NotifyStationDisassociated(const String16& mac_address);
- }
system/connectivity/wificond/ap_interface_impl.cpp
- void ApInterfaceImpl::OnStationEvent(
- StationEvent event,
- const array<uint8_t, ETH_ALEN>& mac_address) {
- if (event == NEW_STATION) {
- // 省略原有代码
- binder_->NotifyStationAssociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
- } else if (event == DEL_STATION) {
- // 省略原有代码
- binder_->NotifyStationDisassociated(String16(LoggingUtils::GetMacString(mac_address).c_str()));
- }
- }
system/connectivity/wificond/ap_interface_binder.cpp
- // 此处省略原有代码
- void ApInterfaceBinder::NotifyStationAssociated(const String16& mac_address) {
- if (ap_interface_event_callback_ != nullptr) {
- ap_interface_event_callback_->onStationAssociated(mac_address);
- }
- }
-
- void ApInterfaceBinder::NotifyStationDisassociated(const String16& mac_address) {
- if (ap_interface_event_callback_ != nullptr) {
- ap_interface_event_callback_->onStationDisassociated(mac_address);
- }
- }
frameworks/base/core/res/AndroidManifest.xml
- // 省略原有代码
- <!-- For HiCar SDK OS -->
- <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_JOIN" />
- <protected-broadcast android:name="android.net.wifi.WIFI_AP_STA_LEAVE" />