Merge "Remove the extra line below context button" into tm-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 744ae6c..214d32a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -9,7 +9,7 @@
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.READ_MEDIA_IMAGE" />
+ <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
@@ -1517,6 +1517,8 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
+ <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
+ android:value="@string/menu_key_apps"/>
</activity-alias>
<activity android:name=".applications.InstalledAppOpenByDefaultActivity"
@@ -1529,6 +1531,8 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
+ <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
+ android:value="@string/menu_key_apps"/>
</activity>
<!-- Provide direct entry into manage apps showing running services. -->
diff --git a/res/layout/profile_select_tablayout.xml b/res/layout/profile_select_tablayout.xml
deleted file mode 100644
index 3e83bb9..0000000
--- a/res/layout/profile_select_tablayout.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<!--
- Copyright (C) 2019 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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:theme="@style/Theme.MaterialComponents.DayNight"
- android:clipToPadding="true"
- android:clipChildren="true"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
-
- <com.google.android.material.tabs.TabLayout
- android:background="@android:color/transparent"
- android:id="@+id/tabs"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- app:tabMaxWidth="0dp"
- app:tabGravity="fill"
- app:tabMode="fixed"
- app:tabIndicatorColor="@*android:color/accent_device_default"
- app:tabSelectedTextColor="@*android:color/accent_device_default"
- app:tabTextColor="?android:attr/textColorSecondary" />
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="?android:attr/listDivider"/>
-
- <androidx.viewpager.widget.ViewPager
- android:id="@+id/view_pager"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- </androidx.viewpager.widget.ViewPager>
-</LinearLayout>
diff --git a/res/layout/support_details_dialog.xml b/res/layout/support_details_dialog.xml
index 0233a1b..2390f90 100644
--- a/res/layout/support_details_dialog.xml
+++ b/res/layout/support_details_dialog.xml
@@ -33,6 +33,8 @@
android:layout_width="@dimen/admin_details_dialog_icon_size"
android:layout_height="@dimen/admin_details_dialog_icon_size"
android:scaleType="fitCenter"
+ android:src="@drawable/ic_lock_closed"
+ android:tint="?android:attr/colorAccent"
android:contentDescription="@null"/>
<TextView
android:id="@+id/admin_support_dialog_title"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c1a6dfe..bd9cbbd 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5401,9 +5401,9 @@
<!-- Summary text for the accessibility button preference. [CHAR LIMIT=50] -->
<string name="accessibility_button_summary">Quickly access accessibility features</string>
<!-- Description for the accessibility button in gesture navigation. Explain how this page works. [CHAR LIMIT=NONE] -->
- <string name="accessibility_button_gesture_description"><b>How to use the button or gesture</b>\n\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. To use the feature, tap the accessibility button or gesture</string>
+ <string name="accessibility_button_gesture_description"><b>To get started</b>\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. Choose whether you want to use a button or gesture to access the feature</string>
<!-- Description for the accessibility button page. Explain how this page works. [CHAR LIMIT=NONE] -->
- <string name="accessibility_button_description"><b>How to use the button</b>\n\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. To use the feature, tap the accessibility button</string>
+ <string name="accessibility_button_description"><b>To get started</b>\n1. Go to accessibility settings\n2. Select a feature and tap the shortcut\n3. Choose the button to use to access the feature</string>
<!-- Title for the button or gesture of the accessibility button. [CHAR LIMIT=35] -->
<string name="accessibility_button_or_gesture_title">Use button or gesture</string>
<!-- Title for the location of the accessibility button. [CHAR LIMIT=35] -->
diff --git a/res/xml/notification_access_permission_details.xml b/res/xml/notification_access_permission_details.xml
index cec383c..9867b6d 100644
--- a/res/xml/notification_access_permission_details.xml
+++ b/res/xml/notification_access_permission_details.xml
@@ -26,7 +26,7 @@
android:layout="@layout/settings_entity_header"
settings:controller="com.android.settings.applications.specialaccess.notificationaccess.HeaderPreferenceController"/>
- <com.android.settings.widget.FilterTouchesSwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="notification_access_switch"
android:title="@string/notification_access_detail_switch"
settings:controller="com.android.settings.applications.specialaccess.notificationaccess.ApprovalPreferenceController"/>
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
index 0ff960f..930fbe4 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
@@ -16,6 +16,7 @@
package com.android.settings.accessibility;
+import android.app.settings.SettingsEnums;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -57,7 +58,7 @@
@Override
public int getMetricsCategory() {
- return super.getMetricsCategory();
+ return SettingsEnums.SUW_ACCESSIBILITY_TEXT_READING_OPTIONS;
}
@Override
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
index a43b9fd..0767e65 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
@@ -27,10 +27,10 @@
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.SwitchPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.RestrictedSwitchPreference;
public class ApprovalPreferenceController extends BasePreferenceController {
@@ -78,9 +78,11 @@
@Override
public void updateState(Preference pref) {
- final SwitchPreference preference = (SwitchPreference) pref;
+ final RestrictedSwitchPreference preference =
+ (RestrictedSwitchPreference) pref;
final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
- preference.setChecked(isServiceEnabled(mCn));
+ final boolean isEnabled = isServiceEnabled(mCn);
+ preference.setChecked(isEnabled);
preference.setOnPreferenceChangeListener((p, newValue) -> {
final boolean access = (Boolean) newValue;
if (!access) {
@@ -103,6 +105,7 @@
return false;
}
});
+ preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
}
public void disable(final ComponentName cn) {
diff --git a/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java b/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
index f1e312a..f5ad76b 100644
--- a/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
+++ b/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
@@ -56,6 +56,13 @@
}
/**
+ * Returns whether at least one face template or fingerprint has been enrolled.
+ */
+ public boolean hasEnrolled() {
+ return hasEnrolledFingerprints() || hasEnrolledFace();
+ }
+
+ /**
* Returns the {@link EnforcedAdmin} in case parental consent is required to change both
* face and fingerprint settings.
*
@@ -84,8 +91,7 @@
public String getSummary() {
final int numFingerprintsEnrolled = mFingerprintManager != null
? mFingerprintManager.getEnrolledFingerprints(mUserId).size() : 0;
- final boolean faceEnrolled = mFaceManager != null
- && mFaceManager.hasEnrolledTemplates(mUserId);
+ final boolean faceEnrolled = hasEnrolledFace();
if (faceEnrolled && numFingerprintsEnrolled > 1) {
return mContext.getString(
@@ -105,6 +111,14 @@
}
}
+ private boolean hasEnrolledFingerprints() {
+ return mFingerprintManager != null && mFingerprintManager.hasEnrolledFingerprints(mUserId);
+ }
+
+ private boolean hasEnrolledFace() {
+ return mFaceManager != null && mFaceManager.hasEnrolledTemplates(mUserId);
+ }
+
/**
* Returns the class name of the Settings page corresponding to combined biometric settings.
*/
diff --git a/src/com/android/settings/biometrics/face/FaceStatusUtils.java b/src/com/android/settings/biometrics/face/FaceStatusUtils.java
index 4e25543..1749aca 100644
--- a/src/com/android/settings/biometrics/face/FaceStatusUtils.java
+++ b/src/com/android/settings/biometrics/face/FaceStatusUtils.java
@@ -75,7 +75,10 @@
: FaceEnrollIntroduction.class.getName();
}
- private boolean hasEnrolled() {
+ /**
+ * Returns whether at least one face template has been enrolled.
+ */
+ public boolean hasEnrolled() {
return mFaceManager.hasEnrolledTemplates(mUserId);
}
}
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroduction.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroduction.java
index 2ef5446..23595fb 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroduction.java
@@ -35,6 +35,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollIntroduction;
@@ -55,6 +56,7 @@
private static final String TAG = "FingerprintIntro";
+ @VisibleForTesting
private FingerprintManager mFingerprintManager;
@Nullable private FooterButton mPrimaryFooterButton;
@Nullable private FooterButton mSecondaryFooterButton;
@@ -213,6 +215,8 @@
@Override
protected int checkMaxEnrolled() {
final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
+ final boolean isDeferredSetupWizard =
+ WizardManagerHelper.isDeferredSetupWizard(getIntent());
if (mFingerprintManager != null) {
final List<FingerprintSensorPropertiesInternal> props =
mFingerprintManager.getSensorPropertiesInternal();
@@ -220,9 +224,11 @@
final int max = props.get(0).maxEnrollmentsPerUser;
final int numEnrolledFingerprints =
mFingerprintManager.getEnrolledFingerprints(mUserId).size();
- final int maxFingerprintsEnrollableIfSUW = getApplicationContext().getResources()
- .getInteger(R.integer.suw_max_fingerprints_enrollable);
- if (isSetupWizard) {
+ final int maxFingerprintsEnrollableIfSUW =
+ getApplicationContext()
+ .getResources()
+ .getInteger(R.integer.suw_max_fingerprints_enrollable);
+ if (isSetupWizard && !isDeferredSetupWizard) {
if (numEnrolledFingerprints >= maxFingerprintsEnrollableIfSUW) {
return R.string.fingerprint_intro_error_max;
} else {
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtils.java b/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtils.java
index d23195d..5707f32 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtils.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtils.java
@@ -82,7 +82,10 @@
: FingerprintEnrollIntroduction.class.getName();
}
- private boolean hasEnrolled() {
+ /**
+ * Returns whether at least one fingerprint has been enrolled.
+ */
+ public boolean hasEnrolled() {
return mFingerprintManager.hasEnrolledFingerprints(mUserId);
}
}
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index 9a157d6..8fdc370 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -369,6 +369,7 @@
}
return true;
})
+ .sorted(Comparator.comparingInt(UiccSlotMapping::getLogicalSlotIndex))
.mapToInt(uiccSlotMapping -> uiccSlotMapping.getLogicalSlotIndex())
.findFirst()
.orElse(INVALID_LOGICAL_SLOT_ID);
diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
index c302915..74d8e01 100644
--- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java
+++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
@@ -65,6 +65,7 @@
combinedBiometricStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
disablingAdmin == null /* enabled */,
+ combinedBiometricStatusUtils.hasEnrolled(),
safetyEvent);
return;
}
@@ -82,6 +83,7 @@
faceStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
disablingAdmin == null /* enabled */,
+ faceStatusUtils.hasEnrolled(),
safetyEvent);
return;
@@ -101,6 +103,7 @@
fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
disablingAdmin == null /* enabled */,
+ fingerprintStatusUtils.hasEnrolled(),
safetyEvent);
}
}
@@ -114,12 +117,14 @@
}
private static void setBiometricSafetySourceData(Context context, String title, String summary,
- Intent clickIntent, boolean enabled, SafetyEvent safetyEvent) {
+ Intent clickIntent, boolean enabled, boolean hasEnrolled, SafetyEvent safetyEvent) {
final PendingIntent pendingIntent = createPendingIntent(context, clickIntent);
+ final int statusLevel =
+ enabled && hasEnrolled ? SafetySourceStatus.STATUS_LEVEL_OK
+ : SafetySourceStatus.STATUS_LEVEL_NONE;
- final SafetySourceStatus status = new SafetySourceStatus.Builder(title, summary,
- SafetySourceStatus.STATUS_LEVEL_NONE, pendingIntent)
- .setEnabled(enabled).build();
+ final SafetySourceStatus status = new SafetySourceStatus.Builder(
+ title, summary, statusLevel, pendingIntent).setEnabled(enabled).build();
final SafetySourceData safetySourceData =
new SafetySourceData.Builder().setStatus(status).build();
diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java
index 6f955b2..1027792 100644
--- a/src/com/android/settings/wifi/WifiUtils.java
+++ b/src/com/android/settings/wifi/WifiUtils.java
@@ -41,6 +41,8 @@
private static final int SSID_ASCII_MIN_LENGTH = 1;
private static final int SSID_ASCII_MAX_LENGTH = 32;
+ private static final int PSK_PASSPHRASE_ASCII_MIN_LENGTH = 8;
+ private static final int PSK_PASSPHRASE_ASCII_MAX_LENGTH = 63;
public static boolean isSSIDTooLong(String ssid) {
if (TextUtils.isEmpty(ssid)) {
@@ -62,6 +64,13 @@
public static boolean isHotspotPasswordValid(String password, int securityType) {
final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
try {
+ if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK
+ || securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION) {
+ if (password.length() < PSK_PASSPHRASE_ASCII_MIN_LENGTH
+ || password.length() > PSK_PASSPHRASE_ASCII_MAX_LENGTH) {
+ return false;
+ }
+ }
configBuilder.setPassphrase(password, securityType);
} catch (IllegalArgumentException e) {
return false;
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index f7c546f..c1950be 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -20,6 +20,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.atLeast;
@@ -31,6 +33,7 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.AccessibilityShortcutInfo;
+import android.app.AppOpsManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -110,6 +113,8 @@
@Mock
private PreferenceManager mPreferenceManager;
private ShadowAccessibilityManager mShadowAccessibilityManager;
+ @Mock
+ private AppOpsManager mAppOpsManager;
@Before
public void setup() {
@@ -121,6 +126,9 @@
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
mContext.setTheme(R.style.Theme_AppCompat);
+ when(mContext.getSystemService(AppOpsManager.class)).thenReturn(mAppOpsManager);
+ when(mAppOpsManager.noteOpNoThrow(eq(AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS),
+ anyInt(), anyString())).thenReturn(AppOpsManager.MODE_ALLOWED);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java
new file mode 100644
index 0000000..d8852db
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.settings.biometrics.fingerprint;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.hardware.biometrics.ComponentInfoInternal;
+import android.hardware.biometrics.SensorProperties;
+import android.hardware.fingerprint.Fingerprint;
+import android.hardware.fingerprint.FingerprintManager;
+import android.hardware.fingerprint.FingerprintSensorProperties;
+import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
+
+import com.android.settings.R;
+
+import com.google.android.setupcompat.util.WizardManagerHelper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.android.controller.ActivityController;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class FingerprintEnrollIntroductionTest {
+
+ @Mock private FingerprintManager mFingerprintManager;
+
+ private Context mContext;
+
+ private FingerprintEnrollIntroduction mFingerprintEnrollIntroduction;
+
+ private static final int MAX_ENROLLMENTS = 5;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+
+ final List<ComponentInfoInternal> componentInfo = new ArrayList<>();
+ final FingerprintSensorPropertiesInternal prop =
+ new FingerprintSensorPropertiesInternal(
+ 0 /* sensorId */,
+ SensorProperties.STRENGTH_STRONG,
+ MAX_ENROLLMENTS /* maxEnrollmentsPerUser */,
+ componentInfo,
+ FingerprintSensorProperties.TYPE_REAR,
+ true /* resetLockoutRequiresHardwareAuthToken */);
+ final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
+ props.add(prop);
+ when(mFingerprintManager.getSensorPropertiesInternal()).thenReturn(props);
+ }
+
+ void setupFingerprintEnrollIntroWith(Intent intent) {
+ ActivityController<FingerprintEnrollIntroduction> controller =
+ Robolectric.buildActivity(FingerprintEnrollIntroduction.class, intent);
+ mFingerprintEnrollIntroduction = spy(controller.get());
+ ReflectionHelpers.setField(
+ mFingerprintEnrollIntroduction, "mFingerprintManager", mFingerprintManager);
+ controller.create();
+ }
+
+ void setFingerprintManagerToHave(int numEnrollments) {
+ List<Fingerprint> fingerprints = new ArrayList<>();
+ for (int i = 0; i < numEnrollments; i++) {
+ fingerprints.add(
+ new Fingerprint(
+ "Fingerprint " + i /* name */, 1 /*fingerId */, 1 /* deviceId */));
+ }
+ when(mFingerprintManager.getEnrolledFingerprints(anyInt())).thenReturn(fingerprints);
+ }
+
+ @Test
+ public void intro_CheckCanEnrollNormal() {
+ setupFingerprintEnrollIntroWith(new Intent());
+ setFingerprintManagerToHave(3 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(0);
+ }
+
+ @Test
+ public void intro_CheckMaxEnrolledNormal() {
+ setupFingerprintEnrollIntroWith(new Intent());
+ setFingerprintManagerToHave(7 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(R.string.fingerprint_intro_error_max);
+ }
+
+ @Test
+ public void intro_CheckCanEnrollDuringSUW() {
+ // This code path should depend on suw_max_fingerprints_enrollable versus
+ // FingerprintManager.getSensorProperties...maxEnrollmentsPerUser()
+ Resources resources = mock(Resources.class);
+ when(resources.getInteger(anyInt())).thenReturn(5);
+ when(mContext.getResources()).thenReturn(resources);
+
+ setupFingerprintEnrollIntroWith(
+ new Intent()
+ .putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
+ .putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true));
+ setFingerprintManagerToHave(0 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(0);
+ }
+
+ @Test
+ public void intro_CheckMaxEnrolledDuringSUW() {
+ // This code path should depend on suw_max_fingerprints_enrollable versus
+ // FingerprintManager.getSensorProperties...maxEnrollmentsPerUser()
+ Resources resources = mock(Resources.class);
+ when(mContext.getResources()).thenReturn(resources);
+ when(resources.getInteger(anyInt())).thenReturn(1);
+
+ setupFingerprintEnrollIntroWith(
+ new Intent()
+ .putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
+ .putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true));
+ setFingerprintManagerToHave(1 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(R.string.fingerprint_intro_error_max);
+ }
+
+ @Test
+ public void intro_CheckCanEnrollDuringDeferred() {
+ setupFingerprintEnrollIntroWith(
+ new Intent().putExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, true));
+ setFingerprintManagerToHave(2 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(0);
+ }
+
+ @Test
+ public void intro_CheckMaxEnrolledDuringDeferred() {
+ setupFingerprintEnrollIntroWith(
+ new Intent().putExtra(WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP, true));
+ setFingerprintManagerToHave(6 /* numEnrollments */);
+ int result = mFingerprintEnrollIntroduction.checkMaxEnrolled();
+
+ assertThat(result).isEqualTo(R.string.fingerprint_intro_error_max);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
index a0188f8..3305cde 100644
--- a/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/WhenToDreamPreferenceControllerTest.java
@@ -23,26 +23,23 @@
import android.content.Context;
import androidx.preference.Preference;
+import androidx.test.core.app.ApplicationProvider;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.dream.DreamBackend.WhenToDream;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
-@Ignore
public class WhenToDreamPreferenceControllerTest {
private WhenToDreamPreferenceController mController;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private DreamBackend mBackend;
@@ -50,6 +47,7 @@
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
mController = new WhenToDreamPreferenceController(mContext);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
}
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
index 064f813..249b713 100644
--- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
@@ -18,12 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.AppOpsManager;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
@@ -31,12 +34,12 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -55,6 +58,8 @@
@Mock
NotificationManager mNm;
@Mock
+ AppOpsManager mAppOpsManager;
+ @Mock
PackageManager mPm;
PackageInfo mPkgInfo;
ComponentName mCn = new ComponentName("a", "b");
@@ -75,15 +80,47 @@
mController.setNm(mNm);
mController.setParent(mFragment);
mController.setPkgInfo(mPkgInfo);
+
}
@Test
public void updateState_checked() {
+ when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
+ AppOpsManager.MODE_ALLOWED);
when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
- SwitchPreference pref = new SwitchPreference(mContext);
+ RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
+ mContext);
+ pref.setAppOps(mAppOpsManager);
mController.updateState(pref);
assertThat(pref.isChecked()).isTrue();
+ assertThat(pref.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void restrictedSettings_appOpsDisabled() {
+ when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
+ AppOpsManager.MODE_ERRORED);
+ when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(false);
+ RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
+ mContext);
+ pref.setAppOps(mAppOpsManager);
+
+ mController.updateState(pref);
+ assertThat(pref.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void restrictedSettings_serviceAlreadyEnabled() {
+ when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
+ AppOpsManager.MODE_ERRORED);
+ when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
+ RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
+ mContext);
+ pref.setAppOps(mAppOpsManager);
+
+ mController.updateState(pref);
+ assertThat(pref.isEnabled()).isTrue();
}
@Test
diff --git a/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
index 7d89079..10f1110 100644
--- a/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtilsTest.java
@@ -57,8 +57,7 @@
private static final ComponentName COMPONENT_NAME =
new ComponentName("package", "class");
private static final int USER_ID = UserHandle.myUserId();
- private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);;
-
+ private static final UserHandle USER_HANDLE = new UserHandle(USER_ID);
@Mock
private PackageManager mPackageManager;
@@ -123,6 +122,54 @@
}
@Test
+ public void hasEnrolled_withoutFingerprintHardware_withoutFaceHardware_returnsFalse() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(false);
+
+ assertThat(mCombinedBiometricStatusUtils.hasEnrolled()).isFalse();
+ }
+
+ @Test
+ public void hasEnrolled_withoutFingerprintEnroll_withoutFaceEnroll_returnsFalse() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+
+ assertThat(mCombinedBiometricStatusUtils.hasEnrolled()).isFalse();
+ }
+
+ @Test
+ public void hasEnrolled_withoutFingerprintEnroll_withFaceEnroll_returnsTrue() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+
+ assertThat(mCombinedBiometricStatusUtils.hasEnrolled()).isTrue();
+ }
+
+ @Test
+ public void hasEnrolled_withFingerprintEnroll_withoutFaceEnroll_returnsTrue() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+
+ assertThat(mCombinedBiometricStatusUtils.hasEnrolled()).isTrue();
+ }
+
+ @Test
+ public void hasEnrolled_withFingerprintEnroll_withFaceEnroll_returnsTrue() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+
+ assertThat(mCombinedBiometricStatusUtils.hasEnrolled()).isTrue();
+ }
+
+ @Test
public void getDisabledAdmin_whenFingerprintDisabled_whenFaceDisabled_returnsEnforcedAdmin() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(KEYGUARD_DISABLE_FACE | KEYGUARD_DISABLE_FINGERPRINT);
diff --git a/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
index 8697da7..9f9dd93 100644
--- a/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/face/FaceStatusUtilsTest.java
@@ -115,6 +115,20 @@
}
@Test
+ public void hasEnrolled_withEnrolledTemplates_returnsTrue() {
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+
+ assertThat(mFaceStatusUtils.hasEnrolled()).isTrue();
+ }
+
+ @Test
+ public void hasEnrolled_withoutEnrolledTemplates_returnsFalse() {
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+
+ assertThat(mFaceStatusUtils.hasEnrolled()).isFalse();
+ }
+
+ @Test
public void getDisabledAdmin_whenFaceDisabled_returnsEnforcedAdmin() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
diff --git a/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java b/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
index cbe4298..4ecf82e 100644
--- a/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
+++ b/tests/unit/src/com/android/settings/biometrics/fingerprint/FingerprintStatusUtilsTest.java
@@ -119,6 +119,20 @@
}
@Test
+ public void hasEnrolled_withEnrolledFingerprints_returnsTrue() {
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
+
+ assertThat(mFingerprintStatusUtils.hasEnrolled()).isTrue();
+ }
+
+ @Test
+ public void hasEnrolled_withoutEnrolledFingerprints_returnsFalse() {
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+
+ assertThat(mFingerprintStatusUtils.hasEnrolled()).isFalse();
+ }
+
+ @Test
public void getDisabledAdmin_whenFingerprintDisabled_returnsEnforcedAdmin() {
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
index cc9bdfc..2cf9845 100644
--- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java
@@ -454,7 +454,7 @@
@Test
public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsAToPsimAndPort0_logicalSlot1() {
// There is only one enabled esimPort0 before user enables the psim.
- Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingPsimAndPort1();
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsA();
Collection<SubscriptionInfo> activeSubscriptionInfoList =
createActiveSubscriptionInfoListOneSim(0, 0);
SubscriptionInfo removedSubInfo = null;
@@ -469,7 +469,7 @@
@Test
public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort1_logicalSlot1() {
// There is only one enabled esimPort1 before user enables the psim.
- Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingPsimAndPort1();
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsB();
Collection<SubscriptionInfo> activeSubscriptionInfoList =
createActiveSubscriptionInfoListOneSim(0, 1);
SubscriptionInfo removedSubInfo = null;
@@ -484,7 +484,7 @@
@Test
public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort0_logicalSlot0() {
// There is only one enabled esimPort0 before user enables the psim.
- Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingPsimAndPort1();
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsB();
Collection<SubscriptionInfo> activeSubscriptionInfoList =
createActiveSubscriptionInfoListOneSim(1, 0);
SubscriptionInfo removedSubInfo = null;
@@ -552,6 +552,48 @@
assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
}
+ @Test
+ public void getExcludedLogicalSlotIndex_noEsimAndFromDualPortsAToPsimAndPort1_logicalSlot0() {
+ // There is no profiles enabled on either esim port before user enables the psim.
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsA();
+ Collection<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<>();
+ SubscriptionInfo removedSubInfo = null;
+ int verifyExcludedLogicalSlotIndex = 0;
+
+ int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex(
+ uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true);
+
+ assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
+ }
+
+ @Test
+ public void getExcludedLogicalSlotIndex_noEsimAndFromDualPortsBToPsimAndPort0_logicalSlot0() {
+ // There is no profiles enabled on either esim port before user enables the psim.
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsB();
+ Collection<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<>();
+ SubscriptionInfo removedSubInfo = null;
+ int verifyExcludedLogicalSlotIndex = 0;
+
+ int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex(
+ uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true);
+
+ assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
+ }
+
+ @Test
+ public void getExcludedLogicalSlotIndex_noEsimNoOrdingFromDualPortsBToPsimAndPort1_logical0() {
+ // There is no profiles enabled on either esim port before user enables the psim.
+ Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsBNoOrding();
+ Collection<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<>();
+ SubscriptionInfo removedSubInfo = null;
+ int verifyExcludedLogicalSlotIndex = 0;
+
+ int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex(
+ uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true);
+
+ assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex);
+ }
+
private void compareTwoUiccSlotMappings(Collection<UiccSlotMapping> testUiccSlotMappings,
Collection<UiccSlotMapping> verifyUiccSlotMappings) {
assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size());
@@ -656,7 +698,13 @@
return slotMap;
}
+ private List<UiccSlotMapping> createUiccSlotMappingDualPortsBNoOrding() {
+ List<UiccSlotMapping> slotMap = new ArrayList<>();
+ slotMap.add(new UiccSlotMapping(0, ESIM_PHYSICAL_SLOT, 1));
+ slotMap.add(new UiccSlotMapping(1, ESIM_PHYSICAL_SLOT, 0));
+ return slotMap;
+ }
/**
* The "oneSimSlotDevice" has below cases
* 1) The device is one psim slot and no esim slot
diff --git a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
index 13778f7..3030f0c 100644
--- a/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/BiometricsSafetySourceTest.java
@@ -23,6 +23,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -112,8 +113,8 @@
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
- verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
- any(), any(), any(), any());
+ verify(mSafetyCenterManagerWrapper, never())
+ .setSafetySourceData(any(), any(), any(), any());
}
@Test
@@ -124,8 +125,8 @@
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
- verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
- any(), any(), any(), any());
+ verify(mSafetyCenterManagerWrapper, never())
+ .setSafetySourceData(any(), any(), any(), any());
}
@Test
@@ -137,11 +138,9 @@
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
- ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
- verify(mSafetyCenterManagerWrapper).setSafetySourceData(
- any(), captor.capture(), any(), any());
- assertThat(captor.getValue()).isEqualTo(BiometricsSafetySource.SAFETY_SOURCE_ID);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), any(), any());
}
@Test
@@ -153,11 +152,9 @@
when(mDevicePolicyManager.getKeyguardDisabledFeatures(COMPONENT_NAME)).thenReturn(0);
BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
- ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
- verify(mSafetyCenterManagerWrapper).setSafetySourceData(
- any(), any(), any(), captor.capture());
- assertThat(captor.getValue()).isEqualTo(EVENT_SOURCE_STATE_CHANGED);
+ verify(mSafetyCenterManagerWrapper)
+ .setSafetySourceData(any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
}
@Test
@@ -429,6 +426,128 @@
Settings.CombinedBiometricSettingsActivity.class.getName());
}
+ @Test
+ public void setSafetySourceData_faceAndFingerprint_whenFaceEnrolled_setsOkStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
+ }
+
+ @Test
+ public void setSafetySourceData_faceAndFingerprint_whenFingerprintEnrolled_setsOkStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
+ }
+
+ @Test
+ public void setSafetySourceData_faceAndFingerprint_whenNotEnrolled_setsNoneStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_NONE);
+ }
+
+ @Test
+ public void setSafetySourceData_fingerprint_whenEnrolled_setsOKStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(false);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(true);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
+ }
+
+ @Test
+ public void setSafetySourceData_fingerprint_whenNotEnrolled_setsNoneStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.isHardwareDetected()).thenReturn(false);
+ when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_NONE);
+ }
+
+ @Test
+ public void setSafetySourceData_face_whenEnrolled_setsOKStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(true);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
+ }
+
+ @Test
+ public void setSafetySourceData_face_whenNotEnrolled_setsNoneStatus() {
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+ when(mFaceManager.hasEnrolledTemplates(anyInt())).thenReturn(false);
+
+ BiometricsSafetySource.setSafetySourceData(mApplicationContext, EVENT_SOURCE_STATE_CHANGED);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).setSafetySourceData(
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
+ SafetySourceStatus safetySourceStatus = captor.getValue().getStatus();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_NONE);
+ }
+
private void assertSafetySourceDisabledDataSetWithSingularSummary(String expectedTitleResName,
String expectedSummaryResName) {
assertSafetySourceDisabledDataSet(
@@ -478,13 +597,16 @@
private void assertSafetySourceDisabledDataSet(String expectedTitle, String expectedSummary) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
- any(), any(), captor.capture(), any());
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo(expectedTitle);
assertThat(safetySourceStatus.getSummary().toString()).isEqualTo(expectedSummary);
assertThat(safetySourceStatus.isEnabled()).isFalse();
+ assertThat(safetySourceStatus.getStatusLevel())
+ .isEqualTo(SafetySourceStatus.STATUS_LEVEL_NONE);
+
final Intent clickIntent = safetySourceStatus.getPendingIntent().getIntent();
assertThat(clickIntent).isNotNull();
assertThat(clickIntent.getAction()).isEqualTo(ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
@@ -494,7 +616,7 @@
String expectedSettingsClassName) {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
- any(), any(), captor.capture(), any());
+ any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -509,7 +631,6 @@
.isEqualTo(expectedSettingsClassName);
}
-
private List<Fingerprint> createFingerprintList(int size) {
final List<Fingerprint> fingerprintList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {