summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/WifiConfigStore.java
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-04-12 11:47:26 -0700
committerRoshan Pius <rpius@google.com>2019-04-18 09:35:09 -0700
commit398087d8757bed09b520e54f62780fc389f316a3 (patch)
tree519f2c3c83367194681c38707cad6df64bf95920 /service/java/com/android/server/wifi/WifiConfigStore.java
parentf0b4ccd0d7aa67a71a16b02c91d6377c306c271c (diff)
downloadandroid_frameworks_opt_net_wifi-398087d8757bed09b520e54f62780fc389f316a3.tar.gz
android_frameworks_opt_net_wifi-398087d8757bed09b520e54f62780fc389f316a3.tar.bz2
android_frameworks_opt_net_wifi-398087d8757bed09b520e54f62780fc389f316a3.zip
WifiConfigManager: Handle file creation errors gracefully
If the user's CE directory is not accessible for some reason, all of the user store file creation/read will fail. Handle these errors more gracefully by checking for nulls in that path. Note: If there are errors accessing the CE directory, any existing data within the user store files will be lost. This CL does not attempt to fix that. Bug: 130366402 Test: Existing ACTS tests for config store. Change-Id: I4c51b224e35e0d1b352359cd3be1dbbe2e66936f
Diffstat (limited to 'service/java/com/android/server/wifi/WifiConfigStore.java')
-rw-r--r--service/java/com/android/server/wifi/WifiConfigStore.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index ab7315f44..c7e75a5c4 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -55,6 +55,7 @@ import java.lang.annotation.RetentionPolicy;
import java.nio.charset.StandardCharsets;
import java.security.DigestException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -267,7 +268,7 @@ public class WifiConfigStore {
* @param fileId Identifier for the file. See {@link StoreFileId}.
* @return new instance of the store file or null if the directory cannot be created.
*/
- private static StoreFile createFile(File storeBaseDir, @StoreFileId int fileId) {
+ private static @Nullable StoreFile createFile(File storeBaseDir, @StoreFileId int fileId) {
File storeDir = new File(storeBaseDir, STORE_DIRECTORY_NAME);
if (!storeDir.exists()) {
if (!storeDir.mkdir()) {
@@ -283,7 +284,7 @@ public class WifiConfigStore {
*
* @return new instance of the store file or null if the directory cannot be created.
*/
- public static StoreFile createSharedFile() {
+ public static @Nullable StoreFile createSharedFile() {
return createFile(Environment.getDataMiscDirectory(), STORE_FILE_SHARED_GENERAL);
}
@@ -292,14 +293,19 @@ public class WifiConfigStore {
* The user store file is inside the user's encrypted data directory.
*
* @param userId userId corresponding to the currently logged-in user.
- * @return List of new instances of the store files created.
+ * @return List of new instances of the store files created or null if the directory cannot be
+ * created.
*/
- public static List<StoreFile> createUserFiles(int userId) {
+ public static @Nullable List<StoreFile> createUserFiles(int userId) {
List<StoreFile> storeFiles = new ArrayList<>();
- storeFiles.add(createFile(Environment.getDataMiscCeDirectory(userId),
- STORE_FILE_USER_GENERAL));
- storeFiles.add(createFile(Environment.getDataMiscCeDirectory(userId),
- STORE_FILE_USER_NETWORK_SUGGESTIONS));
+ for (int fileId : Arrays.asList(
+ STORE_FILE_USER_GENERAL, STORE_FILE_USER_NETWORK_SUGGESTIONS)) {
+ StoreFile storeFile = createFile(Environment.getDataMiscCeDirectory(userId), fileId);
+ if (storeFile == null) {
+ return null;
+ }
+ storeFiles.add(storeFile);
+ }
return storeFiles;
}
@@ -500,6 +506,7 @@ public class WifiConfigStore {
*/
public void switchUserStoresAndRead(@NonNull List<StoreFile> userStores)
throws XmlPullParserException, IOException {
+ Preconditions.checkNotNull(userStores);
// Reset user store data.
if (mUserStores != null) {
for (StoreFile userStoreFile : mUserStores) {