Loading core/java/android/app/IUserSwitchObserver.aidl +6 −6 Original line number Original line Diff line number Diff line Loading @@ -19,10 +19,10 @@ package android.app; import android.os.IRemoteCallback; import android.os.IRemoteCallback; /** {@hide} */ /** {@hide} */ interface IUserSwitchObserver { oneway interface IUserSwitchObserver { void onBeforeUserSwitching(int newUserId); void onBeforeUserSwitching(int newUserId, IRemoteCallback reply); oneway void onUserSwitching(int newUserId, IRemoteCallback reply); void onUserSwitching(int newUserId, IRemoteCallback reply); oneway void onUserSwitchComplete(int newUserId); void onUserSwitchComplete(int newUserId); oneway void onForegroundProfileSwitch(int newProfileId); void onForegroundProfileSwitch(int newProfileId); oneway void onLockedBootComplete(int newUserId); void onLockedBootComplete(int newUserId); } } core/java/android/app/UserSwitchObserver.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,11 @@ public class UserSwitchObserver extends IUserSwitchObserver.Stub { } } @Override @Override public void onBeforeUserSwitching(int newUserId) throws RemoteException {} public void onBeforeUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { if (reply != null) { reply.sendResult(null); } } @Override @Override public void onUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { public void onUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { Loading packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt +10 −1 Original line number Original line Diff line number Diff line Loading @@ -61,9 +61,18 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider { /** Callback for notifying of changes. */ /** Callback for notifying of changes. */ @WeaklyReferencedCallback @WeaklyReferencedCallback interface Callback { interface Callback { /** Notifies that the current user will be changed. */ /** * Same as {@link onBeforeUserSwitching(Int, Runnable)} but the callback will be called * automatically after the completion of this method. */ fun onBeforeUserSwitching(newUser: Int) {} fun onBeforeUserSwitching(newUser: Int) {} /** Notifies that the current user will be changed. */ fun onBeforeUserSwitching(newUser: Int, resultCallback: Runnable) { onBeforeUserSwitching(newUser) resultCallback.run() } /** /** * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be called * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be called * automatically after the completion of this method. * automatically after the completion of this method. Loading packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +3 −3 Original line number Original line Diff line number Diff line Loading @@ -196,8 +196,9 @@ internal constructor( private fun registerUserSwitchObserver() { private fun registerUserSwitchObserver() { iActivityManager.registerUserSwitchObserver( iActivityManager.registerUserSwitchObserver( object : UserSwitchObserver() { object : UserSwitchObserver() { override fun onBeforeUserSwitching(newUserId: Int) { override fun onBeforeUserSwitching(newUserId: Int, reply: IRemoteCallback?) { handleBeforeUserSwitching(newUserId) handleBeforeUserSwitching(newUserId) reply?.sendResult(null) } } override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) { override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) { Loading Loading @@ -236,8 +237,7 @@ internal constructor( setUserIdInternal(newUserId) setUserIdInternal(newUserId) notifySubscribers { callback, resultCallback -> notifySubscribers { callback, resultCallback -> callback.onBeforeUserSwitching(newUserId) callback.onBeforeUserSwitching(newUserId, resultCallback) resultCallback.run() } } .await() .await() } } Loading packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplTest.kt +15 −3 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,8 @@ class UserTrackerImplTest : SysuiTestCase() { @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var beforeUserSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager Loading Loading @@ -199,9 +201,10 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userManager).getProfiles(newID) verify(userManager).getProfiles(newID) Loading Loading @@ -341,10 +344,11 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) assertThat(callback.calledOnUserChanging).isEqualTo(1) assertThat(callback.calledOnUserChanging).isEqualTo(1) assertThat(callback.lastUser).isEqualTo(newID) assertThat(callback.lastUser).isEqualTo(newID) Loading Loading @@ -395,7 +399,7 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, any()) captor.value.onUserSwitchComplete(newID) captor.value.onUserSwitchComplete(newID) runCurrent() runCurrent() Loading Loading @@ -453,8 +457,10 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) captor.value.onUserSwitchComplete(newID) captor.value.onUserSwitchComplete(newID) Loading Loading @@ -488,6 +494,7 @@ class UserTrackerImplTest : SysuiTestCase() { } } private class TestCallback : UserTracker.Callback { private class TestCallback : UserTracker.Callback { var calledOnBeforeUserChanging = 0 var calledOnUserChanging = 0 var calledOnUserChanging = 0 var calledOnUserChanged = 0 var calledOnUserChanged = 0 var calledOnProfilesChanged = 0 var calledOnProfilesChanged = 0 Loading @@ -495,6 +502,11 @@ class UserTrackerImplTest : SysuiTestCase() { var lastUserContext: Context? = null var lastUserContext: Context? = null var lastUserProfiles = emptyList<UserInfo>() var lastUserProfiles = emptyList<UserInfo>() override fun onBeforeUserSwitching(newUser: Int) { calledOnBeforeUserChanging++ lastUser = newUser } override fun onUserChanging(newUser: Int, userContext: Context) { override fun onUserChanging(newUser: Int, userContext: Context) { calledOnUserChanging++ calledOnUserChanging++ lastUser = newUser lastUser = newUser Loading Loading
core/java/android/app/IUserSwitchObserver.aidl +6 −6 Original line number Original line Diff line number Diff line Loading @@ -19,10 +19,10 @@ package android.app; import android.os.IRemoteCallback; import android.os.IRemoteCallback; /** {@hide} */ /** {@hide} */ interface IUserSwitchObserver { oneway interface IUserSwitchObserver { void onBeforeUserSwitching(int newUserId); void onBeforeUserSwitching(int newUserId, IRemoteCallback reply); oneway void onUserSwitching(int newUserId, IRemoteCallback reply); void onUserSwitching(int newUserId, IRemoteCallback reply); oneway void onUserSwitchComplete(int newUserId); void onUserSwitchComplete(int newUserId); oneway void onForegroundProfileSwitch(int newProfileId); void onForegroundProfileSwitch(int newProfileId); oneway void onLockedBootComplete(int newUserId); void onLockedBootComplete(int newUserId); } }
core/java/android/app/UserSwitchObserver.java +5 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,11 @@ public class UserSwitchObserver extends IUserSwitchObserver.Stub { } } @Override @Override public void onBeforeUserSwitching(int newUserId) throws RemoteException {} public void onBeforeUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { if (reply != null) { reply.sendResult(null); } } @Override @Override public void onUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { public void onUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException { Loading
packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt +10 −1 Original line number Original line Diff line number Diff line Loading @@ -61,9 +61,18 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider { /** Callback for notifying of changes. */ /** Callback for notifying of changes. */ @WeaklyReferencedCallback @WeaklyReferencedCallback interface Callback { interface Callback { /** Notifies that the current user will be changed. */ /** * Same as {@link onBeforeUserSwitching(Int, Runnable)} but the callback will be called * automatically after the completion of this method. */ fun onBeforeUserSwitching(newUser: Int) {} fun onBeforeUserSwitching(newUser: Int) {} /** Notifies that the current user will be changed. */ fun onBeforeUserSwitching(newUser: Int, resultCallback: Runnable) { onBeforeUserSwitching(newUser) resultCallback.run() } /** /** * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be called * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be called * automatically after the completion of this method. * automatically after the completion of this method. Loading
packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +3 −3 Original line number Original line Diff line number Diff line Loading @@ -196,8 +196,9 @@ internal constructor( private fun registerUserSwitchObserver() { private fun registerUserSwitchObserver() { iActivityManager.registerUserSwitchObserver( iActivityManager.registerUserSwitchObserver( object : UserSwitchObserver() { object : UserSwitchObserver() { override fun onBeforeUserSwitching(newUserId: Int) { override fun onBeforeUserSwitching(newUserId: Int, reply: IRemoteCallback?) { handleBeforeUserSwitching(newUserId) handleBeforeUserSwitching(newUserId) reply?.sendResult(null) } } override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) { override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) { Loading Loading @@ -236,8 +237,7 @@ internal constructor( setUserIdInternal(newUserId) setUserIdInternal(newUserId) notifySubscribers { callback, resultCallback -> notifySubscribers { callback, resultCallback -> callback.onBeforeUserSwitching(newUserId) callback.onBeforeUserSwitching(newUserId, resultCallback) resultCallback.run() } } .await() .await() } } Loading
packages/SystemUI/tests/src/com/android/systemui/settings/UserTrackerImplTest.kt +15 −3 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,8 @@ class UserTrackerImplTest : SysuiTestCase() { @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var iActivityManager: IActivityManager @Mock private lateinit var beforeUserSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock private lateinit var userSwitchingReply: IRemoteCallback @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager @Mock(stubOnly = true) private lateinit var dumpManager: DumpManager Loading Loading @@ -199,9 +201,10 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userManager).getProfiles(newID) verify(userManager).getProfiles(newID) Loading Loading @@ -341,10 +344,11 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) assertThat(callback.calledOnUserChanging).isEqualTo(1) assertThat(callback.calledOnUserChanging).isEqualTo(1) assertThat(callback.lastUser).isEqualTo(newID) assertThat(callback.lastUser).isEqualTo(newID) Loading Loading @@ -395,7 +399,7 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID) captor.value.onBeforeUserSwitching(newID, any()) captor.value.onUserSwitchComplete(newID) captor.value.onUserSwitchComplete(newID) runCurrent() runCurrent() Loading Loading @@ -453,8 +457,10 @@ class UserTrackerImplTest : SysuiTestCase() { val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString()) captor.value.onBeforeUserSwitching(newID, beforeUserSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) captor.value.onUserSwitching(newID, userSwitchingReply) runCurrent() runCurrent() verify(beforeUserSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) verify(userSwitchingReply).sendResult(any()) captor.value.onUserSwitchComplete(newID) captor.value.onUserSwitchComplete(newID) Loading Loading @@ -488,6 +494,7 @@ class UserTrackerImplTest : SysuiTestCase() { } } private class TestCallback : UserTracker.Callback { private class TestCallback : UserTracker.Callback { var calledOnBeforeUserChanging = 0 var calledOnUserChanging = 0 var calledOnUserChanging = 0 var calledOnUserChanged = 0 var calledOnUserChanged = 0 var calledOnProfilesChanged = 0 var calledOnProfilesChanged = 0 Loading @@ -495,6 +502,11 @@ class UserTrackerImplTest : SysuiTestCase() { var lastUserContext: Context? = null var lastUserContext: Context? = null var lastUserProfiles = emptyList<UserInfo>() var lastUserProfiles = emptyList<UserInfo>() override fun onBeforeUserSwitching(newUser: Int) { calledOnBeforeUserChanging++ lastUser = newUser } override fun onUserChanging(newUser: Int, userContext: Context) { override fun onUserChanging(newUser: Int, userContext: Context) { calledOnUserChanging++ calledOnUserChanging++ lastUser = newUser lastUser = newUser Loading