mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-12 04:25:08 -05:00
Eliminate secret debug preferences activity. Add debug preferences to
global preferences.
This commit is contained in:
parent
94c9454c75
commit
581486fbd5
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/debug_version_fmt"
|
||||
/>
|
||||
<CheckBox
|
||||
android:id="@+id/debug_logging"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/debug_enable_debug_logging_label"
|
||||
/>
|
||||
<CheckBox
|
||||
android:id="@+id/sensitive_logging"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/debug_enable_sensitive_logging_label"
|
||||
/>
|
||||
</LinearLayout>
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/dump_settings"
|
||||
android:title="@string/dump_settings_action" />
|
||||
</menu>
|
@ -175,8 +175,10 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based
|
||||
</string>
|
||||
|
||||
<string name="debug_version_fmt">Version: <xliff:g id="version">%s</xliff:g></string>
|
||||
<string name="debug_enable_debug_logging_label">Enable extra debug logging?</string>
|
||||
<string name="debug_enable_sensitive_logging_label">Enable sensitive information debug logging? (May show passwords in logs.)</string>
|
||||
<string name="debug_enable_debug_logging_title">Enable debug logging?</string>
|
||||
<string name="debug_enable_debug_logging_summary">Log extra information for diagnostics</string>
|
||||
<string name="debug_enable_sensitive_logging_title">Log sensitive information(May show passwords in logs.)</string>
|
||||
<string name="debug_enable_sensitive_logging_summary">May show passwords in logs.</string>
|
||||
|
||||
<string name="message_header_mua">K-9 for Android <xliff:g id="version">%s</xliff:g></string>
|
||||
|
||||
@ -530,5 +532,6 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based
|
||||
<string name="setting_theme_dark">Dark</string>
|
||||
<string name="setting_theme_light">Light</string>
|
||||
<string name="display_preferences">Display Preferences</string>
|
||||
<string name="debug_preferences">Diagnostic Preferences</string>
|
||||
<string name="settings_theme_label">Theme</string>
|
||||
</resources>
|
||||
|
@ -24,8 +24,20 @@
|
||||
android:entries="@array/settings_theme_entries"
|
||||
android:entryValues="@array/settings_theme_values"
|
||||
android:dialogTitle="@string/settings_theme_label" />
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/debug_preferences" android:key="debug_preferences">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="debug_logging"
|
||||
android:title="@string/debug_enable_debug_logging_title"
|
||||
android:summary="@string/debug_enable_debug_logging_summary"
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="sensitive_logging"
|
||||
android:title="@string/debug_enable_sensitive_logging_title"
|
||||
android:summary="@string/debug_enable_sensitive_logging_summary"
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import android.app.Application;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
@ -24,6 +25,8 @@ public class Email extends Application {
|
||||
public static File tempDirectory;
|
||||
public static final String LOG_TAG = "k9";
|
||||
|
||||
|
||||
private static int theme = android.R.style.Theme_Light;
|
||||
/**
|
||||
* Some log messages can be sent to a file, so that the logs
|
||||
* can be read using unprivileged access (eg. Terminal Emulator)
|
||||
@ -234,13 +237,24 @@ public class Email extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(SharedPreferences preferences)
|
||||
{
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("enableDebugLogging", Email.DEBUG);
|
||||
editor.putBoolean("enableSensitiveLogging", Email.DEBUG_SENSITIVE);
|
||||
editor.putInt("theme", theme);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
app = this;
|
||||
Preferences prefs = Preferences.getPreferences(this);
|
||||
DEBUG = prefs.getEnableDebugLogging();
|
||||
DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging();
|
||||
SharedPreferences sprefs = prefs.getPreferences();
|
||||
DEBUG = sprefs.getBoolean("enableDebugLogging", false);
|
||||
DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
|
||||
Email.setK9Theme(sprefs.getInt("theme", android.R.style.Theme_Light));
|
||||
MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
|
||||
|
||||
/*
|
||||
@ -280,6 +294,16 @@ public class Email extends Application {
|
||||
|
||||
MailService.appStarted(this);
|
||||
}
|
||||
|
||||
public static int getK9Theme()
|
||||
{
|
||||
return theme;
|
||||
}
|
||||
|
||||
public static void setK9Theme(int ntheme)
|
||||
{
|
||||
theme = ntheme;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.Preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
@ -9,7 +8,7 @@ import android.os.Bundle;
|
||||
public class K9Activity extends Activity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
setTheme(Preferences.getPreferences(this).getTheme());
|
||||
setTheme(Email.getK9Theme());
|
||||
super.onCreate(icicle);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.Preferences;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
@ -9,7 +7,7 @@ import android.os.Bundle;
|
||||
public class K9ListActivity extends ListActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
setTheme(Preferences.getPreferences(this).getTheme());
|
||||
setTheme(Email.getK9Theme());
|
||||
super.onCreate(icicle);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.Preferences;
|
||||
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
@ -10,7 +8,7 @@ import android.os.Bundle;
|
||||
public class K9PreferenceActivity extends PreferenceActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
setTheme(Preferences.getPreferences(this).getTheme());
|
||||
setTheme(Email.getK9Theme());
|
||||
super.onCreate(icicle);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.android.email.preferences.Editor;
|
||||
import com.android.email.preferences.Storage;
|
||||
|
||||
@ -101,30 +99,6 @@ public class Preferences {
|
||||
getPreferences().edit().putString("defaultAccountUuid", account.getUuid()).commit();
|
||||
}
|
||||
|
||||
public void setEnableDebugLogging(boolean value) {
|
||||
getPreferences().edit().putBoolean("enableDebugLogging", value).commit();
|
||||
}
|
||||
|
||||
public boolean getEnableDebugLogging() {
|
||||
return getPreferences().getBoolean("enableDebugLogging", false);
|
||||
}
|
||||
|
||||
public void setTheme(int theme) {
|
||||
getPreferences().edit().putInt("theme", theme).commit();
|
||||
}
|
||||
|
||||
public int getTheme() {
|
||||
return getPreferences().getInt("theme", android.R.style.Theme_Light);
|
||||
}
|
||||
|
||||
public void setEnableSensitiveLogging(boolean value) {
|
||||
getPreferences().edit().putBoolean("enableSensitiveLogging", value).commit();
|
||||
}
|
||||
|
||||
public boolean getEnableSensitiveLogging() {
|
||||
return getPreferences().getBoolean("enableSensitiveLogging", false);
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
if (Config.LOGV) {
|
||||
for (String key : getPreferences().getAll().keySet()) {
|
||||
|
@ -57,15 +57,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
||||
private ConcurrentHashMap<String, Integer> unreadMessageCounts = new ConcurrentHashMap<String, Integer>();
|
||||
|
||||
private ConcurrentHashMap<Account, String> pendingWork = new ConcurrentHashMap<Account, String>();
|
||||
/**
|
||||
* Key codes used to open a debug settings screen.
|
||||
*/
|
||||
private static int[] secretKeyCodes = {
|
||||
KeyEvent.KEYCODE_D, KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_B, KeyEvent.KEYCODE_U,
|
||||
KeyEvent.KEYCODE_G
|
||||
};
|
||||
|
||||
private int mSecretKeyCodeIndex = 0;
|
||||
private Account mSelectedContextAccount;
|
||||
|
||||
private AccountsHandler mHandler = new AccountsHandler();
|
||||
@ -581,15 +573,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (event.getKeyCode() == secretKeyCodes[mSecretKeyCodeIndex]) {
|
||||
mSecretKeyCodeIndex++;
|
||||
if (mSecretKeyCodeIndex == secretKeyCodes.length) {
|
||||
mSecretKeyCodeIndex = 0;
|
||||
startActivity(new Intent(this, Debug.class));
|
||||
}
|
||||
} else {
|
||||
mSecretKeyCodeIndex = 0;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
@ -1,91 +0,0 @@
|
||||
|
||||
package com.android.email.activity;
|
||||
|
||||
import com.android.email.K9Activity;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import com.android.email.Email;
|
||||
import com.android.email.Preferences;
|
||||
import com.android.email.R;
|
||||
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Debug extends K9Activity implements OnCheckedChangeListener {
|
||||
private TextView mVersionView;
|
||||
private CheckBox mEnableDebugLoggingView;
|
||||
private CheckBox mEnableSensitiveLoggingView;
|
||||
|
||||
private Preferences mPreferences;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.debug);
|
||||
|
||||
mPreferences = Preferences.getPreferences(this);
|
||||
|
||||
mVersionView = (TextView)findViewById(R.id.version);
|
||||
mEnableDebugLoggingView = (CheckBox)findViewById(R.id.debug_logging);
|
||||
mEnableSensitiveLoggingView = (CheckBox)findViewById(R.id.sensitive_logging);
|
||||
|
||||
mEnableDebugLoggingView.setOnCheckedChangeListener(this);
|
||||
mEnableSensitiveLoggingView.setOnCheckedChangeListener(this);
|
||||
|
||||
mVersionView.setText(String.format(getString(R.string.debug_version_fmt).toString(), getVersionNumber()));
|
||||
|
||||
mEnableDebugLoggingView.setChecked(Email.DEBUG);
|
||||
mEnableSensitiveLoggingView.setChecked(Email.DEBUG_SENSITIVE);
|
||||
}
|
||||
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.getId() == R.id.debug_logging) {
|
||||
Email.DEBUG = isChecked;
|
||||
mPreferences.setEnableDebugLogging(Email.DEBUG);
|
||||
} else if (buttonView.getId() == R.id.sensitive_logging) {
|
||||
Email.DEBUG_SENSITIVE = isChecked;
|
||||
mPreferences.setEnableSensitiveLogging(Email.DEBUG_SENSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.dump_settings) {
|
||||
Preferences.getPreferences(this).dump();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.debug_option, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getVersionNumber() {
|
||||
String version = "?";
|
||||
int vnum;
|
||||
|
||||
try {
|
||||
PackageInfo pi =
|
||||
getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
version = Integer.toString(pi.versionCode);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e){
|
||||
Log.e(Email.LOG_TAG, "Package name not found: " + e.getMessage());
|
||||
};
|
||||
return version;
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.CheckBoxPreference;
|
||||
@ -26,8 +27,13 @@ public class Prefs extends K9PreferenceActivity {
|
||||
|
||||
private static final String PREFERENCE_TOP_CATERGORY = "preferences";
|
||||
private static final String PREFERENCE_THEME = "theme";
|
||||
private static final String PREFERENCE_DEBUG_LOGGING = "debug_logging";
|
||||
private static final String PREFERENCE_SENSITIVE_LOGGING = "sensitive_logging";
|
||||
|
||||
private ListPreference mTheme;
|
||||
private CheckBoxPreference mDebugLogging;
|
||||
private CheckBoxPreference mSensitiveLogging;
|
||||
|
||||
|
||||
public static void actionPrefs(Context context) {
|
||||
Intent i = new Intent(context, Prefs.class);
|
||||
@ -41,11 +47,8 @@ public class Prefs extends K9PreferenceActivity {
|
||||
|
||||
addPreferencesFromResource(R.xml.global_preferences);
|
||||
|
||||
Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
|
||||
|
||||
|
||||
mTheme = (ListPreference) findPreference(PREFERENCE_THEME);
|
||||
mTheme.setValue(String.valueOf(Preferences.getPreferences(this).getTheme() == android.R.style.Theme ? "dark" : "light"));
|
||||
mTheme.setValue(String.valueOf(Email.getK9Theme() == android.R.style.Theme ? "dark" : "light"));
|
||||
mTheme.setSummary(mTheme.getEntry());
|
||||
mTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@ -57,6 +60,12 @@ public class Prefs extends K9PreferenceActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mDebugLogging = (CheckBoxPreference)findPreference(PREFERENCE_DEBUG_LOGGING);
|
||||
mSensitiveLogging = (CheckBoxPreference)findPreference(PREFERENCE_SENSITIVE_LOGGING);
|
||||
|
||||
mDebugLogging.setChecked(Email.DEBUG);
|
||||
mSensitiveLogging.setChecked(Email.DEBUG_SENSITIVE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +74,11 @@ public class Prefs extends K9PreferenceActivity {
|
||||
}
|
||||
|
||||
private void saveSettings() {
|
||||
Preferences.getPreferences(this).setTheme(mTheme.getValue().equals("dark") ? android.R.style.Theme : android.R.style.Theme_Light);
|
||||
SharedPreferences preferences = Preferences.getPreferences(this).getPreferences();
|
||||
Email.setK9Theme(mTheme.getValue().equals("dark") ? android.R.style.Theme : android.R.style.Theme_Light);
|
||||
Email.DEBUG = mDebugLogging.isChecked();
|
||||
Email.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
|
||||
Email.save(preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user