OSDN Git Service

1/n Start adding Face settings (base, intro)
authorKevin Chyn <kchyn@google.com>
Tue, 26 Jun 2018 00:58:31 +0000 (17:58 -0700)
committerKevin Chyn <kchyn@google.com>
Sat, 30 Jun 2018 01:19:34 +0000 (18:19 -0700)
This change refactors common biometric settings code as well to minimize
duplicated code in areas such as:
    Preference Controller
    EnrollBase
    EnrollIntro

This change also updates ChooseLock to have Face + Pin/Pattern/Pass

Bug: 110589286

Test: Fingerprint settings/enrollment still works
Test: make -j56 RunSettingsRoboTests
Change-Id: Ie35406a01b85617423beece42683ac086e9bc4a7

31 files changed:
AndroidManifest.xml
res/drawable/face_enroll_introduction.xml [new file with mode: 0644]
res/drawable/ic_face_header.xml [new file with mode: 0644]
res/layout/face_enroll_introduction.xml [new file with mode: 0644]
res/layout/face_enroll_introduction_footer.xml [new file with mode: 0644]
res/values/strings.xml
res/values/styles.xml
res/values/themes.xml
res/xml/security_dashboard_settings.xml
src/com/android/settings/Utils.java
src/com/android/settings/biometrics/BiometricEnrollBase.java [moved from src/com/android/settings/biometrics/fingerprint/FingerprintEnrollBase.java with 86% similarity]
src/com/android/settings/biometrics/BiometricEnrollIntroduction.java [new file with mode: 0644]
src/com/android/settings/biometrics/BiometricSettings.java [new file with mode: 0644]
src/com/android/settings/biometrics/BiometricStatusPreferenceController.java [new file with mode: 0644]
src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java [new file with mode: 0644]
src/com/android/settings/biometrics/face/FaceStatusPreferenceController.java [new file with mode: 0644]
src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java
src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroduction.java
src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
src/com/android/settings/biometrics/fingerprint/FingerprintStatusPreferenceController.java
src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFinish.java
src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroduction.java
src/com/android/settings/password/ChooseLockGeneric.java
src/com/android/settings/security/SecuritySettings.java
tests/robotests/src/com/android/settings/biometrics/face/FaceStatusPreferenceControllerTest.java [new file with mode: 0644]
tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintStatusPreferenceControllerTest.java
tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollIntroductionTest.java

index 6a2af9e..5595d44 100644 (file)
             android:windowSoftInputMode="stateHidden|adjustResize"
             android:theme="@style/GlifTheme.Light"/>
 
+        <activity android:name=".biometrics.face.FaceEnrollIntroduction" android:exported="false" />
+
         <activity android:name=".biometrics.fingerprint.FingerprintSettings" android:exported="false"/>
         <activity android:name=".biometrics.fingerprint.FingerprintEnrollFindSensor" android:exported="false"/>
         <activity android:name=".biometrics.fingerprint.FingerprintEnrollEnrolling" android:exported="false"/>
diff --git a/res/drawable/face_enroll_introduction.xml b/res/drawable/face_enroll_introduction.xml
new file mode 100644 (file)
index 0000000..4493d66
--- /dev/null
@@ -0,0 +1,23 @@
+<!--
+  ~ Copyright (C) 2018 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M9,11.75A1.25,1.25 0 0,0 7.75,13A1.25,1.25 0 0,0 9,14.25A1.25,1.25 0 0,0 10.25,13A1.25,1.25 0 0,0 9,11.75M15,11.75A1.25,1.25 0 0,0 13.75,13A1.25,1.25 0 0,0 15,14.25A1.25,1.25 0 0,0 16.25,13A1.25,1.25 0 0,0 15,11.75M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20C7.59,20 4,16.41 4,12C4,11.71 4,11.42 4.05,11.14C6.41,10.09 8.28,8.16 9.26,5.77C11.07,8.33 14.05,10 17.42,10C18.2,10 18.95,9.91 19.67,9.74C19.88,10.45 20,11.21 20,12C20,16.41 16.41,20 12,20Z" />
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_face_header.xml b/res/drawable/ic_face_header.xml
new file mode 100644 (file)
index 0000000..4493d66
--- /dev/null
@@ -0,0 +1,23 @@
+<!--
+  ~ Copyright (C) 2018 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M9,11.75A1.25,1.25 0 0,0 7.75,13A1.25,1.25 0 0,0 9,14.25A1.25,1.25 0 0,0 10.25,13A1.25,1.25 0 0,0 9,11.75M15,11.75A1.25,1.25 0 0,0 13.75,13A1.25,1.25 0 0,0 15,14.25A1.25,1.25 0 0,0 16.25,13A1.25,1.25 0 0,0 15,11.75M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20C7.59,20 4,16.41 4,12C4,11.71 4,11.42 4.05,11.14C6.41,10.09 8.28,8.16 9.26,5.77C11.07,8.33 14.05,10 17.42,10C18.2,10 18.95,9.91 19.67,9.74C19.88,10.45 20,11.21 20,12C20,16.41 16.41,20 12,20Z" />
+</vector>
\ No newline at end of file
diff --git a/res/layout/face_enroll_introduction.xml b/res/layout/face_enroll_introduction.xml
new file mode 100644 (file)
index 0000000..a56bca5
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2018 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
+  -->
+
+<com.android.setupwizardlib.GlifLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    style="?attr/face_layout_theme"
+    android:id="@+id/setup_wizard_layout"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:suwFooter="@layout/face_enroll_introduction_footer">
+
+    <LinearLayout
+        style="@style/SuwContentFrame"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:clipChildren="false"
+        android:clipToPadding="false"
+        android:orientation="vertical">
+
+        <com.android.setupwizardlib.view.RichTextView
+            android:id="@+id/description_text"
+            style="@style/SuwDescription.Glif"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/security_settings_face_enroll_introduction_message" />
+
+        <com.android.setupwizardlib.view.RichTextView
+            android:id="@+id/error_text"
+            style="@style/SuwDescription.Glif"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <com.android.setupwizardlib.view.FillContentLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight="1">
+
+            <ImageView
+                style="@style/SuwContentIllustration"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:contentDescription="@null"
+                android:src="@drawable/face_enroll_introduction" />
+
+        </com.android.setupwizardlib.view.FillContentLayout>
+
+    </LinearLayout>
+
+</com.android.setupwizardlib.GlifLayout>
diff --git a/res/layout/face_enroll_introduction_footer.xml b/res/layout/face_enroll_introduction_footer.xml
new file mode 100644 (file)
index 0000000..0fcc13b
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2018 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
+  -->
+
+<!-- TODO: Use aapt:attr when it is fixed (b/36809755) -->
+<com.android.setupwizardlib.view.ButtonBarLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    style="@style/SuwGlifButtonBar.Stackable"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <Button
+        android:id="@+id/face_cancel_button"
+        style="@style/SuwGlifButton.Secondary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/security_settings_face_enroll_introduction_cancel" />
+
+    <Space
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_weight="1" />
+
+    <Button
+        android:id="@+id/face_next_button"
+        style="@style/SuwGlifButton.Primary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/suw_next_button_label" />
+
+</com.android.setupwizardlib.view.ButtonBarLayout>
index d799ea5..0ff5318 100644 (file)
     <string name="security_dashboard_summary">Screen lock, fingerprint</string>
     <!-- Summary for Security settings when fingerprint is not supported [CHAR LIMIT=NONE]-->
     <string name="security_dashboard_summary_no_fingerprint">Screen lock</string>
+
+    <!-- Face enrollment and settings --><skip />
+    <!-- Message shown in summary field when face authentication is set up. [CHAR LIMIT=22] -->
+    <string name="security_settings_face_preference_summary">Face added</string>
+    <!-- Message shown in summary field when face authentication is not set up. [CHAR LIMIT=40] -->
+    <string name="security_settings_face_preference_summary_none">Tap to set up face authentication</string>
+    <!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=22] -->
+    <string name="security_settings_face_preference_title">Face authentication</string>
+    <!-- Button text to cancel enrollment from the introduction [CHAR LIMIT=22] -->
+    <string name="security_settings_face_enroll_introduction_cancel">Cancel</string>
+    <!-- Introduction title shown in face enrollment to introduce the face unlock feature [CHAR LIMIT=30] -->
+    <string name="security_settings_face_enroll_introduction_title">Unlock with your face</string>
+    <!-- Introduction title shown in face enrollment to introduce the face authentication feature, when face unlock is disabled by device admin [CHAR LIMIT=40] -->
+    <string name="security_settings_face_enroll_introduction_title_unlock_disabled">Use your face to authenticate</string>
+    <!-- Introduction detail message shown in face enrollment dialog [CHAR LIMIT=NONE]-->
+    <string name="security_settings_face_enroll_introduction_message">Use your face to unlock your phone, authorize purchases, or sign in to apps.</string>
+    <!-- Introduction detail message shown in face enrollment dialog, when face unlock is disabled by device admin [CHAR LIMIT=NONE] -->
+    <string name="security_settings_face_enroll_introduction_message_unlock_disabled">Use you</string>
+    <!-- Introduction detail message shwon in face enrollment screen in setup wizard. [CHAR LIMIT=NONE] -->
+    <string name="security_settings_face_enroll_introduction_message_setup">Use your face to unlock your phone, authorize purchases, or sign in to apps</string>
+    <!-- Text shown when "Add face" button is disabled -->
+    <string name="face_add_max">You can add up to <xliff:g id="count" example="5">%d</xliff:g> fingerprints</string>
+    <!-- Text shown when users has enrolled a maximum number of faces [CHAR LIMIT=NONE] -->
+    <string name="face_intro_error_max">You\u2019ve added the maximum number of faces</string>
+    <!-- Text shown when an unknown error caused the device to be unable to add faces [CHAR LIMIT=NONE] -->
+    <string name="face_intro_error_unknown">Can\u2019t add more faces</string>
+
     <!-- Fingerprint enrollment and settings --><skip />
     <!-- Title shown for menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
     <string name="security_settings_fingerprint_preference_title">Fingerprint</string>
 
     <!-- Search keyword for Ambient display settings screen. -->
     <string name="keywords_ambient_display_screen">Ambient display, Lock screen display</string>
+
+    <!-- Search keyword for face settings. -->
+    <string name="keywords_face_settings">face</string>
+
     <!-- Search keyword for fingerprint settings. -->
     <string name="keywords_fingerprint_settings">fingerprint</string>
 
index 37219d6..ba462d8 100644 (file)
         <item name="android:icon">@drawable/ic_fingerprint_header</item>
     </style>
 
+    <style name="FaceLayoutTheme">
+        <item name="android:icon">@drawable/ic_face_header</item>
+    </style>
+
     <style name="TextAppearance.ConfirmDeviceCredentialsErrorText"
         parent="android:TextAppearance.Material.Body1">
         <item name="android:textColor">?android:attr/colorError</item>
index 8c38649..13d516b 100644 (file)
@@ -16,6 +16,7 @@
 
 <resources>
     <attr name="fingerprint_layout_theme" format="reference" />
+    <attr name="face_layout_theme" format="reference" />
     <attr name="ic_menu_moreoverflow" format="reference" />
     <attr name="side_margin" format="reference|dimension" />
     <attr name="wifi_signal_color" format="reference" />
@@ -26,6 +27,7 @@
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
@@ -44,6 +46,7 @@
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
@@ -62,6 +65,7 @@
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
@@ -80,6 +84,7 @@
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
         <item name="android:windowBackground">?android:attr/colorBackground</item>
         <item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
         <item name="side_margin">0dip</item>
         <item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
         <item name="*android:preferenceFragmentPaddingSide">@dimen/settings_side_margin</item>
 
         <item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
+        <item name="face_layout_theme">@style/FaceLayoutTheme</item>
         <item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_holo_dark</item>
         <item name="wifi_signal">@drawable/wifi_signal</item>
         <item name="wifi_signal_color">?android:attr/colorAccent</item>
index 8a3d108..e543ad9 100644 (file)
             android:summary="@string/summary_placeholder"
             settings:keywords="@string/keywords_fingerprint_settings" />
 
+        <Preference
+            android:key="face_settings"
+            android:title="@string/security_settings_face_preference_title"
+            android:summary="@string/summary_placeholder"
+            settings:keywords="@string/keywords_face_settings" />
     </PreferenceCategory>
 
     <!-- work profile security section -->
index 2a1d8c4..109bbf9 100644 (file)
@@ -49,6 +49,7 @@ import android.graphics.Canvas;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.VectorDrawable;
+import android.hardware.face.FaceManager;
 import android.hardware.fingerprint.FingerprintManager;
 import android.net.ConnectivityManager;
 import android.net.LinkProperties;
@@ -813,6 +814,19 @@ public final class Utils extends com.android.settingslib.Utils {
         return fingerprintManager != null && fingerprintManager.isHardwareDetected();
     }
 
+    public static FaceManager getFaceManagerOrNull(Context context) {
+        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
+            return (FaceManager) context.getSystemService(Context.FACE_SERVICE);
+        } else {
+            return null;
+        }
+    }
+
+    public static boolean hasFaceHardware(Context context) {
+        FaceManager faceManager = getFaceManagerOrNull(context);
+        return faceManager != null && faceManager.isHardwareDetected();
+    }
+
     /**
      * Launches an intent which may optionally have a user id defined.
      * @param fragment Fragment to use to launch the activity.
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -14,7 +14,7 @@
  * limitations under the License
  */
 
-package com.android.settings.biometrics.fingerprint;
+package com.android.settings.biometrics;
 
 import android.annotation.Nullable;
 import android.content.Intent;
@@ -29,6 +29,8 @@ import android.widget.TextView;
 
 import com.android.settings.R;
 import com.android.settings.SetupWizardUtils;
+import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
+import com.android.settings.biometrics.fingerprint.FingerprintSettings;
 import com.android.settings.core.InstrumentedActivity;
 import com.android.settings.password.ChooseLockSettingsHelper;
 import com.android.setupwizardlib.GlifLayout;
@@ -36,11 +38,11 @@ import com.android.setupwizardlib.GlifLayout;
 /**
  * Base activity for all fingerprint enrollment steps.
  */
-public abstract class FingerprintEnrollBase extends InstrumentedActivity
+public abstract class BiometricEnrollBase extends InstrumentedActivity
         implements View.OnClickListener {
-    public static final int RESULT_FINISHED = FingerprintSettings.RESULT_FINISHED;
-    static final int RESULT_SKIP = FingerprintSettings.RESULT_SKIP;
-    static final int RESULT_TIMEOUT = FingerprintSettings.RESULT_TIMEOUT;
+    public static final int RESULT_FINISHED = BiometricSettings.RESULT_FINISHED;
+    public static final int RESULT_SKIP = BiometricSettings.RESULT_SKIP;
+    public static final int RESULT_TIMEOUT = BiometricSettings.RESULT_TIMEOUT;
 
     protected byte[] mToken;
     protected int mUserId;
@@ -118,7 +120,7 @@ public abstract class FingerprintEnrollBase extends InstrumentedActivity
     protected void onNextButtonClick() {
     }
 
-    protected Intent getEnrollingIntent() {
+    protected Intent getFingerprintEnrollingIntent() {
         Intent intent = new Intent();
         intent.setClassName("com.android.settings", FingerprintEnrollEnrolling.class.getName());
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
new file mode 100644 (file)
index 0000000..98775f2
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.password.ChooseLockGeneric;
+import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.setupwizardlib.span.LinkSpan;
+
+/**
+ * Abstract base class for the intro onboarding activity for biometric enrollment.
+ */
+public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
+        implements LinkSpan.OnClickListener {
+
+    public static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
+    public static final int BIOMETRIC_FIND_SENSOR_REQUEST = 2;
+    public static final int LEARN_MORE_REQUEST = 3;
+
+    private UserManager mUserManager;
+    private boolean mHasPassword;
+    private boolean mBiometricUnlockDisabledByAdmin;
+    private TextView mErrorText;
+
+    /**
+     * @return true if the biometric is disabled by a device administrator
+     */
+    protected abstract boolean isDisabledByAdmin();
+
+    /**
+     * @return the layout resource
+     */
+    protected abstract int getLayoutResource();
+
+    /**
+     * @return the header resource for if the biometric has been disabled by a device administrator
+     */
+    protected abstract int getHeaderResDisabledByAdmin();
+
+    /**
+     * @return the default header resource
+     */
+    protected abstract int getHeaderResDefault();
+
+    /**
+     * @return the description resource for if the biometric has been disabled by a device admin
+     */
+    protected abstract int getDescriptionResDisabledByAdmin();
+
+    /**
+     * @return the cancel button
+     */
+    protected abstract Button getCancelButton();
+
+    /**
+     * @return the next button
+     */
+    protected abstract Button getNextButton();
+
+    /**
+     * @return the error TextView
+     */
+    protected abstract TextView getErrorTextView();
+
+    /**
+     * @return 0 if there are no errors, otherwise returns the resource ID for the error string
+     * to be displayed.
+     */
+    protected abstract int checkMaxEnrolled();
+
+    /**
+     * @return the challenge generated by the biometric hardware
+     */
+    protected abstract long getChallenge();
+
+    /**
+     * @return one of the ChooseLockSettingsHelper#EXTRA_KEY_FOR_* constants
+     */
+    protected abstract String getExtraKeyForBiometric();
+
+    /**
+     * @return the intent for proceeding to the next step of enrollment
+     */
+    protected abstract Intent getFindSensorIntent();
+
+    /**
+     * @param span
+     */
+    public abstract void onClick(LinkSpan span);
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mBiometricUnlockDisabledByAdmin = isDisabledByAdmin();
+
+        setContentView(getLayoutResource());
+        if (mBiometricUnlockDisabledByAdmin) {
+            setHeaderText(getHeaderResDisabledByAdmin());
+        } else {
+            setHeaderText(getHeaderResDefault());
+        }
+
+        Button cancelButton = getCancelButton();
+        cancelButton.setOnClickListener(v -> onCancelButtonClick());
+
+        mErrorText = getErrorTextView();
+
+        mUserManager = UserManager.get(this);
+        updatePasswordQuality();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+
+        final int errorMsg = checkMaxEnrolled();
+        if (errorMsg == 0) {
+            mErrorText.setText(null);
+            getNextButton().setVisibility(View.VISIBLE);
+        } else {
+            mErrorText.setText(errorMsg);
+            getNextButton().setVisibility(View.GONE);
+        }
+    }
+
+    private void updatePasswordQuality() {
+        final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
+                .getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId));
+        mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+    }
+
+    @Override
+    protected void onNextButtonClick() {
+        if (!mHasPassword) {
+            // No biometrics registered, launch into enrollment wizard.
+            launchChooseLock();
+        } else {
+            // Lock thingy is already set up, launch directly into find sensor step from wizard.
+            launchFindSensor(null);
+        }
+    }
+
+    private void launchChooseLock() {
+        Intent intent = getChooseLockIntent();
+        long challenge = getChallenge();
+        intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
+                DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
+        intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
+        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
+        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
+        intent.putExtra(getExtraKeyForBiometric(), true);
+        if (mUserId != UserHandle.USER_NULL) {
+            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
+        }
+        startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
+    }
+
+    private void launchFindSensor(byte[] token) {
+        Intent intent = getFindSensorIntent();
+        if (token != null) {
+            intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
+        }
+        if (mUserId != UserHandle.USER_NULL) {
+            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
+        }
+        startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST);
+    }
+
+    protected Intent getChooseLockIntent() {
+        return new Intent(this, ChooseLockGeneric.class);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        final boolean isResultFinished = resultCode == RESULT_FINISHED;
+        if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST) {
+            if (isResultFinished || resultCode == RESULT_SKIP) {
+                final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
+                setResult(result, data);
+                finish();
+                return;
+            }
+        } else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
+            if (isResultFinished) {
+                updatePasswordQuality();
+                byte[] token = data.getByteArrayExtra(
+                        ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
+                launchFindSensor(token);
+                return;
+            }
+        } else if (requestCode == LEARN_MORE_REQUEST) {
+            overridePendingTransition(R.anim.suw_slide_back_in, R.anim.suw_slide_back_out);
+        }
+        super.onActivityResult(requestCode, resultCode, data);
+    }
+
+    protected void onCancelButtonClick() {
+        finish();
+    }
+
+    @Override
+    protected void initViews() {
+        super.initViews();
+
+        TextView description = (TextView) findViewById(R.id.description_text);
+        if (mBiometricUnlockDisabledByAdmin) {
+            description.setText(getDescriptionResDisabledByAdmin());
+        }
+    }
+}
diff --git a/src/com/android/settings/biometrics/BiometricSettings.java b/src/com/android/settings/biometrics/BiometricSettings.java
new file mode 100644 (file)
index 0000000..ccb4c5e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 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;
+
+import com.android.settings.SubSettings;
+
+/**
+ * Abstract base class for biometric settings, such as Fingerprint, Face, Iris
+ */
+public abstract class BiometricSettings extends SubSettings {
+    /**
+     * Used by the choose fingerprint wizard to indicate the wizard is
+     * finished, and each activity in the wizard should finish.
+     * <p>
+     * Previously, each activity in the wizard would finish itself after
+     * starting the next activity. However, this leads to broken 'Back'
+     * behavior. So, now an activity does not finish itself until it gets this
+     * result.
+     */
+    protected static final int RESULT_FINISHED = RESULT_FIRST_USER;
+
+    /**
+     * Used by the enrolling screen during setup wizard to skip over setting up fingerprint, which
+     * will be useful if the user accidentally entered this flow.
+     */
+    protected static final int RESULT_SKIP = RESULT_FIRST_USER + 1;
+
+    /**
+     * Like {@link #RESULT_FINISHED} except this one indicates enrollment failed because the
+     * device was left idle. This is used to clear the credential token to require the user to
+     * re-enter their pin/pattern/password before continuing.
+     */
+    protected static final int RESULT_TIMEOUT = RESULT_FIRST_USER + 2;
+}
diff --git a/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java b/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java
new file mode 100644 (file)
index 0000000..4a52ef3
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.Utils;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+import androidx.preference.Preference;
+
+public abstract class BiometricStatusPreferenceController extends BasePreferenceController {
+
+    protected final UserManager mUm;
+    protected final LockPatternUtils mLockPatternUtils;
+
+    protected final int mUserId = UserHandle.myUserId();
+    protected final int mProfileChallengeUserId;
+
+    /**
+     * @return true if the manager is not null and the hardware is detected.
+     */
+    protected abstract boolean isDeviceSupported();
+
+    /**
+     * @return true if the user has enrolled biometrics of the subclassed type.
+     */
+    protected abstract boolean hasEnrolledBiometrics();
+
+    /**
+     * @return the summary text if biometrics are enrolled.
+     */
+    protected abstract String getSummaryTextEnrolled();
+
+    /**
+     * @return the summary text if no biometrics are enrolled.
+     */
+    protected abstract String getSummaryTextNoneEnrolled();
+
+    /**
+     * @return the class name for the settings page.
+     */
+    protected abstract String getSettingsClassName();
+
+    /**
+     * @return the class name for entry to enrollment.
+     */
+    protected abstract String getEnrollClassName();
+
+    public BiometricStatusPreferenceController(Context context, String key) {
+        super(context, key);
+        mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        mLockPatternUtils = FeatureFactory.getFactory(context)
+                .getSecurityFeatureProvider()
+                .getLockPatternUtils(context);
+        mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        if (!isDeviceSupported()) {
+            return UNSUPPORTED_ON_DEVICE;
+        }
+        if (isUserSupported()) {
+            return AVAILABLE;
+        } else {
+            return DISABLED_FOR_USER;
+        }
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        if (!isAvailable()) {
+            if (preference != null) {
+                preference.setVisible(false);
+            }
+            return;
+        } else {
+            preference.setVisible(true);
+        }
+        final int userId = getUserId();
+        final String clazz;
+        if (hasEnrolledBiometrics()) {
+            preference.setSummary(getSummaryTextEnrolled());
+            clazz = getSettingsClassName();
+        } else {
+            preference.setSummary(getSummaryTextNoneEnrolled());
+            clazz = getEnrollClassName();
+        }
+        preference.setOnPreferenceClickListener(target -> {
+            final Context context = target.getContext();
+            final UserManager userManager = UserManager.get(context);
+            if (Utils.startQuietModeDialogIfNecessary(context, userManager,
+                    userId)) {
+                return false;
+            }
+            Intent intent = new Intent();
+            intent.setClassName("com.android.settings", clazz);
+            intent.putExtra(Intent.EXTRA_USER_ID, userId);
+            context.startActivity(intent);
+            return true;
+        });
+    }
+
+    protected int getUserId() {
+        return mUserId;
+    }
+
+    protected boolean isUserSupported() {
+        return true;
+    }
+}
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
new file mode 100644 (file)
index 0000000..b4a33f3
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2018 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.face;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.hardware.face.FaceManager;
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricEnrollIntroduction;
+import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.setupwizardlib.span.LinkSpan;
+
+public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
+
+    private static final String TAG = "FaceIntro";
+
+    private FaceManager mFaceManager;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mFaceManager = Utils.getFaceManagerOrNull(this);
+    }
+
+    @Override
+    protected boolean isDisabledByAdmin() {
+        return RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
+                this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
+    }
+
+    @Override
+    protected int getLayoutResource() {
+        return R.layout.face_enroll_introduction;
+    }
+
+    @Override
+    protected int getHeaderResDisabledByAdmin() {
+        return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
+    }
+
+    @Override
+    protected int getHeaderResDefault() {
+        return R.string.security_settings_face_enroll_introduction_title;
+    }
+
+    @Override
+    protected int getDescriptionResDisabledByAdmin() {
+        return R.string.security_settings_fingerprint_enroll_introduction_message_unlock_disabled;
+    }
+
+    @Override
+    protected Button getCancelButton() {
+        return findViewById(R.id.face_cancel_button);
+    }
+
+    @Override
+    protected Button getNextButton() {
+        return findViewById(R.id.face_next_button);
+    }
+
+    @Override
+    protected TextView getErrorTextView() {
+        return findViewById(R.id.error_text);
+    }
+
+    @Override
+    protected int checkMaxEnrolled() {
+        if (mFaceManager != null) {
+            final int max = getResources().getInteger(
+                    com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
+            final int numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
+            if (numEnrolledFaces >= max) {
+                return R.string.face_intro_error_max;
+            }
+        } else {
+            return R.string.face_intro_error_unknown;
+        }
+        return 0;
+    }
+
+    @Override
+    protected long getChallenge() {
+        if (mFaceManager == null) {
+            return 0;
+        }
+        return mFaceManager.preEnroll();
+    }
+
+    @Override
+    protected String getExtraKeyForBiometric() {
+        return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
+    }
+
+    @Override
+    protected Intent getFindSensorIntent() {
+        return null; // TODO
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.FACE_ENROLL_INTRO;
+    }
+
+    @Override
+    public void onClick(LinkSpan span) {
+        // TODO(b/110906762)
+    }
+}
diff --git a/src/com/android/settings/biometrics/face/FaceStatusPreferenceController.java b/src/com/android/settings/biometrics/face/FaceStatusPreferenceController.java
new file mode 100644 (file)
index 0000000..96f22e0
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 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.face;
+
+import android.content.Context;
+import android.hardware.face.FaceManager;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricStatusPreferenceController;
+
+public class FaceStatusPreferenceController extends BiometricStatusPreferenceController {
+
+    private static final String KEY_FACE_SETTINGS = "face_settings";
+
+    protected final FaceManager mFaceManager;
+
+    public FaceStatusPreferenceController(Context context) {
+        this(context, KEY_FACE_SETTINGS);
+    }
+
+    public FaceStatusPreferenceController(Context context, String key) {
+        super(context, key);
+        mFaceManager = Utils.getFaceManagerOrNull(context);
+    }
+
+    @Override
+    protected boolean isDeviceSupported() {
+        return mFaceManager != null && mFaceManager.isHardwareDetected();
+    }
+
+    @Override
+    protected boolean hasEnrolledBiometrics() {
+        return mFaceManager.hasEnrolledFaces(mUserId);
+    }
+
+    @Override
+    protected String getSummaryTextEnrolled() {
+        return mContext.getResources()
+                .getString(R.string.security_settings_face_preference_summary);
+    }
+
+    @Override
+    protected String getSummaryTextNoneEnrolled() {
+        return mContext.getResources()
+                .getString(R.string.security_settings_face_preference_summary_none);
+    }
+
+    @Override
+    protected String getSettingsClassName() {
+        return null;
+    }
+
+    @Override
+    protected String getEnrollClassName() {
+        return FaceEnrollIntroduction.class.getName();
+    }
+
+}
index 2b7a20b..9b0d1a6 100644 (file)
@@ -44,13 +44,14 @@ import android.widget.TextView;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
+import com.android.settings.biometrics.BiometricEnrollBase;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
 import com.android.settings.password.ChooseLockSettingsHelper;
 
 /**
  * Activity which handles the actual enrolling for fingerprint.
  */
-public class FingerprintEnrollEnrolling extends FingerprintEnrollBase
+public class FingerprintEnrollEnrolling extends BiometricEnrollBase
         implements FingerprintEnrollSidecar.Listener {
 
     static final String TAG_SIDECAR = "sidecar";
index bc01458..047dda8 100644 (file)
@@ -27,6 +27,7 @@ import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricEnrollBase;
 import com.android.settings.biometrics.fingerprint.FingerprintEnrollSidecar.Listener;
 import com.android.settings.password.ChooseLockSettingsHelper;
 
@@ -35,7 +36,7 @@ import androidx.annotation.Nullable;
 /**
  * Activity explaining the fingerprint sensor location for fingerprint enrollment.
  */
-public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
+public class FingerprintEnrollFindSensor extends BiometricEnrollBase {
 
     @VisibleForTesting
     static final int CONFIRM_REQUEST = 1;
@@ -166,7 +167,7 @@ public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
             }
             getFragmentManager().beginTransaction().remove(mSidecar).commitAllowingStateLoss();
             mSidecar = null;
-            startActivityForResult(getEnrollingIntent(), ENROLLING);
+            startActivityForResult(getFingerprintEnrollingIntent(), ENROLLING);
         }
     }
 
index 8b175ec..db6b5bc 100644 (file)
@@ -25,11 +25,12 @@ import android.widget.Button;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricEnrollBase;
 
 /**
  * Activity which concludes fingerprint enrollment.
  */
-public class FingerprintEnrollFinish extends FingerprintEnrollBase {
+public class FingerprintEnrollFinish extends BiometricEnrollBase {
 
     private static final int REQUEST_ADD_ANOTHER = 1;
 
@@ -71,7 +72,7 @@ public class FingerprintEnrollFinish extends FingerprintEnrollBase {
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.add_another_button) {
-            startActivityForResult(getEnrollingIntent(), REQUEST_ADD_ANOTHER);
+            startActivityForResult(getFingerprintEnrollingIntent(), REQUEST_ADD_ANOTHER);
         }
         super.onClick(v);
     }
index dfcdace..ed111f4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -21,195 +21,109 @@ import android.content.ActivityNotFoundException;
 import android.content.Intent;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.Bundle;
-import android.os.UserHandle;
-import android.os.UserManager;
 import android.util.Log;
-import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;
 
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
 import com.android.settings.Utils;
-import com.android.settings.password.ChooseLockGeneric;
+import com.android.settings.biometrics.BiometricEnrollIntroduction;
 import com.android.settings.password.ChooseLockSettingsHelper;
 import com.android.settingslib.HelpUtils;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.setupwizardlib.span.LinkSpan;
 
-/**
- * Onboarding activity for fingerprint enrollment.
- */
-public class FingerprintEnrollIntroduction extends FingerprintEnrollBase
-        implements View.OnClickListener, LinkSpan.OnClickListener {
+public class FingerprintEnrollIntroduction extends BiometricEnrollIntroduction {
 
     private static final String TAG = "FingerprintIntro";
 
-    protected static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
-    protected static final int FINGERPRINT_FIND_SENSOR_REQUEST = 2;
-    protected static final int LEARN_MORE_REQUEST = 3;
-
-    private UserManager mUserManager;
-    private boolean mHasPassword;
-    private boolean mFingerprintUnlockDisabledByAdmin;
-    private TextView mErrorText;
+    private FingerprintManager mFingerprintManager;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        mFingerprintUnlockDisabledByAdmin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
-                this, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId) != null;
-
-        setContentView(R.layout.fingerprint_enroll_introduction);
-        if (mFingerprintUnlockDisabledByAdmin) {
-            setHeaderText(R.string
-                    .security_settings_fingerprint_enroll_introduction_title_unlock_disabled);
-        } else {
-            setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
-        }
-
-        Button cancelButton = (Button) findViewById(R.id.fingerprint_cancel_button);
-        cancelButton.setOnClickListener(this);
-
-        mErrorText = (TextView) findViewById(R.id.error_text);
-
-        mUserManager = UserManager.get(this);
-        updatePasswordQuality();
+        mFingerprintManager = Utils.getFingerprintManagerOrNull(this);
     }
 
     @Override
-    protected void onResume() {
-        super.onResume();
-
-        final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(this);
-        int errorMsg = 0;
-        if (fingerprintManager != null) {
-            final int max = getResources().getInteger(
-                    com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
-            final int numEnrolledFingerprints =
-                    fingerprintManager.getEnrolledFingerprints(mUserId).size();
-            if (numEnrolledFingerprints >= max) {
-                errorMsg = R.string.fingerprint_intro_error_max;
-            }
-        } else {
-            errorMsg = R.string.fingerprint_intro_error_unknown;
-        }
-        if (errorMsg == 0) {
-            mErrorText.setText(null);
-            getNextButton().setVisibility(View.VISIBLE);
-        } else {
-            mErrorText.setText(errorMsg);
-            getNextButton().setVisibility(View.GONE);
-        }
+    protected boolean isDisabledByAdmin() {
+        return RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
+                this, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId) != null;
     }
 
-    private void updatePasswordQuality() {
-        final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
-                .getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId));
-        mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+    @Override
+    protected int getLayoutResource() {
+        return R.layout.fingerprint_enroll_introduction;
     }
 
     @Override
-    protected Button getNextButton() {
-        return (Button) findViewById(R.id.fingerprint_next_button);
+    protected int getHeaderResDisabledByAdmin() {
+        return R.string.security_settings_fingerprint_enroll_introduction_title_unlock_disabled;
     }
 
     @Override
-    protected void onNextButtonClick() {
-        if (!mHasPassword) {
-            // No fingerprints registered, launch into enrollment wizard.
-            launchChooseLock();
-        } else {
-            // Lock thingy is already set up, launch directly into find sensor step from wizard.
-            launchFindSensor(null);
-        }
+    protected int getHeaderResDefault() {
+        return R.string.security_settings_fingerprint_enroll_introduction_title;
     }
 
-    private void launchChooseLock() {
-        Intent intent = getChooseLockIntent();
-        long challenge = Utils.getFingerprintManagerOrNull(this).preEnroll();
-        intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
-                DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
-        intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
-        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
-        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
-        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true);
-        if (mUserId != UserHandle.USER_NULL) {
-            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
-        }
-        startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
+    @Override
+    protected int getDescriptionResDisabledByAdmin() {
+        return R.string.security_settings_fingerprint_enroll_introduction_message_unlock_disabled;
     }
 
-    private void launchFindSensor(byte[] token) {
-        Intent intent = getFindSensorIntent();
-        if (token != null) {
-            intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
-        }
-        if (mUserId != UserHandle.USER_NULL) {
-            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
-        }
-        startActivityForResult(intent, FINGERPRINT_FIND_SENSOR_REQUEST);
+    @Override
+    protected Button getCancelButton() {
+        return findViewById(R.id.fingerprint_cancel_button);
     }
 
-    protected Intent getChooseLockIntent() {
-        return new Intent(this, ChooseLockGeneric.class);
+    @Override
+    protected Button getNextButton() {
+        return findViewById(R.id.fingerprint_next_button);
     }
 
-    protected Intent getFindSensorIntent() {
-        return new Intent(this, FingerprintEnrollFindSensor.class);
+    @Override
+    protected TextView getErrorTextView() {
+        return findViewById(R.id.error_text);
     }
 
     @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        final boolean isResultFinished = resultCode == RESULT_FINISHED;
-        if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST) {
-            if (isResultFinished || resultCode == RESULT_SKIP) {
-                final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
-                setResult(result, data);
-                finish();
-                return;
-            }
-        } else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
-            if (isResultFinished) {
-                updatePasswordQuality();
-                byte[] token = data.getByteArrayExtra(
-                        ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
-                launchFindSensor(token);
-                return;
+    protected int checkMaxEnrolled() {
+        if (mFingerprintManager != null) {
+            final int max = getResources().getInteger(
+                    com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
+            final int numEnrolledFingerprints =
+                    mFingerprintManager.getEnrolledFingerprints(mUserId).size();
+            if (numEnrolledFingerprints >= max) {
+                return R.string.fingerprint_intro_error_max;
             }
-        } else if (requestCode == LEARN_MORE_REQUEST) {
-            overridePendingTransition(R.anim.suw_slide_back_in, R.anim.suw_slide_back_out);
+        } else {
+            return R.string.fingerprint_intro_error_unknown;
         }
-        super.onActivityResult(requestCode, resultCode, data);
+        return 0;
     }
 
     @Override
-    public void onClick(View v) {
-        if (v.getId() == R.id.fingerprint_cancel_button) {
-            onCancelButtonClick();
-        } else {
-            super.onClick(v);
+    protected long getChallenge() {
+        if (mFingerprintManager == null) {
+            return 0;
         }
+        return mFingerprintManager.preEnroll();
     }
 
     @Override
-    public int getMetricsCategory() {
-        return MetricsEvent.FINGERPRINT_ENROLL_INTRO;
+    protected String getExtraKeyForBiometric() {
+        return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT;
     }
 
-    protected void onCancelButtonClick() {
-        finish();
+    @Override
+    protected Intent getFindSensorIntent() {
+        return new Intent(this, FingerprintEnrollFindSensor.class);
     }
 
     @Override
-    protected void initViews() {
-        super.initViews();
-
-        TextView description = (TextView) findViewById(R.id.description_text);
-        if (mFingerprintUnlockDisabledByAdmin) {
-            description.setText(R.string
-                    .security_settings_fingerprint_enroll_introduction_message_unlock_disabled);
-        }
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.FINGERPRINT_ENROLL_INTRO;
     }
 
     @Override
index 60e09d2..5539016 100644 (file)
@@ -43,6 +43,7 @@ import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.SubSettings;
 import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricSettings;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
 import com.android.settings.password.ChooseLockGeneric;
 import com.android.settings.password.ChooseLockSettingsHelper;
@@ -66,34 +67,10 @@ import androidx.preference.PreferenceViewHolder;
 /**
  * Settings screen for fingerprints
  */
-public class FingerprintSettings extends SubSettings {
+public class FingerprintSettings extends BiometricSettings {
 
     private static final String TAG = "FingerprintSettings";
 
-    /**
-     * Used by the choose fingerprint wizard to indicate the wizard is
-     * finished, and each activity in the wizard should finish.
-     * <p>
-     * Previously, each activity in the wizard would finish itself after
-     * starting the next activity. However, this leads to broken 'Back'
-     * behavior. So, now an activity does not finish itself until it gets this
-     * result.
-     */
-    protected static final int RESULT_FINISHED = RESULT_FIRST_USER;
-
-    /**
-     * Used by the enrolling screen during setup wizard to skip over setting up fingerprint, which
-     * will be useful if the user accidentally entered this flow.
-     */
-    protected static final int RESULT_SKIP = RESULT_FIRST_USER + 1;
-
-    /**
-     * Like {@link #RESULT_FINISHED} except this one indicates enrollment failed because the
-     * device was left idle. This is used to clear the credential token to require the user to
-     * re-enter their pin/pattern/password before continuing.
-     */
-    protected static final int RESULT_TIMEOUT = RESULT_FIRST_USER + 2;
-
     private static final long LOCKOUT_DURATION = 30000; // time we have to wait for fp to reset, ms
 
     public static final String ANNOTATION_URL = "url";
index e13e8ac..2fcff5c 100644 (file)
 package com.android.settings.biometrics.fingerprint;
 
 import android.content.Context;
-import android.content.Intent;
-import android.hardware.fingerprint.Fingerprint;
 import android.hardware.fingerprint.FingerprintManager;
-import android.os.UserHandle;
-import android.os.UserManager;
 
-import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.R;
 import com.android.settings.Utils;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.biometrics.BiometricStatusPreferenceController;
 
-import java.util.List;
-
-import androidx.preference.Preference;
-
-public class FingerprintStatusPreferenceController extends BasePreferenceController {
+public class FingerprintStatusPreferenceController extends BiometricStatusPreferenceController {
 
     private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
 
     protected final FingerprintManager mFingerprintManager;
-    protected final UserManager mUm;
-    protected final LockPatternUtils mLockPatternUtils;
-
-    protected final int mUserId = UserHandle.myUserId();
-    protected final int mProfileChallengeUserId;
 
     public FingerprintStatusPreferenceController(Context context) {
         this(context, KEY_FINGERPRINT_SETTINGS);
@@ -51,69 +36,39 @@ public class FingerprintStatusPreferenceController extends BasePreferenceControl
     public FingerprintStatusPreferenceController(Context context, String key) {
         super(context, key);
         mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
-        mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
-        mLockPatternUtils = FeatureFactory.getFactory(context)
-                .getSecurityFeatureProvider()
-                .getLockPatternUtils(context);
-        mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
     }
 
     @Override
-    public int getAvailabilityStatus() {
-        if (mFingerprintManager == null || !mFingerprintManager.isHardwareDetected()) {
-            return UNSUPPORTED_ON_DEVICE;
-        }
-        if (isUserSupported()) {
-            return AVAILABLE;
-        } else {
-            return DISABLED_FOR_USER;
-        }
+    protected boolean isDeviceSupported() {
+        return mFingerprintManager != null && mFingerprintManager.isHardwareDetected();
+    }
+
+    @Override
+    protected boolean hasEnrolledBiometrics() {
+        return mFingerprintManager.hasEnrolledFingerprints(mUserId);
     }
 
     @Override
-    public void updateState(Preference preference) {
-        if (!isAvailable()) {
-            if (preference != null) {
-                preference.setVisible(false);
-            }
-            return;
-        } else {
-            preference.setVisible(true);
-        }
-        final int userId = getUserId();
-        final List<Fingerprint> items = mFingerprintManager.getEnrolledFingerprints(userId);
-        final int fingerprintCount = items != null ? items.size() : 0;
-        final String clazz;
-        if (fingerprintCount > 0) {
-            preference.setSummary(mContext.getResources().getQuantityString(
-                    R.plurals.security_settings_fingerprint_preference_summary,
-                    fingerprintCount, fingerprintCount));
-            clazz = FingerprintSettings.class.getName();
-        } else {
-            preference.setSummary(
-                    R.string.security_settings_fingerprint_preference_summary_none);
-            clazz = FingerprintEnrollIntroduction.class.getName();
-        }
-        preference.setOnPreferenceClickListener(target -> {
-            final Context context = target.getContext();
-            final UserManager userManager = UserManager.get(context);
-            if (Utils.startQuietModeDialogIfNecessary(context, userManager,
-                    userId)) {
-                return false;
-            }
-            Intent intent = new Intent();
-            intent.setClassName("com.android.settings", clazz);
-            intent.putExtra(Intent.EXTRA_USER_ID, userId);
-            context.startActivity(intent);
-            return true;
-        });
+    protected String getSummaryTextEnrolled() {
+        final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(mUserId).size();
+        return mContext.getResources().getQuantityString(
+                R.plurals.security_settings_fingerprint_preference_summary,
+                numEnrolled, numEnrolled);
     }
 
-    protected int getUserId() {
-        return mUserId;
+    @Override
+    protected String getSummaryTextNoneEnrolled() {
+        return mContext.getString(R.string.security_settings_fingerprint_preference_summary_none);
+    }
+
+    @Override
+    protected String getSettingsClassName() {
+        return FingerprintSettings.class.getName();
     }
 
-    protected boolean isUserSupported() {
-        return true;
+    @Override
+    protected String getEnrollClassName() {
+        return FingerprintEnrollIntroduction.class.getName();
     }
+
 }
index d3acbea..40275c3 100644 (file)
@@ -42,7 +42,7 @@ public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSenso
     }
 
     @Override
-    protected Intent getEnrollingIntent() {
+    protected Intent getFingerprintEnrollingIntent() {
         Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
         if (mUserId != UserHandle.USER_NULL) {
index c73417b..49eac16 100644 (file)
@@ -28,7 +28,7 @@ import com.android.settings.password.ChooseLockSettingsHelper;
 public class SetupFingerprintEnrollFinish extends FingerprintEnrollFinish {
 
     @Override
-    protected Intent getEnrollingIntent() {
+    protected Intent getFingerprintEnrollingIntent() {
         Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
         if (mUserId != UserHandle.USER_NULL) {
index c7c0bb4..9fcbbf5 100644 (file)
@@ -97,7 +97,7 @@ public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntrodu
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         // if lock was already present, do not return intent data since it must have been
         // reported in previous attempts
-        if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST && isKeyguardSecure()
+        if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST && isKeyguardSecure()
                 && !mAlreadyHadLockScreenSetup) {
             data = getMetricIntent(data);
         }
index 68678dc..137270c 100644 (file)
@@ -52,8 +52,8 @@ import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricEnrollBase;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.biometrics.fingerprint.FingerprintEnrollBase;
 import com.android.settings.biometrics.fingerprint.FingerprintEnrollFindSensor;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -360,7 +360,7 @@ public class ChooseLockGeneric extends SettingsActivity {
                     }
                 }
             } else if (requestCode == CHOOSE_LOCK_BEFORE_FINGERPRINT_REQUEST
-                    && resultCode == FingerprintEnrollBase.RESULT_FINISHED) {
+                    && resultCode == BiometricEnrollBase.RESULT_FINISHED) {
                 Intent intent = getFindSensorIntent(getActivity());
                 if (data != null) {
                     intent.putExtras(data.getExtras());
index 30ac402..905b709 100644 (file)
@@ -15,7 +15,8 @@
  */
 package com.android.settings.security;
 
-import static com.android.settings.security.EncryptionStatusPreferenceController.PREF_KEY_ENCRYPTION_SECURITY_PAGE;
+import static com.android.settings.security.EncryptionStatusPreferenceController
+        .PREF_KEY_ENCRYPTION_SECURITY_PAGE;
 
 import android.app.Activity;
 import android.content.Context;
@@ -26,11 +27,12 @@ import android.provider.SearchIndexableResource;
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
 import com.android.settings.Utils;
+import com.android.settings.biometrics.face.FaceStatusPreferenceController;
+import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
+import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
-import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
-import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
 import com.android.settings.location.LocationPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
@@ -123,6 +125,7 @@ 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 ChangeScreenLockPreferenceController(context, host));
         controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
diff --git a/tests/robotests/src/com/android/settings/biometrics/face/FaceStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/biometrics/face/FaceStatusPreferenceControllerTest.java
new file mode 100644 (file)
index 0000000..df01aca
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2018 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.face;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+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.pm.PackageManager;
+import android.hardware.face.Face;
+import android.hardware.face.FaceManager;
+import android.os.UserManager;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
+
+import java.util.Collections;
+
+import androidx.preference.Preference;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class FaceStatusPreferenceControllerTest {
+    @Mock
+    private LockPatternUtils mLockPatternUtils;
+    @Mock
+    private FaceManager mFaceManager;
+    @Mock
+    private UserManager mUm;
+    @Mock
+    private PackageManager mPackageManager;
+
+    private FakeFeatureFactory mFeatureFactory;
+    private Context mContext;
+    private FaceStatusPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
+        ShadowApplication.getInstance().setSystemService(Context.FACE_SERVICE, mFaceManager);
+        ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+        mPreference = new Preference(mContext);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+                .thenReturn(mLockPatternUtils);
+        when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
+        mController = new FaceStatusPreferenceController(mContext);
+    }
+
+    @Test
+    public void getAvailabilityStatus_noFaceManger_DISABLED() {
+        when(mFaceManager.isHardwareDetected()).thenReturn(false);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_hasFaceManger_AVAILABLE() {
+        when(mFaceManager.isHardwareDetected()).thenReturn(true);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void updateState_notSupported_shouldDoNothing() {
+        when(mFaceManager.isHardwareDetected()).thenReturn(false);
+
+        mController.updateState(mPreference);
+
+        assertThat(mPreference.isVisible()).isFalse();
+    }
+
+    @Test
+    public void updateState_noFace_shouldShowDefaultSummary() {
+        when(mFaceManager.isHardwareDetected()).thenReturn(true);
+
+        mController.updateState(mPreference);
+
+        assertThat(mPreference.getSummary()).isEqualTo(
+                mContext.getString(R.string.security_settings_face_preference_summary_none));
+        assertThat(mPreference.isVisible()).isTrue();
+        assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
+    }
+
+    @Test
+    public void updateState_hasFace_shouldShowSummary() {
+        when(mFaceManager.isHardwareDetected()).thenReturn(true);
+        when(mFaceManager.getEnrolledFaces(anyInt()))
+                .thenReturn(Collections.singletonList(mock(Face.class)));
+        when(mFaceManager.hasEnrolledFaces(anyInt()))
+                .thenReturn(true);
+
+        mController.updateState(mPreference);
+
+        assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources()
+                .getString(R.string.security_settings_face_preference_summary));
+        assertThat(mPreference.isVisible()).isTrue();
+        assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
+    }
+}
index 338b3c0..70a68ec 100644 (file)
@@ -31,6 +31,7 @@ import android.os.CancellationSignal;
 import android.widget.Button;
 
 import com.android.settings.R;
+import com.android.settings.biometrics.BiometricEnrollBase;
 import com.android.settings.password.ChooseLockSettingsHelper;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -137,7 +138,7 @@ public class FingerprintEnrollFindSensorTest {
 
         ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
         assertThat(shadowActivity.getResultCode()).named("result code")
-                .isEqualTo(FingerprintEnrollBase.RESULT_SKIP);
+                .isEqualTo(BiometricEnrollBase.RESULT_SKIP);
     }
 
     private EnrollmentCallback verifyAndCaptureEnrollmentCallback() {
index 7fe114b..cb22837 100644 (file)
@@ -121,6 +121,8 @@ public class FingerprintStatusPreferenceControllerTest {
         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
         when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
                 .thenReturn(Collections.singletonList(mock(Fingerprint.class)));
+        when(mFingerprintManager.hasEnrolledFingerprints(anyInt()))
+                .thenReturn(true);
 
         mController.updateState(mPreference);
 
index bbdb443..36ccc68 100644 (file)
@@ -27,6 +27,8 @@ import android.view.View;
 import android.widget.Button;
 
 import com.android.settings.R;
+import com.android.settings.biometrics.BiometricEnrollBase;
+import com.android.settings.biometrics.BiometricEnrollIntroduction;
 import com.android.settings.biometrics.fingerprint.SetupFingerprintEnrollIntroductionTest.ShadowStorageManagerWrapper;
 import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
 import com.android.settings.password.SetupSkipDialog;
@@ -118,7 +120,7 @@ public class SetupFingerprintEnrollIntroductionTest {
         ShadowActivity shadowActivity = Shadows.shadowOf(mController.get());
         assertThat(mController.get().isFinishing()).named("Is finishing").isTrue();
         assertThat(shadowActivity.getResultCode()).named("Result code")
-            .isEqualTo(FingerprintEnrollBase.RESULT_SKIP);
+            .isEqualTo(BiometricEnrollBase.RESULT_SKIP);
     }
 
     @Test
@@ -179,8 +181,8 @@ public class SetupFingerprintEnrollIntroductionTest {
     public void testOnResultFromFindSensor_shouldNotSetIntentDataIfLockScreenPresentBeforeLaunch() {
         getShadowKeyguardManager().setIsKeyguardSecure(true);
         SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
-        activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
-            FingerprintEnrollBase.RESULT_FINISHED, null);
+        activity.onActivityResult(BiometricEnrollIntroduction.BIOMETRIC_FIND_SENSOR_REQUEST,
+            BiometricEnrollBase.RESULT_FINISHED, null);
         assertThat(Shadows.shadowOf(activity).getResultIntent()).isNull();
     }
 
@@ -189,8 +191,8 @@ public class SetupFingerprintEnrollIntroductionTest {
         getShadowKeyguardManager().setIsKeyguardSecure(false);
         SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
         getShadowKeyguardManager().setIsKeyguardSecure(true);
-        activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
-            FingerprintEnrollBase.RESULT_FINISHED, null);
+        activity.onActivityResult(BiometricEnrollIntroduction.BIOMETRIC_FIND_SENSOR_REQUEST,
+            BiometricEnrollBase.RESULT_FINISHED, null);
         assertThat(Shadows.shadowOf(activity).getResultIntent()).isNotNull();
     }
 
@@ -198,8 +200,8 @@ public class SetupFingerprintEnrollIntroductionTest {
     public void testOnResultFromFindSensor_shouldNotSetIntentDataIfLockScreenNotAdded() {
         getShadowKeyguardManager().setIsKeyguardSecure(false);
         SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
-        activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
-            FingerprintEnrollBase.RESULT_FINISHED, null);
+        activity.onActivityResult(BiometricEnrollIntroduction.BIOMETRIC_FIND_SENSOR_REQUEST,
+            BiometricEnrollBase.RESULT_FINISHED, null);
         assertThat(Shadows.shadowOf(activity).getResultIntent()).isNull();
     }