Merge "Adding slice for Face Enrollment" into qt-r1-dev
am: 35252d1b9f
Change-Id: Ic36d9fd8f00b01fe4c35e005cd9192b9cfe900e9
This commit is contained in:
29
res/drawable/ic_face_24dp.xml
Normal file
29
res/drawable/ic_face_24dp.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M10.25,13c0,0.69-0.56,1.25-1.25,1.25S7.75,13.69,7.75,13S8.31,11.75,9,11.75S10.25,12.31,10.25,13z M15,11.75 c-0.69,0-1.25,0.56-1.25,1.25s0.56,1.25,1.25,1.25s1.25-0.56,1.25-1.25S15.69,11.75,15,11.75z M22,12c0,5.52-4.48,10-10,10 S2,17.52,2,12S6.48,2,12,2S22,6.48,22,12z M20,12c0-0.78-0.12-1.53-0.33-2.24C18.97,9.91,18.25,10,17.5,10 c-3.13,0-5.92-1.44-7.76-3.69c-1.05,2.56-3.14,4.57-5.74,5.55C4.01,11.9,4,11.95,4,12c0,4.41,3.59,8,8,8S20,16.41,20,12z" />
|
||||
<path
|
||||
android:pathData="M0,0h24v24H0V0z" />
|
||||
</vector>
|
@@ -976,7 +976,8 @@
|
||||
<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] -->
|
||||
<string name="security_settings_face_settings_remove_dialog_details">The images and biometric data used by face unlock will be permanently and securely deleted. After removal, you will need your PIN, pattern, or password to unlock your phone, sign in to apps, and confirm payments.</string>
|
||||
|
||||
<!-- Subtitle shown for contextual setting face enrollment [CHAR LIMIT=NONE] -->
|
||||
<string name="security_settings_face_settings_context_subtitle">Use face unlock to unlock your phone</string>
|
||||
|
||||
<!-- Fingerprint enrollment and settings --><skip />
|
||||
<!-- Title shown for menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
|
||||
|
@@ -32,6 +32,7 @@ import com.android.settings.biometrics.BiometricEnrollBase;
|
||||
import com.android.settings.biometrics.BiometricEnrollSidecar;
|
||||
import com.android.settings.biometrics.BiometricErrorDialog;
|
||||
import com.android.settings.biometrics.BiometricsEnrollEnrolling;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupcompat.template.FooterButton;
|
||||
@@ -184,6 +185,10 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
|
||||
// TODO: Have this match any animations that UX comes up with
|
||||
if (remaining == 0) {
|
||||
// Force the reload of the FaceEnroll slice in case a user has enrolled,
|
||||
// this will cause the slice to no longer appear.
|
||||
getApplicationContext().getContentResolver().notifyChange(
|
||||
CustomSliceRegistry.FACE_ENROLL_SLICE_URI, null);
|
||||
launchFinish(mToken);
|
||||
}
|
||||
}
|
||||
|
@@ -72,6 +72,12 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
|
||||
.setCardName(contextualAdaptiveSleepSliceUri)
|
||||
.setCardCategory(ContextualCard.Category.DEFAULT)
|
||||
.build();
|
||||
final ContextualCard contextualFaceSettingsCard =
|
||||
ContextualCard.newBuilder()
|
||||
.setSliceUri(CustomSliceRegistry.FACE_ENROLL_SLICE_URI.toString())
|
||||
.setCardName(CustomSliceRegistry.FACE_ENROLL_SLICE_URI.toString())
|
||||
.setCardCategory(ContextualCard.Category.DEFAULT)
|
||||
.build();
|
||||
final ContextualCardList cards = ContextualCardList.newBuilder()
|
||||
.addCard(wifiCard)
|
||||
.addCard(connectedDeviceCard)
|
||||
@@ -79,6 +85,7 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
|
||||
.addCard(batteryFixCard)
|
||||
.addCard(notificationChannelCard)
|
||||
.addCard(contextualAdaptiveSleepCard)
|
||||
.addCard(contextualFaceSettingsCard)
|
||||
.build();
|
||||
|
||||
return cards;
|
||||
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.homepage.contextualcards.slices;
|
||||
|
||||
|
||||
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_SUCCESS;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.ListBuilder.RowBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.face.FaceProfileStatusPreferenceController;
|
||||
import com.android.settings.security.SecuritySettings;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
|
||||
public class FaceSetupSlice implements CustomSliceable {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public FaceSetupSlice(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final BiometricManager biometricManager = mContext.getSystemService(BiometricManager.class);
|
||||
final PackageManager packageManager = mContext.getPackageManager();
|
||||
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_FACE)) {
|
||||
// no face hardware
|
||||
return null;
|
||||
} else if (biometricManager.canAuthenticate() == BIOMETRIC_SUCCESS) {
|
||||
// face hardware, and already enrolled
|
||||
return null;
|
||||
}
|
||||
|
||||
final CharSequence title = mContext.getText(
|
||||
R.string.security_settings_face_settings_enroll);
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext,
|
||||
CustomSliceRegistry.FACE_ENROLL_SLICE_URI, ListBuilder.INFINITY)
|
||||
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_face_24dp);
|
||||
return listBuilder
|
||||
.addRow(buildRowBuilder(title,
|
||||
mContext.getText(R.string.security_settings_face_settings_context_subtitle),
|
||||
icon, mContext, getIntent()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return CustomSliceRegistry.FACE_ENROLL_SLICE_URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
SecuritySettings.class.getName(),
|
||||
FaceProfileStatusPreferenceController.KEY_FACE_SETTINGS,
|
||||
mContext.getText(R.string.security_settings_face_settings_enroll).toString(),
|
||||
SettingsEnums.SLICE)
|
||||
.setClassName(mContext.getPackageName(), SubSettings.class.getName());
|
||||
}
|
||||
|
||||
private static RowBuilder buildRowBuilder(CharSequence title, CharSequence subTitle,
|
||||
IconCompat icon, Context context, Intent intent) {
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(
|
||||
PendingIntent.getActivity(context, 0, intent, 0), icon, ListBuilder.ICON_IMAGE,
|
||||
title);
|
||||
return new RowBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setSubtitle(subTitle)
|
||||
.setPrimaryAction(primarySliceAction);
|
||||
}
|
||||
}
|
@@ -37,6 +37,7 @@ import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice;
|
||||
import com.android.settings.location.LocationSlice;
|
||||
@@ -162,6 +163,15 @@ public class CustomSliceRegistry {
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath("enhanced_4g_lte")
|
||||
.build();
|
||||
/**
|
||||
* Slice Uri for Face Enrollment
|
||||
*/
|
||||
public static final Uri FACE_ENROLL_SLICE_URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath("face_unlock_greeting_card")
|
||||
.build();
|
||||
/**
|
||||
* Backing Uri for the Flashlight Slice.
|
||||
*/
|
||||
@@ -347,6 +357,7 @@ public class CustomSliceRegistry {
|
||||
sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class);
|
||||
sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class);
|
||||
sUriToSlice.put(EMERGENCY_INFO_SLICE_URI, EmergencyInfoSlice.class);
|
||||
sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
|
||||
sUriToSlice.put(FLASHLIGHT_SLICE_URI, FlashlightSlice.class);
|
||||
sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class);
|
||||
sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.homepage.contextualcards.slices;
|
||||
|
||||
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_ERROR_NO_BIOMETRICS;
|
||||
import static android.hardware.biometrics.BiometricManager.BIOMETRIC_SUCCESS;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FaceSetupSliceTest {
|
||||
|
||||
private BiometricManager mBiometricManager;
|
||||
private Context mContext;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPackageManager = spy(mContext.getPackageManager());
|
||||
mBiometricManager = spy(mContext.getSystemService(BiometricManager.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_noFaceSupported_shouldReturnNull() {
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
assertThat(setupSlice.getSlice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceSupportedUserEnrolled_shouldReturnNull() {
|
||||
when(mBiometricManager.canAuthenticate()).thenReturn(BIOMETRIC_SUCCESS);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(BiometricManager.class)).thenReturn(mBiometricManager);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
assertThat(setupSlice.getSlice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_faceSupportedUserNotEnrolled_shouldReturnNonNull() {
|
||||
when(mBiometricManager.canAuthenticate()).thenReturn(BIOMETRIC_ERROR_NO_BIOMETRICS);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(BiometricManager.class)).thenReturn(mBiometricManager);
|
||||
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
|
||||
assertThat(setupSlice.getSlice()).isNotNull();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user