Skip to content

Commit afd3577

Browse files
committed
Settings: Power button press to unlock with fingerprint [2/2]
* this is for devices that have fingerprint sensor embedded in the power button, such as modern side mounted fp devices and requires overlay in device tree (refer fwb counterpart) Signed-off-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
1 parent 9ac95bc commit afd3577

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

res/values/wave_strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,9 @@
235235
<string name="incall_vibrate_call_wait_title">Vibrate on call waiting</string>
236236
<string name="incall_vibrate_disconnect_title">Vibrate on disconnect</string>
237237

238+
<!-- Power Button Fingerprint -->
239+
<string name="fingerprint_power_button_press_title">Press to unlock</string>
240+
<string name="fingerprint_power_button_press_off_summary">Touch power button to unlock with fingerprint when screen is off</string>
241+
<string name="fingerprint_power_button_press_on_summary">Press power button firmly to unlock with fingerprint when screen is off</string>
242+
238243
</resources>

src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.android.settings.biometrics.fingerprint;
1818

19-
2019
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
2120

2221
import android.app.Activity;
@@ -33,6 +32,7 @@
3332
import android.os.Handler;
3433
import android.os.UserHandle;
3534
import android.os.UserManager;
35+
import android.provider.Settings;
3636
import android.text.TextUtils;
3737
import android.util.Log;
3838
import android.view.View;
@@ -51,6 +51,7 @@
5151
import com.android.settings.SettingsPreferenceFragment;
5252
import com.android.settings.SubSettings;
5353
import com.android.settings.Utils;
54+
import com.android.settings.accessibility.DividerSwitchPreference;
5455
import com.android.settings.biometrics.BiometricEnrollBase;
5556
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
5657
import com.android.settings.password.ChooseLockGeneric;
@@ -111,6 +112,8 @@ public static class FingerprintSettingsFragment extends SettingsPreferenceFragme
111112
private static final String KEY_FINGERPRINT_ADD = "key_fingerprint_add";
112113
private static final String KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE =
113114
"fingerprint_enable_keyguard_toggle";
115+
private static final String KEY_FINGERPRINT_POWER_BUTTON_PRESS =
116+
"fingerprint_power_button_press";
114117
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
115118

116119
private static final int MSG_REFRESH_FINGERPRINT_TEMPLATES = 1000;
@@ -373,6 +376,12 @@ private PreferenceScreen createPreferenceHierarchy() {
373376
return root;
374377
}
375378

379+
private boolean isPowerButtonPressEnabled() {
380+
return Settings.Secure.getIntForUser(getContext().getContentResolver(),
381+
Settings.Secure.FINGERPRINT_POWER_BUTTON_PRESS, 0,
382+
UserHandle.USER_CURRENT) == 1;
383+
}
384+
376385
private void addFingerprintItemPreferences(PreferenceGroup root) {
377386
root.removeAll();
378387
final List<Fingerprint> items = mFingerprintManager.getEnrolledFingerprints(mUserId);
@@ -402,6 +411,18 @@ private void addFingerprintItemPreferences(PreferenceGroup root) {
402411
root.addPreference(addPreference);
403412
addPreference.setOnPreferenceChangeListener(this);
404413
updateAddPreference();
414+
if (getContext().getResources().getBoolean(
415+
com.android.internal.R.bool.config_powerButtonFingerprint)) {
416+
DividerSwitchPreference powerButtonPref = new DividerSwitchPreference(root.getContext());
417+
powerButtonPref.setKey(KEY_FINGERPRINT_POWER_BUTTON_PRESS);
418+
powerButtonPref.setTitle(R.string.fingerprint_power_button_press_title);
419+
powerButtonPref.setSummary(isPowerButtonPressEnabled() ?
420+
R.string.fingerprint_power_button_press_on_summary :
421+
R.string.fingerprint_power_button_press_off_summary);
422+
powerButtonPref.setChecked(isPowerButtonPressEnabled());
423+
powerButtonPref.setOnPreferenceChangeListener(this);
424+
root.addPreference(powerButtonPref);
425+
}
405426
createFooterPreference(root);
406427
}
407428

@@ -549,6 +570,14 @@ public boolean onPreferenceChange(Preference preference, Object value) {
549570
final String key = preference.getKey();
550571
if (KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE.equals(key)) {
551572
// TODO
573+
} else if (KEY_FINGERPRINT_POWER_BUTTON_PRESS.equals(key)) {
574+
boolean enabled = (Boolean) value;
575+
result = Settings.Secure.putIntForUser(getContext().getContentResolver(),
576+
Settings.Secure.FINGERPRINT_POWER_BUTTON_PRESS,
577+
enabled ? 1 : 0, UserHandle.USER_CURRENT);
578+
if (result)
579+
preference.setSummary(enabled ? R.string.fingerprint_power_button_press_on_summary
580+
: R.string.fingerprint_power_button_press_off_summary);
552581
} else {
553582
Log.v(TAG, "Unknown key:" + key);
554583
}

0 commit comments

Comments
 (0)