前言
在展銳Android V項目開發中,需要修改softAp/P2P熱點名稱時,發現集成GMS后直接修改framework層代碼無效。具體表現為:
- 修改
packages/modules/Wifi/WifiApConfigStore
中的getDefaultApConfiguration
方法 - 編譯燒錄后修改不生效
問題根源在于:Wi-Fi模塊在Android S(12)及以上版本已納入Mainline模塊
Mainline模塊機制解析
什么是Mainline?
Google將部分核心模塊獨立開發維護,這些模塊會隨系統更新單獨升級,不再依賴AOSP版本迭代。這導致:
- 修改本地代碼會被系統預置模塊覆蓋
- 整編時無法打包修改后的模塊
受影響模塊列表
參考Google官方文檔:模塊化系統架構
Wi-Fi模塊自Android 11開始Mainline化
問題分析
修改失效原因
- 代碼覆蓋:Mainline模塊優先級高于本地修改
- 編譯機制:GMS版本會強制使用預置模塊
- 認證限制:關閉Mainline會影響GTS測試
解決方案矩陣
方案 | 適用場景 | 限制條件 |
---|---|---|
Overlay機制 | 修改配置參數 | 需展銳平臺支持 |
運行時設置 | 動態修改熱點名 | 需處理沖突邏輯 |
關閉Mainline | 僅限國內版本 | 影響GMS認證 |
具體解決方案
方案1:使用Overlay機制(推薦)
展銳平臺已提供Overlay配置入口:
vendor/sprd/platform/frameworks/opt/net/wifi/service/ServiceUniWifiResources/res/values/config.xml
<string name="config_wifi_softap_ssid">custom</string>
<string name="config_wifi_p2p_device_name">MyP2PName</string>
方案2:運行時動態設置
通過系統廣播監聽實現首次啟動配置:
// 監聽BOOT_COMPLETED廣播
public class HotspotInitializer extends BroadcastReceiver {private static final String PREF_HOTSPOT_SET = "hotspot_initialized";@Overridepublic void onReceive(Context context, Intent intent) {if (isAlreadyConfigured(context)) return;WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);SoftApConfiguration config = wifiManager.getSoftApConfiguration();String newSsid = SystemProperties.get("ro.product.model") + "_HOTSPOT";wifiManager.setSoftApConfiguration(new SoftApConfiguration.Builder(config).setSsid(newSsid).build());markAsConfigured(context);}private boolean isAlreadyConfigured(Context ctx) {return PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean(PREF_HOTSPOT_SET, false);}
}
關鍵點:
- 使用SharedPreferences記錄配置狀態
- 通過系統屬性獲取設備型號作為SSID基礎
- 需在AndroidManifest.xml中注冊廣播接收器
方案3:關閉Mainline模塊(僅限國內版本)
在BoardConfig.mk中添加:
# 關閉Wi-Fi Mainline模塊(影響GTS測試)
MAINLINE_INCLUDE_WIFI_MODULE := false
風險提示:
- 可能導致GMS認證失敗
- 無法接收Wi-Fi模塊安全更新
- 僅建議在非GMS版本或測試環境使用
總結與建議
- 優先方案:使用Overlay機制(方案1),這是最安全合規的方式
- 備選方案:運行時設置(方案2),需處理好配置沖突
- 最后手段:關閉Mainline(方案3),僅限特定場景使用
對于GMS認證設備,建議采用方案1+方案2組合:
- 使用Overlay設置默認值
- 通過運行時機制允許用戶自定義
- 保留系統設置入口作為最終配置渠道
最后
附上Android15上測試可用的修改方法:
vendor/sprd/platform/packages/app/UniWifi/app/res/values/config.xml
<!-- Carrier default softap ssid via IMEI, like as 1234, name1, name2 --><string-array translatable="false" name="config_uniwifi_softap_default_ssid_via_imei"></string-array><!-- Customer default softap ssid -->
- <string translatable="false" name="config_uniwifi_softap_default_ssid"></string>
+ <string translatable="false" name="config_uniwifi_softap_default_ssid">custom</string><!-- Preset Carrier Network as Suggestion according to software version --><!-- ro.carrier, ssid, eap type(WifiConfiguration.SECURITY_TYPE#3-5-9),