2013-07-10 01:26:18 +00:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-09-03 21:04:47 +00:00
|
|
|
import android.content.SharedPreferences;
|
2015-11-08 01:12:02 +00:00
|
|
|
import android.hardware.Camera.CameraInfo;
|
2017-12-19 22:42:00 +00:00
|
|
|
import android.net.Uri;
|
2015-03-11 21:23:45 +00:00
|
|
|
import android.os.Build;
|
2013-07-10 01:26:18 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2015-03-30 19:36:40 +00:00
|
|
|
import android.provider.Settings;
|
2015-08-24 22:24:31 +00:00
|
|
|
import android.support.annotation.ArrayRes;
|
|
|
|
import android.support.annotation.NonNull;
|
2017-08-08 23:37:15 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2017-04-22 06:04:54 +00:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2018-08-01 15:09:24 +00:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2013-07-10 01:26:18 +00:00
|
|
|
|
2018-02-26 22:02:12 +00:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
2015-08-24 22:24:31 +00:00
|
|
|
import org.thoughtcrime.securesms.R;
|
2018-02-26 22:02:12 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.requirements.SqlCipherMigrationRequirementProvider;
|
2018-03-01 17:51:37 +00:00
|
|
|
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
|
2017-09-21 17:03:05 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
|
2018-02-16 04:33:10 +00:00
|
|
|
import org.whispersystems.libsignal.util.Medium;
|
2015-07-31 22:05:24 +00:00
|
|
|
|
2014-05-05 18:48:26 +00:00
|
|
|
import java.io.IOException;
|
2018-02-16 04:33:10 +00:00
|
|
|
import java.security.SecureRandom;
|
2015-08-24 22:24:31 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2014-05-05 18:48:26 +00:00
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public class TextSecurePreferences {
|
|
|
|
|
2014-12-12 03:36:46 +00:00
|
|
|
private static final String TAG = TextSecurePreferences.class.getSimpleName();
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static final String IDENTITY_PREF = "pref_choose_identity";
|
|
|
|
public static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
|
|
|
|
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
|
|
|
|
public static final String THEME_PREF = "pref_theme";
|
|
|
|
public static final String LANGUAGE_PREF = "pref_language";
|
2015-02-17 04:31:44 +00:00
|
|
|
private static final String MMSC_CUSTOM_HOST_PREF = "pref_apn_mmsc_custom_host";
|
2013-07-11 21:58:40 +00:00
|
|
|
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
|
2015-02-17 04:31:44 +00:00
|
|
|
private static final String MMSC_CUSTOM_PROXY_PREF = "pref_apn_mms_custom_proxy";
|
2013-07-11 21:58:40 +00:00
|
|
|
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
|
2015-02-17 04:31:44 +00:00
|
|
|
private static final String MMSC_CUSTOM_PROXY_PORT_PREF = "pref_apn_mms_custom_proxy_port";
|
2013-07-11 21:58:40 +00:00
|
|
|
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
|
2015-02-17 04:31:44 +00:00
|
|
|
private static final String MMSC_CUSTOM_USERNAME_PREF = "pref_apn_mmsc_custom_username";
|
2014-11-25 08:48:09 +00:00
|
|
|
public static final String MMSC_USERNAME_PREF = "pref_apn_mmsc_username";
|
2015-02-17 04:31:44 +00:00
|
|
|
private static final String MMSC_CUSTOM_PASSWORD_PREF = "pref_apn_mmsc_custom_password";
|
2014-11-25 08:48:09 +00:00
|
|
|
public static final String MMSC_PASSWORD_PREF = "pref_apn_mmsc_password";
|
2013-07-11 21:58:40 +00:00
|
|
|
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
|
|
|
|
public static final String THREAD_TRIM_NOW = "pref_trim_now";
|
2013-11-18 23:29:19 +00:00
|
|
|
public static final String ENABLE_MANUAL_MMS_PREF = "pref_enable_manual_mms";
|
2013-07-11 21:58:40 +00:00
|
|
|
|
2014-05-05 18:48:26 +00:00
|
|
|
private static final String LAST_VERSION_CODE_PREF = "last_version_code";
|
2015-09-29 20:14:22 +00:00
|
|
|
private static final String LAST_EXPERIENCE_VERSION_PREF = "last_experience_version_code";
|
2017-09-04 02:44:33 +00:00
|
|
|
private static final String EXPERIENCE_DISMISSED_PREF = "experience_dismissed";
|
2014-01-07 02:52:18 +00:00
|
|
|
public static final String RINGTONE_PREF = "pref_key_ringtone";
|
2013-07-11 21:58:40 +00:00
|
|
|
private static final String VIBRATE_PREF = "pref_key_vibrate";
|
|
|
|
private static final String NOTIFICATION_PREF = "pref_key_enable_notifications";
|
2014-01-07 02:52:18 +00:00
|
|
|
public static final String LED_COLOR_PREF = "pref_led_color";
|
|
|
|
public static final String LED_BLINK_PREF = "pref_led_blink";
|
2013-07-11 21:58:40 +00:00
|
|
|
private static final String LED_BLINK_PREF_CUSTOM = "pref_led_blink_custom";
|
2014-01-07 02:52:18 +00:00
|
|
|
public static final String ALL_MMS_PREF = "pref_all_mms";
|
|
|
|
public static final String ALL_SMS_PREF = "pref_all_sms";
|
2014-12-13 00:07:02 +00:00
|
|
|
public static final String PASSPHRASE_TIMEOUT_INTERVAL_PREF = "pref_timeout_interval";
|
2018-03-04 19:35:37 +00:00
|
|
|
public static final String PASSPHRASE_TIMEOUT_PREF = "pref_timeout_passphrase";
|
2014-03-30 09:28:38 +00:00
|
|
|
public static final String SCREEN_SECURITY_PREF = "pref_screen_security";
|
2013-07-11 21:58:40 +00:00
|
|
|
private static final String ENTER_SENDS_PREF = "pref_enter_sends";
|
|
|
|
private static final String ENTER_PRESENT_PREF = "pref_enter_key";
|
|
|
|
private static final String SMS_DELIVERY_REPORT_PREF = "pref_delivery_report_sms";
|
2015-01-18 03:10:46 +00:00
|
|
|
public static final String MMS_USER_AGENT = "pref_mms_user_agent";
|
|
|
|
private static final String MMS_CUSTOM_USER_AGENT = "pref_custom_mms_user_agent";
|
2013-07-11 21:58:40 +00:00
|
|
|
private static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
|
|
|
|
private static final String LOCAL_NUMBER_PREF = "pref_local_number";
|
|
|
|
private static final String VERIFYING_STATE_PREF = "pref_verifying";
|
2014-02-21 00:14:58 +00:00
|
|
|
public static final String REGISTERED_GCM_PREF = "pref_gcm_registered";
|
2013-07-11 21:58:40 +00:00
|
|
|
private static final String GCM_PASSWORD_PREF = "pref_gcm_password";
|
|
|
|
private static final String PROMPTED_PUSH_REGISTRATION_PREF = "pref_prompted_push_registration";
|
2014-01-08 22:29:05 +00:00
|
|
|
private static final String PROMPTED_DEFAULT_SMS_PREF = "pref_prompted_default_sms";
|
2017-02-20 20:00:03 +00:00
|
|
|
private static final String PROMPTED_OPTIMIZE_DOZE_PREF = "pref_prompted_optimize_doze";
|
2015-10-19 18:23:12 +00:00
|
|
|
private static final String PROMPTED_SHARE_PREF = "pref_prompted_share";
|
2013-08-28 22:35:30 +00:00
|
|
|
private static final String SIGNALING_KEY_PREF = "pref_signaling_key";
|
2013-10-13 11:38:26 +00:00
|
|
|
private static final String DIRECTORY_FRESH_TIME_PREF = "pref_directory_refresh_time";
|
2017-02-26 22:36:43 +00:00
|
|
|
private static final String UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time";
|
|
|
|
private static final String UPDATE_APK_DOWNLOAD_ID = "pref_update_apk_download_id";
|
|
|
|
private static final String UPDATE_APK_DIGEST = "pref_update_apk_digest";
|
2017-01-06 17:19:58 +00:00
|
|
|
private static final String SIGNED_PREKEY_ROTATION_TIME_PREF = "pref_signed_pre_key_rotation_time";
|
2013-11-18 23:29:19 +00:00
|
|
|
private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
|
2017-04-15 03:51:22 +00:00
|
|
|
private static final String SHOW_INVITE_REMINDER_PREF = "pref_show_invite_reminder";
|
2017-04-15 05:59:30 +00:00
|
|
|
public static final String MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size";
|
2013-11-18 23:29:19 +00:00
|
|
|
|
2014-02-18 20:48:20 +00:00
|
|
|
private static final String LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id";
|
2014-07-13 01:06:22 +00:00
|
|
|
private static final String SIGNED_PREKEY_REGISTERED_PREF = "pref_signed_prekey_registered";
|
2014-12-24 20:40:28 +00:00
|
|
|
private static final String WIFI_SMS_PREF = "pref_wifi_sms";
|
2014-07-13 01:06:22 +00:00
|
|
|
|
2017-02-20 20:00:03 +00:00
|
|
|
private static final String GCM_DISABLED_PREF = "pref_gcm_disabled";
|
2014-12-12 03:36:46 +00:00
|
|
|
private static final String GCM_REGISTRATION_ID_PREF = "pref_gcm_registration_id";
|
|
|
|
private static final String GCM_REGISTRATION_ID_VERSION_PREF = "pref_gcm_registration_id_version";
|
2017-03-17 17:28:06 +00:00
|
|
|
private static final String GCM_REGISTRATION_ID_TIME_PREF = "pref_gcm_registration_id_last_set_time";
|
2015-01-26 01:43:24 +00:00
|
|
|
private static final String WEBSOCKET_REGISTERED_PREF = "pref_websocket_registered";
|
2015-03-31 19:34:49 +00:00
|
|
|
private static final String RATING_LATER_PREF = "pref_rating_later";
|
|
|
|
private static final String RATING_ENABLED_PREF = "pref_rating_enabled";
|
2017-01-06 17:19:58 +00:00
|
|
|
private static final String SIGNED_PREKEY_FAILURE_COUNT_PREF = "pref_signed_prekey_failure_count";
|
2014-12-12 03:36:46 +00:00
|
|
|
|
|
|
|
public static final String REPEAT_ALERTS_PREF = "pref_repeat_alerts";
|
2015-07-31 22:05:24 +00:00
|
|
|
public static final String NOTIFICATION_PRIVACY_PREF = "pref_notification_privacy";
|
2017-04-22 06:04:54 +00:00
|
|
|
public static final String NOTIFICATION_PRIORITY_PREF = "pref_notification_priority";
|
2015-12-19 12:07:44 +00:00
|
|
|
public static final String NEW_CONTACTS_NOTIFICATIONS = "pref_enable_new_contacts_notifications";
|
2016-11-09 17:37:40 +00:00
|
|
|
public static final String WEBRTC_CALLING_PREF = "pref_webrtc_calling";
|
2015-07-31 22:05:24 +00:00
|
|
|
|
2015-08-24 22:24:31 +00:00
|
|
|
public static final String MEDIA_DOWNLOAD_MOBILE_PREF = "pref_media_download_mobile";
|
|
|
|
public static final String MEDIA_DOWNLOAD_WIFI_PREF = "pref_media_download_wifi";
|
|
|
|
public static final String MEDIA_DOWNLOAD_ROAMING_PREF = "pref_media_download_roaming";
|
|
|
|
|
2015-09-07 23:11:40 +00:00
|
|
|
public static final String SYSTEM_EMOJI_PREF = "pref_system_emoji";
|
2015-10-23 19:51:28 +00:00
|
|
|
private static final String MULTI_DEVICE_PROVISIONED_PREF = "pref_multi_device";
|
2015-11-08 01:12:02 +00:00
|
|
|
public static final String DIRECT_CAPTURE_CAMERA_ID = "pref_direct_capture_camera_id";
|
2017-02-17 21:12:48 +00:00
|
|
|
private static final String ALWAYS_RELAY_CALLS_PREF = "pref_turn_only";
|
2017-08-08 23:37:15 +00:00
|
|
|
private static final String PROFILE_KEY_PREF = "pref_profile_key";
|
2017-08-16 04:03:31 +00:00
|
|
|
private static final String PROFILE_NAME_PREF = "pref_profile_name";
|
2017-10-16 20:11:42 +00:00
|
|
|
private static final String PROFILE_AVATAR_ID_PREF = "pref_profile_avatar_id";
|
2017-09-21 18:27:53 +00:00
|
|
|
public static final String READ_RECEIPTS_PREF = "pref_read_receipts";
|
2017-10-04 01:57:23 +00:00
|
|
|
public static final String INCOGNITO_KEYBORAD_PREF = "pref_incognito_keyboard";
|
2017-11-16 00:29:00 +00:00
|
|
|
private static final String UNAUTHORIZED_RECEIVED = "pref_unauthorized_received";
|
2017-11-21 19:54:18 +00:00
|
|
|
private static final String SUCCESSFUL_DIRECTORY_PREF = "pref_successful_directory";
|
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
private static final String DATABASE_ENCRYPTED_SECRET = "pref_database_encrypted_secret";
|
|
|
|
private static final String DATABASE_UNENCRYPTED_SECRET = "pref_database_unencrypted_secret";
|
|
|
|
private static final String ATTACHMENT_ENCRYPTED_SECRET = "pref_attachment_encrypted_secret";
|
|
|
|
private static final String ATTACHMENT_UNENCRYPTED_SECRET = "pref_attachment_unencrypted_secret";
|
|
|
|
private static final String NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration";
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static final String CALL_NOTIFICATIONS_PREF = "pref_call_notifications";
|
|
|
|
public static final String CALL_RINGTONE_PREF = "pref_call_ringtone";
|
|
|
|
public static final String CALL_VIBRATE_PREF = "pref_call_vibrate";
|
|
|
|
|
2018-02-16 04:33:10 +00:00
|
|
|
private static final String NEXT_PRE_KEY_ID = "pref_next_pre_key_id";
|
|
|
|
private static final String ACTIVE_SIGNED_PRE_KEY_ID = "pref_active_signed_pre_key_id";
|
|
|
|
private static final String NEXT_SIGNED_PRE_KEY_ID = "pref_next_signed_pre_key_id";
|
|
|
|
|
2018-02-26 17:58:18 +00:00
|
|
|
public static final String BACKUP_ENABLED = "pref_backup_enabled";
|
|
|
|
private static final String BACKUP_PASSPHRASE = "pref_backup_passphrase";
|
|
|
|
private static final String BACKUP_TIME = "pref_backup_next_time";
|
|
|
|
public static final String BACKUP_NOW = "pref_backup_create";
|
|
|
|
|
2018-03-04 19:35:37 +00:00
|
|
|
public static final String SCREEN_LOCK = "pref_android_screen_lock";
|
|
|
|
public static final String SCREEN_LOCK_TIMEOUT = "pref_android_screen_lock_timeout";
|
|
|
|
|
2018-03-01 17:51:37 +00:00
|
|
|
public static final String REGISTRATION_LOCK_PREF = "pref_registration_lock";
|
|
|
|
private static final String REGISTRATION_LOCK_PIN_PREF = "pref_registration_lock_pin";
|
|
|
|
private static final String REGISTRATION_LOCK_LAST_REMINDER_TIME = "pref_registration_lock_last_reminder_time";
|
|
|
|
private static final String REGISTRATION_LOCK_NEXT_REMINDER_INTERVAL = "pref_registration_lock_next_reminder_interval";
|
|
|
|
|
2018-06-11 16:37:01 +00:00
|
|
|
private static final String SERVICE_OUTAGE = "pref_service_outage";
|
|
|
|
private static final String LAST_OUTAGE_CHECK_TIME = "pref_last_outage_check_time";
|
|
|
|
|
2018-07-07 00:28:58 +00:00
|
|
|
private static final String LAST_FULL_CONTACT_SYNC_TIME = "pref_last_full_contact_sync_time";
|
|
|
|
private static final String NEEDS_FULL_CONTACT_SYNC = "pref_needs_full_contact_sync";
|
|
|
|
|
2018-07-26 14:10:46 +00:00
|
|
|
private static final String LOG_ENCRYPTED_SECRET = "pref_log_encrypted_secret";
|
|
|
|
private static final String LOG_UNENCRYPTED_SECRET = "pref_log_unencrypted_secret";
|
|
|
|
|
2018-03-04 19:35:37 +00:00
|
|
|
public static boolean isScreenLockEnabled(@NonNull Context context) {
|
|
|
|
return getBooleanPreference(context, SCREEN_LOCK, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setScreenLockEnabled(@NonNull Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, SCREEN_LOCK, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getScreenLockTimeout(@NonNull Context context) {
|
|
|
|
return getLongPreference(context, SCREEN_LOCK_TIMEOUT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setScreenLockTimeout(@NonNull Context context, long value) {
|
|
|
|
setLongPreference(context, SCREEN_LOCK_TIMEOUT, value);
|
|
|
|
}
|
|
|
|
|
2018-03-01 17:51:37 +00:00
|
|
|
public static boolean isRegistrationtLockEnabled(@NonNull Context context) {
|
|
|
|
return getBooleanPreference(context, REGISTRATION_LOCK_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRegistrationtLockEnabled(@NonNull Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, REGISTRATION_LOCK_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getRegistrationLockPin(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, REGISTRATION_LOCK_PIN_PREF, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRegistrationLockPin(@NonNull Context context, String pin) {
|
|
|
|
setStringPreference(context, REGISTRATION_LOCK_PIN_PREF, pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getRegistrationLockLastReminderTime(@NonNull Context context) {
|
|
|
|
return getLongPreference(context, REGISTRATION_LOCK_LAST_REMINDER_TIME, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRegistrationLockLastReminderTime(@NonNull Context context, long time) {
|
|
|
|
setLongPreference(context, REGISTRATION_LOCK_LAST_REMINDER_TIME, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getRegistrationLockNextReminderInterval(@NonNull Context context) {
|
|
|
|
return getLongPreference(context, REGISTRATION_LOCK_NEXT_REMINDER_INTERVAL, RegistrationLockReminders.INITIAL_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRegistrationLockNextReminderInterval(@NonNull Context context, long value) {
|
|
|
|
setLongPreference(context, REGISTRATION_LOCK_NEXT_REMINDER_INTERVAL, value);
|
|
|
|
}
|
|
|
|
|
2018-02-26 17:58:18 +00:00
|
|
|
public static void setBackupPassphrase(@NonNull Context context, @Nullable String passphrase) {
|
|
|
|
setStringPreference(context, BACKUP_PASSPHRASE, passphrase);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getBackupPassphrase(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, BACKUP_PASSPHRASE, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setBackupEnabled(@NonNull Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, BACKUP_ENABLED, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isBackupEnabled(@NonNull Context context) {
|
|
|
|
return getBooleanPreference(context, BACKUP_ENABLED, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setNextBackupTime(@NonNull Context context, long time) {
|
|
|
|
setLongPreference(context, BACKUP_TIME, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getNextBackupTime(@NonNull Context context) {
|
|
|
|
return getLongPreference(context, BACKUP_TIME, -1);
|
|
|
|
}
|
|
|
|
|
2018-02-16 04:33:10 +00:00
|
|
|
public static int getNextPreKeyId(@NonNull Context context) {
|
|
|
|
return getIntegerPreference(context, NEXT_PRE_KEY_ID, new SecureRandom().nextInt(Medium.MAX_VALUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setNextPreKeyId(@NonNull Context context, int value) {
|
|
|
|
setIntegerPrefrence(context, NEXT_PRE_KEY_ID, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getNextSignedPreKeyId(@NonNull Context context) {
|
|
|
|
return getIntegerPreference(context, NEXT_SIGNED_PRE_KEY_ID, new SecureRandom().nextInt(Medium.MAX_VALUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setNextSignedPreKeyId(@NonNull Context context, int value) {
|
|
|
|
setIntegerPrefrence(context, NEXT_SIGNED_PRE_KEY_ID, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getActiveSignedPreKeyId(@NonNull Context context) {
|
|
|
|
return getIntegerPreference(context, ACTIVE_SIGNED_PRE_KEY_ID, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setActiveSignedPreKeyId(@NonNull Context context, int value) {
|
|
|
|
setIntegerPrefrence(context, ACTIVE_SIGNED_PRE_KEY_ID, value);;
|
|
|
|
}
|
|
|
|
|
2018-01-25 03:17:44 +00:00
|
|
|
public static void setNeedsSqlCipherMigration(@NonNull Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, value);
|
2018-02-26 22:02:12 +00:00
|
|
|
EventBus.getDefault().post(new SqlCipherMigrationRequirementProvider.SqlCipherNeedsMigrationEvent());
|
2018-01-25 03:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getNeedsSqlCipherMigration(@NonNull Context context) {
|
|
|
|
return getBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setAttachmentEncryptedSecret(@NonNull Context context, @NonNull String secret) {
|
|
|
|
setStringPreference(context, ATTACHMENT_ENCRYPTED_SECRET, secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setAttachmentUnencryptedSecret(@NonNull Context context, @Nullable String secret) {
|
|
|
|
setStringPreference(context, ATTACHMENT_UNENCRYPTED_SECRET, secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getAttachmentEncryptedSecret(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, ATTACHMENT_ENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getAttachmentUnencryptedSecret(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, ATTACHMENT_UNENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setDatabaseEncryptedSecret(@NonNull Context context, @NonNull String secret) {
|
|
|
|
setStringPreference(context, DATABASE_ENCRYPTED_SECRET, secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setDatabaseUnencryptedSecret(@NonNull Context context, @Nullable String secret) {
|
|
|
|
setStringPreference(context, DATABASE_UNENCRYPTED_SECRET, secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getDatabaseUnencryptedSecret(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, DATABASE_UNENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @Nullable String getDatabaseEncryptedSecret(@NonNull Context context) {
|
|
|
|
return getStringPreference(context, DATABASE_ENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
2017-11-21 19:54:18 +00:00
|
|
|
public static void setHasSuccessfullyRetrievedDirectory(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, SUCCESSFUL_DIRECTORY_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasSuccessfullyRetrievedDirectory(Context context) {
|
|
|
|
return getBooleanPreference(context, SUCCESSFUL_DIRECTORY_PREF, false);
|
|
|
|
}
|
2017-11-16 00:29:00 +00:00
|
|
|
|
|
|
|
public static void setUnauthorizedReceived(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, UNAUTHORIZED_RECEIVED, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isUnauthorizedRecieved(Context context) {
|
|
|
|
return getBooleanPreference(context, UNAUTHORIZED_RECEIVED, false);
|
|
|
|
}
|
2017-10-04 01:57:23 +00:00
|
|
|
|
|
|
|
public static boolean isIncognitoKeyboardEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, INCOGNITO_KEYBORAD_PREF, false);
|
|
|
|
}
|
2017-09-16 05:38:53 +00:00
|
|
|
|
|
|
|
public static boolean isReadReceiptsEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, READ_RECEIPTS_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setReadReceiptsEnabled(Context context, boolean enabled) {
|
|
|
|
setBooleanPreference(context, READ_RECEIPTS_PREF, enabled);
|
|
|
|
}
|
2017-08-08 23:37:15 +00:00
|
|
|
|
|
|
|
public static @Nullable String getProfileKey(Context context) {
|
|
|
|
return getStringPreference(context, PROFILE_KEY_PREF, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setProfileKey(Context context, String key) {
|
|
|
|
setStringPreference(context, PROFILE_KEY_PREF, key);
|
|
|
|
}
|
2017-02-17 21:12:48 +00:00
|
|
|
|
2017-08-16 04:03:31 +00:00
|
|
|
public static void setProfileName(Context context, String name) {
|
|
|
|
setStringPreference(context, PROFILE_NAME_PREF, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getProfileName(Context context) {
|
|
|
|
return getStringPreference(context, PROFILE_NAME_PREF, null);
|
|
|
|
}
|
|
|
|
|
2017-10-16 20:11:42 +00:00
|
|
|
public static void setProfileAvatarId(Context context, int id) {
|
|
|
|
setIntegerPrefrence(context, PROFILE_AVATAR_ID_PREF, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getProfileAvatarId(Context context) {
|
|
|
|
return getIntegerPreference(context, PROFILE_AVATAR_ID_PREF, 0);
|
|
|
|
}
|
|
|
|
|
2017-04-22 06:04:54 +00:00
|
|
|
public static int getNotificationPriority(Context context) {
|
|
|
|
return Integer.valueOf(getStringPreference(context, NOTIFICATION_PRIORITY_PREF, String.valueOf(NotificationCompat.PRIORITY_HIGH)));
|
|
|
|
}
|
|
|
|
|
2017-04-15 05:59:30 +00:00
|
|
|
public static int getMessageBodyTextSize(Context context) {
|
|
|
|
return Integer.valueOf(getStringPreference(context, MESSAGE_BODY_TEXT_SIZE_PREF, "16"));
|
|
|
|
}
|
|
|
|
|
2017-02-17 21:12:48 +00:00
|
|
|
public static boolean isTurnOnly(Context context) {
|
|
|
|
return getBooleanPreference(context, ALWAYS_RELAY_CALLS_PREF, false);
|
|
|
|
}
|
2015-11-08 01:12:02 +00:00
|
|
|
|
2017-02-20 20:00:03 +00:00
|
|
|
public static boolean isGcmDisabled(Context context) {
|
|
|
|
return getBooleanPreference(context, GCM_DISABLED_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setGcmDisabled(Context context, boolean disabled) {
|
|
|
|
setBooleanPreference(context, GCM_DISABLED_PREF, disabled);
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:37:40 +00:00
|
|
|
public static boolean isWebrtcCallingEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, WEBRTC_CALLING_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setWebrtcCallingEnabled(Context context, boolean enabled) {
|
|
|
|
setBooleanPreference(context, WEBRTC_CALLING_PREF, enabled);
|
|
|
|
}
|
|
|
|
|
2015-11-08 01:12:02 +00:00
|
|
|
public static void setDirectCaptureCameraId(Context context, int value) {
|
|
|
|
setIntegerPrefrence(context, DIRECT_CAPTURE_CAMERA_ID, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public static int getDirectCaptureCameraId(Context context) {
|
|
|
|
return getIntegerPreference(context, DIRECT_CAPTURE_CAMERA_ID, CameraInfo.CAMERA_FACING_FRONT);
|
|
|
|
}
|
2015-10-23 19:51:28 +00:00
|
|
|
|
|
|
|
public static void setMultiDevice(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isMultiDevice(Context context) {
|
|
|
|
return getBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, false);
|
|
|
|
}
|
2015-09-07 23:11:40 +00:00
|
|
|
|
2017-01-06 17:19:58 +00:00
|
|
|
public static void setSignedPreKeyFailureCount(Context context, int value) {
|
|
|
|
setIntegerPrefrence(context, SIGNED_PREKEY_FAILURE_COUNT_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSignedPreKeyFailureCount(Context context) {
|
|
|
|
return getIntegerPreference(context, SIGNED_PREKEY_FAILURE_COUNT_PREF, 0);
|
|
|
|
}
|
|
|
|
|
2015-07-31 22:05:24 +00:00
|
|
|
public static NotificationPrivacyPreference getNotificationPrivacy(Context context) {
|
|
|
|
return new NotificationPrivacyPreference(getStringPreference(context, NOTIFICATION_PRIVACY_PREF, "all"));
|
|
|
|
}
|
2014-12-12 03:36:46 +00:00
|
|
|
|
2015-12-19 12:07:44 +00:00
|
|
|
public static boolean isNewContactsNotificationEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, NEW_CONTACTS_NOTIFICATIONS, true);
|
|
|
|
}
|
|
|
|
|
2015-03-31 19:34:49 +00:00
|
|
|
public static long getRatingLaterTimestamp(Context context) {
|
|
|
|
return getLongPreference(context, RATING_LATER_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRatingLaterTimestamp(Context context, long timestamp) {
|
|
|
|
setLongPreference(context, RATING_LATER_PREF, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isRatingEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, RATING_ENABLED_PREF, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRatingEnabled(Context context, boolean enabled) {
|
|
|
|
setBooleanPreference(context, RATING_ENABLED_PREF, enabled);
|
|
|
|
}
|
|
|
|
|
2015-01-26 01:43:24 +00:00
|
|
|
public static boolean isWebsocketRegistered(Context context) {
|
|
|
|
return getBooleanPreference(context, WEBSOCKET_REGISTERED_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setWebsocketRegistered(Context context, boolean registered) {
|
|
|
|
setBooleanPreference(context, WEBSOCKET_REGISTERED_PREF, registered);
|
|
|
|
}
|
|
|
|
|
2014-12-24 20:40:28 +00:00
|
|
|
public static boolean isWifiSmsEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, WIFI_SMS_PREF, false);
|
|
|
|
}
|
|
|
|
|
2014-12-12 03:36:46 +00:00
|
|
|
public static int getRepeatAlertsCount(Context context) {
|
|
|
|
try {
|
|
|
|
return Integer.parseInt(getStringPreference(context, REPEAT_ALERTS_PREF, "0"));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRepeatAlertsCount(Context context, int count) {
|
|
|
|
setStringPreference(context, REPEAT_ALERTS_PREF, String.valueOf(count));
|
|
|
|
}
|
|
|
|
|
2014-07-13 01:06:22 +00:00
|
|
|
public static boolean isSignedPreKeyRegistered(Context context) {
|
|
|
|
return getBooleanPreference(context, SIGNED_PREKEY_REGISTERED_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSignedPreKeyRegistered(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, SIGNED_PREKEY_REGISTERED_PREF, value);
|
|
|
|
}
|
2014-02-20 22:49:31 +00:00
|
|
|
|
2014-07-23 22:40:45 +00:00
|
|
|
public static void setGcmRegistrationId(Context context, String registrationId) {
|
|
|
|
setStringPreference(context, GCM_REGISTRATION_ID_PREF, registrationId);
|
|
|
|
setIntegerPrefrence(context, GCM_REGISTRATION_ID_VERSION_PREF, Util.getCurrentApkReleaseVersion(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getGcmRegistrationId(Context context) {
|
|
|
|
int storedRegistrationIdVersion = getIntegerPreference(context, GCM_REGISTRATION_ID_VERSION_PREF, 0);
|
|
|
|
|
|
|
|
if (storedRegistrationIdVersion != Util.getCurrentApkReleaseVersion(context)) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return getStringPreference(context, GCM_REGISTRATION_ID_PREF, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 17:28:06 +00:00
|
|
|
public static long getGcmRegistrationIdLastSetTime(Context context) {
|
|
|
|
return getLongPreference(context, GCM_REGISTRATION_ID_TIME_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setGcmRegistrationIdLastSetTime(Context context, long timestamp) {
|
|
|
|
setLongPreference(context, GCM_REGISTRATION_ID_TIME_PREF, timestamp);
|
|
|
|
}
|
|
|
|
|
2015-03-11 21:23:45 +00:00
|
|
|
public static boolean isSmsEnabled(Context context) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
return Util.isDefaultSmsProvider(context);
|
|
|
|
} else {
|
|
|
|
return isInterceptAllSmsEnabled(context);
|
|
|
|
}
|
2014-03-01 22:17:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 20:48:20 +00:00
|
|
|
public static int getLocalRegistrationId(Context context) {
|
|
|
|
return getIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLocalRegistrationId(Context context, int registrationId) {
|
|
|
|
setIntegerPrefrence(context, LOCAL_REGISTRATION_ID_PREF, registrationId);
|
|
|
|
}
|
|
|
|
|
2013-11-18 23:29:19 +00:00
|
|
|
public static boolean isInThreadNotifications(Context context) {
|
|
|
|
return getBooleanPreference(context, IN_THREAD_NOTIFICATION_PREF, true);
|
|
|
|
}
|
2013-10-13 11:38:26 +00:00
|
|
|
|
2017-01-06 17:19:58 +00:00
|
|
|
public static long getSignedPreKeyRotationTime(Context context) {
|
|
|
|
return getLongPreference(context, SIGNED_PREKEY_ROTATION_TIME_PREF, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSignedPreKeyRotationTime(Context context, long value) {
|
|
|
|
setLongPreference(context, SIGNED_PREKEY_ROTATION_TIME_PREF, value);
|
|
|
|
}
|
|
|
|
|
2013-10-13 11:38:26 +00:00
|
|
|
public static long getDirectoryRefreshTime(Context context) {
|
|
|
|
return getLongPreference(context, DIRECTORY_FRESH_TIME_PREF, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setDirectoryRefreshTime(Context context, long value) {
|
|
|
|
setLongPreference(context, DIRECTORY_FRESH_TIME_PREF, value);
|
|
|
|
}
|
2013-07-11 21:58:40 +00:00
|
|
|
|
2017-02-26 22:36:43 +00:00
|
|
|
public static long getUpdateApkRefreshTime(Context context) {
|
|
|
|
return getLongPreference(context, UPDATE_APK_REFRESH_TIME_PREF, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUpdateApkRefreshTime(Context context, long value) {
|
|
|
|
setLongPreference(context, UPDATE_APK_REFRESH_TIME_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUpdateApkDownloadId(Context context, long value) {
|
|
|
|
setLongPreference(context, UPDATE_APK_DOWNLOAD_ID, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getUpdateApkDownloadId(Context context) {
|
|
|
|
return getLongPreference(context, UPDATE_APK_DOWNLOAD_ID, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUpdateApkDigest(Context context, String value) {
|
|
|
|
setStringPreference(context, UPDATE_APK_DIGEST, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getUpdateApkDigest(Context context) {
|
|
|
|
return getStringPreference(context, UPDATE_APK_DIGEST, null);
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static String getLocalNumber(Context context) {
|
2017-08-02 19:51:46 +00:00
|
|
|
return getStringPreference(context, LOCAL_NUMBER_PREF, null);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLocalNumber(Context context, String localNumber) {
|
|
|
|
setStringPreference(context, LOCAL_NUMBER_PREF, localNumber);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPushServerPassword(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getStringPreference(context, GCM_PASSWORD_PREF, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPushServerPassword(Context context, String password) {
|
|
|
|
setStringPreference(context, GCM_PASSWORD_PREF, password);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 22:35:30 +00:00
|
|
|
public static void setSignalingKey(Context context, String signalingKey) {
|
|
|
|
setStringPreference(context, SIGNALING_KEY_PREF, signalingKey);
|
|
|
|
}
|
|
|
|
|
2013-08-30 00:01:30 +00:00
|
|
|
public static String getSignalingKey(Context context) {
|
|
|
|
return getStringPreference(context, SIGNALING_KEY_PREF, null);
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static boolean isEnterImeKeyEnabled(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getBooleanPreference(context, ENTER_PRESENT_PREF, false);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isEnterSendsEnabled(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getBooleanPreference(context, ENTER_SENDS_PREF, false);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPasswordDisabled(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getBooleanPreference(context, DISABLE_PASSPHRASE_PREF, false);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPasswordDisabled(Context context, boolean disabled) {
|
2013-07-11 21:58:40 +00:00
|
|
|
setBooleanPreference(context, DISABLE_PASSPHRASE_PREF, disabled);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static boolean getUseCustomMmsc(Context context) {
|
|
|
|
boolean legacy = TextSecurePreferences.isLegacyUseLocalApnsEnabled(context);
|
|
|
|
return getBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, legacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseCustomMmsc(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, value);
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static String getMmscUrl(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getStringPreference(context, MMSC_HOST_PREF, "");
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setMmscUrl(Context context, String mmsc) {
|
|
|
|
setStringPreference(context, MMSC_HOST_PREF, mmsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getUseCustomMmscProxy(Context context) {
|
|
|
|
boolean legacy = TextSecurePreferences.isLegacyUseLocalApnsEnabled(context);
|
|
|
|
return getBooleanPreference(context, MMSC_CUSTOM_PROXY_PREF, legacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseCustomMmscProxy(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MMSC_CUSTOM_PROXY_PREF, value);
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static String getMmscProxy(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getStringPreference(context, MMSC_PROXY_HOST_PREF, "");
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setMmscProxy(Context context, String value) {
|
|
|
|
setStringPreference(context, MMSC_PROXY_HOST_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getUseCustomMmscProxyPort(Context context) {
|
|
|
|
boolean legacy = TextSecurePreferences.isLegacyUseLocalApnsEnabled(context);
|
|
|
|
return getBooleanPreference(context, MMSC_CUSTOM_PROXY_PORT_PREF, legacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseCustomMmscProxyPort(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MMSC_CUSTOM_PROXY_PORT_PREF, value);
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static String getMmscProxyPort(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "");
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setMmscProxyPort(Context context, String value) {
|
|
|
|
setStringPreference(context, MMSC_PROXY_PORT_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getUseCustomMmscUsername(Context context) {
|
|
|
|
boolean legacy = TextSecurePreferences.isLegacyUseLocalApnsEnabled(context);
|
|
|
|
return getBooleanPreference(context, MMSC_CUSTOM_USERNAME_PREF, legacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseCustomMmscUsername(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MMSC_CUSTOM_USERNAME_PREF, value);
|
|
|
|
}
|
|
|
|
|
2014-11-25 08:48:09 +00:00
|
|
|
public static String getMmscUsername(Context context) {
|
|
|
|
return getStringPreference(context, MMSC_USERNAME_PREF, "");
|
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setMmscUsername(Context context, String value) {
|
|
|
|
setStringPreference(context, MMSC_USERNAME_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getUseCustomMmscPassword(Context context) {
|
|
|
|
boolean legacy = TextSecurePreferences.isLegacyUseLocalApnsEnabled(context);
|
|
|
|
return getBooleanPreference(context, MMSC_CUSTOM_PASSWORD_PREF, legacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseCustomMmscPassword(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, MMSC_CUSTOM_PASSWORD_PREF, value);
|
|
|
|
}
|
|
|
|
|
2014-11-25 08:48:09 +00:00
|
|
|
public static String getMmscPassword(Context context) {
|
|
|
|
return getStringPreference(context, MMSC_PASSWORD_PREF, "");
|
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setMmscPassword(Context context, String value) {
|
|
|
|
setStringPreference(context, MMSC_PASSWORD_PREF, value);
|
|
|
|
}
|
|
|
|
|
2015-01-18 03:10:46 +00:00
|
|
|
public static String getMmsUserAgent(Context context, String defaultUserAgent) {
|
|
|
|
boolean useCustom = getBooleanPreference(context, MMS_CUSTOM_USER_AGENT, false);
|
|
|
|
|
|
|
|
if (useCustom) return getStringPreference(context, MMS_USER_AGENT, defaultUserAgent);
|
|
|
|
else return defaultUserAgent;
|
|
|
|
}
|
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
public static String getIdentityContactUri(Context context) {
|
2013-07-11 21:58:40 +00:00
|
|
|
return getStringPreference(context, IDENTITY_PREF, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setIdentityContactUri(Context context, String identityUri) {
|
|
|
|
setStringPreference(context, IDENTITY_PREF, identityUri);
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 01:57:23 +00:00
|
|
|
public static void setScreenSecurityEnabled(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, SCREEN_SECURITY_PREF, value);
|
|
|
|
}
|
|
|
|
|
2014-02-26 21:15:45 +00:00
|
|
|
public static boolean isScreenSecurityEnabled(Context context) {
|
2017-10-04 01:57:23 +00:00
|
|
|
return getBooleanPreference(context, SCREEN_SECURITY_PREF, false);
|
2014-02-26 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static boolean isLegacyUseLocalApnsEnabled(Context context) {
|
2013-11-18 23:29:19 +00:00
|
|
|
return getBooleanPreference(context, ENABLE_MANUAL_MMS_PREF, false);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:48:26 +00:00
|
|
|
public static int getLastVersionCode(Context context) {
|
|
|
|
return getIntegerPreference(context, LAST_VERSION_CODE_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLastVersionCode(Context context, int versionCode) throws IOException {
|
|
|
|
if (!setIntegerPrefrenceBlocking(context, LAST_VERSION_CODE_PREF, versionCode)) {
|
|
|
|
throw new IOException("couldn't write version code to sharedpreferences");
|
|
|
|
}
|
2015-09-29 20:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getLastExperienceVersionCode(Context context) {
|
|
|
|
return getIntegerPreference(context, LAST_EXPERIENCE_VERSION_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLastExperienceVersionCode(Context context, int versionCode) {
|
|
|
|
setIntegerPrefrence(context, LAST_EXPERIENCE_VERSION_PREF, versionCode);
|
|
|
|
}
|
2014-05-05 18:48:26 +00:00
|
|
|
|
2017-09-04 02:44:33 +00:00
|
|
|
public static int getExperienceDismissedVersionCode(Context context) {
|
|
|
|
return getIntegerPreference(context, EXPERIENCE_DISMISSED_PREF, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setExperienceDismissedVersionCode(Context context, int versionCode) {
|
|
|
|
setIntegerPrefrence(context, EXPERIENCE_DISMISSED_PREF, versionCode);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static String getTheme(Context context) {
|
|
|
|
return getStringPreference(context, THEME_PREF, "light");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isVerifying(Context context) {
|
|
|
|
return getBooleanPreference(context, VERIFYING_STATE_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setVerifying(Context context, boolean verifying) {
|
|
|
|
setBooleanPreference(context, VERIFYING_STATE_PREF, verifying);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPushRegistered(Context context) {
|
|
|
|
return getBooleanPreference(context, REGISTERED_GCM_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPushRegistered(Context context, boolean registered) {
|
|
|
|
Log.w("TextSecurePreferences", "Setting push registered: " + registered);
|
|
|
|
setBooleanPreference(context, REGISTERED_GCM_PREF, registered);
|
|
|
|
}
|
|
|
|
|
2017-04-15 03:51:22 +00:00
|
|
|
public static boolean isShowInviteReminders(Context context) {
|
|
|
|
return getBooleanPreference(context, SHOW_INVITE_REMINDER_PREF, true);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static boolean isPassphraseTimeoutEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, PASSPHRASE_TIMEOUT_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getPassphraseTimeoutInterval(Context context) {
|
|
|
|
return getIntegerPreference(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, 5 * 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPassphraseTimeoutInterval(Context context, int interval) {
|
|
|
|
setIntegerPrefrence(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getLanguage(Context context) {
|
|
|
|
return getStringPreference(context, LANGUAGE_PREF, "zz");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLanguage(Context context, String language) {
|
|
|
|
setStringPreference(context, LANGUAGE_PREF, language);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSmsDeliveryReportsEnabled(Context context) {
|
2014-02-26 20:38:50 +00:00
|
|
|
return getBooleanPreference(context, SMS_DELIVERY_REPORT_PREF, false);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPromptedPushRegistration(Context context) {
|
|
|
|
return getBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPromptedPushRegistration(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, value);
|
|
|
|
}
|
|
|
|
|
2014-01-08 22:29:05 +00:00
|
|
|
public static boolean hasPromptedDefaultSmsProvider(Context context) {
|
|
|
|
return getBooleanPreference(context, PROMPTED_DEFAULT_SMS_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPromptedDefaultSmsProvider(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, PROMPTED_DEFAULT_SMS_PREF, value);
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:00:03 +00:00
|
|
|
public static void setPromptedOptimizeDoze(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, PROMPTED_OPTIMIZE_DOZE_PREF, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPromptedOptimizeDoze(Context context) {
|
|
|
|
return getBooleanPreference(context, PROMPTED_OPTIMIZE_DOZE_PREF, false);
|
|
|
|
}
|
|
|
|
|
2015-10-19 18:23:12 +00:00
|
|
|
public static boolean hasPromptedShare(Context context) {
|
|
|
|
return getBooleanPreference(context, PROMPTED_SHARE_PREF, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setPromptedShare(Context context, boolean value) {
|
|
|
|
setBooleanPreference(context, PROMPTED_SHARE_PREF, value);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static boolean isInterceptAllMmsEnabled(Context context) {
|
2014-01-07 02:52:18 +00:00
|
|
|
return getBooleanPreference(context, ALL_MMS_PREF, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInterceptAllSmsEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, ALL_SMS_PREF, true);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isNotificationsEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, NOTIFICATION_PREF, true);
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static boolean isCallNotificationsEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, CALL_NOTIFICATIONS_PREF, true);
|
|
|
|
}
|
|
|
|
|
2017-12-19 22:42:00 +00:00
|
|
|
public static @NonNull Uri getNotificationRingtone(Context context) {
|
2017-12-01 20:55:24 +00:00
|
|
|
String result = getStringPreference(context, RINGTONE_PREF, Settings.System.DEFAULT_NOTIFICATION_URI.toString());
|
|
|
|
|
|
|
|
if (result != null && result.startsWith("file:")) {
|
|
|
|
result = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
|
|
|
|
}
|
|
|
|
|
2017-12-19 22:42:00 +00:00
|
|
|
return Uri.parse(result);
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static @NonNull Uri getCallNotificationRingtone(Context context) {
|
|
|
|
String result = getStringPreference(context, CALL_RINGTONE_PREF, Settings.System.DEFAULT_RINGTONE_URI.toString());
|
|
|
|
|
|
|
|
if (result != null && result.startsWith("file:")) {
|
|
|
|
result = Settings.System.DEFAULT_RINGTONE_URI.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Uri.parse(result);
|
|
|
|
}
|
|
|
|
|
2017-12-19 22:42:00 +00:00
|
|
|
public static void removeNotificationRingtone(Context context) {
|
|
|
|
removePreference(context, RINGTONE_PREF);
|
2017-12-01 20:55:24 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static void removeCallNotificationRingtone(Context context) {
|
|
|
|
removePreference(context, CALL_RINGTONE_PREF);
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:55:24 +00:00
|
|
|
public static void setNotificationRingtone(Context context, String ringtone) {
|
|
|
|
setStringPreference(context, RINGTONE_PREF, ringtone);
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static void setCallNotificationRingtone(Context context, String ringtone) {
|
|
|
|
setStringPreference(context, CALL_RINGTONE_PREF, ringtone);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static boolean isNotificationVibrateEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, VIBRATE_PREF, true);
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
public static boolean isCallNotificationVibrateEnabled(Context context) {
|
|
|
|
boolean defaultValue = true;
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
defaultValue = (Settings.System.getInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 1) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return getBooleanPreference(context, CALL_VIBRATE_PREF, defaultValue);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static String getNotificationLedColor(Context context) {
|
2015-05-07 06:20:04 +00:00
|
|
|
return getStringPreference(context, LED_COLOR_PREF, "blue");
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getNotificationLedPattern(Context context) {
|
|
|
|
return getStringPreference(context, LED_BLINK_PREF, "500,2000");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getNotificationLedPatternCustom(Context context) {
|
|
|
|
return getStringPreference(context, LED_BLINK_PREF_CUSTOM, "500,2000");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setNotificationLedPatternCustom(Context context, String pattern) {
|
|
|
|
setStringPreference(context, LED_BLINK_PREF_CUSTOM, pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isThreadLengthTrimmingEnabled(Context context) {
|
|
|
|
return getBooleanPreference(context, THREAD_TRIM_ENABLED, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getThreadTrimLength(Context context) {
|
|
|
|
return Integer.parseInt(getStringPreference(context, THREAD_TRIM_LENGTH, "500"));
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-07 23:11:40 +00:00
|
|
|
public static boolean isSystemEmojiPreferred(Context context) {
|
|
|
|
return getBooleanPreference(context, SYSTEM_EMOJI_PREF, false);
|
|
|
|
}
|
|
|
|
|
2015-08-24 22:24:31 +00:00
|
|
|
public static @NonNull Set<String> getMobileMediaDownloadAllowed(Context context) {
|
|
|
|
return getMediaDownloadAllowed(context, MEDIA_DOWNLOAD_MOBILE_PREF, R.array.pref_media_download_mobile_data_default);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @NonNull Set<String> getWifiMediaDownloadAllowed(Context context) {
|
|
|
|
return getMediaDownloadAllowed(context, MEDIA_DOWNLOAD_WIFI_PREF, R.array.pref_media_download_wifi_default);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @NonNull Set<String> getRoamingMediaDownloadAllowed(Context context) {
|
|
|
|
return getMediaDownloadAllowed(context, MEDIA_DOWNLOAD_ROAMING_PREF, R.array.pref_media_download_roaming_default);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static @NonNull Set<String> getMediaDownloadAllowed(Context context, String key, @ArrayRes int defaultValuesRes) {
|
|
|
|
return getStringSetPreference(context,
|
|
|
|
key,
|
|
|
|
new HashSet<>(Arrays.asList(context.getResources().getStringArray(defaultValuesRes))));
|
|
|
|
}
|
|
|
|
|
2018-06-11 16:37:01 +00:00
|
|
|
public static void setLastOutageCheckTime(Context context, long timestamp) {
|
|
|
|
setLongPreference(context, LAST_OUTAGE_CHECK_TIME, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getLastOutageCheckTime(Context context) {
|
|
|
|
return getLongPreference(context, LAST_OUTAGE_CHECK_TIME, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setServiceOutage(Context context, boolean isOutage) {
|
|
|
|
setBooleanPreference(context, SERVICE_OUTAGE, isOutage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean getServiceOutage(Context context) {
|
|
|
|
return getBooleanPreference(context, SERVICE_OUTAGE, false);
|
|
|
|
}
|
|
|
|
|
2018-07-07 00:28:58 +00:00
|
|
|
public static long getLastFullContactSyncTime(Context context) {
|
|
|
|
return getLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLastFullContactSyncTime(Context context, long timestamp) {
|
|
|
|
setLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean needsFullContactSync(Context context) {
|
|
|
|
return getBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setNeedsFullContactSync(Context context, boolean needsSync) {
|
|
|
|
setBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, needsSync);
|
|
|
|
}
|
|
|
|
|
2018-07-26 14:10:46 +00:00
|
|
|
public static void setLogEncryptedSecret(Context context, String base64Secret) {
|
|
|
|
setStringPreference(context, LOG_ENCRYPTED_SECRET, base64Secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getLogEncryptedSecret(Context context) {
|
|
|
|
return getStringPreference(context, LOG_ENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLogUnencryptedSecret(Context context, String base64Secret) {
|
|
|
|
setStringPreference(context, LOG_UNENCRYPTED_SECRET, base64Secret);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getLogUnencryptedSecret(Context context) {
|
|
|
|
return getStringPreference(context, LOG_UNENCRYPTED_SECRET, null);
|
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static void setBooleanPreference(Context context, String key, boolean value) {
|
2014-05-05 18:48:26 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static boolean getBooleanPreference(Context context, String key, boolean defaultValue) {
|
2013-07-10 01:26:18 +00:00
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, defaultValue);
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
public static void setStringPreference(Context context, String key, String value) {
|
2014-05-05 18:48:26 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(key, value).apply();
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:44 +00:00
|
|
|
public static String getStringPreference(Context context, String key, String defaultValue) {
|
2013-07-10 01:26:18 +00:00
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getString(key, defaultValue);
|
|
|
|
}
|
2013-07-11 21:58:40 +00:00
|
|
|
|
|
|
|
private static int getIntegerPreference(Context context, String key, int defaultValue) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getInt(key, defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setIntegerPrefrence(Context context, String key, int value) {
|
2014-05-05 18:48:26 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(key, value).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean setIntegerPrefrenceBlocking(Context context, String key, int value) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(key, value).commit();
|
2013-07-11 21:58:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 11:38:26 +00:00
|
|
|
private static long getLongPreference(Context context, String key, long defaultValue) {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getLong(key, defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setLongPreference(Context context, String key, long value) {
|
2014-05-05 18:48:26 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(key, value).apply();
|
2013-10-13 11:38:26 +00:00
|
|
|
}
|
2015-08-24 22:24:31 +00:00
|
|
|
|
2017-12-19 22:42:00 +00:00
|
|
|
private static void removePreference(Context context, String key) {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().remove(key).apply();
|
|
|
|
}
|
|
|
|
|
2015-08-24 22:24:31 +00:00
|
|
|
private static Set<String> getStringSetPreference(Context context, String key, Set<String> defaultValues) {
|
2015-09-03 21:04:47 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
if (prefs.contains(key)) {
|
2017-10-03 17:24:45 +00:00
|
|
|
return prefs.getStringSet(key, Collections.<String>emptySet());
|
2015-09-03 21:04:47 +00:00
|
|
|
} else {
|
|
|
|
return defaultValues;
|
|
|
|
}
|
2015-08-24 22:24:31 +00:00
|
|
|
}
|
2013-07-10 01:26:18 +00:00
|
|
|
}
|