List of usage examples for android.app KeyguardManager isKeyguardSecure
public boolean isKeyguardSecure()
From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); utilsProvider = (UtilitiesProviderInterface) getActivity(); PreferenceUtils.reset();/*from w w w . jav a 2 s .co m*/ // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); for (String PREFERENCE_KEY : PREFERENCE_KEYS) { findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this); } gplus = (CheckBox) findPreference("plus_pic"); if (BuildConfig.IS_VERSION_FDROID) gplus.setEnabled(false); // crypt master password final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference( PREFERENCE_CRYPT_MASTER_PASSWORD); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { // encryption feature not available masterPasswordPreference.setEnabled(false); } if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) { masterPasswordPreference.setEnabled(false); } CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT); try { // finger print sensor final FingerprintManager fingerprintManager = (FingerprintManager) getActivity() .getSystemService(Context.FINGERPRINT_SERVICE); final KeyguardManager keyguardManager = (KeyguardManager) getActivity() .getSystemService(Context.KEYGUARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) { checkBoxFingerprint.setEnabled(true); } checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_permission), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !fingerprintManager.hasEnrolledFingerprints()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_not_enrolled), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !keyguardManager.isKeyguardSecure()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG) .show(); return false; } masterPasswordPreference.setEnabled(false); return true; } }); } catch (NoClassDefFoundError error) { error.printStackTrace(); // fingerprint manager class not defined in the framework checkBoxFingerprint.setEnabled(false); } // Hide root preference Preference mRootMode = findPreference("rootmode"); PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc"); mMisc.removePreference(mRootMode); }