Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/connectivity/AccessPointControllerImplTest.kt +18 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.connectivity import android.content.Context import android.os.UserHandle import android.os.UserManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.TestableLooper.RunWithLooper import androidx.lifecycle.Lifecycle Loading Loading @@ -251,9 +252,25 @@ class AccessPointControllerImplTest : SysuiTestCase() { val primaryUserMockContext = mock<Context>() mContext.prepareCreateContextAsUser(UserHandle.of(PRIMARY_USER_ID), primaryUserMockContext) controller.onUserSwitched(PRIMARY_USER_ID) // Create is expected to be called once when the test starts and a second time when the user // is switched. // is switched. The first WifiPickerTracker should have its onStop() method called prior to // the new WifiPickerTracker being created. verify(wifiPickerTrackerFactory, times(2)).create(any(), any(), any(), any()) verify(wifiPickerTracker).onStop() } @Test @DisableFlags(FLAG_MULTIUSER_WIFI_PICKER_TRACKER_SUPPORT) fun switchUsers_flagDisabled() { val primaryUserMockContext = mock<Context>() mContext.prepareCreateContextAsUser(UserHandle.of(PRIMARY_USER_ID), primaryUserMockContext) controller.onUserSwitched(PRIMARY_USER_ID) // Create is expected to only be called once when the test starts, switching users should // have no effects. verify(wifiPickerTrackerFactory, times(1)).create(any(), any(), any(), any()) verify(wifiPickerTracker, never()).onStop() } private companion object { Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -1248,10 +1248,12 @@ class WifiRepositoryImplTest : SysuiTestCase() { otherUserMockContext, ) userRepository.setSelectedUserInfo(ANOTHER_USER) verify(wifiPickerTracker).onStop() // THEN we use the different user's context to create WifiPickerTracker val newCaptor = argumentCaptor<Context>() verify(wifiPickerTrackerFactory).create(newCaptor.capture(), any(), any(), any()) verify(wifiPickerTracker).onStop() assertThat(newCaptor.firstValue).isEqualTo(otherUserMockContext) } Loading Loading @@ -1288,6 +1290,7 @@ class WifiRepositoryImplTest : SysuiTestCase() { // THEN we do NOT re-create WifiPickerTracker because the multiuser flag is off verify(wifiPickerTrackerFactory, never()).create(any(), any(), any(), any()) verify(wifiPickerTracker, never()).onStop() } private fun getCallback(): WifiPickerTracker.WifiPickerTrackerCallback { Loading packages/SystemUI/src/com/android/systemui/statusbar/connectivity/AccessPointControllerImpl.java +11 −6 Original line number Diff line number Diff line Loading @@ -132,13 +132,10 @@ public class AccessPointControllerImpl implements AccessPointController, } if (mWifiPickerTracker != null) { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.CREATED)); mWifiPickerTracker.onStop(); } Context context = mContext.createContextAsUser(UserHandle.of(newUserId), /* flags= */ 0); mWifiPickerTracker = mWifiPickerTrackerFactory.create(context, mLifecycle, this, TAG); if (!mCallbacks.isEmpty()) { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.STARTED)); } } @Override Loading @@ -147,9 +144,13 @@ public class AccessPointControllerImpl implements AccessPointController, if (DEBUG) Log.d(TAG, "addCallback " + callback); mCallbacks.add(callback); if (mCallbacks.size() == 1) { if (mWifiPickerTrackerFactory.isSupported()) { mWifiPickerTracker.onStart(); } else { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.STARTED)); } } } @Override public void removeAccessPointCallback(AccessPointCallback callback) { Loading @@ -157,9 +158,13 @@ public class AccessPointControllerImpl implements AccessPointController, if (DEBUG) Log.d(TAG, "removeCallback " + callback); mCallbacks.remove(callback); if (mCallbacks.isEmpty()) { if (mWifiPickerTrackerFactory.isSupported()) { mWifiPickerTracker.onStop(); } else { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.CREATED)); } } } @Override public void scanForAccessPoints() { Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt +10 −13 Original line number Diff line number Diff line Loading @@ -87,8 +87,12 @@ constructor( override val lifecycle = LifecycleRegistry(this).also { if (multiuserWifiPickerTrackerSupport()) { mainExecutor.execute { it.currentState = Lifecycle.State.STARTED } } else { mainExecutor.execute { it.currentState = Lifecycle.State.CREATED } } } private var wifiPickerTracker: WifiPickerTracker? = null Loading Loading @@ -178,6 +182,10 @@ constructor( trySend(new) } } // If a WifiPicker already exists, call onStop to begin its shutdown // process in preparation for a new one to be created. wifiPickerTracker?.onStop() wifiPickerTracker = wifiPickerTrackerFactory .create(currentContext, lifecycle, callback, "WifiRepository") Loading @@ -189,17 +197,7 @@ constructor( // costly and should be avoided whenever possible). this?.disableScanning() } // The lifecycle must be STARTED in order for the callback to receive // events. mainExecutor.execute { lifecycle.currentState = Lifecycle.State.STARTED } awaitClose { mainExecutor.execute { lifecycle.currentState = Lifecycle.State.CREATED } } awaitClose { mainExecutor.execute { wifiPickerTracker?.onStop() } } } .stateIn(scope, SharingStarted.Eagerly, current) } Loading Loading @@ -275,7 +273,6 @@ constructor( trySend(new) } } wifiPickerTracker = wifiPickerTrackerFactory .create(applicationContext, lifecycle, callback, "WifiRepository") Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/connectivity/AccessPointControllerImplTest.kt +18 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.connectivity import android.content.Context import android.os.UserHandle import android.os.UserManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.TestableLooper.RunWithLooper import androidx.lifecycle.Lifecycle Loading Loading @@ -251,9 +252,25 @@ class AccessPointControllerImplTest : SysuiTestCase() { val primaryUserMockContext = mock<Context>() mContext.prepareCreateContextAsUser(UserHandle.of(PRIMARY_USER_ID), primaryUserMockContext) controller.onUserSwitched(PRIMARY_USER_ID) // Create is expected to be called once when the test starts and a second time when the user // is switched. // is switched. The first WifiPickerTracker should have its onStop() method called prior to // the new WifiPickerTracker being created. verify(wifiPickerTrackerFactory, times(2)).create(any(), any(), any(), any()) verify(wifiPickerTracker).onStop() } @Test @DisableFlags(FLAG_MULTIUSER_WIFI_PICKER_TRACKER_SUPPORT) fun switchUsers_flagDisabled() { val primaryUserMockContext = mock<Context>() mContext.prepareCreateContextAsUser(UserHandle.of(PRIMARY_USER_ID), primaryUserMockContext) controller.onUserSwitched(PRIMARY_USER_ID) // Create is expected to only be called once when the test starts, switching users should // have no effects. verify(wifiPickerTrackerFactory, times(1)).create(any(), any(), any(), any()) verify(wifiPickerTracker, never()).onStop() } private companion object { Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -1248,10 +1248,12 @@ class WifiRepositoryImplTest : SysuiTestCase() { otherUserMockContext, ) userRepository.setSelectedUserInfo(ANOTHER_USER) verify(wifiPickerTracker).onStop() // THEN we use the different user's context to create WifiPickerTracker val newCaptor = argumentCaptor<Context>() verify(wifiPickerTrackerFactory).create(newCaptor.capture(), any(), any(), any()) verify(wifiPickerTracker).onStop() assertThat(newCaptor.firstValue).isEqualTo(otherUserMockContext) } Loading Loading @@ -1288,6 +1290,7 @@ class WifiRepositoryImplTest : SysuiTestCase() { // THEN we do NOT re-create WifiPickerTracker because the multiuser flag is off verify(wifiPickerTrackerFactory, never()).create(any(), any(), any(), any()) verify(wifiPickerTracker, never()).onStop() } private fun getCallback(): WifiPickerTracker.WifiPickerTrackerCallback { Loading
packages/SystemUI/src/com/android/systemui/statusbar/connectivity/AccessPointControllerImpl.java +11 −6 Original line number Diff line number Diff line Loading @@ -132,13 +132,10 @@ public class AccessPointControllerImpl implements AccessPointController, } if (mWifiPickerTracker != null) { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.CREATED)); mWifiPickerTracker.onStop(); } Context context = mContext.createContextAsUser(UserHandle.of(newUserId), /* flags= */ 0); mWifiPickerTracker = mWifiPickerTrackerFactory.create(context, mLifecycle, this, TAG); if (!mCallbacks.isEmpty()) { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.STARTED)); } } @Override Loading @@ -147,9 +144,13 @@ public class AccessPointControllerImpl implements AccessPointController, if (DEBUG) Log.d(TAG, "addCallback " + callback); mCallbacks.add(callback); if (mCallbacks.size() == 1) { if (mWifiPickerTrackerFactory.isSupported()) { mWifiPickerTracker.onStart(); } else { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.STARTED)); } } } @Override public void removeAccessPointCallback(AccessPointCallback callback) { Loading @@ -157,9 +158,13 @@ public class AccessPointControllerImpl implements AccessPointController, if (DEBUG) Log.d(TAG, "removeCallback " + callback); mCallbacks.remove(callback); if (mCallbacks.isEmpty()) { if (mWifiPickerTrackerFactory.isSupported()) { mWifiPickerTracker.onStop(); } else { mMainExecutor.execute(() -> mLifecycle.setCurrentState(Lifecycle.State.CREATED)); } } } @Override public void scanForAccessPoints() { Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt +10 −13 Original line number Diff line number Diff line Loading @@ -87,8 +87,12 @@ constructor( override val lifecycle = LifecycleRegistry(this).also { if (multiuserWifiPickerTrackerSupport()) { mainExecutor.execute { it.currentState = Lifecycle.State.STARTED } } else { mainExecutor.execute { it.currentState = Lifecycle.State.CREATED } } } private var wifiPickerTracker: WifiPickerTracker? = null Loading Loading @@ -178,6 +182,10 @@ constructor( trySend(new) } } // If a WifiPicker already exists, call onStop to begin its shutdown // process in preparation for a new one to be created. wifiPickerTracker?.onStop() wifiPickerTracker = wifiPickerTrackerFactory .create(currentContext, lifecycle, callback, "WifiRepository") Loading @@ -189,17 +197,7 @@ constructor( // costly and should be avoided whenever possible). this?.disableScanning() } // The lifecycle must be STARTED in order for the callback to receive // events. mainExecutor.execute { lifecycle.currentState = Lifecycle.State.STARTED } awaitClose { mainExecutor.execute { lifecycle.currentState = Lifecycle.State.CREATED } } awaitClose { mainExecutor.execute { wifiPickerTracker?.onStop() } } } .stateIn(scope, SharingStarted.Eagerly, current) } Loading Loading @@ -275,7 +273,6 @@ constructor( trySend(new) } } wifiPickerTracker = wifiPickerTrackerFactory .create(applicationContext, lifecycle, callback, "WifiRepository") Loading