Add ActiveUnlock check when picking preference
Modify BiometricsSettingBase to also track if the hardware is supported and if the controller is a work profile controller. If the hardware is supported and active unlock is enabled, non-work profile controllers will still be displayed. Test: make RunSettingsRoboTests Test: manually flip flags on device with active unlock, confirm new layout used Bug: 264813302 Change-Id: Idb0e994453d4fd5c078c45f87d5d8cee339053a2
This commit is contained in:
@@ -25,6 +25,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
@@ -37,11 +38,17 @@ public abstract class BiometricStatusPreferenceController extends BasePreference
|
||||
protected final int mProfileChallengeUserId;
|
||||
|
||||
private final BiometricNavigationUtils mBiometricNavigationUtils;
|
||||
private final ActiveUnlockStatusUtils mActiveUnlockStatusUtils;
|
||||
|
||||
/**
|
||||
* @return true if the controller should be shown exclusively.
|
||||
*/
|
||||
protected abstract boolean isDeviceSupported();
|
||||
|
||||
/**
|
||||
* @return true if the manager is not null and the hardware is detected.
|
||||
*/
|
||||
protected abstract boolean isDeviceSupported();
|
||||
protected abstract boolean isHardwareSupported();
|
||||
|
||||
/**
|
||||
* @return the summary text.
|
||||
@@ -61,13 +68,21 @@ public abstract class BiometricStatusPreferenceController extends BasePreference
|
||||
.getLockPatternUtils(context);
|
||||
mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
|
||||
mBiometricNavigationUtils = new BiometricNavigationUtils(getUserId());
|
||||
mActiveUnlockStatusUtils = new ActiveUnlockStatusUtils(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mActiveUnlockStatusUtils.isAvailable()) {
|
||||
return getAvailabilityStatusWithWorkProfileCheck();
|
||||
}
|
||||
if (!isDeviceSupported()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return getAvailabilityFromUserSupported();
|
||||
}
|
||||
|
||||
private int getAvailabilityFromUserSupported() {
|
||||
if (isUserSupported()) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
@@ -75,6 +90,21 @@ public abstract class BiometricStatusPreferenceController extends BasePreference
|
||||
}
|
||||
}
|
||||
|
||||
// Since this code is flag guarded by mActiveUnlockStatusUtils.isAvailable(), we don't need to
|
||||
// do another check here.
|
||||
private int getAvailabilityStatusWithWorkProfileCheck() {
|
||||
if (!isHardwareSupported()) {
|
||||
// no hardware, never show
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (!isDeviceSupported() && isWorkProfileController()) {
|
||||
// hardware supported but work profile, don't show
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
// hardware supported, not work profile, active unlock enabled
|
||||
return getAvailabilityFromUserSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (!isAvailable()) {
|
||||
@@ -105,4 +135,11 @@ public abstract class BiometricStatusPreferenceController extends BasePreference
|
||||
protected boolean isUserSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the controller controls is used for work profile.
|
||||
*/
|
||||
protected boolean isWorkProfileController() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.settings.biometrics.activeunlock;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ComponentInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.BasePreferenceController.AvailabilityStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Utilities for active unlock details shared between Security Settings and Safety Center. */
|
||||
public class ActiveUnlockStatusUtils {
|
||||
|
||||
/** The flag to determining whether active unlock in settings is enabled. */
|
||||
public static final String CONFIG_FLAG_NAME = "active_unlock_in_settings";
|
||||
|
||||
/** Flag value that represents the layout for unlock intent should be used. */
|
||||
public static final String UNLOCK_INTENT_LAYOUT = "unlock_intent_layout";
|
||||
|
||||
/** Flag value that represents the layout for biometric failure should be used. */
|
||||
public static final String BIOMETRIC_FAILURE_LAYOUT = "biometric_failure_layout";
|
||||
|
||||
private static final String ACTIVE_UNLOCK_PROVIDER = "active_unlock_provider";
|
||||
private static final String ACTIVE_UNLOCK_TARGET = "active_unlock_target";
|
||||
|
||||
private static final String TAG = "ActiveUnlockStatusUtils";
|
||||
|
||||
private final Context mContext;
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
public ActiveUnlockStatusUtils(@NonNull Context context) {
|
||||
mContext = context;
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
}
|
||||
|
||||
/** Returns whether the active unlock settings entity should be shown. */
|
||||
public boolean isAvailable() {
|
||||
return getAvailability() == BasePreferenceController.AVAILABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the active unlock layout with the unlock on intent configuration should be
|
||||
* used.
|
||||
*/
|
||||
public boolean useUnlockIntentLayout() {
|
||||
return isAvailable() && UNLOCK_INTENT_LAYOUT.equals(getFlagState());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns whether the active unlock layout with the unlock on biometric failure configuration
|
||||
* should be used.
|
||||
*/
|
||||
public boolean useBiometricFailureLayout() {
|
||||
return isAvailable() && BIOMETRIC_FAILURE_LAYOUT.equals(getFlagState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authority used to fetch dynamic active unlock content.
|
||||
*/
|
||||
@Nullable
|
||||
public String getAuthority() {
|
||||
final String authority = Settings.Secure.getString(
|
||||
mContext.getContentResolver(), ACTIVE_UNLOCK_PROVIDER);
|
||||
if (authority == null) {
|
||||
Log.i(TAG, "authority not set");
|
||||
return null;
|
||||
}
|
||||
final List<PackageInfo> packageInfos =
|
||||
mContext.getPackageManager().getInstalledPackages(
|
||||
PackageManager.PackageInfoFlags.of(PackageManager.GET_PROVIDERS));
|
||||
for (PackageInfo packageInfo : packageInfos) {
|
||||
final ProviderInfo[] providers = packageInfo.providers;
|
||||
if (providers != null) {
|
||||
for (ProviderInfo provider : providers) {
|
||||
if (authority.equals(provider.authority) && isSystemApp(provider)) {
|
||||
return authority;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "authority not valid");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isSystemApp(ComponentInfo componentInfo) {
|
||||
final ApplicationInfo applicationInfo = componentInfo.applicationInfo;
|
||||
if (applicationInfo == null) {
|
||||
Log.e(TAG, "application info is null");
|
||||
return false;
|
||||
}
|
||||
return applicationInfo.isSystemApp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intent used to launch the active unlock activity.
|
||||
*/
|
||||
@Nullable
|
||||
public Intent getIntent() {
|
||||
final String targetAction = Settings.Secure.getString(
|
||||
mContentResolver, ACTIVE_UNLOCK_TARGET);
|
||||
if (targetAction == null) {
|
||||
Log.i(TAG, "Target action not set");
|
||||
return null;
|
||||
}
|
||||
final Intent intent = new Intent(targetAction);
|
||||
final ActivityInfo activityInfo = intent.resolveActivityInfo(
|
||||
mContext.getPackageManager(), PackageManager.MATCH_ALL);
|
||||
if (activityInfo == null) {
|
||||
Log.e(TAG, "Target activity not found");
|
||||
return null;
|
||||
}
|
||||
if (!isSystemApp(activityInfo)) {
|
||||
Log.e(TAG, "Target application is not system");
|
||||
return null;
|
||||
}
|
||||
Log.i(TAG, "Target application is valid");
|
||||
return intent;
|
||||
}
|
||||
|
||||
/** Returns the availability status of the active unlock feature. */
|
||||
@AvailabilityStatus
|
||||
int getAvailability() {
|
||||
if (!Utils.hasFingerprintHardware(mContext) && !Utils.hasFaceHardware(mContext)) {
|
||||
return BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (!UNLOCK_INTENT_LAYOUT.equals(getFlagState())
|
||||
&& !BIOMETRIC_FAILURE_LAYOUT.equals(getFlagState())) {
|
||||
return BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
if (getAuthority() != null && getIntent() != null) {
|
||||
return BasePreferenceController.AVAILABLE;
|
||||
}
|
||||
return BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private static String getFlagState() {
|
||||
return DeviceConfig.getProperty(DeviceConfig.NAMESPACE_REMOTE_AUTH, CONFIG_FLAG_NAME);
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,9 @@ public class BiometricFaceProfileStatusPreferenceController extends
|
||||
protected int getUserId() {
|
||||
return mProfileChallengeUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWorkProfileController() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ public class BiometricFaceStatusPreferenceController extends FaceStatusPreferenc
|
||||
|
||||
@Override
|
||||
protected boolean isDeviceSupported() {
|
||||
return Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);
|
||||
return Utils.isMultipleBiometricsSupported(mContext) && isHardwareSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHardwareSupported() {
|
||||
return Utils.hasFaceHardware(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,9 @@ public class BiometricFingerprintProfileStatusPreferenceController extends
|
||||
protected int getUserId() {
|
||||
return mProfileChallengeUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWorkProfileController() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,11 @@ public class BiometricFingerprintStatusPreferenceController extends
|
||||
|
||||
@Override
|
||||
protected boolean isDeviceSupported() {
|
||||
return Utils.isMultipleBiometricsSupported(mContext)
|
||||
&& Utils.hasFingerprintHardware(mContext);
|
||||
return Utils.isMultipleBiometricsSupported(mContext) && isHardwareSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHardwareSupported() {
|
||||
return Utils.hasFingerprintHardware(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -69,7 +70,10 @@ public class BiometricSettingsAppPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!Utils.isMultipleBiometricsSupported(mContext)) {
|
||||
final ActiveUnlockStatusUtils activeUnlockStatusUtils =
|
||||
new ActiveUnlockStatusUtils(mContext);
|
||||
if (!Utils.isMultipleBiometricsSupported(mContext)
|
||||
&& !activeUnlockStatusUtils.isAvailable()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (mFaceManager == null || mFingerprintManager == null) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -63,9 +64,18 @@ public class BiometricSettingsKeyguardPreferenceController extends TogglePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final ActiveUnlockStatusUtils activeUnlockStatusUtils =
|
||||
new ActiveUnlockStatusUtils(mContext);
|
||||
if (activeUnlockStatusUtils.isAvailable()) {
|
||||
return getAvailabilityFromRestrictingAdmin();
|
||||
}
|
||||
if (!Utils.isMultipleBiometricsSupported(mContext)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return getAvailabilityFromRestrictingAdmin();
|
||||
}
|
||||
|
||||
private int getAvailabilityFromRestrictingAdmin() {
|
||||
return getRestrictingAdmin() != null ? DISABLED_FOR_USER : AVAILABLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,4 +62,9 @@ public class CombinedBiometricProfileStatusPreferenceController extends
|
||||
protected String getSettingsClassName() {
|
||||
return mCombinedBiometricStatusUtils.getProfileSettingsClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWorkProfileController() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.BiometricStatusPreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -84,6 +85,11 @@ public class CombinedBiometricStatusPreferenceController extends
|
||||
return mCombinedBiometricStatusUtils.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHardwareSupported() {
|
||||
return Utils.hasFaceHardware(mContext) || Utils.hasFingerprintHardware(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
@@ -84,4 +84,9 @@ public class FaceProfileStatusPreferenceController extends FaceStatusPreferenceC
|
||||
mContext.getResources().getString(
|
||||
R.string.security_settings_face_profile_preference_title)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWorkProfileController() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,11 @@ public class FaceStatusPreferenceController extends BiometricStatusPreferenceCon
|
||||
return mFaceStatusUtils.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHardwareSupported() {
|
||||
return Utils.hasFaceHardware(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
@@ -53,4 +53,9 @@ public class FingerprintProfileStatusPreferenceController
|
||||
protected int getUserId() {
|
||||
return mProfileChallengeUserId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWorkProfileController() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,11 @@ public class FingerprintStatusPreferenceController extends BiometricStatusPrefer
|
||||
return mFingerprintStatusUtils.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isHardwareSupported() {
|
||||
return Utils.hasFingerprintHardware(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
Reference in New Issue
Block a user