Move all the shared data from biometric controllers to separate utility classes
Test: atest SettingsUnitTests Bug: 215517420 Change-Id: Ic5421cd910ae77d4e7c0a29ae0337edb98a1d3b9
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.biometrics.BiometricAuthenticator;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.ParentalControlsUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
/**
|
||||
* Utilities for face details shared between Security Settings and Safety Center.
|
||||
*/
|
||||
public class FaceStatusUtils {
|
||||
|
||||
private final int mUserId = UserHandle.myUserId();
|
||||
private final Context mContext;
|
||||
private final FaceManager mFaceManager;
|
||||
|
||||
public FaceStatusUtils(Context context, FaceManager faceManager) {
|
||||
mContext = context;
|
||||
mFaceManager = faceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the face settings entity should be shown.
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link EnforcedAdmin} if parental consent is required to change face settings.
|
||||
*
|
||||
* @return null if face settings does not require a parental consent.
|
||||
*/
|
||||
public EnforcedAdmin getDisablingAdmin() {
|
||||
return ParentalControlsUtils.parentConsentRequired(
|
||||
mContext, BiometricAuthenticator.TYPE_FACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary of face settings entity.
|
||||
*/
|
||||
public String getSummary() {
|
||||
return mContext.getResources().getString(hasEnrolled()
|
||||
? R.string.security_settings_face_preference_summary
|
||||
: R.string.security_settings_face_preference_summary_none);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name of the Settings page corresponding to face settings.
|
||||
*/
|
||||
public String getSettingsClassName() {
|
||||
return hasEnrolled() ? Settings.FaceSettingsActivity.class.getName()
|
||||
: FaceEnrollIntroduction.class.getName();
|
||||
}
|
||||
|
||||
private boolean hasEnrolled() {
|
||||
return mFaceManager.hasEnrolledTemplates(mUserId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user