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