Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7435ca08 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Add UserSwitchObserver.onBeforeUserSwitching and make SysUI use it.

During a user switch, allow SystemUI to update its source of truth
for current user before WallpaperManagerService, to put wallpaper
colors changed events in order. Otherwise, ThemeOverlayController
receives onColorsChanged call before UserTrackerImpl updates current
user id and thinks colors are changed for non-current user.

Bug: 274925897
Test: atest UserTrackerImplTest
Test: atest UserControllerTest
Change-Id: Ib5e467a18d75d633b2ebaecbaf00fb65f8be6c77
parent 7a64585e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.IRemoteCallback;

/** {@hide} */
oneway interface IUserSwitchObserver {
    void onBeforeUserSwitching(int newUserId);
    void onUserSwitching(int newUserId, IRemoteCallback reply);
    void onUserSwitchComplete(int newUserId);
    void onForegroundProfileSwitch(int newProfileId);
+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@ public class UserSwitchObserver extends IUserSwitchObserver.Stub {
    public UserSwitchObserver() {
    }

    @Override
    public void onBeforeUserSwitching(int newUserId) throws RemoteException {}

    @Override
    public void onUserSwitching(int newUserId, IRemoteCallback reply) throws RemoteException {
        if (reply != null) {
+4 −3
Original line number Diff line number Diff line
@@ -161,6 +161,10 @@ open class UserTrackerImpl internal constructor(

    private fun registerUserSwitchObserver() {
        iActivityManager.registerUserSwitchObserver(object : UserSwitchObserver() {
            override fun onBeforeUserSwitching(newUserId: Int) {
                setUserIdInternal(newUserId)
            }

            override fun onUserSwitching(newUserId: Int, reply: IRemoteCallback?) {
                backgroundHandler.run {
                    handleUserSwitching(newUserId)
@@ -181,8 +185,6 @@ open class UserTrackerImpl internal constructor(
        Assert.isNotMainThread()
        Log.i(TAG, "Switching to user $newUserId")

        setUserIdInternal(newUserId)

        val list = synchronized(callbacks) {
            callbacks.toList()
        }
@@ -205,7 +207,6 @@ open class UserTrackerImpl internal constructor(
        Assert.isNotMainThread()
        Log.i(TAG, "Switched to user $newUserId")

        setUserIdInternal(newUserId)
        notifySubscribers {
            onUserChanged(newUserId, userContext)
            onProfilesChanged(userProfiles)
+3 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ class UserTrackerImplTest : SysuiTestCase() {

        val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java)
        verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString())
        captor.value.onBeforeUserSwitching(newID)
        captor.value.onUserSwitching(newID, userSwitchingReply)
        verify(userSwitchingReply).sendResult(any())

@@ -290,6 +291,7 @@ class UserTrackerImplTest : SysuiTestCase() {

        val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java)
        verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString())
        captor.value.onBeforeUserSwitching(newID)
        captor.value.onUserSwitching(newID, userSwitchingReply)
        verify(userSwitchingReply).sendResult(any())

@@ -308,6 +310,7 @@ class UserTrackerImplTest : SysuiTestCase() {

        val captor = ArgumentCaptor.forClass(IUserSwitchObserver::class.java)
        verify(iActivityManager).registerUserSwitchObserver(capture(captor), anyString())
        captor.value.onBeforeUserSwitching(newID)
        captor.value.onUserSwitchComplete(newID)

        assertThat(callback.calledOnUserChanged).isEqualTo(1)
+11 −0
Original line number Diff line number Diff line
@@ -2141,6 +2141,17 @@ class UserController implements Handler.Callback {

        final int observerCount = mUserSwitchObservers.beginBroadcast();
        if (observerCount > 0) {
            for (int i = 0; i < observerCount; i++) {
                final String name = "#" + i + " " + mUserSwitchObservers.getBroadcastCookie(i);
                t.traceBegin("onBeforeUserSwitching-" + name);
                try {
                    mUserSwitchObservers.getBroadcastItem(i).onBeforeUserSwitching(newUserId);
                } catch (RemoteException e) {
                    // Ignore
                } finally {
                    t.traceEnd();
                }
            }
            final ArraySet<String> curWaitingUserSwitchCallbacks = new ArraySet<>();
            synchronized (mLock) {
                uss.switching = true;
Loading