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

Commit 0d77c6d1 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Report time to unlock users

Bug: 67716047
Test: Manual
Change-Id: I701bedf2aa101ed7b4d913a1921471ec38f8cb0e
parent e033dbd7
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
@@ -79,6 +80,7 @@ import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.TimingsTraceLog;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -232,6 +234,7 @@ class UserController implements Handler.Callback {
        mUiHandler = mInjector.getUiHandler(this);
        // User 0 is the first and only user that runs at boot.
        final UserState uss = new UserState(UserHandle.SYSTEM);
        uss.mUnlockProgress.addListener(new UserProgressListener());
        mStartedUsers.put(UserHandle.USER_SYSTEM, uss);
        mUserLru.add(UserHandle.USER_SYSTEM);
        mLockPatternUtils = mInjector.getLockPatternUtils();
@@ -903,6 +906,7 @@ class UserController implements Handler.Callback {
                uss = mStartedUsers.get(userId);
                if (uss == null) {
                    uss = new UserState(UserHandle.of(userId));
                    uss.mUnlockProgress.addListener(new UserProgressListener());
                    mStartedUsers.put(userId, uss);
                    updateStartedUserArrayLU();
                    needStart = true;
@@ -1854,6 +1858,33 @@ class UserController implements Handler.Callback {
        return false;
    }

    private static class UserProgressListener extends IProgressListener.Stub {
        private volatile long mUnlockStarted;
        @Override
        public void onStarted(int id, Bundle extras) throws RemoteException {
            Slog.d(TAG, "Started unlocking user " + id);
            mUnlockStarted = SystemClock.uptimeMillis();
        }

        @Override
        public void onProgress(int id, int progress, Bundle extras) throws RemoteException {
            Slog.d(TAG, "Unlocking user " + id + " progress " + progress);
        }

        @Override
        public void onFinished(int id, Bundle extras) throws RemoteException {
            long unlockTime = SystemClock.uptimeMillis() - mUnlockStarted;

            // Report system user unlock time to perf dashboard
            if (id == UserHandle.USER_SYSTEM) {
                new TimingsTraceLog("SystemServerTiming", Trace.TRACE_TAG_SYSTEM_SERVER)
                        .logDuration("SystemUserUnlock", unlockTime);
            } else {
                Slog.d(TAG, "Unlocking user " + id + " took " + unlockTime + " ms");
            }
        }
    };

    @VisibleForTesting
    static class Injector {
        private final ActivityManagerService mService;