Merge "Plumb remove functionality through"
This commit is contained in:
@@ -59,6 +59,10 @@ public class FaceSettings extends DashboardFragment {
|
|||||||
private byte[] mToken;
|
private byte[] mToken;
|
||||||
private FaceSettingsAttentionPreferenceController mAttentionController;
|
private FaceSettingsAttentionPreferenceController mAttentionController;
|
||||||
|
|
||||||
|
private final FaceSettingsRemoveButtonPreferenceController.Listener mRemovalListener = () -> {
|
||||||
|
getActivity().finish();
|
||||||
|
};
|
||||||
|
|
||||||
public static boolean isAvailable(Context context) {
|
public static boolean isAvailable(Context context) {
|
||||||
FaceManager manager = Utils.getFaceManagerOrNull(context);
|
FaceManager manager = Utils.getFaceManagerOrNull(context);
|
||||||
return manager != null && manager.isHardwareDetected();
|
return manager != null && manager.isHardwareDetected();
|
||||||
@@ -146,10 +150,13 @@ public class FaceSettings extends DashboardFragment {
|
|||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
final List<AbstractPreferenceController> controllers =
|
final List<AbstractPreferenceController> controllers =
|
||||||
buildPreferenceControllers(context, getSettingsLifecycle());
|
buildPreferenceControllers(context, getSettingsLifecycle());
|
||||||
|
// There's no great way of doing this right now :/
|
||||||
for (AbstractPreferenceController controller : controllers) {
|
for (AbstractPreferenceController controller : controllers) {
|
||||||
if (controller instanceof FaceSettingsAttentionPreferenceController) {
|
if (controller instanceof FaceSettingsAttentionPreferenceController) {
|
||||||
mAttentionController = (FaceSettingsAttentionPreferenceController) controller;
|
mAttentionController = (FaceSettingsAttentionPreferenceController) controller;
|
||||||
break;
|
} else if (controller instanceof FaceSettingsRemoveButtonPreferenceController) {
|
||||||
|
((FaceSettingsRemoveButtonPreferenceController) controller)
|
||||||
|
.setListener(mRemovalListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,8 +17,13 @@
|
|||||||
package com.android.settings.biometrics.face;
|
package com.android.settings.biometrics.face;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.face.Face;
|
||||||
|
import android.hardware.face.FaceManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
@@ -26,18 +31,61 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the remove button.
|
* Controller for the remove button. This assumes that there is only a single face enrolled. The UI
|
||||||
|
* will likely change if multiple enrollments are allowed/supported.
|
||||||
*/
|
*/
|
||||||
public class FaceSettingsRemoveButtonPreferenceController extends BasePreferenceController
|
public class FaceSettingsRemoveButtonPreferenceController extends BasePreferenceController
|
||||||
implements View.OnClickListener {
|
implements View.OnClickListener {
|
||||||
|
|
||||||
|
private static final String TAG = "FaceSettings/Remove";
|
||||||
private static final String KEY = "security_settings_face_delete_faces_container";
|
private static final String KEY = "security_settings_face_delete_faces_container";
|
||||||
|
|
||||||
|
interface Listener {
|
||||||
|
void onRemoved();
|
||||||
|
}
|
||||||
|
|
||||||
private Button mButton;
|
private Button mButton;
|
||||||
|
private List<Face> mFaces;
|
||||||
|
private Listener mListener;
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final int mUserId;
|
||||||
|
private final FaceManager mFaceManager;
|
||||||
|
private final FaceManager.RemovalCallback mRemovalCallback = new FaceManager.RemovalCallback() {
|
||||||
|
@Override
|
||||||
|
public void onRemovalError(Face face, int errMsgId, CharSequence errString) {
|
||||||
|
Log.e(TAG, "Unable to remove face: " + face.getBiometricId()
|
||||||
|
+ " error: " + errMsgId + " " + errString);
|
||||||
|
Toast.makeText(mContext, errString, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemovalSucceeded(Face face, int remaining) {
|
||||||
|
if (remaining == 0) {
|
||||||
|
mFaces = mFaceManager.getEnrolledFaces(mUserId);
|
||||||
|
if (!mFaces.isEmpty()) {
|
||||||
|
mButton.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
mListener.onRemoved();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.v(TAG, "Remaining: " + remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public FaceSettingsRemoveButtonPreferenceController(Context context, String preferenceKey) {
|
public FaceSettingsRemoveButtonPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
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) {
|
public FaceSettingsRemoveButtonPreferenceController(Context context) {
|
||||||
@@ -66,7 +114,21 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v == mButton) {
|
if (v == mButton) {
|
||||||
|
mButton.setEnabled(false);
|
||||||
|
if (mFaces.isEmpty()) {
|
||||||
|
Log.e(TAG, "No faces");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mFaces.size() > 1) {
|
||||||
|
Log.e(TAG, "Multiple enrollments: " + mFaces.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the first/only face
|
||||||
|
mFaceManager.remove(mFaces.get(0), mUserId, mRemovalCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(Listener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user