summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-03-28 12:42:03 -0700
committerRoshan Pius <rpius@google.com>2019-03-29 12:41:25 -0700
commit6b3f8a279d1bd2cde761a9fee3d9c96436324b6f (patch)
tree2db66d6d26e7305e54ca1cdeb8d5f4e67bdeaa83
parente5d7c64224453d5b7415babf6bf898195137d1f2 (diff)
downloadandroid_frameworks_opt_net_wifi-6b3f8a279d1bd2cde761a9fee3d9c96436324b6f.tar.gz
android_frameworks_opt_net_wifi-6b3f8a279d1bd2cde761a9fee3d9c96436324b6f.tar.bz2
android_frameworks_opt_net_wifi-6b3f8a279d1bd2cde761a9fee3d9c96436324b6f.zip
WifiConfigManager: Ignore user unlock for non current user
Changes in the CL: a) Ignore user unlock if the user id is not for current active user. b) Reset the |mDeferredUserUnlockRead| on a user switch( mDeferredUserUnlockRead might be set from a previous user unlock). Bug: 129434351 Test: Ensured that the device persists the saved networks on reboot. Test: Will send the patch to Android auto team to ensure that their issue is resolved. Test: atest com.android.server.wifi Test: Will send for full regression. Change-Id: If3c1dd8026323b8747d086a767e49a0d899ee990
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java75
2 files changed, 82 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 81b513920..701b010bd 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -2871,6 +2871,8 @@ public class WifiConfigManager {
Log.w(TAG, "User switch before store is read!");
mConfiguredNetworks.setNewUser(userId);
mCurrentUserId = userId;
+ // Reset any state from previous user unlock.
+ mDeferredUserUnlockRead = false;
// Cannot read data from new user's CE store file before they log-in.
mPendingUnlockStoreRead = true;
return new HashSet<>();
@@ -2905,12 +2907,16 @@ public class WifiConfigManager {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Handling user unlock for " + userId);
}
+ if (userId != mCurrentUserId) {
+ Log.e(TAG, "Ignore user unlock for non current user " + userId);
+ return;
+ }
if (mPendingStoreRead) {
Log.w(TAG, "Ignore user unlock until store is read!");
mDeferredUserUnlockRead = true;
return;
}
- if (userId == mCurrentUserId && mPendingUnlockStoreRead) {
+ if (mPendingUnlockStoreRead) {
handleUserUnlockOrSwitch(mCurrentUserId);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 36e7d482e..cadd45f31 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -3318,6 +3318,81 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies that the store read after bootup received after
+ * a previous user unlock and user switch via {@link WifiConfigManager#handleUserSwitch(int)}
+ * results in a user store read.
+ */
+ @Test
+ public void testHandleBootupAfterPreviousUserUnlockAndSwitch() throws Exception {
+ int user1 = TEST_DEFAULT_USER;
+ int user2 = TEST_DEFAULT_USER + 1;
+ setupUserProfiles(user2);
+
+ // Unlock the user1 (default user) for the first time and ensure that we don't read the data
+ // (need to wait for loadFromStore invocation).
+ mWifiConfigManager.handleUserUnlock(user1);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).read();
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).write(anyBoolean());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .switchUserStoresAndRead(any(List.class));
+
+ // Switch from user1 to user2 and ensure that we don't read or write any data
+ // (need to wait for loadFromStore invocation).
+ mWifiConfigManager.handleUserSwitch(user2);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).read();
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).write(anyBoolean());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .switchUserStoresAndRead(any(List.class));
+
+ // Now load from the store.
+ assertTrue(mWifiConfigManager.loadFromStore());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore).read();
+
+ // Unlock the user2 and ensure that we read from the user store.
+ setupStoreDataForUserRead(new ArrayList<>(), new HashMap<>());
+ mWifiConfigManager.handleUserUnlock(user2);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore)
+ .switchUserStoresAndRead(any(List.class));
+ }
+
+ /**
+ * Verifies that the store read after bootup received after
+ * a user switch and unlock of a previous user via {@link WifiConfigManager#
+ * handleUserSwitch(int)} results in a user store read.
+ */
+ @Test
+ public void testHandleBootupAfterUserSwitchAndPreviousUserUnlock() throws Exception {
+ int user1 = TEST_DEFAULT_USER;
+ int user2 = TEST_DEFAULT_USER + 1;
+ setupUserProfiles(user2);
+
+ // Switch from user1 to user2 and ensure that we don't read or write any data
+ // (need to wait for loadFromStore invocation).
+ mWifiConfigManager.handleUserSwitch(user2);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).read();
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).write(anyBoolean());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .switchUserStoresAndRead(any(List.class));
+
+ // Unlock the user1 for the first time and ensure that we don't read the data
+ mWifiConfigManager.handleUserUnlock(user1);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).read();
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never()).write(anyBoolean());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .switchUserStoresAndRead(any(List.class));
+
+ // Now load from the store.
+ assertTrue(mWifiConfigManager.loadFromStore());
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore).read();
+
+ // Unlock the user2 and ensure that we read from the user store.
+ setupStoreDataForUserRead(new ArrayList<>(), new HashMap<>());
+ mWifiConfigManager.handleUserUnlock(user2);
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore)
+ .switchUserStoresAndRead(any(List.class));
+ }
+
+ /**
* 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.
*/