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

Commit 94aedc05 authored by Eric Biggers's avatar Eric Biggers
Browse files

Remove obsolete Smart Lock developer settings

There is no code that changes the trust_agents_extend_unlock or
lock_screen_when_trust_lost settings from their default values.  These
settings were introduced as a "temporary convenience for dogfooding"
when the "extend unlock" feature was initially added in Android 10
(https://android.googlesource.com/platform/frameworks/base/+/15f7dd0c29881228b40d6db7f7f6e5d151cdb832).

Before Android 10 was released, extend unlock became the default
(https://android.googlesource.com/platform/frameworks/base/+/d3268c2dca1f09b6cef01579588b7aeb7c867cb9).

In Android 11, the ability to toggle these settings was removed from the
Settings app
(https://android.googlesource.com/platform/packages/apps/Settings/+/638aa7c066c4046ebc092fcfe4b29eb35040fbfc).

Therefore, there's no need to support anything other than the default
values of these settings.  Simplify the code accordingly.  Note, no
tests need to be removed because the non-default values were untested.

Bug: 120871688
Test: atest TrustTests
Change-Id: I6697b578712dfb57f9e709c541454b43e79d3a14
parent ae8e8431
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -10663,20 +10663,6 @@ public final class Settings {
        public static final String SEARCH_PRESS_HOLD_NAV_HANDLE_ENABLED =
                "search_press_hold_nav_handle_enabled";
        /**
         * Control whether Trust Agents are in active unlock or extend unlock mode.
         * @hide
         */
        @Readable
        public static final String TRUST_AGENTS_EXTEND_UNLOCK = "trust_agents_extend_unlock";
        /**
         * Control whether the screen locks when trust is lost.
         * @hide
         */
        @Readable
        public static final String LOCK_SCREEN_WHEN_TRUST_LOST = "lock_screen_when_trust_lost";
        /**
         * Control whether Night display is currently activated.
         * @hide
+0 −2
Original line number Diff line number Diff line
@@ -165,12 +165,10 @@ public class SecureSettings {
        Settings.Secure.CHARGING_VIBRATION_ENABLED,
        Settings.Secure.ACCESSIBILITY_NON_INTERACTIVE_UI_TIMEOUT_MS,
        Settings.Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS,
        Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK,
        Settings.Secure.UI_NIGHT_MODE,
        Settings.Secure.UI_NIGHT_MODE_CUSTOM_TYPE,
        Settings.Secure.DARK_THEME_CUSTOM_START_TIME,
        Settings.Secure.DARK_THEME_CUSTOM_END_TIME,
        Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST,
        Settings.Secure.SKIP_DIRECTION,
        Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
        Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT,
+0 −2
Original line number Diff line number Diff line
@@ -245,9 +245,7 @@ public class SecureSettingsValidators {
                Secure.ACCESSIBILITY_INTERACTIVE_UI_TIMEOUT_MS, NON_NEGATIVE_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.USER_SETUP_COMPLETE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ASSIST_GESTURE_SETUP_COMPLETE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.TRUST_AGENTS_EXTEND_UNLOCK, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.LOCK_SCREEN_CUSTOM_CLOCK_FACE, JSON_OBJECT_VALIDATOR);
        VALIDATORS.put(Secure.LOCK_SCREEN_WHEN_TRUST_LOST, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.SKIP_GESTURE, BOOLEAN_VALIDATOR);
        /*
         * Only used if FeatureFlag "settings_skip_direction_mutable" is enabled.
+7 −113
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.app.trust.ITrustListener;
import android.app.trust.ITrustManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -42,11 +41,9 @@ import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricSourceType;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -224,7 +221,6 @@ public class TrustManagerService extends SystemService {
            mIdleTrustableTimeoutAlarmListenerForUser = new SparseArray<>();
    private AlarmManager mAlarmManager;
    private final Object mAlarmLock = new Object();
    private final SettingsObserver mSettingsObserver;

    private final StrongAuthTracker mStrongAuthTracker;

@@ -266,7 +262,6 @@ public class TrustManagerService extends SystemService {
        mLockPatternUtils = injector.getLockPatternUtils();
        mStrongAuthTracker = new StrongAuthTracker(context, injector.getLooper());
        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        mSettingsObserver = new SettingsObserver(mHandler);
    }

    @Override
@@ -294,103 +289,10 @@ public class TrustManagerService extends SystemService {
        }
    }

    // Extend unlock config and logic
    private final class SettingsObserver extends ContentObserver {
        private final Uri TRUST_AGENTS_EXTEND_UNLOCK =
                Settings.Secure.getUriFor(Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK);

        private final Uri LOCK_SCREEN_WHEN_TRUST_LOST =
                Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST);

        private final boolean mIsAutomotive;
        private final ContentResolver mContentResolver;
        private boolean mTrustAgentsNonrenewableTrust;
        private boolean mLockWhenTrustLost;

        /**
         * Creates a settings observer
         *
         * @param handler The handler to run {@link #onChange} on, or null if none.
         */
        SettingsObserver(Handler handler) {
            super(handler);

            PackageManager packageManager = getContext().getPackageManager();
            mIsAutomotive = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);

            mContentResolver = getContext().getContentResolver();
            updateContentObserver();
        }

        void updateContentObserver() {
            mContentResolver.unregisterContentObserver(this);
            mContentResolver.registerContentObserver(TRUST_AGENTS_EXTEND_UNLOCK,
                    false /* notifyForDescendents */,
                    this /* observer */,
                    mCurrentUser);
            mContentResolver.registerContentObserver(LOCK_SCREEN_WHEN_TRUST_LOST,
                    false /* notifyForDescendents */,
                    this /* observer */,
                    mCurrentUser);

            // Update the value immediately
            onChange(true /* selfChange */, TRUST_AGENTS_EXTEND_UNLOCK);
            onChange(true /* selfChange */, LOCK_SCREEN_WHEN_TRUST_LOST);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            if (TRUST_AGENTS_EXTEND_UNLOCK.equals(uri)) {
                // Smart lock should only grant non-renewable trust. The only exception is for
                // automotive, where it can actively unlock the head unit.
                int defaultValue = mIsAutomotive ? 0 : 1;

                mTrustAgentsNonrenewableTrust =
                        Settings.Secure.getIntForUser(
                                mContentResolver,
                                Settings.Secure.TRUST_AGENTS_EXTEND_UNLOCK,
                                defaultValue,
                                mCurrentUser) != 0;
            } else if (LOCK_SCREEN_WHEN_TRUST_LOST.equals(uri)) {
                mLockWhenTrustLost =
                        Settings.Secure.getIntForUser(
                                mContentResolver,
                                Settings.Secure.LOCK_SCREEN_WHEN_TRUST_LOST,
                                0 /* default */,
                                mCurrentUser) != 0;
            }
        }

        boolean getTrustAgentsNonrenewableTrust() {
            return mTrustAgentsNonrenewableTrust;
        }

        boolean getLockWhenTrustLost() {
            return mLockWhenTrustLost;
        }
    }

    private void maybeLockScreen(int userId) {
        if (userId != mCurrentUser) {
            return;
        }

        if (mSettingsObserver.getLockWhenTrustLost()) {
            if (DEBUG) Slog.d(TAG, "Locking device because trust was lost");
            try {
                WindowManagerGlobal.getWindowManagerService().lockNow(null);
            } catch (RemoteException e) {
                Slog.e(TAG, "Error locking screen when trust was lost");
            }

            // If active unlocking is not allowed, cancel any pending trust timeouts because the
            // screen is already locked.
            TrustedTimeoutAlarmListener alarm = mTrustTimeoutAlarmListenerForUser.get(userId);
            if (alarm != null && mSettingsObserver.getTrustAgentsNonrenewableTrust()) {
                mAlarmManager.cancel(alarm);
                alarm.setQueued(false /* isQueued */);
            }
        }
    // Automotive head units can be unlocked by a trust agent, even when the agent doesn't use
    // FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE.
    private boolean isAutomotive() {
        return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
    }

    private void scheduleTrustTimeout(boolean override, boolean isTrustableTimeout) {
@@ -587,12 +489,10 @@ public class TrustManagerService extends SystemService {
        synchronized (mUserTrustState) {
            wasTrusted = (mUserTrustState.get(userId) == TrustState.TRUSTED);
            wasTrustable = (mUserTrustState.get(userId) == TrustState.TRUSTABLE);
            boolean isAutomotive = getContext().getPackageManager().hasSystemFeature(
                    PackageManager.FEATURE_AUTOMOTIVE);
            boolean renewingTrust = wasTrustable && (
                    (flags & TrustAgentService.FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) != 0);
            boolean canMoveToTrusted =
                    alreadyUnlocked || isFromUnlock || renewingTrust || isAutomotive;
                    alreadyUnlocked || isFromUnlock || renewingTrust || isAutomotive();
            boolean upgradingTrustForCurrentUser = (userId == mCurrentUser);

            if (trustedByAtLeastOneAgent && wasTrusted) {
@@ -619,9 +519,7 @@ public class TrustManagerService extends SystemService {
                isNowTrusted, newlyUnlocked, userId, flags, getTrustGrantedMessages(userId));
        if (isNowTrusted != wasTrusted) {
            refreshDeviceLockedForUser(userId);
            if (!isNowTrusted) {
                maybeLockScreen(userId);
            } else {
            if (isNowTrusted) {
                boolean isTrustableTimeout =
                        (flags & FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) != 0;
                // Every time we grant renewable trust we should override the idle trustable
@@ -1831,9 +1729,7 @@ public class TrustManagerService extends SystemService {
            synchronized(mUsersUnlockedByBiometric) {
                mUsersUnlockedByBiometric.put(userId, true);
            }
            // In non-renewable trust mode we need to refresh trust state here, which will call
            // refreshDeviceLockedForUser()
            int updateTrustOnUnlock = mSettingsObserver.getTrustAgentsNonrenewableTrust() ? 1 : 0;
            int updateTrustOnUnlock = isAutomotive() ? 0 : 1;
            mHandler.obtainMessage(MSG_REFRESH_DEVICE_LOCKED_FOR_USER, userId,
                    updateTrustOnUnlock).sendToTarget();
            mHandler.obtainMessage(MSG_REFRESH_TRUSTABLE_TIMERS_AFTER_AUTH, userId).sendToTarget();
@@ -1942,7 +1838,6 @@ public class TrustManagerService extends SystemService {
                        break;
                    case MSG_SWITCH_USER:
                        mCurrentUser = msg.arg1;
                        mSettingsObserver.updateContentObserver();
                        refreshDeviceLockedForUser(UserHandle.USER_ALL);
                        break;
                    case MSG_STOP_USER:
@@ -2175,7 +2070,6 @@ public class TrustManagerService extends SystemService {
                mLockPatternUtils.requireStrongAuth(
                        mStrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED, mUserId);
            }
            maybeLockScreen(mUserId);
        }

        protected abstract void handleAlarm();