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

Commit 0c54aa17 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Unregister user switch observer in ActivityManagerShellCommand.

ActivityManagerShellCommand does not unregisterUserSwitchObserver
after registerUserSwitchObserver, which leads to a leak of
unnecessary callbacks. This CL adds unregistering in finally block.

Bug: 242176088
Test: Manual test with adb and perfetto.
Change-Id: I14d66a00c5dd3f881d393a386a2678835c99a900
parent 2667ba46
Loading
Loading
Loading
Loading
+28 −22
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.app.IActivityManager;
import android.app.IActivityTaskManager;
import android.app.IStopUserCallback;
import android.app.IUidObserver;
import android.app.IUserSwitchObserver;
import android.app.KeyguardManager;
import android.app.ProfilerInfo;
import android.app.RemoteServiceException.CrashedByAdbException;
@@ -1937,15 +1938,17 @@ final class ActivityManagerShellCommand extends ShellCommand {

        // Register switch observer.
        final CountDownLatch switchLatch = new CountDownLatch(1);
        mInterface.registerUserSwitchObserver(
                new UserSwitchObserver() {
        final IUserSwitchObserver userSwitchObserver = new UserSwitchObserver() {
            @Override
            public void onUserSwitchComplete(int newUserId) {
                if (userId == newUserId) {
                    switchLatch.countDown();
                }
            }
                }, ActivityManagerShellCommand.class.getName());
        };
        try {
            mInterface.registerUserSwitchObserver(userSwitchObserver,
                    ActivityManagerShellCommand.class.getName());

            // Switch.
            boolean switched = mInterface.switchUser(userId);
@@ -1962,6 +1965,9 @@ final class ActivityManagerShellCommand extends ShellCommand {
            }

            return switched;
        } finally {
            mInterface.unregisterUserSwitchObserver(userSwitchObserver);
        }
    }

    int runSwitchUser(PrintWriter pw) throws RemoteException {