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

Commit 520da04f authored by Derek Jedral's avatar Derek Jedral Committed by Beverly
Browse files

Add newlyUnlocked to onTrustChanged

onTrustChanged doesn't notify listeners if the trust change was actually
used to unlock the device, and so listeners cannot react to the change
properly. We need to pass an additional boolean.

Test: manual test
Bug: 258001148
Change-Id: Ia205640fbdb5ddeb328ea81f1fe74c80ce25bca8
parent b3dc6d16
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import java.util.List;
 * {@hide}
 */
oneway interface ITrustListener {
    void onTrustChanged(boolean enabled, int userId, int flags,
    void onTrustChanged(boolean enabled, boolean newlyUnlocked, int userId, int flags,
        in List<String> trustGrantedMessages);
    void onTrustManagedChanged(boolean managed, int userId);
    void onTrustError(in CharSequence message);
+16 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.SystemService;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.hardware.biometrics.BiometricSourceType;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -45,6 +46,7 @@ public class TrustManager {

    private static final String TAG = "TrustManager";
    private static final String DATA_FLAGS = "initiatedByUser";
    private static final String DATA_NEWLY_UNLOCKED = "newlyUnlocked";
    private static final String DATA_MESSAGE = "message";
    private static final String DATA_GRANTED_MESSAGES = "grantedMessages";

@@ -171,13 +173,14 @@ public class TrustManager {
        try {
            ITrustListener.Stub iTrustListener = new ITrustListener.Stub() {
                @Override
                public void onTrustChanged(boolean enabled, int userId, int flags,
                        List<String> trustGrantedMessages) {
                public void onTrustChanged(boolean enabled, boolean newlyUnlocked, int userId,
                        int flags, List<String> trustGrantedMessages) {
                    Message m = mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId,
                            trustListener);
                    if (flags != 0) {
                        m.getData().putInt(DATA_FLAGS, flags);
                    }
                    m.getData().putInt(DATA_NEWLY_UNLOCKED, newlyUnlocked ? 1 : 0);
                    m.getData().putCharSequenceArrayList(
                            DATA_GRANTED_MESSAGES, (ArrayList) trustGrantedMessages);
                    m.sendToTarget();
@@ -265,9 +268,14 @@ public class TrustManager {
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case MSG_TRUST_CHANGED:
                    int flags = msg.peekData() != null ? msg.peekData().getInt(DATA_FLAGS) : 0;
                    ((TrustListener) msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2, flags,
                            msg.getData().getStringArrayList(DATA_GRANTED_MESSAGES));
                    Bundle data = msg.peekData();
                    int flags = data != null ? data.getInt(DATA_FLAGS) : 0;
                    boolean enabled = msg.arg1 != 0;
                    int newlyUnlockedInt =
                            data != null ? data.getInt(DATA_NEWLY_UNLOCKED) : 0;
                    boolean newlyUnlocked = newlyUnlockedInt != 0;
                    ((TrustListener) msg.obj).onTrustChanged(enabled, newlyUnlocked, msg.arg2,
                            flags, msg.getData().getStringArrayList(DATA_GRANTED_MESSAGES));
                    break;
                case MSG_TRUST_MANAGED_CHANGED:
                    ((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2);
@@ -284,6 +292,8 @@ public class TrustManager {
        /**
         * Reports that the trust state has changed.
         * @param enabled If true, the system believes the environment to be trusted.
         * @param newlyUnlocked If true, the system believes the device is newly unlocked due
         *        to the trust changing.
         * @param userId The user, for which the trust changed.
         * @param flags Flags specified by the trust agent when granting trust. See
         *     {@link android.service.trust.TrustAgentService#grantTrust(CharSequence, long, int)
@@ -291,7 +301,7 @@ public class TrustManager {
         * @param trustGrantedMessages Messages to display to the user when trust has been granted
         *        by one or more trust agents.
         */
        void onTrustChanged(boolean enabled, int userId, int flags,
        void onTrustChanged(boolean enabled, boolean newlyUnlocked, int userId, int flags,
                List<String> trustGrantedMessages);

        /**
+1 −1
Original line number Diff line number Diff line
@@ -480,7 +480,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    @Override
    public void onTrustChanged(boolean enabled, int userId, int flags,
    public void onTrustChanged(boolean enabled, boolean newlyUnlocked, int userId, int flags,
            List<String> trustGrantedMessages) {
        Assert.isMainThread();
        boolean wasTrusted = mUserHasTrust.get(userId, false);
+13 −6
Original line number Diff line number Diff line
@@ -823,7 +823,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);
        mTestableLooper.processAllMessages();
        lockscreenBypassIsAllowed();
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */,
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, true /* newlyUnlocked */,
                KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */,
                new ArrayList<>());
        keyguardIsVisible();
@@ -834,7 +834,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    public void testIgnoresAuth_whenTrustAgentOnKeyguard_withoutBypass() {
        mKeyguardUpdateMonitor.dispatchStartedWakingUp(PowerManager.WAKE_REASON_POWER_BUTTON);
        mTestableLooper.processAllMessages();
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */,
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, true /* newlyUnlocked */,
                KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>());
        keyguardIsVisible();
        verify(mFaceManager, never()).authenticate(any(), any(), any(), any(), anyInt(),
@@ -1049,8 +1049,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    @Test
    public void testGetUserCanSkipBouncer_whenTrust() {
        int user = KeyguardUpdateMonitor.getCurrentUser();
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, user, 0 /* flags */,
                new ArrayList<>());
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, true /* newlyUnlocked */,
                user, 0 /* flags */, new ArrayList<>());
        assertThat(mKeyguardUpdateMonitor.getUserCanSkipBouncer(user)).isTrue();
    }

@@ -1314,7 +1314,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        when(mStrongAuthTracker.hasUserAuthenticatedSinceBoot()).thenReturn(true);

        // WHEN trust is enabled (ie: via smartlock)
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */,
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, true /* newlyUnlocked */,
                KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */, new ArrayList<>());

        // THEN we shouldn't listen for udfps
@@ -1418,7 +1418,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
    @Test
    public void testShowTrustGrantedMessage_onTrustGranted() {
        // WHEN trust is enabled (ie: via some trust agent) with a trustGranted string
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */,
        mKeyguardUpdateMonitor.onTrustChanged(true /* enabled */, true /* newlyUnlocked */,
                KeyguardUpdateMonitor.getCurrentUser(), 0 /* flags */,
                Arrays.asList("Unlocked by wearable"));

@@ -1870,6 +1870,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // WHEN onTrustChanged with TRUST_DISMISS_KEYGUARD flag
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                getCurrentUser() /* userId */,
                TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD /* flags */,
                null /* trustGrantedMessages */);
@@ -1893,6 +1894,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // WHEN onTrustChanged with TRUST_DISMISS_KEYGUARD flag
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                getCurrentUser() /* userId */,
                TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD /* flags */,
                null /* trustGrantedMessages */);
@@ -1917,6 +1919,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // WHEN onTrustChanged for a different user
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                546 /* userId, not the current userId */,
                0 /* flags */,
                null /* trustGrantedMessages */);
@@ -1941,6 +1944,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // flags (temporary & rewable is active unlock)
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                getCurrentUser() /* userId */,
                TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD
                        | TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE /* flags */,
@@ -1968,6 +1972,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // WHEN onTrustChanged with INITIATED_BY_USER flag
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                getCurrentUser() /* userId, not the current userId */,
                TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER /* flags */,
                null /* trustGrantedMessages */);
@@ -1992,6 +1997,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        // WHEN onTrustChanged with INITIATED_BY_USER flag
        mKeyguardUpdateMonitor.onTrustChanged(
                true /* enabled */,
                true /* newlyUnlocked */,
                getCurrentUser() /* userId, not the current userId */,
                TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER
                        | TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE /* flags */,
@@ -2216,6 +2222,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {

    private void currentUserDoesNotHaveTrust() {
        mKeyguardUpdateMonitor.onTrustChanged(
                false,
                false,
                KeyguardUpdateMonitor.getCurrentUser(),
                -1,
+1 −1
Original line number Diff line number Diff line
@@ -417,7 +417,7 @@ public class Fingerprint21UdfpsMock extends Fingerprint21 implements TrustManage
    }

    @Override
    public void onTrustChanged(boolean enabled, int userId, int flags,
    public void onTrustChanged(boolean enabled, boolean newlyUnlocked, int userId, int flags,
            List<String> trustGrantedMessages) {
        mUserHasTrust.put(userId, enabled);
    }
Loading