diff options
author | Roshan Pius <rpius@google.com> | 2020-02-24 19:06:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-24 19:06:10 +0000 |
commit | 861798ec8b5c8770bb883a101ceed513ef7954c4 (patch) | |
tree | a9f17817b16e03b74b3d8930fee8727929e6cbb2 /service | |
parent | 9416ff33f0d1fbff7877c7a2c0e866922b4ace94 (diff) | |
parent | 491745ab15898e068a4733650012ae2dcca6c593 (diff) |
Merge "wifi-service: Copy to apex data folders" into rvc-dev
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiApConfigStore.java | 2 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigStore.java | 38 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/util/Environment.java | 38 | ||||
-rw-r--r-- | service/wifi.rc | 7 |
4 files changed, 71 insertions, 14 deletions
diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java index 1dc2464dd..46a52ab72 100644 --- a/service/java/com/android/server/wifi/WifiApConfigStore.java +++ b/service/java/com/android/server/wifi/WifiApConfigStore.java @@ -122,7 +122,7 @@ public class WifiApConfigStore { WifiConfigManager wifiConfigManager, ActiveModeWarden activeModeWarden) { this(context, wifiInjector, handler, backupManagerProxy, wifiConfigStore, wifiConfigManager, activeModeWarden, - new File(Environment.getWifiSharedFolder(), LEGACY_AP_CONFIG_FILE)); + new File(Environment.getLegacyWifiSharedDirectory(), LEGACY_AP_CONFIG_FILE)); } WifiApConfigStore(Context context, diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java index dddb0447e..cd998d0e3 100644 --- a/service/java/com/android/server/wifi/WifiConfigStore.java +++ b/service/java/com/android/server/wifi/WifiConfigStore.java @@ -53,6 +53,8 @@ import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -287,6 +289,19 @@ public class WifiConfigStore { return true; } + private static void copyLegacyStoreFileIfNeeded(File legacyStoreFile, File storeFile) { + try { + // If the new store file exists, nothing to copy. + if (storeFile.exists()) return; + // If the legacy file does not exist, nothing to copy. + if (!legacyStoreFile.exists()) return; + Log.d(TAG, "Copying wifi store file from " + legacyStoreFile + " to " + storeFile); + Files.copy(legacyStoreFile.toPath(), storeFile.toPath()); + } catch (SecurityException | IOException e) { + Log.e(TAG, "Failed to copy the legacy store file", e); + } + } + /** * Helper method to create a store file instance for either the shared store or user store. * Note: The method creates the store directory if not already present. This may be needed for @@ -294,12 +309,15 @@ public class WifiConfigStore { * * @param storeDir Base directory under which the store file is to be stored. The store file * will be at <storeDir>/WifiConfigStore.xml. + * @param legacyStoreDir Base directory under which the store file was stored. The store file + * will be at <storeDir>/WifiConfigStore.xml. This is needed to perform + * a one time migration of the files from this folder to |storeDir|. * @param fileId Identifier for the file. See {@link StoreFileId}. * @param shouldEncryptCredentials Whether to encrypt credentials or not. * @return new instance of the store file or null if the directory cannot be created. */ - private static @Nullable StoreFile createFile(File storeDir, @StoreFileId int fileId, - boolean shouldEncryptCredentials) { + private static @Nullable StoreFile createFile(File storeDir, File legacyStoreDir, + @StoreFileId int fileId, boolean shouldEncryptCredentials) { if (!storeDir.exists()) { if (!storeDir.mkdir()) { Log.w(TAG, "Could not create store directory " + storeDir); @@ -307,6 +325,11 @@ public class WifiConfigStore { } } File file = new File(storeDir, STORE_ID_TO_FILE_NAME.get(fileId)); + // Note: This performs a one time migration of the existing wifi config store files + // from the old /data/misc/wifi & /data/misc_ce/<userId>/wifi folder to the + // wifi apex folder. + copyLegacyStoreFileIfNeeded( + new File(legacyStoreDir, STORE_ID_TO_FILE_NAME.get(fileId)), file); WifiConfigStoreEncryptionUtil encryptionUtil = null; if (shouldEncryptCredentials) { encryptionUtil = new WifiConfigStoreEncryptionUtil(file.getName()); @@ -314,11 +337,12 @@ public class WifiConfigStore { return new StoreFile(file, fileId, encryptionUtil); } - private static @Nullable List<StoreFile> createFiles(File storeDir, + private static @Nullable List<StoreFile> createFiles(File storeDir, File legacyStoreDir, List<Integer> storeFileIds, boolean shouldEncryptCredentials) { List<StoreFile> storeFiles = new ArrayList<>(); for (int fileId : storeFileIds) { - StoreFile storeFile = createFile(storeDir, fileId, shouldEncryptCredentials); + StoreFile storeFile = + createFile(storeDir, legacyStoreDir, fileId, shouldEncryptCredentials); if (storeFile == null) { return null; } @@ -335,7 +359,8 @@ public class WifiConfigStore { */ public static @NonNull List<StoreFile> createSharedFiles(boolean shouldEncryptCredentials) { return createFiles( - Environment.getWifiSharedFolder(), + Environment.getWifiSharedDirectory(), + Environment.getLegacyWifiSharedDirectory(), Arrays.asList(STORE_FILE_SHARED_GENERAL, STORE_FILE_SHARED_SOFTAP), shouldEncryptCredentials); } @@ -352,7 +377,8 @@ public class WifiConfigStore { public static @Nullable List<StoreFile> createUserFiles(int userId, boolean shouldEncryptCredentials) { return createFiles( - Environment.getWifiUserFolder(userId), + Environment.getWifiUserDirectory(userId), + Environment.getLegacyWifiUserDirectory(userId), Arrays.asList(STORE_FILE_USER_GENERAL, STORE_FILE_USER_NETWORK_SUGGESTIONS), shouldEncryptCredentials); } diff --git a/service/java/com/android/server/wifi/util/Environment.java b/service/java/com/android/server/wifi/util/Environment.java index 06887ac01..7b6ae1e84 100644 --- a/service/java/com/android/server/wifi/util/Environment.java +++ b/service/java/com/android/server/wifi/util/Environment.java @@ -16,6 +16,9 @@ package com.android.server.wifi.util; +import android.content.ApexContext; +import android.os.UserHandle; + import java.io.File; /** @@ -25,9 +28,14 @@ import java.io.File; */ public class Environment { /** + * Wifi apex name. + */ + private static final String WIFI_APEX_NAME = "com.android.wifi"; + + /** * Directory to store the wifi config store / shared preference files under. */ - private static final String WIFI_STORE_DIRECTORY_NAME = "wifi"; + private static final String LEGACY_WIFI_STORE_DIRECTORY_NAME = "wifi"; /** * Get data/misc directory @@ -61,16 +69,32 @@ public class Environment { /** - * TODO (b/148660313): Move to apex folder. + * Wifi shared folder. + */ + public static File getWifiSharedDirectory() { + return ApexContext.getApexContext(WIFI_APEX_NAME).getDeviceProtectedDataDir(); + } + + /** + * Wifi user specific folder. + */ + public static File getWifiUserDirectory(int userId) { + return ApexContext.getApexContext(WIFI_APEX_NAME).getCredentialProtectedDataDirForUser( + UserHandle.of(userId)); + } + + + /** + * Pre apex wifi shared folder. */ - public static File getWifiSharedFolder() { - return new File(Environment.getDataMiscDirectory(), WIFI_STORE_DIRECTORY_NAME); + public static File getLegacyWifiSharedDirectory() { + return new File(getDataMiscDirectory(), LEGACY_WIFI_STORE_DIRECTORY_NAME); } /** - * TODO (b/148660313): Move to apex folder. + * Pre apex wifi user folder. */ - public static File getWifiUserFolder(int userId) { - return new File(Environment.getDataMiscCeDirectory(userId), WIFI_STORE_DIRECTORY_NAME); + public static File getLegacyWifiUserDirectory(int userId) { + return new File(getDataMiscCeDirectory(userId), LEGACY_WIFI_STORE_DIRECTORY_NAME); } } diff --git a/service/wifi.rc b/service/wifi.rc index ce879b5da..eceee0ae0 100644 --- a/service/wifi.rc +++ b/service/wifi.rc @@ -14,6 +14,13 @@ # limitations under the License. # +# These are needed for migration of data to wifi apex directory. +on post-fs-data + restorecon_recursive /data/misc/apexdata/com.android.wifi + +on property:sys.user.0.ce_available=true + restorecon_recursive /data/misc_ce/0/apexdata/com.android.wifi + # Below are for kernel tracing related stuff. on fs setprop sys.wifitracing.started 0 |