Search in sources :

Example 1 with BiometricError

use of android.hardware.biometrics.BiometricManager.BiometricError in project android_packages_apps_Settings by omnirom.

the class BiometricEnrollActivity method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent intent = getIntent();
    if (this instanceof InternalActivity) {
        mUserId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
        if (BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
            mGkPwHandle = BiometricUtils.getGatekeeperPasswordHandle(getIntent());
        }
    }
    if (savedInstanceState != null) {
        mConfirmingCredentials = savedInstanceState.getBoolean(SAVED_STATE_CONFIRMING_CREDENTIALS, false);
        mIsEnrollActionLogged = savedInstanceState.getBoolean(SAVED_STATE_ENROLL_ACTION_LOGGED, false);
        mParentalOptions = savedInstanceState.getBundle(SAVED_STATE_PARENTAL_OPTIONS);
        if (savedInstanceState.containsKey(SAVED_STATE_GK_PW_HANDLE)) {
            mGkPwHandle = savedInstanceState.getLong(SAVED_STATE_GK_PW_HANDLE);
        }
    }
    // Log a framework stats event if this activity was launched via intent action.
    if (!mIsEnrollActionLogged && ACTION_BIOMETRIC_ENROLL.equals(intent.getAction())) {
        mIsEnrollActionLogged = true;
        // Get the current status for each authenticator type.
        @BiometricError final int strongBiometricStatus;
        @BiometricError final int weakBiometricStatus;
        @BiometricError final int deviceCredentialStatus;
        final BiometricManager bm = getSystemService(BiometricManager.class);
        if (bm != null) {
            strongBiometricStatus = bm.canAuthenticate(Authenticators.BIOMETRIC_STRONG);
            weakBiometricStatus = bm.canAuthenticate(Authenticators.BIOMETRIC_WEAK);
            deviceCredentialStatus = bm.canAuthenticate(Authenticators.DEVICE_CREDENTIAL);
        } else {
            strongBiometricStatus = BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE;
            weakBiometricStatus = BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE;
            deviceCredentialStatus = BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE;
        }
        FrameworkStatsLog.write(FrameworkStatsLog.AUTH_ENROLL_ACTION_INVOKED, strongBiometricStatus == BiometricManager.BIOMETRIC_SUCCESS, weakBiometricStatus == BiometricManager.BIOMETRIC_SUCCESS, deviceCredentialStatus == BiometricManager.BIOMETRIC_SUCCESS, intent.hasExtra(EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED), intent.getIntExtra(EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, 0));
    }
    // Put the theme in the intent so it gets propagated to other activities in the flow
    if (intent.getStringExtra(WizardManagerHelper.EXTRA_THEME) == null) {
        intent.putExtra(WizardManagerHelper.EXTRA_THEME, SetupWizardUtils.getThemeString(intent));
    }
    final PackageManager pm = getApplicationContext().getPackageManager();
    mHasFeatureFingerprint = pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT);
    mHasFeatureFace = pm.hasSystemFeature(PackageManager.FEATURE_FACE);
    // determine what can be enrolled
    final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
    if (mHasFeatureFace) {
        final FaceManager faceManager = getSystemService(FaceManager.class);
        final List<FaceSensorPropertiesInternal> faceProperties = faceManager.getSensorPropertiesInternal();
        if (!faceProperties.isEmpty()) {
            final int maxEnrolls = isSetupWizard ? 1 : faceProperties.get(0).maxEnrollmentsPerUser;
            mIsFaceEnrollable = faceManager.getEnrolledFaces(mUserId).size() < maxEnrolls;
        }
    }
    if (mHasFeatureFingerprint) {
        final FingerprintManager fpManager = getSystemService(FingerprintManager.class);
        final List<FingerprintSensorPropertiesInternal> fpProperties = fpManager.getSensorPropertiesInternal();
        if (!fpProperties.isEmpty()) {
            final int maxEnrolls = isSetupWizard ? 1 : fpProperties.get(0).maxEnrollmentsPerUser;
            mIsFingerprintEnrollable = fpManager.getEnrolledFingerprints(mUserId).size() < maxEnrolls;
        }
    }
    mParentalOptionsRequired = intent.getBooleanExtra(EXTRA_REQUIRE_PARENTAL_CONSENT, false);
    mSkipReturnToParent = intent.getBooleanExtra(EXTRA_SKIP_RETURN_TO_PARENT, false);
    Log.d(TAG, "parentalOptionsRequired: " + mParentalOptionsRequired + ", skipReturnToParent: " + mSkipReturnToParent + ", isSetupWizard: " + isSetupWizard);
    // module. This can be removed when there is a way to notify consent status out of band.
    if (isSetupWizard && mParentalOptionsRequired) {
        Log.w(TAG, "Enrollment with parental consent is not supported when launched " + " directly from SuW - skipping enrollment");
        setResult(RESULT_SKIP);
        finish();
        return;
    }
    // restarting the process once it has been fully completed at least one time.
    if (isSetupWizard && mParentalOptionsRequired) {
        final boolean consentAlreadyManaged = ParentalControlsUtils.parentConsentRequired(this, BiometricAuthenticator.TYPE_FACE | BiometricAuthenticator.TYPE_FINGERPRINT) != null;
        if (consentAlreadyManaged) {
            Log.w(TAG, "Consent was already setup - skipping enrollment");
            setResult(RESULT_SKIP);
            finish();
            return;
        }
    }
    // start enrollment process if we haven't bailed out yet
    if (mParentalOptionsRequired && mParentalOptions == null) {
        mParentalConsentHelper = new ParentalConsentHelper(mIsFaceEnrollable, mIsFingerprintEnrollable, mGkPwHandle);
        setOrConfirmCredentialsNow();
    } else {
        startEnroll();
    }
}
Also used : FingerprintSensorPropertiesInternal(android.hardware.fingerprint.FingerprintSensorPropertiesInternal) BiometricError(android.hardware.biometrics.BiometricManager.BiometricError) Intent(android.content.Intent) FaceSensorPropertiesInternal(android.hardware.face.FaceSensorPropertiesInternal) BiometricManager(android.hardware.biometrics.BiometricManager) PackageManager(android.content.pm.PackageManager) FingerprintManager(android.hardware.fingerprint.FingerprintManager) FaceManager(android.hardware.face.FaceManager)

Example 2 with BiometricError

use of android.hardware.biometrics.BiometricManager.BiometricError in project android_packages_apps_Settings by omnirom.

the class BiometricEnrollActivity method startEnrollWith.

private void startEnrollWith(@Authenticators.Types int authenticators, boolean setupWizard) {
    // If the caller is not setup wizard, and the user has something enrolled, finish.
    if (!setupWizard) {
        final BiometricManager bm = getSystemService(BiometricManager.class);
        @BiometricError final int result = bm.canAuthenticate(authenticators);
        if (result != BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) {
            Log.e(TAG, "Unexpected result (has enrollments): " + result);
            finish();
            return;
        }
    }
    boolean canUseFace = mHasFeatureFace;
    boolean canUseFingerprint = mHasFeatureFingerprint;
    if (mParentalOptionsRequired) {
        if (mParentalOptions == null) {
            throw new IllegalStateException("consent options required, but not set");
        }
        canUseFace = canUseFace && ParentalConsentHelper.hasFaceConsent(mParentalOptions);
        canUseFingerprint = canUseFingerprint && ParentalConsentHelper.hasFingerprintConsent(mParentalOptions);
    }
    // This will need to be updated if the device has sensors other than BIOMETRIC_STRONG
    if (!setupWizard && authenticators == BiometricManager.Authenticators.DEVICE_CREDENTIAL) {
        launchCredentialOnlyEnroll();
        finish();
    } else if (canUseFace && canUseFingerprint) {
        if (mGkPwHandle != null) {
            launchFaceAndFingerprintEnroll();
        } else {
            setOrConfirmCredentialsNow();
        }
    } else if (canUseFingerprint) {
        launchFingerprintOnlyEnroll();
    } else if (canUseFace) {
        launchFaceOnlyEnroll();
    } else {
        // no modalities available
        if (mParentalOptionsRequired) {
            Log.d(TAG, "No consent for any modality: skipping enrollment");
            setResult(RESULT_OK, newResultIntent());
        } else {
            Log.e(TAG, "Unknown state, finishing (was SUW: " + setupWizard + ")");
        }
        finish();
    }
}
Also used : BiometricManager(android.hardware.biometrics.BiometricManager) BiometricError(android.hardware.biometrics.BiometricManager.BiometricError)

Aggregations

BiometricManager (android.hardware.biometrics.BiometricManager)2 BiometricError (android.hardware.biometrics.BiometricManager.BiometricError)2 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 FaceManager (android.hardware.face.FaceManager)1 FaceSensorPropertiesInternal (android.hardware.face.FaceSensorPropertiesInternal)1 FingerprintManager (android.hardware.fingerprint.FingerprintManager)1 FingerprintSensorPropertiesInternal (android.hardware.fingerprint.FingerprintSensorPropertiesInternal)1