Skip to content
Snippets Groups Projects
Commit 898a9950 authored by Shawn Lin's avatar Shawn Lin Committed by Android (Google) Code Review
Browse files

Merge "Support onBeforeUserSwitching in UserTracker.Callback" into main

parents 2c2859bb b37f9cc6
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -227,6 +227,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
......
......@@ -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) {} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment