summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt7
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/settings/FakeUserTracker.kt6
3 files changed, 17 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt b/packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt
index cf1fbe3685e3..d6f1ed9c3334 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt
+++ b/packages/SystemUI/src/com/android/systemui/settings/UserTracker.kt
@@ -68,6 +68,10 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider {
*/
@WeaklyReferencedCallback
interface Callback {
+ /**
+ * Notifies that the current user will be changed.
+ */
+ fun onBeforeUserSwitching(newUser: Int) {}
/**
* Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be
diff --git a/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt b/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
index 393a698bcdb7..096e37f01255 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt
@@ -226,6 +226,13 @@ open class UserTrackerImpl internal constructor(
protected open fun handleBeforeUserSwitching(newUserId: Int) {
Assert.isNotMainThread()
setUserIdInternal(newUserId)
+
+ val list = synchronized(callbacks) {
+ callbacks.toList()
+ }
+ list.forEach {
+ it.callback.get()?.onBeforeUserSwitching(newUserId)
+ }
}
@WorkerThread
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/settings/FakeUserTracker.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/settings/FakeUserTracker.kt
index 4307ff980be4..7494ccf32a2c 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/settings/FakeUserTracker.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/settings/FakeUserTracker.kt
@@ -69,10 +69,16 @@ class FakeUserTracker(
_userId = _userInfo.id
_userHandle = UserHandle.of(_userId)
+ onBeforeUserSwitching()
onUserChanging()
onUserChanged()
}
+ fun onBeforeUserSwitching(userId: Int = _userId) {
+ val copy = callbacks.toList()
+ copy.forEach { it.onBeforeUserSwitching(userId) }
+ }
+
fun onUserChanging(userId: Int = _userId) {
val copy = callbacks.toList()
copy.forEach { it.onUserChanging(userId, userContext) {} }