在系统中预置一个 wifi 的 ssid 和 pwd,这样在系统烧写启动完成后开机打开 wifi 就能
自动连接指定 ssid。
1、获取 WifiConfigStore.xml
R 版本此文件路径位于
/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
userdebug 版本下先连接好指定 ssid,将 WifiConfigStore.xml copy 出来,大致长这样。
<?xml version='1.0' encoding='utf-8' standalone='yes' ?> <WifiConfigStoreData> <int name="Version" value="3" /> <NetworkList> <Network> <WifiConfiguration> <string name="ConfigKey">"kotlin555"WPA_PSK</string> <string name="SSID">"kotlin555"</string> <string name="PreSharedKey">"123456789"</string> <null name="WEPKeys" /> <int name="WEPTxKeyIndex" value="0" /> <boolean name="HiddenSSID" value="false" /> <boolean name="RequirePMF" value="false" /> <byte-array name="AllowedKeyMgmt" num="1">02</byte-array> <byte-array name="AllowedProtocols" num="1">03</byte-array> <byte-array name="AllowedAuthAlgos" num="0"></byte-array> <byte-array name="AllowedGroupCiphers" num="1">2f</byte-array> <byte-array name="AllowedPairwiseCiphers" num="1">0e</byte-array> <byte-array name="AllowedGroupMgmtCiphers" num="1">04</byte-array> <byte-array name="AllowedSuiteBCiphers" num="0"></byte-array> <boolean name="Shared" value="true" /> <int name="WapiPskType" value="0" /> <null name="WapiPsk" /> <boolean name="AutoJoinEnabled" value="true" /> <boolean name="Trusted" value="true" /> <null name="BSSID" /> <int name="Status" value="2" /> <null name="FQDN" /> <null name="ProviderFriendlyName" /> <null name="LinkedNetworksList" /> <null name="DefaultGwMacAddress" /> <boolean name="ValidatedInternetAccess" value="true" /> <boolean name="NoInternetAccessExpected" value="false" /> <boolean name="MeteredHint" value="false" /> <int name="MeteredOverride" value="0" /> <boolean name="UseExternalScores" value="false" /> <int name="CreatorUid" value="1000" /> <string name="CreatorName">android.uid.system:1000</string> <int name="LastUpdateUid" value="1000" /> <string name="LastUpdateName">android.uid.system:1000</string> <int name="LastConnectUid" value="1000" /> <boolean name="IsLegacyPasspointConfig" value="false" /> <long-array name="RoamingConsortiumOIs" num="0" /> <string name="RandomizedMacAddress">52:b3:02:9e:ca:e4</string> <int name="MacRandomizationSetting" value="0" /> <int name="CarrierId" value="-1" /> <boolean name="IsMostRecentlyConnected" value="true" /> </WifiConfiguration> <NetworkStatus> <string name="SelectionStatus">NETWORK_SELECTION_ENABLED</string> <string name="DisableReason">NETWORK_SELECTION_ENABLE</string> <null name="ConnectChoice" /> <boolean name="HasEverConnected" value="true" /> </NetworkStatus> <IpConfiguration> <string name="IpAssignment">DHCP</string> <string name="ProxySettings">NONE</string> </IpConfiguration> </Network> </NetworkList> <MacAddressMap> <map name="MacMapEntry" /> </MacAddressMap> <Settings> <map name="Values"> <boolean name="wifi_p2p_pending_factory_reset" value="false" /> <boolean name="wifi_scan_throttle_enabled" value="true" /> <null name="wifi_p2p_device_name" /> <boolean name="wifi_scan_always_enabled" value="false" /> <boolean name="wifi_verbose_logging_enabled" value="false" /> </map> </Settings> <PasspointConfigData> <long name="ProviderIndex" value="0" /> </PasspointConfigData> </WifiConfigStoreData>
2、将 WifiConfigStore 放置到指定路径下
方式一、卒
PRODUCT_COPY_FILES +=
PRODUCT_COPY_FILES +=
vendor/mediatek/WifiConfigStore.xml:data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
烧写后开不了机了,data 分区下不允许放置其它东西
方式二、卒
先将 WifiConfigStore.xml 扔到 /system/etc/ 随便目录都行,
用 java 代码 read /system/etc/WifiConfigStore.xml 写入 /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
权限不够,加权限加到地老天荒
方式三、可
加在 init.rc 中去 copy 这个文件,init.rc 自带 root 权限
build\make\target\product\handheld_system.mk
on property:spc.provisioned=1 copy /system/etc/WifiConfigStore.xml /data/misc/apexdata/com.android.wifi/WifiConfigStore.xml
找地方触发 spc.provisioned 只能执行一次,不能每次启动都去 copy, 这样会覆盖用户自己保存的其它 wifi 信息
加在 provision
还有大佬提供的另外一种思路,我没具体验证,这里也贴一下