Search in sources :

Example 41 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android_packages_apps_Settings by omnirom.

the class FingerprintEnrollFinish method onResume.

@Override
protected void onResume() {
    super.onResume();
    FooterButton addButton = mFooterBarMixin.getSecondaryButton();
    final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
    boolean hideAddAnother = false;
    if (fpm != null) {
        int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
        int max = getResources().getInteger(com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
        hideAddAnother = enrolled >= max;
    }
    if (hideAddAnother) {
        // Don't show "Add" button if too many fingerprints already added
        addButton.setVisibility(View.INVISIBLE);
    } else {
        addButton.setOnClickListener(this::onAddAnotherButtonClick);
    }
}
Also used : FooterButton(com.google.android.setupcompat.template.FooterButton) FingerprintManager(android.hardware.fingerprint.FingerprintManager)

Example 42 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager 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 43 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android_packages_apps_Settings by omnirom.

the class SetNewPasswordController method create.

public static SetNewPasswordController create(Context context, Ui ui, Intent intent, IBinder activityToken) {
    // Trying to figure out which user is setting new password. If it is
    // ACTION_SET_NEW_PARENT_PROFILE_PASSWORD or the calling user is not allowed to set
    // separate profile challenge, it is the current user to set new password. Otherwise,
    // it is the user who starts this activity setting new password.
    int userId = ActivityManager.getCurrentUser();
    if (ACTION_SET_NEW_PASSWORD.equals(intent.getAction())) {
        final int callingUserId = Utils.getSecureTargetUser(activityToken, UserManager.get(context), null, intent.getExtras()).getIdentifier();
        final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
        if (lockPatternUtils.isSeparateProfileChallengeAllowed(callingUserId)) {
            userId = callingUserId;
        }
    }
    // Create a wrapper of FingerprintManager for testing, see IFingerPrintManager for details.
    final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
    final FaceManager faceManager = Utils.getFaceManagerOrNull(context);
    return new SetNewPasswordController(userId, context.getPackageManager(), fingerprintManager, faceManager, (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE), ui);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) FaceManager(android.hardware.face.FaceManager)

Example 44 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android_frameworks_base by crdroidandroid.

the class KeymasterUtils method addUserAuthArgs.

/**
     * Adds keymaster arguments to express the key's authorization policy supported by user
     * authentication.
     *
     * @param userAuthenticationRequired whether user authentication is required to authorize the
     *        use of the key.
     * @param userAuthenticationValidityDurationSeconds duration of time (seconds) for which user
     *        authentication is valid as authorization for using the key or {@code -1} if every
     *        use of the key needs authorization.
     *
     * @throws IllegalStateException if user authentication is required but the system is in a wrong
     *         state (e.g., secure lock screen not set up) for generating or importing keys that
     *         require user authentication.
     */
public static void addUserAuthArgs(KeymasterArguments args, boolean userAuthenticationRequired, int userAuthenticationValidityDurationSeconds, boolean userAuthenticationValidWhileOnBody, boolean invalidatedByBiometricEnrollment) {
    if (!userAuthenticationRequired) {
        args.addBoolean(KeymasterDefs.KM_TAG_NO_AUTH_REQUIRED);
        return;
    }
    if (userAuthenticationValidityDurationSeconds == -1) {
        // Every use of this key needs to be authorized by the user. This currently means
        // fingerprint-only auth.
        FingerprintManager fingerprintManager = KeyStore.getApplicationContext().getSystemService(FingerprintManager.class);
        // TODO: Restore USE_FINGERPRINT permission check in
        // FingerprintManager.getAuthenticatorId once the ID is no longer needed here.
        long fingerprintOnlySid = (fingerprintManager != null) ? fingerprintManager.getAuthenticatorId() : 0;
        if (fingerprintOnlySid == 0) {
            throw new IllegalStateException("At least one fingerprint must be enrolled to create keys requiring user" + " authentication for every use");
        }
        long sid;
        if (invalidatedByBiometricEnrollment) {
            // The fingerprint-only SID will change on fingerprint enrollment or removal of all,
            // enrolled fingerprints, invalidating the key.
            sid = fingerprintOnlySid;
        } else {
            // The root SID will *not* change on fingerprint enrollment, or removal of all
            // enrolled fingerprints, allowing the key to remain valid.
            sid = getRootSid();
        }
        args.addUnsignedLong(KeymasterDefs.KM_TAG_USER_SECURE_ID, KeymasterArguments.toUint64(sid));
        args.addEnum(KeymasterDefs.KM_TAG_USER_AUTH_TYPE, KeymasterDefs.HW_AUTH_FINGERPRINT);
        if (userAuthenticationValidWhileOnBody) {
            throw new ProviderException("Key validity extension while device is on-body is not " + "supported for keys requiring fingerprint authentication");
        }
    } else {
        // The key is authorized for use for the specified amount of time after the user has
        // authenticated. Whatever unlocks the secure lock screen should authorize this key.
        long rootSid = getRootSid();
        args.addUnsignedLong(KeymasterDefs.KM_TAG_USER_SECURE_ID, KeymasterArguments.toUint64(rootSid));
        args.addEnum(KeymasterDefs.KM_TAG_USER_AUTH_TYPE, KeymasterDefs.HW_AUTH_PASSWORD | KeymasterDefs.HW_AUTH_FINGERPRINT);
        args.addUnsignedInt(KeymasterDefs.KM_TAG_AUTH_TIMEOUT, userAuthenticationValidityDurationSeconds);
        if (userAuthenticationValidWhileOnBody) {
            args.addBoolean(KeymasterDefs.KM_TAG_ALLOW_WHILE_ON_BODY);
        }
    }
}
Also used : ProviderException(java.security.ProviderException) FingerprintManager(android.hardware.fingerprint.FingerprintManager)

Example 45 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android_packages_apps_Settings by LineageOS.

the class FingerprintEnrollIntroduction method onResume.

@Override
protected void onResume() {
    super.onResume();
    final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(this);
    int errorMsg = 0;
    if (fingerprintManager != null) {
        final int max = getResources().getInteger(com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
        final int numEnrolledFingerprints = fingerprintManager.getEnrolledFingerprints(mUserId).size();
        if (numEnrolledFingerprints >= max) {
            errorMsg = R.string.fingerprint_intro_error_max;
        }
    } else {
        errorMsg = R.string.fingerprint_intro_error_unknown;
    }
    if (errorMsg == 0) {
        mErrorText.setText(null);
        getNextButton().setVisibility(View.VISIBLE);
    } else {
        mErrorText.setText(errorMsg);
        getNextButton().setVisibility(View.GONE);
    }
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager)

Aggregations

FingerprintManager (android.hardware.fingerprint.FingerprintManager)82 Test (org.junit.Test)18 Intent (android.content.Intent)11 ComponentName (android.content.ComponentName)8 Button (android.widget.Button)8 KeyguardManager (android.app.KeyguardManager)7 Context (android.content.Context)7 Fingerprint (android.hardware.fingerprint.Fingerprint)7 UserManager (android.os.UserManager)7 Preference (android.support.v7.preference.Preference)7 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)7 SpannableString (android.text.SpannableString)7 TextPaint (android.text.TextPaint)7 LockPatternUtils (com.android.internal.widget.LockPatternUtils)7 FingerprintEnrollSuggestionActivity (com.android.settings.Settings.FingerprintEnrollSuggestionActivity)6 FingerprintSuggestionActivity (com.android.settings.fingerprint.FingerprintSuggestionActivity)6 WallpaperSuggestionActivity (com.android.settings.wallpaper.WallpaperSuggestionActivity)6 TwoTargetPreference (com.android.settingslib.TwoTargetPreference)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 FaceManager (android.hardware.face.FaceManager)5