Loading packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +22 −40 Original line number Diff line number Diff line Loading @@ -227,22 +227,10 @@ open class UserTrackerImpl internal constructor( protected open fun handleBeforeUserSwitching(newUserId: Int) { setUserIdInternal(newUserId) val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { val callback = it.callback.get() if (callback != null) { it.executor.execute { notifySubscribers { callback, resultCallback -> callback.onBeforeUserSwitching(newUserId) latch.countDown() } } else { latch.countDown() } } latch.await() resultCallback.run() }.await() } @WorkerThread Loading @@ -250,21 +238,9 @@ open class UserTrackerImpl internal constructor( Assert.isNotMainThread() Log.i(TAG, "Switching to user $newUserId") val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { val callback = it.callback.get() if (callback != null) { it.executor.execute { callback.onUserChanging(userId, userContext) { latch.countDown() } } } else { latch.countDown() } } latch.await() notifySubscribers { callback, resultCallback -> callback.onUserChanging(newUserId, userContext, resultCallback) }.await() } @WorkerThread Loading Loading @@ -294,9 +270,9 @@ open class UserTrackerImpl internal constructor( Assert.isNotMainThread() Log.i(TAG, "Switched to user $newUserId") notifySubscribers { onUserChanged(newUserId, userContext) onProfilesChanged(userProfiles) notifySubscribers { callback, _ -> callback.onUserChanged(newUserId, userContext) callback.onProfilesChanged(userProfiles) } } Loading @@ -308,8 +284,8 @@ open class UserTrackerImpl internal constructor( synchronized(mutex) { userProfiles = profiles.map { UserInfo(it) } // save a "deep" copy } notifySubscribers { onProfilesChanged(profiles) notifySubscribers { callback, _ -> callback.onProfilesChanged(profiles) } } Loading @@ -325,18 +301,24 @@ open class UserTrackerImpl internal constructor( } } private inline fun notifySubscribers(crossinline action: UserTracker.Callback.() -> Unit) { private inline fun notifySubscribers( crossinline action: (UserTracker.Callback, resultCallback: Runnable) -> Unit ): CountDownLatch { val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { if (it.callback.get() != null) { val callback = it.callback.get() if (callback != null) { it.executor.execute { it.callback.get()?.action() action(callback) { latch.countDown() } } } else { latch.countDown() } } return latch } override fun dump(pw: PrintWriter, args: Array<out String>) { Loading Loading
packages/SystemUI/src/com/android/systemui/settings/UserTrackerImpl.kt +22 −40 Original line number Diff line number Diff line Loading @@ -227,22 +227,10 @@ open class UserTrackerImpl internal constructor( protected open fun handleBeforeUserSwitching(newUserId: Int) { setUserIdInternal(newUserId) val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { val callback = it.callback.get() if (callback != null) { it.executor.execute { notifySubscribers { callback, resultCallback -> callback.onBeforeUserSwitching(newUserId) latch.countDown() } } else { latch.countDown() } } latch.await() resultCallback.run() }.await() } @WorkerThread Loading @@ -250,21 +238,9 @@ open class UserTrackerImpl internal constructor( Assert.isNotMainThread() Log.i(TAG, "Switching to user $newUserId") val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { val callback = it.callback.get() if (callback != null) { it.executor.execute { callback.onUserChanging(userId, userContext) { latch.countDown() } } } else { latch.countDown() } } latch.await() notifySubscribers { callback, resultCallback -> callback.onUserChanging(newUserId, userContext, resultCallback) }.await() } @WorkerThread Loading Loading @@ -294,9 +270,9 @@ open class UserTrackerImpl internal constructor( Assert.isNotMainThread() Log.i(TAG, "Switched to user $newUserId") notifySubscribers { onUserChanged(newUserId, userContext) onProfilesChanged(userProfiles) notifySubscribers { callback, _ -> callback.onUserChanged(newUserId, userContext) callback.onProfilesChanged(userProfiles) } } Loading @@ -308,8 +284,8 @@ open class UserTrackerImpl internal constructor( synchronized(mutex) { userProfiles = profiles.map { UserInfo(it) } // save a "deep" copy } notifySubscribers { onProfilesChanged(profiles) notifySubscribers { callback, _ -> callback.onProfilesChanged(profiles) } } Loading @@ -325,18 +301,24 @@ open class UserTrackerImpl internal constructor( } } private inline fun notifySubscribers(crossinline action: UserTracker.Callback.() -> Unit) { private inline fun notifySubscribers( crossinline action: (UserTracker.Callback, resultCallback: Runnable) -> Unit ): CountDownLatch { val list = synchronized(callbacks) { callbacks.toList() } val latch = CountDownLatch(list.size) list.forEach { if (it.callback.get() != null) { val callback = it.callback.get() if (callback != null) { it.executor.execute { it.callback.get()?.action() action(callback) { latch.countDown() } } } else { latch.countDown() } } return latch } override fun dump(pw: PrintWriter, args: Array<out String>) { Loading