前言
在展锐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),