2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2011-06-26 00:24:19 +00:00
|
|
|
import android.text.TextUtils;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
2011-06-26 00:24:19 +00:00
|
|
|
import com.android.emailcommon.Logging;
|
2011-10-10 22:53:27 +00:00
|
|
|
import com.android.emailcommon.provider.Account;
|
2013-05-26 04:32:32 +00:00
|
|
|
import com.android.mail.utils.LogUtils;
|
2011-06-26 00:24:19 +00:00
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
2013-06-08 00:31:15 +00:00
|
|
|
import java.util.Collections;
|
2011-06-26 00:24:19 +00:00
|
|
|
import java.util.HashSet;
|
2013-06-08 00:31:15 +00:00
|
|
|
import java.util.Set;
|
2010-02-01 23:53:46 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
public class Preferences {
|
2009-08-14 00:43:25 +00:00
|
|
|
|
|
|
|
// Preferences file
|
2011-09-14 08:00:24 +00:00
|
|
|
public static final String PREFERENCES_FILE = "AndroidMail.Main";
|
2009-08-14 00:43:25 +00:00
|
|
|
|
|
|
|
// Preferences field names
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2009-08-14 00:43:25 +00:00
|
|
|
private static final String ACCOUNT_UUIDS = "accountUuids";
|
|
|
|
private static final String ENABLE_DEBUG_LOGGING = "enableDebugLogging";
|
|
|
|
private static final String ENABLE_EXCHANGE_LOGGING = "enableExchangeLogging";
|
|
|
|
private static final String ENABLE_EXCHANGE_FILE_LOGGING = "enableExchangeFileLogging";
|
2011-03-02 00:48:06 +00:00
|
|
|
private static final String ENABLE_STRICT_MODE = "enableStrictMode";
|
2010-02-01 23:53:46 +00:00
|
|
|
private static final String DEVICE_UID = "deviceUID";
|
2010-01-28 18:07:51 +00:00
|
|
|
private static final String ONE_TIME_INITIALIZATION_PROGRESS = "oneTimeInitializationProgress";
|
2014-06-12 23:20:14 +00:00
|
|
|
private static final String LAST_ACCOUNT_USED = "lastAccountUsed";
|
|
|
|
// The following are only used for migration
|
|
|
|
@Deprecated
|
2010-09-09 22:34:19 +00:00
|
|
|
private static final String AUTO_ADVANCE_DIRECTION = "autoAdvance";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2011-06-26 00:24:19 +00:00
|
|
|
private static final String TRUSTED_SENDERS = "trustedSenders";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
private static final String CONFIRM_DELETE = "confirm_delete";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
private static final String CONFIRM_SEND = "confirm_send";
|
2013-02-14 22:34:33 +00:00
|
|
|
@Deprecated
|
2012-07-26 16:22:22 +00:00
|
|
|
private static final String SWIPE_DELETE = "swipe_delete";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2013-04-26 05:13:29 +00:00
|
|
|
private static final String CONV_LIST_ICON = "conversation_list_icons";
|
2013-05-04 01:49:51 +00:00
|
|
|
@Deprecated
|
|
|
|
private static final String REPLY_ALL = "reply_all";
|
2010-09-09 22:34:19 +00:00
|
|
|
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2010-09-09 22:34:19 +00:00
|
|
|
public static final int AUTO_ADVANCE_NEWER = 0;
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2010-09-09 22:34:19 +00:00
|
|
|
public static final int AUTO_ADVANCE_OLDER = 1;
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2010-09-09 22:34:19 +00:00
|
|
|
public static final int AUTO_ADVANCE_MESSAGE_LIST = 2;
|
|
|
|
// "move to older" was the behavior on older versions.
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2011-04-13 18:30:56 +00:00
|
|
|
private static final int AUTO_ADVANCE_DEFAULT = AUTO_ADVANCE_OLDER;
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
private static final boolean CONFIRM_DELETE_DEFAULT = false;
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
private static final boolean CONFIRM_SEND_DEFAULT = false;
|
2009-08-14 00:43:25 +00:00
|
|
|
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2013-04-11 21:16:01 +00:00
|
|
|
public static final String CONV_LIST_ICON_SENDER_IMAGE = "senderimage";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2013-04-11 21:16:01 +00:00
|
|
|
public static final String CONV_LIST_ICON_NONE = "none";
|
2014-06-12 23:20:14 +00:00
|
|
|
@Deprecated
|
2013-04-26 05:13:29 +00:00
|
|
|
public static final String CONV_LIST_ICON_DEFAULT = CONV_LIST_ICON_SENDER_IMAGE;
|
2013-04-11 21:16:01 +00:00
|
|
|
|
2010-05-10 21:20:16 +00:00
|
|
|
private static Preferences sPreferences;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
2011-06-26 00:24:19 +00:00
|
|
|
private final SharedPreferences mSharedPreferences;
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
private Preferences(Context context) {
|
2009-08-14 00:43:25 +00:00
|
|
|
mSharedPreferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO need to think about what happens if this gets GCed along with the
|
|
|
|
* Activity that initialized it. Do we lose ability to read Preferences in
|
|
|
|
* further Activities? Maybe this should be stored in the Application
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
public static synchronized Preferences getPreferences(Context context) {
|
2010-05-10 21:20:16 +00:00
|
|
|
if (sPreferences == null) {
|
|
|
|
sPreferences = new Preferences(context);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
2010-05-10 21:20:16 +00:00
|
|
|
return sPreferences;
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 08:00:24 +00:00
|
|
|
public static SharedPreferences getSharedPreferences(Context context) {
|
|
|
|
return getPreferences(context).mSharedPreferences;
|
|
|
|
}
|
|
|
|
|
2011-05-06 19:07:39 +00:00
|
|
|
public static String getLegacyBackupPreference(Context context) {
|
|
|
|
return getPreferences(context).mSharedPreferences.getString(ACCOUNT_UUIDS, null);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2011-05-06 19:07:39 +00:00
|
|
|
public static void clearLegacyBackupPreference(Context context) {
|
|
|
|
getPreferences(context).mSharedPreferences.edit().remove(ACCOUNT_UUIDS).apply();
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setEnableDebugLogging(boolean value) {
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().putBoolean(ENABLE_DEBUG_LOGGING, value).apply();
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 00:43:25 +00:00
|
|
|
public boolean getEnableDebugLogging() {
|
|
|
|
return mSharedPreferences.getBoolean(ENABLE_DEBUG_LOGGING, false);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 04:58:54 +00:00
|
|
|
public void setEnableExchangeLogging(boolean value) {
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().putBoolean(ENABLE_EXCHANGE_LOGGING, value).apply();
|
2009-08-09 04:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getEnableExchangeLogging() {
|
2009-08-14 00:43:25 +00:00
|
|
|
return mSharedPreferences.getBoolean(ENABLE_EXCHANGE_LOGGING, false);
|
2009-08-09 04:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setEnableExchangeFileLogging(boolean value) {
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().putBoolean(ENABLE_EXCHANGE_FILE_LOGGING, value).apply();
|
2009-08-09 04:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getEnableExchangeFileLogging() {
|
2009-08-14 00:43:25 +00:00
|
|
|
return mSharedPreferences.getBoolean(ENABLE_EXCHANGE_FILE_LOGGING, false);
|
2009-08-09 04:58:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 00:48:06 +00:00
|
|
|
public void setEnableStrictMode(boolean value) {
|
|
|
|
mSharedPreferences.edit().putBoolean(ENABLE_STRICT_MODE, value).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getEnableStrictMode() {
|
|
|
|
return mSharedPreferences.getBoolean(ENABLE_STRICT_MODE, false);
|
|
|
|
}
|
|
|
|
|
2010-02-01 23:53:46 +00:00
|
|
|
/**
|
|
|
|
* Generate a new "device UID". This is local to Email app only, to prevent possibility
|
|
|
|
* of correlation with any other user activities in any other apps.
|
|
|
|
* @return a persistent, unique ID
|
|
|
|
*/
|
|
|
|
public synchronized String getDeviceUID() {
|
|
|
|
String result = mSharedPreferences.getString(DEVICE_UID, null);
|
|
|
|
if (result == null) {
|
|
|
|
result = UUID.randomUUID().toString();
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().putString(DEVICE_UID, result).apply();
|
2010-02-01 23:53:46 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-28 18:07:51 +00:00
|
|
|
public int getOneTimeInitializationProgress() {
|
|
|
|
return mSharedPreferences.getInt(ONE_TIME_INITIALIZATION_PROGRESS, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOneTimeInitializationProgress(int progress) {
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().putInt(ONE_TIME_INITIALIZATION_PROGRESS, progress).apply();
|
2010-01-28 18:07:51 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 23:20:14 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
2010-09-09 22:34:19 +00:00
|
|
|
public int getAutoAdvanceDirection() {
|
|
|
|
return mSharedPreferences.getInt(AUTO_ADVANCE_DIRECTION, AUTO_ADVANCE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2013-07-16 00:59:30 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
2013-04-11 21:16:01 +00:00
|
|
|
public String getConversationListIcon() {
|
2013-04-26 05:13:29 +00:00
|
|
|
return mSharedPreferences.getString(CONV_LIST_ICON, CONV_LIST_ICON_SENDER_IMAGE);
|
2013-04-11 21:16:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 23:20:14 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
public boolean getConfirmDelete() {
|
|
|
|
return mSharedPreferences.getBoolean(CONFIRM_DELETE, CONFIRM_DELETE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2014-06-12 23:20:14 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
2012-06-28 17:40:46 +00:00
|
|
|
public boolean getConfirmSend() {
|
|
|
|
return mSharedPreferences.getBoolean(CONFIRM_SEND, CONFIRM_SEND_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2013-02-14 22:34:33 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
|
|
|
public boolean hasSwipeDelete() {
|
|
|
|
return mSharedPreferences.contains(SWIPE_DELETE);
|
2012-07-26 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 22:34:33 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
|
|
|
public boolean getSwipeDelete() {
|
|
|
|
return mSharedPreferences.getBoolean(SWIPE_DELETE, false);
|
2012-07-26 16:22:22 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 01:49:51 +00:00
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
|
|
|
public boolean hasReplyAll() {
|
|
|
|
return mSharedPreferences.contains(REPLY_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @deprecated Only used for migration */
|
|
|
|
@Deprecated
|
|
|
|
public boolean getReplyAll() {
|
|
|
|
return mSharedPreferences.getBoolean(REPLY_ALL, false);
|
|
|
|
}
|
|
|
|
|
2011-06-26 00:24:19 +00:00
|
|
|
/**
|
2014-06-10 18:27:55 +00:00
|
|
|
* @deprecated This has been moved to {@link com.android.mail.preferences.MailPrefs}, and is
|
|
|
|
* only here for migration.
|
2011-06-26 00:24:19 +00:00
|
|
|
*/
|
2013-06-08 00:31:15 +00:00
|
|
|
@Deprecated
|
|
|
|
public Set<String> getWhitelistedSenderAddresses() {
|
|
|
|
try {
|
|
|
|
return parseEmailSet(mSharedPreferences.getString(TRUSTED_SENDERS, ""));
|
|
|
|
} catch (JSONException e) {
|
2013-06-25 22:15:02 +00:00
|
|
|
return Collections.emptySet();
|
2011-06-26 00:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet<String> parseEmailSet(String serialized) throws JSONException {
|
|
|
|
HashSet<String> result = new HashSet<String>();
|
|
|
|
if (!TextUtils.isEmpty(serialized)) {
|
|
|
|
JSONArray arr = new JSONArray(serialized);
|
|
|
|
for (int i = 0, len = arr.length(); i < len; i++) {
|
|
|
|
result.add((String) arr.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-10-10 22:53:27 +00:00
|
|
|
/**
|
|
|
|
* Returns the last used account ID as set by {@link #setLastUsedAccountId}.
|
|
|
|
* The system makes no attempt to automatically track what is considered a "use" - clients
|
|
|
|
* are expected to call {@link #setLastUsedAccountId} manually.
|
|
|
|
*
|
|
|
|
* Note that the last used account may have been deleted in the background so there is also
|
|
|
|
* no guarantee that the account exists.
|
|
|
|
*/
|
|
|
|
public long getLastUsedAccountId() {
|
|
|
|
return mSharedPreferences.getLong(LAST_ACCOUNT_USED, Account.NO_ACCOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the specified ID of the last account used. Treated as an opaque ID and does not
|
|
|
|
* validate the value. Value is saved asynchronously.
|
|
|
|
*/
|
|
|
|
public void setLastUsedAccountId(long accountId) {
|
|
|
|
mSharedPreferences
|
|
|
|
.edit()
|
|
|
|
.putLong(LAST_ACCOUNT_USED, accountId)
|
|
|
|
.apply();
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
public void clear() {
|
2010-11-01 15:51:26 +00:00
|
|
|
mSharedPreferences.edit().clear().apply();
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void dump() {
|
2011-05-13 18:20:04 +00:00
|
|
|
if (Logging.LOGD) {
|
2009-03-04 03:32:22 +00:00
|
|
|
for (String key : mSharedPreferences.getAll().keySet()) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.v(Logging.LOG_TAG, key + " = " + mSharedPreferences.getAll().get(key));
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|