| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.biometrics; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.app.admin.DevicePolicyManager; |
| 22 |
import android.content.ComponentName; |
| 23 |
import android.content.Context; |
| 24 |
import android.os.Build; |
| 25 |
import android.os.UserHandle; |
| 26 |
import android.provider.Settings; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class ParentalControlsUtilsInternal { |
| 34 |
|
| 35 |
private static final String TEST_ALWAYS_REQUIRE_CONSENT_PACKAGE = |
| 36 |
"android.hardware.biometrics.ParentalControlsUtilsInternal.require_consent_package"; |
| 37 |
private static final String TEST_ALWAYS_REQUIRE_CONSENT_CLASS = |
| 38 |
"android.hardware.biometrics.ParentalControlsUtilsInternal.require_consent_class"; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static ComponentName getTestComponentName(@NonNull Context context, int userId) { |
| 48 |
if (Build.IS_USERDEBUG || Build.IS_ENG) { |
| 49 |
final String pkg = Settings.Secure.getStringForUser(context.getContentResolver(), |
| 50 |
TEST_ALWAYS_REQUIRE_CONSENT_PACKAGE, userId); |
| 51 |
final String cls = Settings.Secure.getStringForUser(context.getContentResolver(), |
| 52 |
TEST_ALWAYS_REQUIRE_CONSENT_CLASS, userId); |
| 53 |
return pkg != null && cls != null ? new ComponentName(pkg, cls) : null; |
| 54 |
} |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
public static boolean parentConsentRequired(@NonNull Context context, |
| 59 |
@NonNull DevicePolicyManager dpm, @BiometricAuthenticator.Modality int modality, |
| 60 |
@NonNull UserHandle userHandle) { |
| 61 |
if (getTestComponentName(context, userHandle.getIdentifier()) != null) { |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
return parentConsentRequired(dpm, modality, userHandle); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public static boolean parentConsentRequired(@NonNull DevicePolicyManager dpm, |
| 72 |
@BiometricAuthenticator.Modality int modality, @NonNull UserHandle userHandle) { |
| 73 |
final ComponentName cn = getSupervisionComponentName(dpm, userHandle); |
| 74 |
if (cn == null) { |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
final int keyguardDisabledFeatures = dpm.getKeyguardDisabledFeatures(cn); |
| 79 |
final boolean dpmFpDisabled = containsFlag(keyguardDisabledFeatures, |
| 80 |
DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT); |
| 81 |
final boolean dpmFaceDisabled = containsFlag(keyguardDisabledFeatures, |
| 82 |
DevicePolicyManager.KEYGUARD_DISABLE_FACE); |
| 83 |
final boolean dpmIrisDisabled = containsFlag(keyguardDisabledFeatures, |
| 84 |
DevicePolicyManager.KEYGUARD_DISABLE_IRIS); |
| 85 |
|
| 86 |
final boolean consentRequired; |
| 87 |
if (containsFlag(modality, BiometricAuthenticator.TYPE_FINGERPRINT) && dpmFpDisabled) { |
| 88 |
consentRequired = true; |
| 89 |
} else if (containsFlag(modality, BiometricAuthenticator.TYPE_FACE) && dpmFaceDisabled) { |
| 90 |
consentRequired = true; |
| 91 |
} else if (containsFlag(modality, BiometricAuthenticator.TYPE_IRIS) && dpmIrisDisabled) { |
| 92 |
consentRequired = true; |
| 93 |
} else { |
| 94 |
consentRequired = false; |
| 95 |
} |
| 96 |
|
| 97 |
return consentRequired; |
| 98 |
} |
| 99 |
|
| 100 |
@Nullable |
| 101 |
public static ComponentName getSupervisionComponentName(@NonNull DevicePolicyManager dpm, |
| 102 |
@NonNull UserHandle userHandle) { |
| 103 |
return dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(userHandle); |
| 104 |
} |
| 105 |
|
| 106 |
private static boolean containsFlag(int haystack, int needle) { |
| 107 |
return (haystack & needle) != 0; |
| 108 |
} |
| 109 |
} |