summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java44
2 files changed, 62 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index d3df3e0af..cf9fbcbed 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -253,6 +253,12 @@ public class WifiConfigManager {
*/
private int mCurrentUserId = UserHandle.USER_SYSTEM;
/**
+ * Flag to indicate that the new user's store has not yet been read since user switch.
+ * Initialize this flag to |true| to trigger a read on the first user unlock after
+ * bootup.
+ */
+ private boolean mPendingUnlockStoreRead = true;
+ /**
* This is keeping track of the next network ID to be assigned. Any new networks will be
* assigned |mNextNetworkId| as network ID.
*/
@@ -2282,10 +2288,14 @@ public class WifiConfigManager {
* @param userId The identifier of the new foreground user, after the switch.
*/
private void loadFromStoreAndMigrateAfterUserSwitch(int userId) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "Loading from store after user switch/unlock for " + userId);
+ }
// Switch out the user store file.
mWifiConfigStore.switchUserStore(mWifiConfigStore.createUserFile(userId));
if (loadFromStore()) {
saveToStore(true);
+ mPendingUnlockStoreRead = false;
}
}
@@ -2302,6 +2312,9 @@ public class WifiConfigManager {
* @param userId The identifier of the new foreground user, after the switch.
*/
public void handleUserSwitch(int userId) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "Handling user switch for " + userId);
+ }
if (userId == mCurrentUserId) {
Log.w(TAG, "User already in foreground " + userId);
return;
@@ -2318,6 +2331,7 @@ public class WifiConfigManager {
} else {
// Since the new user is not logged-in yet, we cannot read data from the store files
// yet.
+ mPendingUnlockStoreRead = true;
Log.i(TAG, "Waiting for user unlock to load from store");
}
}
@@ -2331,7 +2345,10 @@ public class WifiConfigManager {
* @param userId The identifier of the user that unlocked.
*/
public void handleUserUnlock(int userId) {
- if (userId == mCurrentUserId) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "Handling user unlock for " + userId);
+ }
+ if (userId == mCurrentUserId && mPendingUnlockStoreRead) {
loadFromStoreAndMigrateAfterUserSwitch(mCurrentUserId);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index d8e657547..401c4f013 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -1764,6 +1764,50 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies the foreground user unlock via {@link WifiConfigManager#handleUserUnlock(int)}
+ * results in a store read after bootup.
+ */
+ @Test
+ public void testHandleUserUnlockAfterBootup() throws Exception {
+ int user1 = TEST_DEFAULT_USER;
+
+ when(mWifiConfigStore.read()).thenReturn(
+ new WifiConfigStoreData(
+ new ArrayList<WifiConfiguration>(), new ArrayList<WifiConfiguration>(),
+ new HashSet<String>()));
+
+ // Unlock the user1 (default user) for the first time and ensure that we read the data.
+ mWifiConfigManager.handleUserUnlock(user1);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore).read();
+ }
+
+ /**
+ * Verifies the foreground user unlock via {@link WifiConfigManager#handleUserUnlock(int)} does
+ * not always result in a store read unless the user had switched or just booted up.
+ */
+ @Test
+ public void testHandleUserUnlockWithoutSwitchOrBootup() throws Exception {
+ int user1 = TEST_DEFAULT_USER;
+ int user2 = TEST_DEFAULT_USER + 1;
+ setupUserProfiles(user2);
+
+ when(mWifiConfigStore.read()).thenReturn(
+ new WifiConfigStoreData(
+ new ArrayList<WifiConfiguration>(), new ArrayList<WifiConfiguration>(),
+ new HashSet<String>()));
+
+ // user2 is unlocked and switched to foreground.
+ when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ mWifiConfigManager.handleUserSwitch(user2);
+ // Ensure that the read was invoked.
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore).read();
+
+ // Unlock the user2 again and ensure that we don't read the data now.
+ mWifiConfigManager.handleUserUnlock(user2);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).read();
+ }
+
+ /**
* Verifies the private network addition using
* {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)}
* by a non foreground user is rejected.