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

Commit 2e00dd93 authored by Mayank Garg's avatar Mayank Garg
Browse files

Fixed User Switch slowed down observer message

Fix: 154879531
Test: m
Change-Id: I6282560457d5b63da5cac01ee11c2b303dcf4d10
parent 6afb8410
Loading
Loading
Loading
Loading
+19 −9
Original line number Original line Diff line number Diff line
@@ -141,9 +141,11 @@ class UserController implements Handler.Callback {
    // giving up on them and unfreezing the screen.
    // giving up on them and unfreezing the screen.
    static final int USER_SWITCH_TIMEOUT_MS = 3 * 1000;
    static final int USER_SWITCH_TIMEOUT_MS = 3 * 1000;


    // Amount of time we wait for observers to handle a user switch before we log a warning.
    /**
    // Must be smaller than USER_SWITCH_TIMEOUT_MS.
     * Amount of time we wait for an observer to handle a user switch before we log a warning. This
    private static final int USER_SWITCH_WARNING_TIMEOUT_MS = 500;
     * wait time is per observer.
     */
    private static final int LONG_USER_SWITCH_OBSERVER_WARNING_TIME_MS = 500;


    // ActivityManager thread message constants
    // ActivityManager thread message constants
    static final int REPORT_USER_SWITCH_MSG = 10;
    static final int REPORT_USER_SWITCH_MSG = 10;
@@ -1877,6 +1879,7 @@ class UserController implements Handler.Callback {
            final AtomicInteger waitingCallbacksCount = new AtomicInteger(observerCount);
            final AtomicInteger waitingCallbacksCount = new AtomicInteger(observerCount);
            final long dispatchStartedTime = SystemClock.elapsedRealtime();
            final long dispatchStartedTime = SystemClock.elapsedRealtime();
            for (int i = 0; i < observerCount; i++) {
            for (int i = 0; i < observerCount; i++) {
                final long dispatchStartedTimeForObserver = SystemClock.elapsedRealtime();
                try {
                try {
                    // Prepend with unique prefix to guarantee that keys are unique
                    // Prepend with unique prefix to guarantee that keys are unique
                    final String name = "#" + i + " " + mUserSwitchObservers.getBroadcastCookie(i);
                    final String name = "#" + i + " " + mUserSwitchObservers.getBroadcastCookie(i);
@@ -1887,13 +1890,20 @@ class UserController implements Handler.Callback {
                        @Override
                        @Override
                        public void sendResult(Bundle data) throws RemoteException {
                        public void sendResult(Bundle data) throws RemoteException {
                            synchronized (mLock) {
                            synchronized (mLock) {
                                long delay = SystemClock.elapsedRealtime() - dispatchStartedTime;
                                long delayForObserver = SystemClock.elapsedRealtime()
                                if (delay > USER_SWITCH_TIMEOUT_MS) {
                                        - dispatchStartedTimeForObserver;
                                    Slogf.e(TAG, "User switch timeout: observer " + name
                                if (delayForObserver > LONG_USER_SWITCH_OBSERVER_WARNING_TIME_MS) {
                                            + " sent result after " + delay + " ms");
                                } else if (delay > USER_SWITCH_WARNING_TIMEOUT_MS) {
                                    Slogf.w(TAG, "User switch slowed down by observer " + name
                                    Slogf.w(TAG, "User switch slowed down by observer " + name
                                            + ": result sent after " + delay + " ms");
                                            + ": result took " + delayForObserver
                                            + " ms to process.");
                                }

                                long totalDelay = SystemClock.elapsedRealtime()
                                        - dispatchStartedTime;
                                if (totalDelay > USER_SWITCH_TIMEOUT_MS) {
                                    Slogf.e(TAG, "User switch timeout: observer " + name
                                            + "'s result was received " + totalDelay
                                            + " ms after dispatchUserSwitch.");
                                }
                                }


                                curWaitingUserSwitchCallbacks.remove(name);
                                curWaitingUserSwitchCallbacks.remove(name);