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

Commit 82e7167b authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Eval dismissKeyguard in KeyguardUpdateMonitor" into tm-qpr-dev

parents 0ceb4ae2 1bdb6906
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M16,0L8,0l-0.95,5.73C5.19,7.19 4,9.45 4,12s1.19,4.81 3.05,6.27L8,24
        h8l0.96,-5.73C18.81,16.81 20,14.54 20,12s-1.19,-4.81 -3.04,-6.27L16,0z
        M12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6z"/>
</vector>
+18 −25
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.SystemClock;
import android.service.trust.TrustAgentService;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.MathUtils;
@@ -68,30 +67,24 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
    private final KeyguardUpdateMonitorCallback mUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
                @Override
                public void onTrustGrantedWithFlags(int flags, int userId, String message) {
                    if (userId != KeyguardUpdateMonitor.getCurrentUser()) return;
                    boolean bouncerVisible = mView.isVisibleToUser();
                    boolean temporaryAndRenewable =
                            (flags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE)
                            != 0;
                    boolean initiatedByUser =
                            (flags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0;
                    boolean dismissKeyguard =
                            (flags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0;

                    if (initiatedByUser || dismissKeyguard) {
                        if ((mViewMediatorCallback.isScreenOn() || temporaryAndRenewable)
                                && (bouncerVisible || dismissKeyguard)) {
                            if (!bouncerVisible) {
                public void onTrustGrantedForCurrentUser(boolean dismissKeyguard,
                        TrustGrantFlags flags, String message) {
                    if (dismissKeyguard) {
                        if (!mView.isVisibleToUser()) {
                            // The trust agent dismissed the keyguard without the user proving
                            // that they are present (by swiping up to show the bouncer). That's
                            // fine if the user proved presence via some other way to the trust
                            // agent.
                            Log.i(TAG, "TrustAgent dismissed Keyguard.");
                        }
                            mSecurityCallback.dismiss(false /* authenticated */, userId,
                                    /* bypassSecondaryLockScreen */ false, SecurityMode.Invalid);
                        mSecurityCallback.dismiss(
                                false /* authenticated */,
                                KeyguardUpdateMonitor.getCurrentUser(),
                                /* bypassSecondaryLockScreen */ false,
                                SecurityMode.Invalid
                        );
                    } else {
                        if (flags.isInitiatedByUser() || flags.dismissKeyguardRequested()) {
                            mViewMediatorCallback.playTrustedSound();
                        }
                    }
+30 −10
Original line number Diff line number Diff line
@@ -486,10 +486,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    FACE_AUTH_TRIGGERED_TRUST_DISABLED);
        }

        if (enabled) {
            String message = null;
        if (KeyguardUpdateMonitor.getCurrentUser() == userId) {
            final boolean userHasTrust = getUserHasTrust(userId);
            if (userHasTrust && trustGrantedMessages != null) {
            if (KeyguardUpdateMonitor.getCurrentUser() == userId
                    && trustGrantedMessages != null) {
                // Show the first non-empty string provided by a trust agent OR intentionally pass
                // an empty string through (to prevent the default trust agent string from showing)
                for (String msg : trustGrantedMessages) {
                    message = msg;
                    if (!TextUtils.isEmpty(message)) {
@@ -497,21 +499,39 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    }
                }
            }

            mLogger.logTrustGrantedWithFlags(flags, userId, message);
            if (userId == getCurrentUser()) {
                final TrustGrantFlags trustGrantFlags = new TrustGrantFlags(flags);
                for (int i = 0; i < mCallbacks.size(); i++) {
                    KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
                    if (cb != null) {
                        cb.onTrustGrantedForCurrentUser(
                                shouldDismissKeyguardOnTrustGrantedWithCurrentUser(trustGrantFlags),
                                trustGrantFlags, message);
                    }
                }
        mLogger.logTrustChanged(wasTrusted, enabled, userId);
        if (message != null) {
            mLogger.logShowTrustGrantedMessage(message.toString());
            }
        }

        mLogger.logTrustChanged(wasTrusted, enabled, userId);
        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onTrustChanged(userId);
                if (enabled) {
                    cb.onTrustGrantedWithFlags(flags, userId, message);
            }
        }
    }

    /**
     * Whether the trust granted call with its passed flags should dismiss keyguard.
     * It's assumed that the trust was granted for the current user.
     */
    private boolean shouldDismissKeyguardOnTrustGrantedWithCurrentUser(TrustGrantFlags flags) {
        final boolean isBouncerShowing = mPrimaryBouncerIsOrWillBeShowing || mUdfpsBouncerShowing;
        return (flags.isInitiatedByUser() || flags.dismissKeyguardRequested())
                && (mDeviceInteractive || flags.temporaryAndRenewable())
                && (isBouncerShowing || flags.dismissKeyguardRequested());
    }

    @Override
+5 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.hardware.biometrics.BiometricSourceType;
import android.telephony.TelephonyManager;
import android.view.WindowManagerPolicyConstants;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.settingslib.fuelgauge.BatteryStatus;
@@ -175,11 +176,13 @@ public class KeyguardUpdateMonitorCallback {

    /**
     * Called after trust was granted.
     * @param userId of the user that has been granted trust
     * @param dismissKeyguard whether the keyguard should be dismissed as a result of the
     *                        trustGranted
     * @param message optional message the trust agent has provided to show that should indicate
     *                why trust was granted.
     */
    public void onTrustGrantedWithFlags(int flags, int userId, @Nullable String message) { }
    public void onTrustGrantedForCurrentUser(boolean dismissKeyguard,
            @NonNull TrustGrantFlags flags, @Nullable String message) { }

    /**
     * Called when a biometric has been acquired.
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.keyguard;

import android.service.trust.TrustAgentService;

import java.util.Objects;

/**
 * Translating {@link android.service.trust.TrustAgentService.GrantTrustFlags} to a more
 * parsable object. These flags are requested by a TrustAgent.
 */
public class TrustGrantFlags {
    final int mFlags;

    public TrustGrantFlags(int flags) {
        this.mFlags = flags;
    }

    /** {@link TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER} */
    public boolean isInitiatedByUser() {
        return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0;
    }

    /**
     * Trust agent is requesting to dismiss the keyguard.
     * See {@link TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD}.
     *
     * This does not guarantee that the keyguard is dismissed.
     * KeyguardUpdateMonitor makes the final determination whether the keyguard should be dismissed.
     * {@link KeyguardUpdateMonitorCallback#onTrustGrantedForCurrentUser(
     *      boolean, TrustGrantFlags, String).
     */
    public boolean dismissKeyguardRequested() {
        return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0;
    }

    /** {@link TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE} */
    public boolean temporaryAndRenewable() {
        return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) != 0;
    }

    /** {@link TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE} */
    public boolean displayMessage() {
        return (mFlags & TrustAgentService.FLAG_GRANT_TRUST_DISPLAY_MESSAGE) != 0;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof TrustGrantFlags)) {
            return false;
        }

        return ((TrustGrantFlags) o).mFlags == this.mFlags;
    }

    @Override
    public int hashCode() {
      return Objects.hash(mFlags);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("[");
        sb.append(mFlags);
        sb.append("]=");

        if (isInitiatedByUser()) {
            sb.append("initiatedByUser|");
        }
        if (dismissKeyguardRequested()) {
            sb.append("dismissKeyguard|");
        }
        if (temporaryAndRenewable()) {
            sb.append("temporaryAndRenewable|");
        }
        if (displayMessage()) {
            sb.append("displayMessage|");
        }

        return sb.toString();
    }
}
Loading