mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 21:17:42 +00:00
Merge branch 'dev' into trusted_attachment_download
# Conflicts: # app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt # app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
package org.session.libsession.messaging
|
||||
|
||||
import android.content.Context
|
||||
import com.goterl.lazysodium.utils.KeyPair
|
||||
import org.session.libsession.database.MessageDataProvider
|
||||
import org.session.libsession.database.StorageProtocol
|
||||
|
||||
class MessagingModuleConfiguration(
|
||||
val context: Context,
|
||||
val storage: StorageProtocol,
|
||||
val messageDataProvider: MessageDataProvider
|
||||
val messageDataProvider: MessageDataProvider,
|
||||
val keyPairProvider: ()-> KeyPair?
|
||||
) {
|
||||
|
||||
companion object {
|
||||
lateinit var shared: MessagingModuleConfiguration
|
||||
|
||||
fun configure(context: Context,
|
||||
storage: StorageProtocol,
|
||||
messageDataProvider: MessageDataProvider
|
||||
storage: StorageProtocol,
|
||||
messageDataProvider: MessageDataProvider,
|
||||
keyPairProvider: () -> KeyPair?
|
||||
) {
|
||||
if (Companion::shared.isInitialized) { return }
|
||||
shared = MessagingModuleConfiguration(context, storage, messageDataProvider)
|
||||
shared = MessagingModuleConfiguration(context, storage, messageDataProvider, keyPairProvider)
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,7 +6,6 @@ import com.goterl.lazysodium.interfaces.Box
|
||||
import com.goterl.lazysodium.interfaces.Sign
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender.Error
|
||||
import org.session.libsession.utilities.KeyPairUtilities
|
||||
import org.session.libsignal.utilities.Hex
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.session.libsignal.utilities.removing05PrefixIfNeeded
|
||||
@@ -25,7 +24,7 @@ object MessageEncrypter {
|
||||
*/
|
||||
internal fun encrypt(plaintext: ByteArray, recipientHexEncodedX25519PublicKey: String): ByteArray{
|
||||
val context = MessagingModuleConfiguration.shared.context
|
||||
val userED25519KeyPair = KeyPairUtilities.getUserED25519KeyPair(context) ?: throw Error.NoUserED25519KeyPair
|
||||
val userED25519KeyPair = MessagingModuleConfiguration.shared.keyPairProvider() ?: throw Error.NoUserED25519KeyPair
|
||||
val recipientX25519PublicKey = Hex.fromStringCondensed(recipientHexEncodedX25519PublicKey.removing05PrefixIfNeeded())
|
||||
|
||||
val verificationData = plaintext + userED25519KeyPair.publicKey.asBytes + recipientX25519PublicKey
|
||||
|
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.session.libsession.utilities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.session.libsignal.crypto.ecc.ECPublicKey;
|
||||
import org.session.libsignal.crypto.IdentityKey;
|
||||
import org.session.libsignal.crypto.IdentityKeyPair;
|
||||
import org.session.libsignal.exceptions.InvalidKeyException;
|
||||
import org.session.libsignal.crypto.ecc.Curve;
|
||||
import org.session.libsignal.crypto.ecc.ECKeyPair;
|
||||
import org.session.libsignal.crypto.ecc.ECPrivateKey;
|
||||
|
||||
import org.session.libsignal.utilities.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Utility class for working with identity keys.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public class IdentityKeyUtil {
|
||||
|
||||
private static final String MASTER_SECRET_UTIL_PREFERENCES_NAME = "SecureSMS-Preferences";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = IdentityKeyUtil.class.getSimpleName();
|
||||
|
||||
public static final String IDENTITY_PUBLIC_KEY_PREF = "pref_identity_public_v3";
|
||||
public static final String IDENTITY_PRIVATE_KEY_PREF = "pref_identity_private_v3";
|
||||
public static final String ED25519_PUBLIC_KEY = "pref_ed25519_public_key";
|
||||
public static final String ED25519_SECRET_KEY = "pref_ed25519_secret_key";
|
||||
public static final String LOKI_SEED = "loki_seed";
|
||||
|
||||
public static boolean hasIdentityKey(Context context) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0);
|
||||
|
||||
return
|
||||
preferences.contains(IDENTITY_PUBLIC_KEY_PREF) &&
|
||||
preferences.contains(IDENTITY_PRIVATE_KEY_PREF);
|
||||
}
|
||||
|
||||
public static @NonNull IdentityKey getIdentityKey(@NonNull Context context) {
|
||||
if (!hasIdentityKey(context)) throw new AssertionError("There isn't one!");
|
||||
|
||||
try {
|
||||
byte[] publicKeyBytes = Base64.decode(retrieve(context, IDENTITY_PUBLIC_KEY_PREF));
|
||||
return new IdentityKey(publicKeyBytes, 0);
|
||||
} catch (IOException | InvalidKeyException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
|
||||
if (!hasIdentityKey(context)) throw new AssertionError("There isn't one!");
|
||||
|
||||
try {
|
||||
IdentityKey publicKey = getIdentityKey(context);
|
||||
ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));
|
||||
|
||||
return new IdentityKeyPair(publicKey, privateKey);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateIdentityKeyPair(@NonNull Context context) {
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
ECPublicKey publicKey = keyPair.getPublicKey();
|
||||
ECPrivateKey privateKey = keyPair.getPrivateKey();
|
||||
save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(publicKey.serialize()));
|
||||
save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(privateKey.serialize()));
|
||||
}
|
||||
|
||||
public static String retrieve(Context context, String key) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0);
|
||||
return preferences.getString(key, null);
|
||||
}
|
||||
|
||||
public static void save(Context context, String key, String value) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0);
|
||||
Editor preferencesEditor = preferences.edit();
|
||||
|
||||
preferencesEditor.putString(key, value);
|
||||
if (!preferencesEditor.commit()) throw new AssertionError("failed to save identity key/value to shared preferences");
|
||||
}
|
||||
|
||||
public static void delete(Context context, String key) {
|
||||
context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0).edit().remove(key).commit();
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
package org.session.libsession.utilities
|
||||
|
||||
import android.content.Context
|
||||
import com.goterl.lazysodium.LazySodiumAndroid
|
||||
import com.goterl.lazysodium.SodiumAndroid
|
||||
import com.goterl.lazysodium.utils.Key
|
||||
import com.goterl.lazysodium.utils.KeyPair
|
||||
import org.session.libsignal.crypto.ecc.DjbECPrivateKey
|
||||
import org.session.libsignal.crypto.ecc.DjbECPublicKey
|
||||
import org.session.libsignal.crypto.ecc.ECKeyPair
|
||||
import org.session.libsignal.utilities.Base64
|
||||
import org.session.libsignal.utilities.Hex
|
||||
|
||||
object KeyPairUtilities {
|
||||
|
||||
private val sodium by lazy { LazySodiumAndroid(SodiumAndroid()) }
|
||||
|
||||
fun generate(): KeyPairGenerationResult {
|
||||
val seed = sodium.randomBytesBuf(16)
|
||||
try {
|
||||
return generate(seed)
|
||||
} catch (exception: Exception) {
|
||||
return generate()
|
||||
}
|
||||
}
|
||||
|
||||
fun generate(seed: ByteArray): KeyPairGenerationResult {
|
||||
val padding = ByteArray(16) { 0 }
|
||||
val ed25519KeyPair = sodium.cryptoSignSeedKeypair(seed + padding)
|
||||
val sodiumX25519KeyPair = sodium.convertKeyPairEd25519ToCurve25519(ed25519KeyPair)
|
||||
val x25519KeyPair = ECKeyPair(DjbECPublicKey(sodiumX25519KeyPair.publicKey.asBytes), DjbECPrivateKey(sodiumX25519KeyPair.secretKey.asBytes))
|
||||
return KeyPairGenerationResult(seed, ed25519KeyPair, x25519KeyPair)
|
||||
}
|
||||
|
||||
fun store(context: Context, seed: ByteArray, ed25519KeyPair: KeyPair, x25519KeyPair: ECKeyPair) {
|
||||
IdentityKeyUtil.save(context, IdentityKeyUtil.LOKI_SEED, Hex.toStringCondensed(seed))
|
||||
IdentityKeyUtil.save(context, IdentityKeyUtil.IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(x25519KeyPair.publicKey.serialize()))
|
||||
IdentityKeyUtil.save(context, IdentityKeyUtil.IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(x25519KeyPair.privateKey.serialize()))
|
||||
IdentityKeyUtil.save(context, IdentityKeyUtil.ED25519_PUBLIC_KEY, Base64.encodeBytes(ed25519KeyPair.publicKey.asBytes))
|
||||
IdentityKeyUtil.save(context, IdentityKeyUtil.ED25519_SECRET_KEY, Base64.encodeBytes(ed25519KeyPair.secretKey.asBytes))
|
||||
}
|
||||
|
||||
fun hasV2KeyPair(context: Context): Boolean {
|
||||
return (IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_SECRET_KEY) != null)
|
||||
}
|
||||
|
||||
fun getUserED25519KeyPair(context: Context): KeyPair? {
|
||||
val base64EncodedED25519PublicKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_PUBLIC_KEY) ?: return null
|
||||
val base64EncodedED25519SecretKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_SECRET_KEY) ?: return null
|
||||
val ed25519PublicKey = Key.fromBytes(Base64.decode(base64EncodedED25519PublicKey))
|
||||
val ed25519SecretKey = Key.fromBytes(Base64.decode(base64EncodedED25519SecretKey))
|
||||
return KeyPair(ed25519PublicKey, ed25519SecretKey)
|
||||
}
|
||||
|
||||
data class KeyPairGenerationResult(
|
||||
val seed: ByteArray,
|
||||
val ed25519KeyPair: KeyPair,
|
||||
val x25519KeyPair: ECKeyPair
|
||||
)
|
||||
}
|
@@ -22,13 +22,10 @@ object TextSecurePreferences {
|
||||
val events get() = _events.asSharedFlow()
|
||||
|
||||
const val DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase"
|
||||
const val THEME_PREF = "pref_theme"
|
||||
const val LANGUAGE_PREF = "pref_language"
|
||||
const val THREAD_TRIM_LENGTH = "pref_trim_length"
|
||||
const val THREAD_TRIM_NOW = "pref_trim_now"
|
||||
|
||||
private const val LAST_VERSION_CODE_PREF = "last_version_code"
|
||||
private const val LAST_EXPERIENCE_VERSION_PREF = "last_experience_version_code"
|
||||
const val RINGTONE_PREF = "pref_key_ringtone"
|
||||
const val VIBRATE_PREF = "pref_key_vibrate"
|
||||
private const val NOTIFICATION_PREF = "pref_key_enable_notifications"
|
||||
@@ -46,20 +43,15 @@ object TextSecurePreferences {
|
||||
private const val UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time"
|
||||
private const val UPDATE_APK_DOWNLOAD_ID = "pref_update_apk_download_id"
|
||||
private const val UPDATE_APK_DIGEST = "pref_update_apk_digest"
|
||||
|
||||
private const val IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications"
|
||||
const val MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size"
|
||||
|
||||
const val LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id"
|
||||
|
||||
const val REPEAT_ALERTS_PREF = "pref_repeat_alerts"
|
||||
const val NOTIFICATION_PRIVACY_PREF = "pref_notification_privacy"
|
||||
const val NOTIFICATION_PRIORITY_PREF = "pref_notification_priority"
|
||||
|
||||
const val MEDIA_DOWNLOAD_MOBILE_PREF = "pref_media_download_mobile"
|
||||
const val MEDIA_DOWNLOAD_WIFI_PREF = "pref_media_download_wifi"
|
||||
const val MEDIA_DOWNLOAD_ROAMING_PREF = "pref_media_download_roaming"
|
||||
|
||||
const val SYSTEM_EMOJI_PREF = "pref_system_emoji"
|
||||
const val DIRECT_CAPTURE_CAMERA_ID = "pref_direct_capture_camera_id"
|
||||
const val PROFILE_KEY_PREF = "pref_profile_key"
|
||||
@@ -68,45 +60,33 @@ object TextSecurePreferences {
|
||||
const val PROFILE_AVATAR_URL_PREF = "pref_profile_avatar_url"
|
||||
const val READ_RECEIPTS_PREF = "pref_read_receipts"
|
||||
const val INCOGNITO_KEYBORAD_PREF = "pref_incognito_keyboard"
|
||||
|
||||
private const val DATABASE_ENCRYPTED_SECRET = "pref_database_encrypted_secret"
|
||||
private const val DATABASE_UNENCRYPTED_SECRET = "pref_database_unencrypted_secret"
|
||||
private const val ATTACHMENT_ENCRYPTED_SECRET = "pref_attachment_encrypted_secret"
|
||||
private const val ATTACHMENT_UNENCRYPTED_SECRET = "pref_attachment_unencrypted_secret"
|
||||
private const val NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration"
|
||||
|
||||
const val BACKUP_ENABLED = "pref_backup_enabled_v3"
|
||||
private const val BACKUP_PASSPHRASE = "pref_backup_passphrase"
|
||||
private const val ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase"
|
||||
private const val BACKUP_TIME = "pref_backup_next_time"
|
||||
const val BACKUP_NOW = "pref_backup_create"
|
||||
private const val BACKUP_SAVE_DIR = "pref_save_dir"
|
||||
|
||||
const val SCREEN_LOCK = "pref_android_screen_lock"
|
||||
const val SCREEN_LOCK_TIMEOUT = "pref_android_screen_lock_timeout"
|
||||
|
||||
private const val LOG_ENCRYPTED_SECRET = "pref_log_encrypted_secret"
|
||||
private const val LOG_UNENCRYPTED_SECRET = "pref_log_unencrypted_secret"
|
||||
|
||||
private const val NOTIFICATION_CHANNEL_VERSION = "pref_notification_channel_version"
|
||||
private const val NOTIFICATION_MESSAGES_CHANNEL_VERSION = "pref_notification_messages_channel_version"
|
||||
|
||||
const val UNIVERSAL_UNIDENTIFIED_ACCESS = "pref_universal_unidentified_access"
|
||||
|
||||
const val TYPING_INDICATORS = "pref_typing_indicators"
|
||||
|
||||
const val LINK_PREVIEWS = "pref_link_previews"
|
||||
|
||||
private const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
||||
|
||||
const val IS_USING_FCM = "pref_is_using_fcm"
|
||||
private const val FCM_TOKEN = "pref_fcm_token"
|
||||
private const val LAST_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
||||
|
||||
private const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
||||
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
||||
private const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
|
||||
|
||||
private const val LAST_OPEN_DATE = "pref_last_open_date"
|
||||
|
||||
@JvmStatic
|
||||
@@ -338,7 +318,7 @@ object TextSecurePreferences {
|
||||
|
||||
@JvmStatic
|
||||
fun setProfileAvatarId(context: Context, id: Int) {
|
||||
setIntegerPrefrence(context, PROFILE_AVATAR_ID_PREF, id)
|
||||
setIntegerPreference(context, PROFILE_AVATAR_ID_PREF, id)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -367,7 +347,7 @@ object TextSecurePreferences {
|
||||
|
||||
@JvmStatic
|
||||
fun setDirectCaptureCameraId(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, DIRECT_CAPTURE_CAMERA_ID, value)
|
||||
setIntegerPreference(context, DIRECT_CAPTURE_CAMERA_ID, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -395,7 +375,7 @@ object TextSecurePreferences {
|
||||
}
|
||||
|
||||
fun setLocalRegistrationId(context: Context, registrationId: Int) {
|
||||
setIntegerPrefrence(context, LOCAL_REGISTRATION_ID_PREF, registrationId)
|
||||
setIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, registrationId)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -476,24 +456,11 @@ object TextSecurePreferences {
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun setLastVersionCode(context: Context, versionCode: Int) {
|
||||
if (!setIntegerPrefrenceBlocking(context, LAST_VERSION_CODE_PREF, versionCode)) {
|
||||
if (!setIntegerPreferenceBlocking(context, LAST_VERSION_CODE_PREF, versionCode)) {
|
||||
throw IOException("couldn't write version code to sharedpreferences")
|
||||
}
|
||||
}
|
||||
|
||||
fun setLastExperienceVersionCode(context: Context, versionCode: Int) {
|
||||
setIntegerPrefrence(context, LAST_EXPERIENCE_VERSION_PREF, versionCode)
|
||||
}
|
||||
|
||||
fun getTheme(context: Context): String? {
|
||||
return getStringPreference(context, THEME_PREF, "light")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isPushRegistered(context: Context): Boolean {
|
||||
return getBooleanPreference(context, REGISTERED_GCM_PREF, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isPassphraseTimeoutEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PASSPHRASE_TIMEOUT_PREF, false)
|
||||
@@ -601,19 +568,14 @@ object TextSecurePreferences {
|
||||
return getStringSetPreference(context, key, HashSet(Arrays.asList(*context.resources.getStringArray(defaultValuesRes))))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLogEncryptedSecret(context: Context, base64Secret: String?) {
|
||||
setStringPreference(context, LOG_ENCRYPTED_SECRET, base64Secret)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLogEncryptedSecret(context: Context): String? {
|
||||
return getStringPreference(context, LOG_ENCRYPTED_SECRET, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLogUnencryptedSecret(context: Context, base64Secret: String?) {
|
||||
setStringPreference(context, LOG_UNENCRYPTED_SECRET, base64Secret)
|
||||
fun setLogEncryptedSecret(context: Context, base64Secret: String?) {
|
||||
setStringPreference(context, LOG_ENCRYPTED_SECRET, base64Secret)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -621,6 +583,11 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, LOG_UNENCRYPTED_SECRET, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLogUnencryptedSecret(context: Context, base64Secret: String?) {
|
||||
setStringPreference(context, LOG_UNENCRYPTED_SECRET, base64Secret)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getNotificationChannelVersion(context: Context): Int {
|
||||
return getIntegerPreference(context, NOTIFICATION_CHANNEL_VERSION, 1)
|
||||
@@ -628,7 +595,7 @@ object TextSecurePreferences {
|
||||
|
||||
@JvmStatic
|
||||
fun setNotificationChannelVersion(context: Context, version: Int) {
|
||||
setIntegerPrefrence(context, NOTIFICATION_CHANNEL_VERSION, version)
|
||||
setIntegerPreference(context, NOTIFICATION_CHANNEL_VERSION, version)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -638,12 +605,7 @@ object TextSecurePreferences {
|
||||
|
||||
@JvmStatic
|
||||
fun setNotificationMessagesChannelVersion(context: Context, version: Int) {
|
||||
setIntegerPrefrence(context, NOTIFICATION_MESSAGES_CHANNEL_VERSION, version)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setBooleanPreference(context: Context, key: String?, value: Boolean) {
|
||||
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply()
|
||||
setIntegerPreference(context, NOTIFICATION_MESSAGES_CHANNEL_VERSION, version)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -652,8 +614,8 @@ object TextSecurePreferences {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStringPreference(context: Context, key: String?, value: String?) {
|
||||
getDefaultSharedPreferences(context).edit().putString(key, value).apply()
|
||||
fun setBooleanPreference(context: Context, key: String?, value: Boolean) {
|
||||
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -661,15 +623,20 @@ object TextSecurePreferences {
|
||||
return getDefaultSharedPreferences(context).getString(key, defaultValue)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStringPreference(context: Context, key: String?, value: String?) {
|
||||
getDefaultSharedPreferences(context).edit().putString(key, value).apply()
|
||||
}
|
||||
|
||||
private fun getIntegerPreference(context: Context, key: String, defaultValue: Int): Int {
|
||||
return getDefaultSharedPreferences(context).getInt(key, defaultValue)
|
||||
}
|
||||
|
||||
private fun setIntegerPrefrence(context: Context, key: String, value: Int) {
|
||||
private fun setIntegerPreference(context: Context, key: String, value: Int) {
|
||||
getDefaultSharedPreferences(context).edit().putInt(key, value).apply()
|
||||
}
|
||||
|
||||
private fun setIntegerPrefrenceBlocking(context: Context, key: String, value: Int): Boolean {
|
||||
private fun setIntegerPreferenceBlocking(context: Context, key: String, value: Int): Boolean {
|
||||
return getDefaultSharedPreferences(context).edit().putInt(key, value).commit()
|
||||
}
|
||||
|
||||
@@ -694,9 +661,6 @@ object TextSecurePreferences {
|
||||
}
|
||||
}
|
||||
|
||||
// region Loki
|
||||
@JvmStatic
|
||||
|
||||
fun getHasViewedSeed(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_viewed_seed", false)
|
||||
}
|
||||
@@ -723,21 +687,6 @@ object TextSecurePreferences {
|
||||
setLongPreference(context, "last_profile_picture_upload", newValue)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun hasSeenGIFMetaDataWarning(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_seen_gif_metadata_warning", false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setHasSeenGIFMetaDataWarning(context: Context) {
|
||||
setBooleanPreference(context, "has_seen_gif_metadata_warning", true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun clearAll(context: Context) {
|
||||
getDefaultSharedPreferences(context).edit().clear().commit()
|
||||
}
|
||||
|
||||
fun getLastSnodePoolRefreshDate(context: Context?): Long {
|
||||
return getLongPreference(context!!, "last_snode_pool_refresh_date", 0)
|
||||
}
|
||||
@@ -746,13 +695,9 @@ object TextSecurePreferences {
|
||||
setLongPreference(context!!, "last_snode_pool_refresh_date", date.time)
|
||||
}
|
||||
|
||||
fun getIsMigratingKeyPair(context: Context?): Boolean {
|
||||
return getBooleanPreference(context!!, "is_migrating_key_pair", false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setIsMigratingKeyPair(context: Context?, newValue: Boolean) {
|
||||
setBooleanPreference(context!!, "is_migrating_key_pair", newValue)
|
||||
fun shouldUpdateProfile(context: Context, profileUpdateTime: Long): Boolean {
|
||||
return profileUpdateTime > getLongPreference(context, LAST_PROFILE_UPDATE_TIME, 0)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -760,18 +705,6 @@ object TextSecurePreferences {
|
||||
setLongPreference(context, LAST_PROFILE_UPDATE_TIME, profileUpdateTime)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun shouldUpdateProfile(context: Context, profileUpdateTime: Long) =
|
||||
profileUpdateTime > getLongPreference(context, LAST_PROFILE_UPDATE_TIME, 0)
|
||||
|
||||
fun hasPerformedContactMigration(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_performed_contact_migration", false)
|
||||
}
|
||||
|
||||
fun setPerformedContactMigration(context: Context) {
|
||||
setBooleanPreference(context, "has_performed_contact_migration", true)
|
||||
}
|
||||
|
||||
fun getLastOpenTimeDate(context: Context): Long {
|
||||
return getLongPreference(context, LAST_OPEN_DATE, 0)
|
||||
}
|
||||
@@ -787,4 +720,9 @@ object TextSecurePreferences {
|
||||
fun setHasSeenLinkPreviewSuggestionDialog(context: Context) {
|
||||
setBooleanPreference(context, "has_seen_link_preview_suggestion_dialog", true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun clearAll(context: Context) {
|
||||
getDefaultSharedPreferences(context).edit().clear().commit()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user