Search in sources :

Example 46 with FingerprintManager

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

the class FingerprintSettings method getFingerprintPreferenceForUser.

public static Preference getFingerprintPreferenceForUser(Context context, final int userId) {
    final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(context);
    if (fpm == null || !fpm.isHardwareDetected()) {
        Log.v(TAG, "No fingerprint hardware detected!!");
        return null;
    }
    Preference fingerprintPreference = new Preference(context);
    fingerprintPreference.setKey(KEY_FINGERPRINT_SETTINGS);
    fingerprintPreference.setTitle(R.string.security_settings_fingerprint_preference_title);
    final List<Fingerprint> items = fpm.getEnrolledFingerprints(userId);
    final int fingerprintCount = items != null ? items.size() : 0;
    final String clazz;
    if (fingerprintCount > 0) {
        fingerprintPreference.setSummary(context.getResources().getQuantityString(R.plurals.security_settings_fingerprint_preference_summary, fingerprintCount, fingerprintCount));
        clazz = FingerprintSettings.class.getName();
    } else {
        fingerprintPreference.setSummary(R.string.security_settings_fingerprint_preference_summary_none);
        clazz = FingerprintEnrollIntroduction.class.getName();
    }
    fingerprintPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            final Context context = preference.getContext();
            final UserManager userManager = UserManager.get(context);
            if (Utils.startQuietModeDialogIfNecessary(context, userManager, userId)) {
                return false;
            }
            Intent intent = new Intent();
            intent.setClassName("com.android.settings", clazz);
            intent.putExtra(Intent.EXTRA_USER_ID, userId);
            context.startActivity(intent);
            return true;
        }
    });
    return fingerprintPreference;
}
Also used : Context(android.content.Context) Fingerprint(android.hardware.fingerprint.Fingerprint) Intent(android.content.Intent) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Fingerprint(android.hardware.fingerprint.Fingerprint) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) FooterPreference(com.android.settingslib.widget.FooterPreference) TwoTargetPreference(com.android.settingslib.TwoTargetPreference) Preference(android.support.v7.preference.Preference) FingerprintManager(android.hardware.fingerprint.FingerprintManager) UserManager(android.os.UserManager)

Example 47 with FingerprintManager

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

the class SecuritySettingsTest method testSummaryProvider_hasFingerPrint_hasStaticSummary.

@Test
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
    final FingerprintManager fpm = mock(FingerprintManager.class);
    when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
    // Cast to Object to workaround a robolectric casting bug
    when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
    when(fpm.isHardwareDetected()).thenReturn(true);
    mSummaryProvider.setListening(true);
    verify(mContext).getString(R.string.security_dashboard_summary);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) Test(org.junit.Test)

Example 48 with FingerprintManager

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

the class SecuritySettingsTest method testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint.

@Test
public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
    final FingerprintManager fpm = mock(FingerprintManager.class);
    when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(false);
    mSummaryProvider.setListening(true);
    verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) Test(org.junit.Test)

Example 49 with FingerprintManager

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

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 IFingerprintManager fingerprintManagerWrapper = fingerprintManager == null ? null : new FingerprintManagerWrapper(fingerprintManager);
    return new SetNewPasswordController(userId, context.getPackageManager(), fingerprintManagerWrapper, (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE), ui);
}
Also used : FingerprintManager(android.hardware.fingerprint.FingerprintManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils)

Example 50 with FingerprintManager

use of android.hardware.fingerprint.FingerprintManager in project android by nextcloud.

the class FingerprintHandler method startFingerprint.

private void startFingerprint() {
    TextView fingerprintTextView = (TextView) findViewById(R.id.scanfingerprinttext);
    FingerprintManager fingerprintManager = (FingerprintManager) MainApp.getAppContext().getSystemService(Context.FINGERPRINT_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    if (keyguardManager.isKeyguardSecure()) {
        generateKey();
        if (cipherInit()) {
            FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
            FingerprintHandler.Callback callback = new FingerprintHandler.Callback() {

                @Override
                public void onAuthenticated() {
                    fingerprintResult(true);
                }

                @Override
                public void onFailed(String error) {
                    Toast.makeText(MainApp.getAppContext(), error, Toast.LENGTH_LONG).show();
                    ImageView imageView = (ImageView) findViewById(R.id.fingerprinticon);
                    int[][] states = new int[][] { new int[] { android.R.attr.state_activated }, new int[] { -android.R.attr.state_activated } };
                    int[] colors = new int[] { Color.parseColor("#FF0000"), Color.RED };
                    ColorStateList csl = new ColorStateList(states, colors);
                    Drawable drawable = DrawableCompat.wrap(imageView.getDrawable());
                    DrawableCompat.setTintList(drawable, csl);
                    imageView.setImageDrawable(drawable);
                }
            };
            FingerprintHandler helper = new FingerprintHandler(fingerprintTextView, callback);
            cancellationSignal = new CancellationSignal();
            if (ActivityCompat.checkSelfPermission(MainApp.getAppContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            fingerprintManager.authenticate(cryptoObject, cancellationSignal, 0, helper, null);
        }
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) FingerprintManager(android.hardware.fingerprint.FingerprintManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) KeyguardManager(android.app.KeyguardManager) CancellationSignal(android.os.CancellationSignal)

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