Add feature provider for face unlock
Bug: 146085546
Test: Builds
Change-Id: If5c7d57c12a3f679d81cee22fb94a53fce1de29a
diff --git a/res/layout/face_enroll_introduction.xml b/res/layout/face_enroll_introduction.xml
index f551e36..55ac6f9 100644
--- a/res/layout/face_enroll_introduction.xml
+++ b/res/layout/face_enroll_introduction.xml
@@ -124,9 +124,9 @@
android:layout_width="24dp"
android:layout_height="wrap_content"/>
<TextView
+ android:id="@+id/face_enroll_introduction_footer_part_2"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/security_settings_face_enroll_introduction_footer_part_2"/>
+ android:layout_height="wrap_content"/>
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 192f7ea..9418e6d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -990,6 +990,8 @@
<string name="security_settings_face_settings_enroll">Set up face unlock</string>
<!-- Text shown in face settings explaining what your face can be used for. [CHAR LIMIT=NONE] -->
<string name="security_settings_face_settings_footer">Use face unlock to unlock your device, sign in to apps, and confirm payments.\n\nKeep in mind:\nLooking at the phone can unlock it when you don\u2019t intend to.\n\nYour phone can be unlocked by someone else if it\u2019s held up to your face while your eyes are open.\n\nYour phone can be unlocked by someone who looks a lot like you, say, an identical sibling.</string>
+ <!-- Text shown in face settings explaining what your face can be used for. Used when attention checking is not supported. [CHAR LIMIT=NONE] -->
+ <string name="security_settings_face_settings_footer_attention_not_supported">Use face unlock to unlock your device, sign in to apps, and confirm payments.\n\nKeep in mind:\nLooking at the phone can unlock it when you don\u2019t intend to.\n\nYour phone can be unlocked by someone else if it\u2019s held up to your face, even if your eyes are closed.\n\nYour phone can be unlocked by someone who looks a lot like you, say, an identical sibling.</string>
<!-- Dialog title shown when the user removes an enrollment [CHAR LIMIT=35] -->
<string name="security_settings_face_settings_remove_dialog_title">Delete face data?</string>
<!-- Dialog contents shown when the user removes an enrollment [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
index 5f164d6..073c7e6 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
@@ -26,6 +26,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollIntroduction;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -40,12 +41,15 @@
private static final String TAG = "FaceIntro";
private FaceManager mFaceManager;
+ private FaceFeatureProvider mFaceFeatureProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFaceManager = Utils.getFaceManagerOrNull(this);
+ mFaceFeatureProvider = FeatureFactory.getFactory(getApplicationContext())
+ .getFaceFeatureProvider();
mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
@@ -87,6 +91,12 @@
});
}
+ final TextView footer2 = findViewById(R.id.face_enroll_introduction_footer_part_2);
+ final int footer2TextResource =
+ mFaceFeatureProvider.isAttentionSupported(getApplicationContext())
+ ? R.string.security_settings_face_enroll_introduction_footer_part_2
+ : R.string.security_settings_face_settings_footer_attention_not_supported;
+ footer2.setText(footer2TextResource);
}
@Override
diff --git a/src/com/android/settings/biometrics/face/FaceFeatureProvider.java b/src/com/android/settings/biometrics/face/FaceFeatureProvider.java
new file mode 100644
index 0000000..26ea261
--- /dev/null
+++ b/src/com/android/settings/biometrics/face/FaceFeatureProvider.java
@@ -0,0 +1,25 @@
+/*
+ * 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
+ */
+
+package com.android.settings.biometrics.face;
+
+import android.content.Context;
+
+/** Feature provider for face unlock */
+public interface FaceFeatureProvider {
+ /** Returns true if attention checking is supported. */
+ boolean isAttentionSupported(Context context);
+}
diff --git a/src/com/android/settings/biometrics/face/FaceFeatureProviderImpl.java b/src/com/android/settings/biometrics/face/FaceFeatureProviderImpl.java
new file mode 100644
index 0000000..e508600
--- /dev/null
+++ b/src/com/android/settings/biometrics/face/FaceFeatureProviderImpl.java
@@ -0,0 +1,28 @@
+/*
+ * 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
+ */
+
+package com.android.settings.biometrics.face;
+
+import android.content.Context;
+import android.provider.Settings;
+
+public class FaceFeatureProviderImpl implements FaceFeatureProvider {
+
+ @Override
+ public boolean isAttentionSupported(Context context) {
+ return true;
+ }
+}
diff --git a/src/com/android/settings/biometrics/face/FaceSettings.java b/src/com/android/settings/biometrics/face/FaceSettings.java
index 46d288e..eeaa040 100644
--- a/src/com/android/settings/biometrics/face/FaceSettings.java
+++ b/src/com/android/settings/biometrics/face/FaceSettings.java
@@ -37,6 +37,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -69,6 +70,7 @@
private List<Preference> mTogglePreferences;
private Preference mRemoveButton;
private Preference mEnrollButton;
+ private FaceFeatureProvider mFaceFeatureProvider;
private boolean mConfirmingPassword;
@@ -119,6 +121,7 @@
mFaceManager = getPrefContext().getSystemService(FaceManager.class);
mUserId = getActivity().getIntent().getIntExtra(
Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ mFaceFeatureProvider = FeatureFactory.getFactory(getContext()).getFaceFeatureProvider();
if (mUserManager.getUserInfo(mUserId).isManagedProfile()) {
getActivity().setTitle(getActivity().getResources().getString(
@@ -192,6 +195,10 @@
final boolean hasEnrolled = mFaceManager.hasEnrolledTemplates(mUserId);
mEnrollButton.setVisible(!hasEnrolled);
mRemoveButton.setVisible(hasEnrolled);
+
+ if (!mFaceFeatureProvider.isAttentionSupported(getContext())) {
+ removePreference(FaceSettingsAttentionPreferenceController.KEY);
+ }
}
@Override
diff --git a/src/com/android/settings/biometrics/face/FaceSettingsFooterPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsFooterPreferenceController.java
index 838dc0d..c665467 100644
--- a/src/com/android/settings/biometrics/face/FaceSettingsFooterPreferenceController.java
+++ b/src/com/android/settings/biometrics/face/FaceSettingsFooterPreferenceController.java
@@ -23,6 +23,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.utils.AnnotationSpan;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.widget.FooterPreference;
@@ -34,8 +35,11 @@
private static final String ANNOTATION_URL = "url";
+ private FaceFeatureProvider mProvider;
+
public FaceSettingsFooterPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mProvider = FeatureFactory.getFactory(context).getFaceFeatureProvider();
}
public FaceSettingsFooterPreferenceController(Context context) {
@@ -55,7 +59,12 @@
mContext, mContext.getString(R.string.help_url_face), getClass().getName());
final AnnotationSpan.LinkInfo linkInfo =
new AnnotationSpan.LinkInfo(mContext, ANNOTATION_URL, helpIntent);
+
+ final int footerRes = mProvider.isAttentionSupported(mContext)
+ ? R.string.security_settings_face_settings_footer
+ : R.string.security_settings_face_settings_footer_attention_not_supported;
+
preference.setTitle(AnnotationSpan.linkify(
- mContext.getText(R.string.security_settings_face_settings_footer), linkInfo));
+ mContext.getText(footerRes), linkInfo));
}
}
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index d9af345..afbce09 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -26,6 +26,7 @@
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
+import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
@@ -133,6 +134,8 @@
public abstract AwareFeatureProvider getAwareFeatureProvider();
+ public abstract FaceFeatureProvider getFaceFeatureProvider();
+
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 2f9626d..29beb5b 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -30,6 +30,8 @@
import com.android.settings.applications.ApplicationFeatureProviderImpl;
import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.aware.AwareFeatureProviderImpl;
+import com.android.settings.biometrics.face.FaceFeatureProvider;
+import com.android.settings.biometrics.face.FaceFeatureProviderImpl;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProviderImpl;
import com.android.settings.connecteddevice.dock.DockUpdaterFeatureProviderImpl;
@@ -84,6 +86,7 @@
private ContextualCardFeatureProvider mContextualCardFeatureProvider;
private BluetoothFeatureProvider mBluetoothFeatureProvider;
private AwareFeatureProvider mAwareFeatureProvider;
+ private FaceFeatureProvider mFaceFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -255,4 +258,12 @@
}
return mAwareFeatureProvider;
}
+
+ @Override
+ public FaceFeatureProvider getFaceFeatureProvider() {
+ if (mFaceFeatureProvider == null) {
+ mFaceFeatureProvider = new FaceFeatureProviderImpl();
+ }
+ return mFaceFeatureProvider;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index 2a12680..220209c 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -24,6 +24,7 @@
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
+import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
@@ -68,6 +69,7 @@
public final ContextualCardFeatureProvider mContextualCardFeatureProvider;
public final BluetoothFeatureProvider mBluetoothFeatureProvider;
public final AwareFeatureProvider mAwareFeatureProvider;
+ public final FaceFeatureProvider mFaceFeatureProvider;
public PanelFeatureProvider panelFeatureProvider;
public SlicesFeatureProvider slicesFeatureProvider;
@@ -114,6 +116,7 @@
panelFeatureProvider = mock(PanelFeatureProvider.class);
mBluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
mAwareFeatureProvider = mock(AwareFeatureProvider.class);
+ mFaceFeatureProvider = mock(FaceFeatureProvider.class);
}
@Override
@@ -215,4 +218,9 @@
public AwareFeatureProvider getAwareFeatureProvider() {
return mAwareFeatureProvider;
}
+
+ @Override
+ public FaceFeatureProvider getFaceFeatureProvider() {
+ return mFaceFeatureProvider;
+ }
}