Snap for 7641961 from 0af8e8e5cd to sc-qpr1-release

Change-Id: Ic1f2715f999d39093cf2a0b40e5d84419b630d7f
This commit is contained in:
Android Build Coastguard Worker
2021-08-14 03:08:25 +00:00
19 changed files with 267 additions and 33 deletions

View File

@@ -20,6 +20,7 @@ import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.hardware.biometrics.BiometricAuthenticator;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -62,6 +63,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
private TextView mErrorText;
protected boolean mConfirmingCredentials;
protected boolean mNextClicked;
private boolean mParentalConsentRequired;
@Nullable private PorterDuffColorFilter mIconColorFilter;
@@ -138,6 +140,8 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
*/
public abstract void onClick(LinkSpan span);
public abstract @BiometricAuthenticator.Modality int getModality();
protected interface GenerateChallengeCallback {
void onChallengeGenerated(int sensorId, int userId, long challenge);
}
@@ -161,7 +165,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
mBiometricUnlockDisabledByAdmin = isDisabledByAdmin();
setContentView(getLayoutResource());
if (mBiometricUnlockDisabledByAdmin) {
mParentalConsentRequired = ParentalControlsUtils.parentConsentRequired(this, getModality())
!= null;
if (mBiometricUnlockDisabledByAdmin && !mParentalConsentRequired) {
setHeaderText(getHeaderResDisabledByAdmin());
} else {
setHeaderText(getHeaderResDefault());
@@ -399,7 +405,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
protected void initViews() {
super.initViews();
if (mBiometricUnlockDisabledByAdmin) {
if (mBiometricUnlockDisabledByAdmin && !mParentalConsentRequired) {
setDescriptionText(getDescriptionResDisabledByAdmin());
}
}

View File

@@ -18,6 +18,8 @@ package com.android.settings.biometrics.combination;
import android.content.Context;
import android.os.UserHandle;
import androidx.lifecycle.Lifecycle;
/**
* Preference controller for face settings within the biometrics settings page of work profile,
* that controls the ability to unlock the phone with face authentication.
@@ -29,6 +31,11 @@ public class BiometricFaceProfileStatusPreferenceController extends
super(context, key);
}
public BiometricFaceProfileStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isUserSupported() {
return mProfileChallengeUserId != UserHandle.USER_NULL

View File

@@ -17,6 +17,8 @@ package com.android.settings.biometrics.combination;
import android.content.Context;
import androidx.lifecycle.Lifecycle;
import com.android.settings.Utils;
import com.android.settings.biometrics.face.FaceStatusPreferenceController;
@@ -30,6 +32,11 @@ public class BiometricFaceStatusPreferenceController extends FaceStatusPreferenc
super(context, key);
}
public BiometricFaceStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isDeviceSupported() {
return Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);

View File

@@ -18,6 +18,8 @@ package com.android.settings.biometrics.combination;
import android.content.Context;
import android.os.UserHandle;
import androidx.lifecycle.Lifecycle;
/**
* Preference controller for fingerprint settings within the biometrics settings page, that controls
* the ability to unlock the phone with fingerprint.
@@ -29,6 +31,11 @@ public class BiometricFingerprintProfileStatusPreferenceController extends
super(context, key);
}
public BiometricFingerprintProfileStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isUserSupported() {
return mProfileChallengeUserId != UserHandle.USER_NULL

View File

@@ -17,6 +17,8 @@ package com.android.settings.biometrics.combination;
import android.content.Context;
import androidx.lifecycle.Lifecycle;
import com.android.settings.Utils;
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
@@ -31,6 +33,11 @@ public class BiometricFingerprintStatusPreferenceController extends
super(context, key);
}
public BiometricFingerprintStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isDeviceSupported() {
return Utils.isMultipleBiometricsSupported(mContext)

View File

@@ -18,6 +18,8 @@ package com.android.settings.biometrics.combination;
import android.content.Context;
import android.os.UserHandle;
import androidx.lifecycle.Lifecycle;
import com.android.settings.Settings;
/**
@@ -37,6 +39,16 @@ public class CombinedBiometricProfileStatusPreferenceController extends
super(context, key);
}
public CombinedBiometricProfileStatusPreferenceController(
Context context, Lifecycle lifecycle) {
super(context, KEY_BIOMETRIC_SETTINGS, lifecycle);
}
public CombinedBiometricProfileStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isUserSupported() {
return mProfileChallengeUserId != UserHandle.USER_NULL

View File

@@ -21,6 +21,9 @@ import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -38,7 +41,7 @@ import com.android.settingslib.RestrictedPreference;
* with face and fingerprint.
*/
public class CombinedBiometricStatusPreferenceController extends
BiometricStatusPreferenceController {
BiometricStatusPreferenceController implements LifecycleObserver {
private static final String KEY_BIOMETRIC_SETTINGS = "biometric_settings";
@Nullable
@@ -49,13 +52,31 @@ public class CombinedBiometricStatusPreferenceController extends
RestrictedPreference mPreference;
public CombinedBiometricStatusPreferenceController(Context context) {
this(context, KEY_BIOMETRIC_SETTINGS);
this(context, KEY_BIOMETRIC_SETTINGS, null /* lifecycle */);
}
public CombinedBiometricStatusPreferenceController(Context context, String key) {
this(context, key, null /* lifecycle */);
}
public CombinedBiometricStatusPreferenceController(Context context, Lifecycle lifecycle) {
this(context, KEY_BIOMETRIC_SETTINGS, lifecycle);
}
public CombinedBiometricStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key);
mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
mFaceManager = Utils.getFaceManagerOrNull(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
updateStateInternal();
}
@Override
@@ -77,17 +98,19 @@ public class CombinedBiometricStatusPreferenceController extends
@Override
public void updateState(Preference preference) {
super.updateState(preference);
updateStateInternal();
}
private void updateStateInternal() {
// This controller currently is shown if fingerprint&face exist on the device. If this
// changes in the future, the modalities passed into the below will need to be updated.
final RestrictedLockUtils.EnforcedAdmin admin = ParentalControlsUtils
.parentConsentRequired(mContext,
BiometricAuthenticator.TYPE_FACE | BiometricAuthenticator.TYPE_FINGERPRINT);
updateStateInternal(admin);
updateStateInternal(ParentalControlsUtils.parentConsentRequired(mContext,
BiometricAuthenticator.TYPE_FACE | BiometricAuthenticator.TYPE_FINGERPRINT));
}
@VisibleForTesting
void updateStateInternal(@Nullable RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
if (enforcedAdmin != null && mPreference != null) {
if (mPreference != null) {
mPreference.setDisabledByAdmin(enforcedAdmin);
}
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.biometrics.face;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.os.Bundle;
@@ -287,6 +288,11 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
// TODO(b/110906762)
}
@Override
public @BiometricAuthenticator.Modality int getModality() {
return BiometricAuthenticator.TYPE_FACE;
}
@Override
@NonNull
protected FooterButton getPrimaryFooterButton() {

View File

@@ -19,6 +19,7 @@ package com.android.settings.biometrics.face;
import android.content.Context;
import android.os.UserHandle;
import androidx.lifecycle.Lifecycle;
import androidx.preference.Preference;
import com.android.settings.R;
@@ -28,13 +29,21 @@ public class FaceProfileStatusPreferenceController extends FaceStatusPreferenceC
private static final String KEY_FACE_SETTINGS = "face_settings_profile";
public FaceProfileStatusPreferenceController(Context context) {
this(context, KEY_FACE_SETTINGS);
super(context, KEY_FACE_SETTINGS);
}
public FaceProfileStatusPreferenceController(Context context, String key) {
super(context, key);
}
public FaceProfileStatusPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_FACE_SETTINGS, lifecycle);
}
public FaceProfileStatusPreferenceController(Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
public int getAvailabilityStatus() {
// Check if Face for Profile is available.

View File

@@ -21,6 +21,9 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.face.FaceManager;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -33,7 +36,8 @@ import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
public class FaceStatusPreferenceController extends BiometricStatusPreferenceController {
public class FaceStatusPreferenceController extends BiometricStatusPreferenceController
implements LifecycleObserver {
public static final String KEY_FACE_SETTINGS = "face_settings";
@@ -42,12 +46,29 @@ public class FaceStatusPreferenceController extends BiometricStatusPreferenceCon
RestrictedPreference mPreference;
public FaceStatusPreferenceController(Context context) {
this(context, KEY_FACE_SETTINGS);
this(context, KEY_FACE_SETTINGS, null /* lifecycle */);
}
public FaceStatusPreferenceController(Context context, String key) {
this(context, key, null /* lifecycle */);
}
public FaceStatusPreferenceController(Context context, Lifecycle lifecycle) {
this(context, KEY_FACE_SETTINGS, lifecycle);
}
public FaceStatusPreferenceController(Context context, String key, Lifecycle lifecycle) {
super(context, key);
mFaceManager = Utils.getFaceManagerOrNull(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
updateStateInternal();
}
@Override
@@ -69,14 +90,17 @@ public class FaceStatusPreferenceController extends BiometricStatusPreferenceCon
@Override
public void updateState(Preference preference) {
super.updateState(preference);
final RestrictedLockUtils.EnforcedAdmin admin = ParentalControlsUtils
.parentConsentRequired(mContext, BiometricAuthenticator.TYPE_FACE);
updateStateInternal(admin);
updateStateInternal();
}
private void updateStateInternal() {
updateStateInternal(ParentalControlsUtils.parentConsentRequired(
mContext, BiometricAuthenticator.TYPE_FACE));
}
@VisibleForTesting
void updateStateInternal(@Nullable RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
if (enforcedAdmin != null && mPreference != null) {
if (mPreference != null) {
mPreference.setDisabledByAdmin(enforcedAdmin);
}
}

View File

@@ -20,6 +20,7 @@ import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Bundle;
@@ -272,6 +273,11 @@ public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
}
}
@Override
public @BiometricAuthenticator.Modality int getModality() {
return BiometricAuthenticator.TYPE_FINGERPRINT;
}
@Override
@NonNull
protected FooterButton getPrimaryFooterButton() {

View File

@@ -19,19 +19,30 @@ package com.android.settings.biometrics.fingerprint;
import android.content.Context;
import android.os.UserHandle;
import androidx.lifecycle.Lifecycle;
public class FingerprintProfileStatusPreferenceController
extends FingerprintStatusPreferenceController {
public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings_profile";
public FingerprintProfileStatusPreferenceController(Context context) {
this(context, KEY_FINGERPRINT_SETTINGS);
super(context, KEY_FINGERPRINT_SETTINGS);
}
public FingerprintProfileStatusPreferenceController(Context context, String key) {
super(context, key);
}
public FingerprintProfileStatusPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_FINGERPRINT_SETTINGS, lifecycle);
}
public FingerprintProfileStatusPreferenceController(
Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
protected boolean isUserSupported() {
return mProfileChallengeUserId != UserHandle.USER_NULL

View File

@@ -21,6 +21,9 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.fingerprint.FingerprintManager;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -32,7 +35,8 @@ import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
public class FingerprintStatusPreferenceController extends BiometricStatusPreferenceController {
public class FingerprintStatusPreferenceController extends BiometricStatusPreferenceController
implements LifecycleObserver {
private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
@@ -45,8 +49,25 @@ public class FingerprintStatusPreferenceController extends BiometricStatusPrefer
}
public FingerprintStatusPreferenceController(Context context, String key) {
this(context, key, null /* lifecycle */);
}
public FingerprintStatusPreferenceController(Context context, Lifecycle lifecycle) {
this(context, KEY_FINGERPRINT_SETTINGS, lifecycle);
}
public FingerprintStatusPreferenceController(Context context, String key, Lifecycle lifecycle) {
super(context, key);
mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
updateStateInternal();
}
@Override
@@ -69,14 +90,17 @@ public class FingerprintStatusPreferenceController extends BiometricStatusPrefer
@Override
public void updateState(Preference preference) {
super.updateState(preference);
final RestrictedLockUtils.EnforcedAdmin admin = ParentalControlsUtils
.parentConsentRequired(mContext, BiometricAuthenticator.TYPE_FINGERPRINT);
updateStateInternal(admin);
updateStateInternal();
}
private void updateStateInternal() {
updateStateInternal(ParentalControlsUtils.parentConsentRequired(
mContext, BiometricAuthenticator.TYPE_FINGERPRINT));
}
@VisibleForTesting
void updateStateInternal(@Nullable RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
if (enforcedAdmin != null && mPreference != null) {
if (mPreference != null) {
mPreference.setDisabledByAdmin(enforcedAdmin);
}
}

View File

@@ -233,8 +233,13 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC
private final Collator sCollator = Collator.getInstance();
@Override
public int compare(ConversationChannel o1, ConversationChannel o2) {
int labelComparison = sCollator.compare(o1.getShortcutInfo().getLabel(),
o2.getShortcutInfo().getLabel());
int labelComparison = 0;
if (o1.getShortcutInfo().getLabel() != null
&& o2.getShortcutInfo().getLabel() != null) {
labelComparison = sCollator.compare(
o1.getShortcutInfo().getLabel().toString(),
o2.getShortcutInfo().getLabel().toString());
}
if (labelComparison == 0) {
return o1.getNotificationChannel().getId().compareTo(

View File

@@ -116,9 +116,11 @@ public class SecuritySettings extends DashboardFragment {
controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
final List<AbstractPreferenceController> securityPreferenceControllers = new ArrayList<>();
securityPreferenceControllers.add(new FaceStatusPreferenceController(context));
securityPreferenceControllers.add(new FingerprintStatusPreferenceController(context));
securityPreferenceControllers.add(new CombinedBiometricStatusPreferenceController(context));
securityPreferenceControllers.add(new FaceStatusPreferenceController(context, lifecycle));
securityPreferenceControllers.add(new FingerprintStatusPreferenceController(
context, lifecycle));
securityPreferenceControllers.add(new CombinedBiometricStatusPreferenceController(
context, lifecycle));
securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
.setChildren(securityPreferenceControllers));
@@ -130,10 +132,12 @@ public class SecuritySettings extends DashboardFragment {
profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
profileSecurityControllers.add(new VisiblePatternProfilePreferenceController(
context, lifecycle));
profileSecurityControllers.add(new FaceProfileStatusPreferenceController(context));
profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context));
profileSecurityControllers.add(new FaceProfileStatusPreferenceController(
context, lifecycle));
profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(
context, lifecycle));
profileSecurityControllers
.add(new CombinedBiometricProfileStatusPreferenceController(context));
.add(new CombinedBiometricProfileStatusPreferenceController(context, lifecycle));
controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY)
.setChildren(profileSecurityControllers));
controllers.addAll(profileSecurityControllers);

View File

@@ -18,7 +18,10 @@ package com.android.settings.biometrics.combination;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -29,12 +32,14 @@ import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -65,11 +70,15 @@ public class CombinedBiometricStatusPreferenceControllerTest {
private Context mContext;
private CombinedBiometricStatusPreferenceController mController;
private Preference mPreference;
private Lifecycle mLifecycle;
private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
@@ -82,7 +91,8 @@ public class CombinedBiometricStatusPreferenceControllerTest {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
mController = new CombinedBiometricStatusPreferenceController(mContext, TEST_PREF_KEY);
mController = new CombinedBiometricStatusPreferenceController(
mContext, TEST_PREF_KEY, mLifecycle);
}
@Test
@@ -96,5 +106,10 @@ public class CombinedBiometricStatusPreferenceControllerTest {
mController.mPreference = restrictedPreference;
mController.updateStateInternal(admin);
verify(restrictedPreference).setDisabledByAdmin(eq(admin));
reset(admin);
mController.updateStateInternal(null /* enforcedAdmin */);
verify(restrictedPreference, never()).setDisabledByAdmin(any());
}
}

View File

@@ -23,7 +23,10 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,6 +37,7 @@ import android.hardware.face.Face;
import android.hardware.face.FaceManager;
import android.os.UserManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
@@ -41,6 +45,7 @@ import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -71,11 +76,15 @@ public class FaceStatusPreferenceControllerTest {
private Context mContext;
private FaceStatusPreferenceController mController;
private Preference mPreference;
private Lifecycle mLifecycle;
private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
ShadowApplication.getInstance().setSystemService(Context.FACE_SERVICE, mFaceManager);
@@ -85,7 +94,7 @@ public class FaceStatusPreferenceControllerTest {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
mController = new FaceStatusPreferenceController(mContext, TEST_PREF_KEY);
mController = new FaceStatusPreferenceController(mContext, TEST_PREF_KEY, mLifecycle);
}
@Test
@@ -147,5 +156,10 @@ public class FaceStatusPreferenceControllerTest {
mController.mPreference = restrictedPreference;
mController.updateStateInternal(admin);
verify(restrictedPreference).setDisabledByAdmin(eq(admin));
reset(admin);
mController.updateStateInternal(null /* enforcedAdmin */);
verify(restrictedPreference, never()).setDisabledByAdmin(any());
}
}

View File

@@ -23,7 +23,10 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,6 +37,7 @@ import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
@@ -41,6 +45,7 @@ import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -69,11 +74,15 @@ public class FingerprintStatusPreferenceControllerTest {
private Context mContext;
private FingerprintStatusPreferenceController mController;
private Preference mPreference;
private Lifecycle mLifecycle;
private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
@@ -84,7 +93,7 @@ public class FingerprintStatusPreferenceControllerTest {
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
mController = new FingerprintStatusPreferenceController(mContext);
mController = new FingerprintStatusPreferenceController(mContext, mLifecycle);
}
@Test
@@ -145,5 +154,10 @@ public class FingerprintStatusPreferenceControllerTest {
mController.mPreference = restrictedPreference;
mController.updateStateInternal(admin);
verify(restrictedPreference).setDisabledByAdmin(eq(admin));
reset(admin);
mController.updateStateInternal(null /* enforcedAdmin */);
verify(restrictedPreference, never()).setDisabledByAdmin(any());
}
}

View File

@@ -36,6 +36,7 @@ import android.content.pm.ShortcutInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.SpannedString;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -338,4 +339,36 @@ public class RecentConversationsPreferenceControllerTest {
// one for the preference, none for 'clear all'
verify(outerContainer, times(1)).addPreference(any());
}
@Test
public void testSpans() {
ShortcutInfo si = mock(ShortcutInfo.class);
when(si.getLabel()).thenReturn(new SpannedString("hello"));
ConversationChannel ccw = new ConversationChannel(si, 6,
new NotificationChannel("hi", "hi", 4),
null, 7,
true /* hasactivenotifs */);
ShortcutInfo si2 = mock(ShortcutInfo.class);
when(si2.getLabel()).thenReturn("hello");
ConversationChannel ccw2 = new ConversationChannel(si2, 6,
new NotificationChannel("hi2", "hi2", 4),
null, 7,
true /* hasactivenotifs */);
// no crash
mController.mConversationComparator.compare(ccw, ccw2);
}
@Test
public void testNullSpans() {
ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6,
new NotificationChannel("hi", "hi", 4),
null, 7,
true /* hasactivenotifs */);
ConversationChannel ccw2 = new ConversationChannel(mock(ShortcutInfo.class), 6,
new NotificationChannel("hi2", "hi2", 4),
null, 7,
true /* hasactivenotifs */);
// no crash
mController.mConversationComparator.compare(ccw, ccw2);
}
}