summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-03-19 01:26:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-03-19 01:26:25 +0000
commitc5a7be7a8ff56a03a1bc15ae0b15dd8ad1091cca (patch)
tree9de410c191c0b028bafa0327cbee8fe474d4582d /service
parent27d2604a9a7c5673ba9c8779400d8a660093d7a9 (diff)
parentd9f6a328b3f97cdd365fc434cad43a1f222f2faf (diff)
Merge "WifiSoftApConfigStore: Move softap.conf conversion to WifiMigration" into rvc-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiApConfigStore.java111
-rw-r--r--service/java/com/android/server/wifi/WifiConfigStore.java28
-rw-r--r--service/java/com/android/server/wifi/util/ApConfigUtil.java2
3 files changed, 22 insertions, 119 deletions
diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java
index e5d12822b..df901a321 100644
--- a/service/java/com/android/server/wifi/WifiApConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiApConfigStore.java
@@ -22,8 +22,6 @@ import android.content.IntentFilter;
import android.net.MacAddress;
import android.net.util.MacAddressUtils;
import android.net.wifi.SoftApConfiguration;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiMigration;
import android.os.Handler;
import android.os.Process;
import android.text.TextUtils;
@@ -33,10 +31,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.util.ApConfigUtil;
import com.android.wifi.resources.R;
-import java.io.BufferedInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Random;
@@ -55,13 +49,6 @@ public class WifiApConfigStore {
private static final String TAG = "WifiApConfigStore";
- // Note: This is the legacy Softap config file. This is only used for migrating data out
- // of this file on first reboot.
- private static final String LEGACY_AP_CONFIG_FILE = "softap.conf";
-
- @VisibleForTesting
- public static final int AP_CONFIG_FILE_VERSION = 3;
-
private static final int RAND_SSID_INT_MIN = 1000;
private static final int RAND_SSID_INT_MAX = 9999;
@@ -100,14 +87,7 @@ public class WifiApConfigStore {
}
public void reset() {
- if (mPersistentWifiApConfig != null) {
- // Note: Reset is invoked when WifiConfigStore.read() is invoked on boot completed.
- // If we had migrated data from the legacy store before that (which is most likely
- // true because we read the legacy file in the constructor here, whereas
- // WifiConfigStore.read() is only triggered on boot completed), trigger a write to
- // persist the migrated data.
- mHandler.post(() -> mWifiConfigManager.saveToStore(true));
- }
+ mPersistentWifiApConfig = null;
}
public boolean hasNewDataToSerialize() {
@@ -115,47 +95,19 @@ public class WifiApConfigStore {
}
}
- WifiApConfigStore(Context context, WifiInjector wifiInjector, Handler handler,
- BackupManagerProxy backupManagerProxy, WifiConfigStore wifiConfigStore,
- WifiConfigManager wifiConfigManager, ActiveModeWarden activeModeWarden) {
- this(context, wifiInjector, handler, backupManagerProxy, wifiConfigStore,
- wifiConfigManager, activeModeWarden,
- WifiMigration.convertAndRetrieveSharedConfigStoreFile(
- WifiMigration.STORE_FILE_SHARED_SOFTAP));
- }
-
WifiApConfigStore(Context context,
WifiInjector wifiInjector,
Handler handler,
BackupManagerProxy backupManagerProxy,
WifiConfigStore wifiConfigStore,
WifiConfigManager wifiConfigManager,
- ActiveModeWarden activeModeWarden,
- InputStream legacyApConfigFileStream) {
+ ActiveModeWarden activeModeWarden) {
mContext = context;
mHandler = handler;
mBackupManagerProxy = backupManagerProxy;
mWifiConfigManager = wifiConfigManager;
mActiveModeWarden = activeModeWarden;
- // One time migration from legacy config store.
- // TODO (b/149418926): softap migration needs to be fixed. Move the logic
- // below to WifiMigration. This is to allow OEM's who have been supporting some new AOSP R
- // features like blocklist/allowlist in Q and stored the data using the old key/value
- // format.
- if (legacyApConfigFileStream != null) {
- /* Load AP configuration from persistent storage. */
- SoftApConfiguration config =
- loadApConfigurationFromLegacyFile(legacyApConfigFileStream);
- if (config != null) {
- // Persist in the new store.
- persistConfigAndTriggerBackupManagerProxy(config);
- Log.i(TAG, "Migrated data out of legacy store file");
- WifiMigration.removeSharedConfigStoreFile(
- WifiMigration.STORE_FILE_SHARED_SOFTAP);
- }
- }
-
// Register store data listener
wifiConfigStore.registerStoreData(
wifiInjector.makeSoftApStoreData(new SoftApStoreDataSource()));
@@ -268,65 +220,6 @@ public class WifiApConfigStore {
}
/**
- * Load AP configuration from legacy persistent storage.
- * Note: This is deprecated and only used for migrating data once on reboot.
- */
- private static SoftApConfiguration loadApConfigurationFromLegacyFile(InputStream fis) {
- SoftApConfiguration config = null;
- DataInputStream in = null;
- try {
- SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
- in = new DataInputStream(new BufferedInputStream(fis));
-
- int version = in.readInt();
- if (version < 1 || version > AP_CONFIG_FILE_VERSION) {
- Log.e(TAG, "Bad version on hotspot configuration file");
- return null;
- }
- configBuilder.setSsid(in.readUTF());
-
- if (version >= 2) {
- int band = in.readInt();
- int channel = in.readInt();
-
- if (channel == 0) {
- configBuilder.setBand(
- ApConfigUtil.convertWifiConfigBandToSoftApConfigBand(band));
- } else {
- configBuilder.setChannel(channel,
- ApConfigUtil.convertWifiConfigBandToSoftApConfigBand(band));
- }
- }
-
- if (version >= 3) {
- configBuilder.setHiddenSsid(in.readBoolean());
- }
-
- int authType = in.readInt();
- if (authType == WifiConfiguration.KeyMgmt.WPA2_PSK) {
- configBuilder.setPassphrase(in.readUTF(),
- SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
- }
- config = configBuilder.build();
- } catch (IOException e) {
- Log.e(TAG, "Error reading hotspot configuration " + e);
- config = null;
- } catch (IllegalArgumentException ie) {
- Log.e(TAG, "Invalid hotspot configuration " + ie);
- config = null;
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- Log.e(TAG, "Error closing hotspot configuration during read" + e);
- }
- }
- }
- return config;
- }
-
- /**
* Generate a default WPA3 SAE transition (if supported) or WPA2 based
* configuration with a random password.
* We are changing the Wifi Ap configuration storage from secure settings to a
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index a891b0588..9a73f52d5 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -379,7 +379,7 @@ public class WifiConfigStore {
private List<StoreData> retrieveStoreDataListForStoreFile(@NonNull StoreFile storeFile) {
return mStoreDataList
.stream()
- .filter(s -> s.getStoreFileId() == storeFile.mFileId)
+ .filter(s -> s.getStoreFileId() == storeFile.getFileId())
.collect(Collectors.toList());
}
@@ -553,8 +553,7 @@ public class WifiConfigStore {
case STORE_FILE_SHARED_GENERAL:
return WifiMigration.STORE_FILE_SHARED_GENERAL;
case STORE_FILE_SHARED_SOFTAP:
- // TODO (b/149418926): softap migration needs to be fixed.
- return null;
+ return WifiMigration.STORE_FILE_SHARED_SOFTAP;
case STORE_FILE_USER_GENERAL:
return WifiMigration.STORE_FILE_USER_GENERAL;
case STORE_FILE_USER_NETWORK_SUGGESTIONS:
@@ -592,12 +591,14 @@ public class WifiConfigStore {
*/
private void readFromSharedStoreFiles() throws XmlPullParserException, IOException {
for (StoreFile sharedStoreFile : mSharedStores) {
- byte[] sharedDataBytes = readDataFromMigrationSharedStoreFile(sharedStoreFile.mFileId);
+ byte[] sharedDataBytes =
+ readDataFromMigrationSharedStoreFile(sharedStoreFile.getFileId());
if (sharedDataBytes == null) {
+ // nothing to migrate, do normal read.
sharedDataBytes = sharedStoreFile.readRawData();
} else {
Log.i(TAG, "Read data out of shared migration store file: "
- + sharedStoreFile.mAtomicFile.getBaseFile().getName());
+ + sharedStoreFile.getName());
// Save the migrated file contents to the regular store file and delete the
// migrated stored file.
sharedStoreFile.storeRawDataToWrite(sharedDataBytes);
@@ -605,7 +606,7 @@ public class WifiConfigStore {
// Note: If the migrated store file is at the same location as the store file,
// then the OEM implementation should ignore this remove.
WifiMigration.removeSharedConfigStoreFile(
- getMigrationStoreFileId(sharedStoreFile.mFileId));
+ getMigrationStoreFileId(sharedStoreFile.getFileId()));
}
deserializeData(sharedDataBytes, sharedStoreFile);
}
@@ -619,12 +620,13 @@ public class WifiConfigStore {
private void readFromUserStoreFiles() throws XmlPullParserException, IOException {
for (StoreFile userStoreFile : mUserStores) {
byte[] userDataBytes = readDataFromMigrationUserStoreFile(
- userStoreFile.mFileId, userStoreFile.mUserHandle);
+ userStoreFile.getFileId(), userStoreFile.mUserHandle);
if (userDataBytes == null) {
+ // nothing to migrate, do normal read.
userDataBytes = userStoreFile.readRawData();
} else {
Log.i(TAG, "Read data out of user migration store file: "
- + userStoreFile.mAtomicFile.getBaseFile().getName());
+ + userStoreFile.getName());
// Save the migrated file contents to the regular store file and delete the
// migrated stored file.
userStoreFile.storeRawDataToWrite(userDataBytes);
@@ -632,7 +634,7 @@ public class WifiConfigStore {
// Note: If the migrated store file is at the same location as the store file,
// then the OEM implementation should ignore this remove.
WifiMigration.removeUserConfigStoreFile(
- getMigrationStoreFileId(userStoreFile.mFileId),
+ getMigrationStoreFileId(userStoreFile.getFileId()),
userStoreFile.mUserHandle);
}
deserializeData(userDataBytes, userStoreFile);
@@ -878,6 +880,14 @@ public class WifiConfigStore {
mEncryptionUtil = encryptionUtil;
}
+ public String getName() {
+ return mAtomicFile.getBaseFile().getName();
+ }
+
+ public @StoreFileId int getFileId() {
+ return mFileId;
+ }
+
/**
* @return Returns the encryption util used for this store file.
*/
diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java
index 552231ed2..d385e3edc 100644
--- a/service/java/com/android/server/wifi/util/ApConfigUtil.java
+++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java
@@ -178,7 +178,7 @@ public class ApConfigUtil {
case WifiConfiguration.AP_BAND_ANY:
return SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ;
default:
- return -1;
+ return SoftApConfiguration.BAND_2GHZ;
}
}