Add yubikey default PIN preference

This commit is contained in:
Dominik Schürmann 2014-09-05 19:40:04 +02:00
parent 2a9b083012
commit fa9bbdd60c
5 changed files with 47 additions and 15 deletions

View File

@ -78,6 +78,7 @@ public final class Constants {
public static final String CACHED_CONSOLIDATE = "cachedConsolidate";
public static final String CACHED_CONSOLIDATE_SECRETS = "cachedConsolidateSecrets";
public static final String CACHED_CONSOLIDATE_PUBLICS = "cachedConsolidatePublics";
public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin";
}
public static final class Defaults {

View File

@ -179,6 +179,16 @@ public class Preferences {
return mSharedPreferences.getBoolean(Constants.Pref.FIRST_TIME, true);
}
public boolean useDefaultYubikeyPin() {
return mSharedPreferences.getBoolean(Pref.USE_DEFAULT_YUBIKEY_PIN, true);
}
public void setUseDefaultYubikeyPin(boolean useDefaultYubikeyPin) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Pref.USE_DEFAULT_YUBIKEY_PIN, useDefaultYubikeyPin);
editor.commit();
}
public void setFirstTime(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.Pref.FIRST_TIME, value);
@ -216,6 +226,16 @@ public class Preferences {
editor.commit();
}
public void setWriteVersionHeader(boolean conceal) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.Pref.WRITE_VERSION_HEADER, conceal);
editor.commit();
}
public boolean getWriteVersionHeader() {
return mSharedPreferences.getBoolean(Constants.Pref.WRITE_VERSION_HEADER, false);
}
public void updatePreferences() {
// migrate keyserver to hkps
if (mSharedPreferences.getInt(Constants.Pref.KEY_SERVERS_DEFAULT_VERSION, 0) !=
@ -256,14 +276,4 @@ public class Preferences {
setDefaultHashAlgorithm(HashAlgorithmTags.SHA512);
}
}
public void setWriteVersionHeader(boolean conceal) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.Pref.WRITE_VERSION_HEADER, conceal);
editor.commit();
}
public boolean getWriteVersionHeader() {
return mSharedPreferences.getBoolean(Constants.Pref.WRITE_VERSION_HEADER, false);
}
}

View File

@ -53,11 +53,6 @@ public class PreferencesActivity extends PreferenceActivity {
sPreferences = Preferences.getPreferences(this);
super.onCreate(savedInstanceState);
// final ActionBar actionBar = getSupportActionBar();
// actionBar.setDisplayShowTitleEnabled(true);
// actionBar.setDisplayHomeAsUpEnabled(false);
// actionBar.setHomeButtonEnabled(false);
String action = getIntent().getAction();
if (action != null && action.equals(ACTION_PREFS_GEN)) {
@ -122,6 +117,9 @@ public class PreferencesActivity extends PreferenceActivity {
initializeWriteVersionHeader(
(CheckBoxPreference) findPreference(Constants.Pref.WRITE_VERSION_HEADER));
initializeUseDefaultYubikeyPin(
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// Load the legacy preferences headers
addPreferencesFromResource(R.xml.preference_headers_legacy);
@ -265,6 +263,9 @@ public class PreferencesActivity extends PreferenceActivity {
initializeWriteVersionHeader(
(CheckBoxPreference) findPreference(Constants.Pref.WRITE_VERSION_HEADER));
initializeUseDefaultYubikeyPin(
(CheckBoxPreference) findPreference(Constants.Pref.USE_DEFAULT_YUBIKEY_PIN));
}
}
@ -396,4 +397,15 @@ public class PreferencesActivity extends PreferenceActivity {
}
});
}
private static void initializeUseDefaultYubikeyPin(final CheckBoxPreference mUseDefaultYubikeyPin) {
mUseDefaultYubikeyPin.setChecked(sPreferences.useDefaultYubikeyPin());
mUseDefaultYubikeyPin.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
mUseDefaultYubikeyPin.setChecked((Boolean) newValue);
sPreferences.setUseDefaultYubikeyPin((Boolean) newValue);
return false;
}
});
}
}

View File

@ -93,6 +93,8 @@
<string name="label_file_ascii_armor">Files: ASCII Armor</string>
<string name="label_write_version_header">Let others know that you\'re using OpenKeychain</string>
<string name="label_write_version_header_summary">Writes \'OpenKeychain v2.7\' to OpenPGP signatures, ciphertext, and exported keys</string>
<string name="label_use_default_yubikey_pin">Use default Yubikey PIN</string>
<string name="label_label_use_default_yubikey_pin_summary">Uses default PIN (123456) to access Yubikeys over NFC</string>
<string name="label_asymmetric_from">Signed by:</string>
<string name="label_to">Encrypt to:</string>
<string name="label_delete_after_encryption">Files: Delete After Encryption</string>

View File

@ -28,4 +28,11 @@
android:title="@string/label_write_version_header"
android:summary="@string/label_write_version_header_summary" />
</PreferenceCategory>
<CheckBoxPreference
android:key="useDefaultYubikeyPin"
android:persistent="false"
android:defaultValue="true"
android:title="@string/label_use_default_yubikey_pin"
android:summary="@string/label_label_use_default_yubikey_pin_summary" />
</PreferenceScreen>