Settings should be per-profile
Also, don't show keyguard option for work profile Fixes: 129905061 Test: Builds Change-Id: I18f573f39ee4e54a3385cc65079bb794633cc560
This commit is contained in:
@@ -925,9 +925,9 @@
|
||||
<!-- Button text to exit face wizard after everything is done [CHAR LIMIT=15] -->
|
||||
<string name="security_settings_face_enroll_done">Done</string>
|
||||
<!-- Title for a category shown for the face settings page. [CHAR LIMIT=20] -->
|
||||
<string name="security_settings_face_settings_use_face_category">Use your face to</string>
|
||||
<string name="security_settings_face_settings_use_face_category">Use your face for</string>
|
||||
<!-- Text shown on a toggle which allows or disallows the device to use face for unlocking the device. [CHAR LIMIT=20] -->
|
||||
<string name="security_settings_face_settings_use_face_unlock_phone">Unlock your device</string>
|
||||
<string name="security_settings_face_settings_use_face_unlock_phone">Unlocking your device</string>
|
||||
<!-- Text shown on a toggle which allows or disallows the device to use face authentication for apps. This will be presented to the user together with the context of security_settings_face_settings_use_face_category. [CHAR LIMIT=30] -->
|
||||
<string name="security_settings_face_settings_use_face_for_apps">App sign-in \u0026 payments</string>
|
||||
<!-- Text shown on a toggle which disables/enables face authentication, depending if the user's eyes are open. [CHAR LIMIT=30] -->
|
||||
|
@@ -27,6 +27,7 @@ import android.content.Intent;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -53,11 +54,13 @@ public class FaceSettings extends DashboardFragment {
|
||||
private static final String TAG = "FaceSettings";
|
||||
private static final String KEY_TOKEN = "key_token";
|
||||
|
||||
private UserManager mUserManager;
|
||||
private FaceManager mFaceManager;
|
||||
private int mUserId;
|
||||
private byte[] mToken;
|
||||
private FaceSettingsAttentionPreferenceController mAttentionController;
|
||||
private FaceSettingsRemoveButtonPreferenceController mRemoveController;
|
||||
private List<AbstractPreferenceController> mControllers;
|
||||
|
||||
private final FaceSettingsRemoveButtonPreferenceController.Listener mRemovalListener = () -> {
|
||||
if (getActivity() != null) {
|
||||
@@ -95,10 +98,24 @@ public class FaceSettings extends DashboardFragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mUserManager = getPrefContext().getSystemService(UserManager.class);
|
||||
mFaceManager = getPrefContext().getSystemService(FaceManager.class);
|
||||
mUserId = getActivity().getIntent().getIntExtra(
|
||||
Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
|
||||
// There is no better way to do this :/
|
||||
for (AbstractPreferenceController controller : mControllers) {
|
||||
if (controller instanceof FaceSettingsPreferenceController) {
|
||||
((FaceSettingsPreferenceController) controller).setUserId(mUserId);
|
||||
}
|
||||
}
|
||||
mRemoveController.setUserId(mUserId);
|
||||
|
||||
// Don't show keyguard controller for work profile settings.
|
||||
if (mUserManager.isManagedProfile(mUserId)) {
|
||||
removePreference(FaceSettingsKeyguardPreferenceController.KEY);
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mToken = savedInstanceState.getByteArray(KEY_TOKEN);
|
||||
}
|
||||
@@ -162,10 +179,9 @@ public class FaceSettings extends DashboardFragment {
|
||||
if (!isAvailable(context)) {
|
||||
return null;
|
||||
}
|
||||
final List<AbstractPreferenceController> controllers =
|
||||
buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
mControllers = buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
// There's no great way of doing this right now :/
|
||||
for (AbstractPreferenceController controller : controllers) {
|
||||
for (AbstractPreferenceController controller : mControllers) {
|
||||
if (controller instanceof FaceSettingsAttentionPreferenceController) {
|
||||
mAttentionController = (FaceSettingsAttentionPreferenceController) controller;
|
||||
} else if (controller instanceof FaceSettingsRemoveButtonPreferenceController) {
|
||||
@@ -175,7 +191,7 @@ public class FaceSettings extends DashboardFragment {
|
||||
}
|
||||
}
|
||||
|
||||
return controllers;
|
||||
return mControllers;
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
|
@@ -21,13 +21,11 @@ import static android.provider.Settings.Secure.FACE_UNLOCK_APP_ENABLED;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller for Face settings page controlling the ability to use
|
||||
* Face authentication in apps (through BiometricPrompt).
|
||||
*/
|
||||
public class FaceSettingsAppPreferenceController extends TogglePreferenceController {
|
||||
public class FaceSettingsAppPreferenceController extends FaceSettingsPreferenceController {
|
||||
|
||||
private static final String KEY = "security_settings_face_app";
|
||||
|
||||
@@ -48,14 +46,14 @@ public class FaceSettingsAppPreferenceController extends TogglePreferenceControl
|
||||
if (!FaceSettings.isAvailable(mContext)) {
|
||||
return false;
|
||||
}
|
||||
return Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED, DEFAULT) == ON;
|
||||
return Settings.Secure.getIntForUser(
|
||||
mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED, DEFAULT, getUserId()) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED,
|
||||
isChecked ? ON : OFF);
|
||||
return Settings.Secure.putIntForUser(mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED,
|
||||
isChecked ? ON : OFF, getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -31,7 +31,7 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
* Preference controller that manages the ability to use face authentication with/without
|
||||
* user attention. See {@link FaceManager#setRequireAttention(boolean, byte[])}.
|
||||
*/
|
||||
public class FaceSettingsAttentionPreferenceController extends TogglePreferenceController {
|
||||
public class FaceSettingsAttentionPreferenceController extends FaceSettingsPreferenceController {
|
||||
|
||||
public static final String KEY = "security_settings_face_require_attention";
|
||||
|
||||
|
@@ -26,7 +26,7 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
/**
|
||||
* Preference controller giving the user an option to always require confirmation.
|
||||
*/
|
||||
public class FaceSettingsConfirmPreferenceController extends TogglePreferenceController {
|
||||
public class FaceSettingsConfirmPreferenceController extends FaceSettingsPreferenceController {
|
||||
|
||||
private static final String KEY = "security_settings_face_require_confirmation";
|
||||
|
||||
@@ -45,14 +45,14 @@ public class FaceSettingsConfirmPreferenceController extends TogglePreferenceCon
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, DEFAULT) == ON;
|
||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, DEFAULT, getUserId()) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, isChecked ? ON : OFF);
|
||||
return Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, isChecked ? ON : OFF, getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -31,9 +31,9 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
* Preference controller for Face settings page controlling the ability to unlock the phone
|
||||
* with face.
|
||||
*/
|
||||
public class FaceSettingsKeyguardPreferenceController extends TogglePreferenceController {
|
||||
public class FaceSettingsKeyguardPreferenceController extends FaceSettingsPreferenceController {
|
||||
|
||||
private static final String KEY = "security_settings_face_keyguard";
|
||||
static final String KEY = "security_settings_face_keyguard";
|
||||
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
@@ -54,14 +54,14 @@ public class FaceSettingsKeyguardPreferenceController extends TogglePreferenceCo
|
||||
} else if (adminDisabled()) {
|
||||
return false;
|
||||
}
|
||||
return Settings.Secure.getInt(
|
||||
mContext.getContentResolver(), FACE_UNLOCK_KEYGUARD_ENABLED, DEFAULT) == ON;
|
||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_KEYGUARD_ENABLED, DEFAULT, getUserId()) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(), FACE_UNLOCK_KEYGUARD_ENABLED,
|
||||
isChecked ? ON : OFF);
|
||||
return Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
FACE_UNLOCK_KEYGUARD_ENABLED, isChecked ? ON : OFF, getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Abstract base class for all face settings toggles.
|
||||
*/
|
||||
public abstract class FaceSettingsPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private int mUserId;
|
||||
|
||||
public FaceSettingsPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
mUserId = userId;
|
||||
}
|
||||
|
||||
protected int getUserId() {
|
||||
return mUserId;
|
||||
}
|
||||
}
|
@@ -82,12 +82,11 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
}
|
||||
|
||||
private Button mButton;
|
||||
private List<Face> mFaces;
|
||||
private Listener mListener;
|
||||
private SettingsActivity mActivity;
|
||||
private int mUserId;
|
||||
|
||||
private final Context mContext;
|
||||
private final int mUserId;
|
||||
private final FaceManager mFaceManager;
|
||||
private final FaceManager.RemovalCallback mRemovalCallback = new FaceManager.RemovalCallback() {
|
||||
@Override
|
||||
@@ -100,8 +99,8 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
@Override
|
||||
public void onRemovalSucceeded(Face face, int remaining) {
|
||||
if (remaining == 0) {
|
||||
mFaces = mFaceManager.getEnrolledFaces(mUserId);
|
||||
if (!mFaces.isEmpty()) {
|
||||
final List<Face> faces = mFaceManager.getEnrolledFaces(mUserId);
|
||||
if (!faces.isEmpty()) {
|
||||
mButton.setEnabled(true);
|
||||
} else {
|
||||
mListener.onRemoved();
|
||||
@@ -117,16 +116,17 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (mFaces.isEmpty()) {
|
||||
final List<Face> faces = mFaceManager.getEnrolledFaces(mUserId);
|
||||
if (faces.isEmpty()) {
|
||||
Log.e(TAG, "No faces");
|
||||
return;
|
||||
}
|
||||
if (mFaces.size() > 1) {
|
||||
Log.e(TAG, "Multiple enrollments: " + mFaces.size());
|
||||
if (faces.size() > 1) {
|
||||
Log.e(TAG, "Multiple enrollments: " + faces.size());
|
||||
}
|
||||
|
||||
// Remove the first/only face
|
||||
mFaceManager.remove(mFaces.get(0), mUserId, mRemovalCallback);
|
||||
mFaceManager.remove(faces.get(0), mUserId, mRemovalCallback);
|
||||
} else {
|
||||
mButton.setEnabled(true);
|
||||
}
|
||||
@@ -137,17 +137,16 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
super(context, preferenceKey);
|
||||
mContext = context;
|
||||
mFaceManager = context.getSystemService(FaceManager.class);
|
||||
// TODO: Use the profile-specific userId instead
|
||||
mUserId = UserHandle.myUserId();
|
||||
if (mFaceManager != null) {
|
||||
mFaces = mFaceManager.getEnrolledFaces(mUserId);
|
||||
}
|
||||
}
|
||||
|
||||
public FaceSettingsRemoveButtonPreferenceController(Context context) {
|
||||
this(context, KEY);
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
mUserId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
Reference in New Issue
Block a user