预制wifi,开机自动连接

diff --git a/device/mediatek/common/mid/common/system/etc/WifiConfigStore.xml b/device/mediatek/common/mid/common/system/etc/WifiConfigStore.xml
new file mode 100755
index 00000000000..e8a8e662a92
--- /dev/null
+++ b/device/mediatek/common/mid/common/system/etc/WifiConfigStore.xml
@@ -0,0 +1,126 @@
+<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
+<WifiConfigStoreData>
+<int name="Version" value="1" />
+<NetworkList>
+<Network>
+<WifiConfiguration>
+<string name="ConfigKey">&quot;googlevpn3&quot;WPA_PSK</string>
+<string name="SSID">&quot;googlevpn3&quot;</string>
+<null name="BSSID" />
+<string name="PreSharedKey">&quot;sw0123456&quot;</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="1">01</byte-array>
+<byte-array name="AllowedGroupCiphers" num="1">0f</byte-array>
+<byte-array name="AllowedPairwiseCiphers" num="1">06</byte-array>
+<byte-array name="AllowedGroupMgmtCiphers" num="0"></byte-array>
+<byte-array name="AllowedSuiteBCiphers" num="0"></byte-array>
+<boolean name="Shared" value="true" />
+<int name="WapiCertSelMode" value="0" />
+<null name="WapiCertSel" />
+<int name="WapiPskType" value="0" />
+<null name="WapiPsk" />
+<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" />
+<int name="UserApproved" value="0" />
+<boolean name="MeteredHint" value="false" />
+<int name="MeteredOverride" value="0" />
+<boolean name="UseExternalScores" value="false" />
+<int name="NumAssociation" value="3" />
+<int name="CreatorUid" value="1000" />
+<string name="CreatorName">android.uid.system:1000</string>
+<string name="CreationTime">time=12-25 10:14:01.347</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">e2:3e:fa:4e:96:d4</string>
+<int name="MacRandomizationSetting" value="0" />
+</WifiConfiguration>
+<NetworkStatus>
+<string name="SelectionStatus">NETWORK_SELECTION_ENABLED</string>
+<string name="DisableReason">NETWORK_SELECTION_ENABLE</string>
+<null name="ConnectChoice" />
+<long name="ConnectChoiceTimeStamp" value="-1" />
+<boolean name="HasEverConnected" value="true" />
+</NetworkStatus>
+<IpConfiguration>
+<string name="IpAssignment">DHCP</string>
+<string name="ProxySettings">NONE</string>
+</IpConfiguration>
+</Network>
+<Network>
+<WifiConfiguration>
+<string name="ConfigKey">&quot;AceAgeConfig&quot;WPA_PSK</string>
+<string name="SSID">&quot;AceAgeConfig&quot;</string>
+<null name="BSSID" />
+<string name="PreSharedKey">&quot;Ace@g3Config&quot;</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="1">01</byte-array>
+<byte-array name="AllowedGroupCiphers" num="1">0f</byte-array>
+<byte-array name="AllowedPairwiseCiphers" num="1">06</byte-array>
+<byte-array name="AllowedGroupMgmtCiphers" num="0"></byte-array>
+<byte-array name="AllowedSuiteBCiphers" num="0"></byte-array>
+<boolean name="Shared" value="true" />
+<int name="WapiCertSelMode" value="0" />
+<null name="WapiCertSel" />
+<int name="WapiPskType" value="0" />
+<null name="WapiPsk" />
+<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" />
+<int name="UserApproved" value="0" />
+<boolean name="MeteredHint" value="false" />
+<int name="MeteredOverride" value="0" />
+<boolean name="UseExternalScores" value="false" />
+<int name="NumAssociation" value="1" />
+<int name="CreatorUid" value="1000" />
+<string name="CreatorName">android.uid.system:1000</string>
+<string name="CreationTime">time=12-26 04:46:22.445</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">ae:7a:c4:1e:fa:a9</string>
+<int name="MacRandomizationSetting" value="0" />
+</WifiConfiguration>
+<NetworkStatus>
+<string name="SelectionStatus">NETWORK_SELECTION_ENABLED</string>
+<string name="DisableReason">NETWORK_SELECTION_ENABLE</string>
+<null name="ConnectChoice" />
+<long name="ConnectChoiceTimeStamp" value="-1" />
+<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>
+<PasspointConfigData>
+<long name="ProviderIndex" value="0" />
+</PasspointConfigData>
+</WifiConfigStoreData>
diff --git a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiConfigStore.java b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiConfigStore.java
old mode 100644
new mode 100755
index 2853bbac579..83153b82307
--- a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -64,6 +64,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
+import java.io.FileInputStream;
+import java.io.InputStream;
 
 /**
  * This class provides a mechanism to save data to persistent store files {@link StoreFile}.
@@ -256,6 +258,28 @@ public class WifiConfigStore {
         // CE storage is accessible via |switchUserStoresAndRead|.
         mUserStores = null;
     }
+       public static void copyWifiFile(String oldPath, String newPath) {
+           try {
+                   int bytesum = 0;
+                   int byteread = 0;
+                   File oldfile = new File(oldPath);
+                   if (oldfile.exists()) {
+                           InputStream inStream = new FileInputStream(oldPath);
+                           FileOutputStream fs = new FileOutputStream(newPath);
+                           byte[] buffer = new byte[1444];
+                           int length;
+                           while ( (byteread = inStream.read(buffer)) != -1) {
+                                   bytesum += byteread; 
+                                   System.out.println(bytesum);
+                                   fs.write(buffer, 0, byteread);
+                           }
+                           inStream.close();
+                   }
+           } catch (Exception e) {
+                   System.out.println("copy error");
+                   e.printStackTrace();
+           }
+       }
 
     /**
      * Set the user store files.
@@ -310,12 +334,24 @@ public class WifiConfigStore {
                 return null;
             }
         }
-        File file = new File(storeDir, STORE_ID_TO_FILE_NAME.get(fileId));
         WifiConfigStoreEncryptionUtil encryptionUtil = null;
+        File wifiFile = new File("/data/misc/wifi/WifiConfigStore.xml");
+
+        if(!wifiFile.exists() && !wifiFile.isDirectory()) {
+             copyWifiFile("/system/etc/WifiConfigStore.xml","/data/misc/wifi/WifiConfigStore.xml"); 
+        // Turn on integrity checking only for single user mode devices.
+        if (shouldEncryptCredentials) {
+            encryptionUtil = new WifiConfigStoreEncryptionUtil(wifiFile.getAbsolutePath());
+        }
+            return new StoreFile(wifiFile, fileId, userHandle, encryptionUtil);
+
+        }else{
+        File file = new File(storeDir, STORE_ID_TO_FILE_NAME.get(fileId));
         if (shouldEncryptCredentials) {
             encryptionUtil = new WifiConfigStoreEncryptionUtil(file.getName());
         }
         return new StoreFile(file, fileId, userHandle, encryptionUtil);
+               }
     }
 
     private static @Nullable List<StoreFile> createFiles(File storeDir, List<Integer> storeFileIds,
 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值