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

Commit 2e628ca9 authored by Thomas Bull's avatar Thomas Bull
Browse files

Improve wear keyguard unlock by prioritizing `checkCredential`

High unlock times have been observed on wear devices specifically.
b/403536398 identified that the low priority of the `checkCredential`
method contributes to this issue.

This change increases the priority of the `checkCredential` method to
`THREAD_FOREGROUND` (priority 118). This priority level was chosen
based on testing in b/403536398, which demonstrated the best performance
gains.

Flag: com.android.internal.widget.flags.run_check_credential_with_higher_priority
Test: m
Bug:407716215
Change-Id: I1c01bdbe9121a4d7e49ea5223ed6d82bc787654b
parent 83fa5c0c
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -2,13 +2,22 @@ package com.android.internal.widget;

import android.annotation.NonNull;
import android.os.AsyncTask;
import android.os.Process;

import android.util.Log;

import com.android.internal.widget.LockPatternUtils.RequestThrottledException;

import static com.android.internal.widget.flags.Flags.runCheckCredentialWithHigherPriority;

/**
 * Helper class to check/verify PIN/Password/Pattern asynchronously.
 */
public final class LockPatternChecker {
    private static final String TAG = "LockPatternChecker";

   private static final int INVALID_PRIORITY = -21;

    /**
     * Interface for a callback to be invoked after security check.
     */
@@ -106,11 +115,33 @@ public final class LockPatternChecker {

            @Override
            protected Boolean doInBackground(Void... args) {
                int originalPriority = INVALID_PRIORITY;
                try {
                    if (runCheckCredentialWithHigherPriority()) {
                        originalPriority = Process.getThreadPriority(Process.myTid());
                        try {
                            Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
                        } catch (SecurityException e) {
                            Log.e(TAG,
                                    "Failed to boost checkCredential thread priority to "
                                            + "priority display", e);
                        }
                    }
                    return utils.checkCredential(credentialCopy, userId, callback::onEarlyMatched);
                } catch (RequestThrottledException ex) {
                    mThrottleTimeout = ex.getTimeoutMs();
                    return false;
                } finally {
                    if (runCheckCredentialWithHigherPriority()
                        && originalPriority != INVALID_PRIORITY) {
                      try {
                            Process.setThreadPriority(originalPriority);
                        } catch (SecurityException e) {
                            Log.e(TAG,
                                    "Failed to restore checkCredential thread priority to "
                                            + "original priority", e);
                        }
                    }
                }
            }

+7 −0
Original line number Diff line number Diff line
@@ -7,3 +7,10 @@ flag {
    description: "Feature flag for changing the default of hiding the last interacted symbol when a physical input device is present"
    bug: "339270220"
}

flag {
    name: "run_check_credential_with_higher_priority"
    namespace: "wear_system_health"
    description: "Feature flag for changing the priority of the check credential task"
    bug: "407716215"
}