Loading packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +19 −8 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; import android.view.InputDevice; import android.view.KeyCharacterMap; Loading Loading @@ -177,7 +178,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis private boolean mBound; private boolean mIsEnabled; private boolean mIsNonPrimaryUser; private boolean mIsSystemOrVisibleBgUser; private int mCurrentBoundedUserId = -1; private boolean mInputFocusTransferStarted; private float mInputFocusTransferStartY; Loading Loading @@ -629,6 +630,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis SysUiState sysUiState, Provider<SceneInteractor> sceneInteractor, UserTracker userTracker, UserManager userManager, WakefulnessLifecycle wakefulnessLifecycle, UiEventLogger uiEventLogger, DisplayTracker displayTracker, Loading @@ -639,10 +641,18 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis Optional<UnfoldTransitionProgressForwarder> unfoldTransitionProgressForwarder, BroadcastDispatcher broadcastDispatcher ) { // b/241601880: This component shouldn't be running for a non-primary user mIsNonPrimaryUser = !Process.myUserHandle().equals(UserHandle.SYSTEM); if (mIsNonPrimaryUser) { Log.wtf(TAG_OPS, "Unexpected initialization for non-primary user", new Throwable()); // b/241601880: This component should only be running for primary users or // secondaryUsers when visibleBackgroundUsers are supported. boolean isSystemUser = Process.myUserHandle().equals(UserHandle.SYSTEM); boolean isVisibleBackgroundUser = userManager.isVisibleBackgroundUsersSupported() && !userManager.isUserForeground(); if (!isSystemUser && isVisibleBackgroundUser) { Log.d(TAG_OPS, "Initialization for visibleBackgroundUser"); } mIsSystemOrVisibleBgUser = isSystemUser || isVisibleBackgroundUser; if (!mIsSystemOrVisibleBgUser) { Log.wtf(TAG_OPS, "Unexpected initialization for non-system foreground user", new Throwable()); } mContext = context; Loading Loading @@ -833,10 +843,11 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis } private void internalConnectToCurrentUser(String reason) { if (mIsNonPrimaryUser) { if (!mIsSystemOrVisibleBgUser) { // This should not happen, but if any per-user SysUI component has a dependency on OPS, // then this could get triggered Log.w(TAG_OPS, "Skipping connection to overview service due to non-primary user " Log.w(TAG_OPS, "Skipping connection to overview service due to non-system foreground user " + "caller"); return; } Loading packages/SystemUI/tests/src/com/android/systemui/recents/OverviewProxyServiceTest.kt +41 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.pm.ResolveInfo import android.os.PowerManager import android.os.Process import android.os.UserHandle import android.os.UserManager import android.testing.TestableContext import android.testing.TestableLooper import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -108,6 +109,7 @@ class OverviewProxyServiceTest : SysuiTestCase() { @Mock private lateinit var navModeController: NavigationModeController @Mock private lateinit var statusBarWinController: NotificationShadeWindowController @Mock private lateinit var userTracker: UserTracker @Mock private lateinit var userManager: UserManager @Mock private lateinit var uiEventLogger: UiEventLogger @Mock private lateinit var sysuiUnlockAnimationController: KeyguardUnlockAnimationController @Mock Loading Loading @@ -199,11 +201,12 @@ class OverviewProxyServiceTest : SysuiTestCase() { } @Test fun connectToOverviewService_primaryUser_expectBindService() { fun connectToOverviewService_primaryUserNoVisibleBgUsersSupported_expectBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.SYSTEM) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() Loading @@ -214,11 +217,46 @@ class OverviewProxyServiceTest : SysuiTestCase() { } @Test fun connectToOverviewService_nonPrimaryUser_expectNoBindService() { fun connectToOverviewService_nonPrimaryUserNoVisibleBgUsersSupported_expectNoBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() verify(spyContext, times(0)).bindServiceAsUser(any(), any(), anyInt(), any()) } finally { mockitoSession.finishMocking() } } @Test fun connectToOverviewService_nonPrimaryBgUserVisibleBgUsersSupported_expectBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(true) `when`(userManager.isUserForeground()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() verify(spyContext, atLeast(1)).bindServiceAsUser(any(), any(), anyInt(), any()) } finally { mockitoSession.finishMocking() } } @Test fun connectToOverviewService_nonPrimaryFgUserVisibleBgUsersSupported_expectNoBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(true) `when`(userManager.isUserForeground()).thenReturn(true) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() Loading @@ -242,6 +280,7 @@ class OverviewProxyServiceTest : SysuiTestCase() { sysUiState, mock(), userTracker, userManager, wakefulnessLifecycle, uiEventLogger, displayTracker, Loading Loading
packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +19 −8 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; import android.view.InputDevice; import android.view.KeyCharacterMap; Loading Loading @@ -177,7 +178,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis private boolean mBound; private boolean mIsEnabled; private boolean mIsNonPrimaryUser; private boolean mIsSystemOrVisibleBgUser; private int mCurrentBoundedUserId = -1; private boolean mInputFocusTransferStarted; private float mInputFocusTransferStartY; Loading Loading @@ -629,6 +630,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis SysUiState sysUiState, Provider<SceneInteractor> sceneInteractor, UserTracker userTracker, UserManager userManager, WakefulnessLifecycle wakefulnessLifecycle, UiEventLogger uiEventLogger, DisplayTracker displayTracker, Loading @@ -639,10 +641,18 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis Optional<UnfoldTransitionProgressForwarder> unfoldTransitionProgressForwarder, BroadcastDispatcher broadcastDispatcher ) { // b/241601880: This component shouldn't be running for a non-primary user mIsNonPrimaryUser = !Process.myUserHandle().equals(UserHandle.SYSTEM); if (mIsNonPrimaryUser) { Log.wtf(TAG_OPS, "Unexpected initialization for non-primary user", new Throwable()); // b/241601880: This component should only be running for primary users or // secondaryUsers when visibleBackgroundUsers are supported. boolean isSystemUser = Process.myUserHandle().equals(UserHandle.SYSTEM); boolean isVisibleBackgroundUser = userManager.isVisibleBackgroundUsersSupported() && !userManager.isUserForeground(); if (!isSystemUser && isVisibleBackgroundUser) { Log.d(TAG_OPS, "Initialization for visibleBackgroundUser"); } mIsSystemOrVisibleBgUser = isSystemUser || isVisibleBackgroundUser; if (!mIsSystemOrVisibleBgUser) { Log.wtf(TAG_OPS, "Unexpected initialization for non-system foreground user", new Throwable()); } mContext = context; Loading Loading @@ -833,10 +843,11 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis } private void internalConnectToCurrentUser(String reason) { if (mIsNonPrimaryUser) { if (!mIsSystemOrVisibleBgUser) { // This should not happen, but if any per-user SysUI component has a dependency on OPS, // then this could get triggered Log.w(TAG_OPS, "Skipping connection to overview service due to non-primary user " Log.w(TAG_OPS, "Skipping connection to overview service due to non-system foreground user " + "caller"); return; } Loading
packages/SystemUI/tests/src/com/android/systemui/recents/OverviewProxyServiceTest.kt +41 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.pm.ResolveInfo import android.os.PowerManager import android.os.Process import android.os.UserHandle import android.os.UserManager import android.testing.TestableContext import android.testing.TestableLooper import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -108,6 +109,7 @@ class OverviewProxyServiceTest : SysuiTestCase() { @Mock private lateinit var navModeController: NavigationModeController @Mock private lateinit var statusBarWinController: NotificationShadeWindowController @Mock private lateinit var userTracker: UserTracker @Mock private lateinit var userManager: UserManager @Mock private lateinit var uiEventLogger: UiEventLogger @Mock private lateinit var sysuiUnlockAnimationController: KeyguardUnlockAnimationController @Mock Loading Loading @@ -199,11 +201,12 @@ class OverviewProxyServiceTest : SysuiTestCase() { } @Test fun connectToOverviewService_primaryUser_expectBindService() { fun connectToOverviewService_primaryUserNoVisibleBgUsersSupported_expectBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.SYSTEM) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() Loading @@ -214,11 +217,46 @@ class OverviewProxyServiceTest : SysuiTestCase() { } @Test fun connectToOverviewService_nonPrimaryUser_expectNoBindService() { fun connectToOverviewService_nonPrimaryUserNoVisibleBgUsersSupported_expectNoBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() verify(spyContext, times(0)).bindServiceAsUser(any(), any(), anyInt(), any()) } finally { mockitoSession.finishMocking() } } @Test fun connectToOverviewService_nonPrimaryBgUserVisibleBgUsersSupported_expectBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(true) `when`(userManager.isUserForeground()).thenReturn(false) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() verify(spyContext, atLeast(1)).bindServiceAsUser(any(), any(), anyInt(), any()) } finally { mockitoSession.finishMocking() } } @Test fun connectToOverviewService_nonPrimaryFgUserVisibleBgUsersSupported_expectNoBindService() { val mockitoSession = ExtendedMockito.mockitoSession().spyStatic(Process::class.java).startMocking() try { `when`(Process.myUserHandle()).thenReturn(UserHandle.of(12345)) `when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(true) `when`(userManager.isUserForeground()).thenReturn(true) val spyContext = spy(context) val ops = createOverviewProxyService(spyContext) ops.startConnectionToCurrentUser() Loading @@ -242,6 +280,7 @@ class OverviewProxyServiceTest : SysuiTestCase() { sysUiState, mock(), userTracker, userManager, wakefulnessLifecycle, uiEventLogger, displayTracker, Loading