diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPassphrase.java b/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPassphrase.java index aede7c441d..7168ed6907 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPassphrase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPassphrase.java @@ -7,7 +7,7 @@ import androidx.annotation.Nullable; import org.thoughtcrime.securesms.crypto.KeyStoreHelper; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; /** * Allows the getting and setting of the backup passphrase, which is stored encrypted on API >= 23. diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPreferences.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPreferences.kt new file mode 100644 index 0000000000..2d8272debd --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/BackupPreferences.kt @@ -0,0 +1,101 @@ +package org.thoughtcrime.securesms.backup + +import android.content.Context +import android.content.SharedPreferences +import android.os.Build +import android.preference.PreferenceManager +import android.preference.PreferenceManager.getDefaultSharedPreferencesName +import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsignal.libsignal.logging.Log +import org.thoughtcrime.securesms.backup.FullBackupImporter.PREF_PREFIX_TYPE_BOOLEAN +import org.thoughtcrime.securesms.backup.FullBackupImporter.PREF_PREFIX_TYPE_INT +import java.util.* + +object BackupPreferences { + // region Backup related + fun getBackupRecords(context: Context): List { + val preferences = PreferenceManager.getDefaultSharedPreferences(context) + val prefsFileName: String + prefsFileName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + getDefaultSharedPreferencesName(context) + } else { + context.packageName + "_preferences" + } + val prefList: LinkedList = LinkedList() + addBackupEntryInt(prefList, preferences, prefsFileName, TextSecurePreferences.LOCAL_REGISTRATION_ID_PREF) + addBackupEntryString(prefList, preferences, prefsFileName, TextSecurePreferences.LOCAL_NUMBER_PREF) + addBackupEntryString(prefList, preferences, prefsFileName, TextSecurePreferences.PROFILE_NAME_PREF) + addBackupEntryString(prefList, preferences, prefsFileName, TextSecurePreferences.PROFILE_AVATAR_URL_PREF) + addBackupEntryInt(prefList, preferences, prefsFileName, TextSecurePreferences.PROFILE_AVATAR_ID_PREF) + addBackupEntryString(prefList, preferences, prefsFileName, TextSecurePreferences.PROFILE_KEY_PREF) + addBackupEntryBoolean(prefList, preferences, prefsFileName, TextSecurePreferences.IS_USING_FCM) + return prefList + } + + private fun addBackupEntryString( + outPrefList: MutableList, + prefs: SharedPreferences, + prefFileName: String, + prefKey: String, + ) { + val value = prefs.getString(prefKey, null) + if (value == null) { + logBackupEntry(prefKey, false) + return + } + outPrefList.add(BackupProtos.SharedPreference.newBuilder() + .setFile(prefFileName) + .setKey(prefKey) + .setValue(value) + .build()) + logBackupEntry(prefKey, true) + } + + private fun addBackupEntryInt( + outPrefList: MutableList, + prefs: SharedPreferences, + prefFileName: String, + prefKey: String, + ) { + val value = prefs.getInt(prefKey, -1) + if (value == -1) { + logBackupEntry(prefKey, false) + return + } + outPrefList.add(BackupProtos.SharedPreference.newBuilder() + .setFile(prefFileName) + .setKey(PREF_PREFIX_TYPE_INT + prefKey) // The prefix denotes the type of the preference. + .setValue(value.toString()) + .build()) + logBackupEntry(prefKey, true) + } + + private fun addBackupEntryBoolean( + outPrefList: MutableList, + prefs: SharedPreferences, + prefFileName: String, + prefKey: String, + ) { + if (!prefs.contains(prefKey)) { + logBackupEntry(prefKey, false) + return + } + outPrefList.add(BackupProtos.SharedPreference.newBuilder() + .setFile(prefFileName) + .setKey(PREF_PREFIX_TYPE_BOOLEAN + prefKey) // The prefix denotes the type of the preference. + .setValue(prefs.getBoolean(prefKey, false).toString()) + .build()) + logBackupEntry(prefKey, true) + } + + private fun logBackupEntry(prefName: String, wasIncluded: Boolean) { + val sb = StringBuilder() + sb.append("Backup preference ") + sb.append(if (wasIncluded) "+ " else "- ") + sb.append('\"').append(prefName).append("\" ") + if (!wasIncluded) { + sb.append("(is empty and not included)") + } + Log.d("Loki", sb.toString()) + } // endregion +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt index b647e70fc9..b316284b86 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt @@ -10,7 +10,11 @@ import com.annimon.stream.function.Predicate import com.google.protobuf.ByteString import net.sqlcipher.database.SQLiteDatabase import org.greenrobot.eventbus.EventBus + import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId +import org.session.libsession.messaging.contacts.avatars.AvatarHelper +import org.session.libsession.utilities.Conversions + import org.thoughtcrime.securesms.backup.BackupProtos.* import org.thoughtcrime.securesms.crypto.AttachmentSecret import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream @@ -20,10 +24,7 @@ import org.thoughtcrime.securesms.database.* import org.thoughtcrime.securesms.logging.Log import org.thoughtcrime.securesms.loki.database.LokiAPIDatabase import org.thoughtcrime.securesms.loki.database.LokiBackupFilesDatabase -import org.thoughtcrime.securesms.profiles.AvatarHelper import org.thoughtcrime.securesms.util.BackupUtil -import org.thoughtcrime.securesms.util.Conversions -import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.Util import org.session.libsignal.libsignal.kdf.HKDFv3 import org.session.libsignal.libsignal.util.ByteUtil @@ -100,7 +101,7 @@ object FullBackupExporter { EventBus.getDefault().post(BackupEvent.createProgress(++count)) outputStream.writePreferenceEntry(preference) } - for (preference in TextSecurePreferences.getBackupRecords(context)) { + for (preference in BackupPreferences.getBackupRecords(context)) { EventBus.getDefault().post(BackupEvent.createProgress(++count)) outputStream.writePreferenceEntry(preference) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt index 88d0aa1104..f431e22057 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt @@ -12,9 +12,9 @@ import org.thoughtcrime.securesms.crypto.AttachmentSecret import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream import org.thoughtcrime.securesms.database.* import org.thoughtcrime.securesms.logging.Log -import org.thoughtcrime.securesms.profiles.AvatarHelper import org.thoughtcrime.securesms.util.BackupUtil +import org.session.libsession.messaging.contacts.avatars.AvatarHelper import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId import org.session.libsession.messaging.threads.Address import org.session.libsession.utilities.Conversions diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java b/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java index 0565ce1ae5..bf5135cea1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java @@ -25,7 +25,7 @@ import androidx.core.view.inputmethod.InputContentInfoCompat; import org.thoughtcrime.securesms.components.emoji.EmojiEditText; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; public class ComposeText extends EmojiEditText { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java b/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java index fe9877829b..bc9c1dd746 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java @@ -22,7 +22,7 @@ import android.widget.TextView; import network.loki.messenger.R; import org.thoughtcrime.securesms.components.CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.CustomPreferenceValidator; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; import java.net.URI; import java.net.URISyntaxException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/camera/CameraView.java b/app/src/main/java/org/thoughtcrime/securesms/components/camera/CameraView.java index 023cf4d48e..28184dd447 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/camera/CameraView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/camera/CameraView.java @@ -38,10 +38,11 @@ import android.view.ViewGroup; import network.loki.messenger.R; import org.thoughtcrime.securesms.util.BitmapUtil; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; import org.session.libsignal.libsignal.util.guava.Optional; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; + import java.io.IOException; import java.util.Collections; import java.util.LinkedList; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiEditText.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiEditText.java index 34dfc06bfc..4475e6174a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiEditText.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiEditText.java @@ -10,7 +10,7 @@ import android.util.AttributeSet; import network.loki.messenger.R; import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; public class EmojiEditText extends AppCompatEditText { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java index 4856e8d261..2bddf9ca8f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiTextView.java @@ -15,8 +15,8 @@ import android.util.TypedValue; import network.loki.messenger.R; import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable; import org.thoughtcrime.securesms.components.emoji.parsing.EmojiParser; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; import org.session.libsignal.libsignal.util.guava.Optional; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiToggle.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiToggle.java index 4d5b85d637..6e1f760bac 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiToggle.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiToggle.java @@ -9,7 +9,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageButton; import org.thoughtcrime.securesms.stickers.StickerKeyboardProvider; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; import network.loki.messenger.R; diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java index 7d6ed5cf07..ea5b65e701 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java @@ -23,7 +23,6 @@ import android.os.Parcelable; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.GroupDatabase; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import java.util.LinkedList; import java.util.List; @@ -31,6 +30,7 @@ import java.util.List; import network.loki.messenger.R; import org.session.libsession.messaging.threads.GroupRecord; +import org.session.libsession.utilities.TextSecurePreferences; /** * This class was originally a layer of indirection between diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java index 6ae2ea42f1..78fda070ae 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -97,7 +97,6 @@ import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener; import org.thoughtcrime.securesms.stickers.StickerUrl; import org.thoughtcrime.securesms.util.DateUtils; -import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.LongClickCopySpan; import org.thoughtcrime.securesms.util.LongClickMovementMethod; import org.thoughtcrime.securesms.util.SearchUtil; @@ -107,6 +106,7 @@ import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPrevie import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.ThemeUtil; import org.session.libsession.utilities.Util; +import org.session.libsession.utilities.GroupUtil; import org.session.libsession.utilities.ViewUtil; import org.session.libsession.utilities.views.Stub; @@ -900,7 +900,7 @@ public class ConversationItem extends LinearLayout // Show custom display names for group chats String displayName = recipient.toShortString(); try { - String serverId = GroupUtil.getDecodedStringId(conversationRecipient.getAddress().serialize()); + String serverId = GroupUtil.getDecodedGroupID(conversationRecipient.getAddress().serialize().getBytes()); String senderDisplayName = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(serverId, recipient.getAddress().serialize()); if (senderDisplayName != null) { displayName = senderDisplayName; } } catch (Exception e) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java index 8b2747d83e..6ab5325334 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationPopupActivity.java @@ -14,7 +14,7 @@ import android.view.View; import android.view.WindowManager; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; +import org.session.libsession.utilities.concurrent.ListenableFuture; import java.util.concurrent.ExecutionException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationSearchViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationSearchViewModel.java index 11d2e2b909..e09d5faf35 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationSearchViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationSearchViewModel.java @@ -13,8 +13,8 @@ import org.thoughtcrime.securesms.search.SearchRepository; import org.thoughtcrime.securesms.search.model.MessageResult; import org.thoughtcrime.securesms.util.CloseableLiveData; import org.thoughtcrime.securesms.util.Debouncer; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; +import org.session.libsession.utilities.Util; +import org.session.libsession.utilities.concurrent.SignalExecutors; import java.io.Closeable; import java.util.List; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java index 311817254e..aa9c287a1f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java @@ -19,11 +19,11 @@ import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.loki.utilities.GeneralUtilitiesKt; import org.thoughtcrime.securesms.loki.utilities.GroupDescription; import org.thoughtcrime.securesms.mms.GlideRequests; -import org.session.libsession.messaging.threads.recipients.Recipient; -import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener; import org.thoughtcrime.securesms.util.DateUtils; import org.session.libsignal.libsignal.util.guava.Optional; +import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener; import org.session.libsession.utilities.ExpirationUtil; import org.session.libsession.utilities.Util; diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java index 2068e855d3..0344551cab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java @@ -5,7 +5,7 @@ import android.content.Context; import android.os.Build; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; import java.security.SecureRandom; diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java index 152cf17b24..0ad22c3a90 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java @@ -5,7 +5,7 @@ import android.content.Context; import android.os.Build; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; import java.io.IOException; import java.security.SecureRandom; diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java index 4aa20f697e..fe714ed433 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/UnidentifiedAccessUtil.java @@ -11,8 +11,8 @@ import org.session.libsignal.metadata.certificate.CertificateValidator; import org.session.libsignal.metadata.certificate.InvalidCertificateException; import org.thoughtcrime.securesms.logging.Log; import org.session.libsession.messaging.threads.recipients.Recipient; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.crypto.UnidentifiedAccess; import org.session.libsignal.service.api.crypto.UnidentifiedAccessPair; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ApnDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ApnDatabase.java index 603e63b163..bf71db3d1e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ApnDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ApnDatabase.java @@ -25,8 +25,8 @@ import android.text.TextUtils; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.LegacyMmsConnection.Apn; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; import org.session.libsignal.libsignal.util.guava.Optional; import java.io.File; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 7a2374e53b..e14b8df11e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -18,6 +18,7 @@ import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.GroupRecord import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.GroupUtil import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.libsignal.util.KeyHelper import org.session.libsignal.libsignal.util.guava.Optional @@ -33,7 +34,6 @@ import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage import org.thoughtcrime.securesms.mms.PartAuthority import org.thoughtcrime.securesms.sms.IncomingGroupMessage import org.thoughtcrime.securesms.sms.IncomingTextMessage -import org.thoughtcrime.securesms.util.GroupUtil class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), StorageProtocol { override fun getUserPublicKey(): String? { @@ -250,12 +250,12 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, override fun insertIncomingInfoMessage(context: Context, senderPublicKey: String, groupID: String, type0: SignalServiceProtos.GroupContext.Type, type1: SignalServiceGroup.Type, name: String, members: Collection, admins: Collection) { val groupContextBuilder = SignalServiceProtos.GroupContext.newBuilder() - .setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupID))) + .setId(ByteString.copyFrom(GroupUtil.getDecodedGroupIDAsData(groupID.toByteArray()))) .setType(type0) .setName(name) .addAllMembers(members) .addAllAdmins(admins) - val group = SignalServiceGroup(type1, GroupUtil.getDecodedId(groupID), SignalServiceGroup.GroupType.SIGNAL, name, members.toList(), null, admins.toList()) + val group = SignalServiceGroup(type1, GroupUtil.getDecodedGroupIDAsData(groupID.toByteArray()), SignalServiceGroup.GroupType.SIGNAL, name, members.toList(), null, admins.toList()) val m = IncomingTextMessage(Address.fromSerialized(senderPublicKey), 1, System.currentTimeMillis(), "", Optional.of(group), 0, true) val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "") val smsDB = DatabaseFactory.getSmsDatabase(context) @@ -265,7 +265,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, override fun insertOutgoingInfoMessage(context: Context, groupID: String, type: SignalServiceProtos.GroupContext.Type, name: String, members: Collection, admins: Collection, threadID: Long) { val recipient = Recipient.from(context, Address.fromSerialized(groupID), false) val groupContextBuilder = SignalServiceProtos.GroupContext.newBuilder() - .setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupID))) + .setId(ByteString.copyFrom(GroupUtil.getDecodedGroupIDAsData(groupID.toByteArray()))) .setType(type) .setName(name) .addAllMembers(members) diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index 2760fdfc9d..820e4ca68e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -40,7 +40,7 @@ import org.thoughtcrime.securesms.service.IncomingMessageObserver; import org.thoughtcrime.securesms.stickers.StickerPackPreviewRepository; import org.thoughtcrime.securesms.stickers.StickerRemoteUriLoader; import org.thoughtcrime.securesms.util.RealtimeSleepTimer; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; import dagger.Module; import dagger.Provides; diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivityToolbarTextSecurePreferencesPersistence.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivityToolbarTextSecurePreferencesPersistence.java index bc3c87cdc6..3147590d6a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivityToolbarTextSecurePreferencesPersistence.java +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivityToolbarTextSecurePreferencesPersistence.java @@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.giph.ui; import android.content.Context; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; class GiphyActivityToolbarTextSecurePreferencesPersistence implements GiphyActivityToolbar.Persistence { diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java index fe5f2eaff1..9b7edd537f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java @@ -24,13 +24,14 @@ import com.bumptech.glide.request.target.Target; import com.bumptech.glide.util.ByteBufferUtil; import network.loki.messenger.R; -import org.thoughtcrime.securesms.color.MaterialColor; import org.thoughtcrime.securesms.giph.model.GiphyImage; import org.thoughtcrime.securesms.giph.model.ChunkedImageUrl; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.GlideRequests; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.ViewUtil; + +import org.session.libsession.utilities.color.MaterialColor; +import org.session.libsession.utilities.Util; +import org.session.libsession.utilities.ViewUtil; import java.util.List; import java.util.concurrent.ExecutionException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java index b897970f73..7693e9eaf8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java @@ -12,18 +12,19 @@ import com.google.protobuf.ByteString; import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; import org.session.libsession.messaging.threads.Address; +import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.utilities.GroupUtil; +import org.session.libsession.utilities.TextSecurePreferences; + import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage; import org.thoughtcrime.securesms.providers.BlobProvider; -import org.session.libsession.messaging.threads.recipients.Recipient; import org.thoughtcrime.securesms.sms.MessageSender; import org.thoughtcrime.securesms.util.BitmapUtil; -import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.MediaUtil; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.session.libsignal.service.api.util.InvalidNumberException; import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext; @@ -38,12 +39,7 @@ import java.util.Set; public class GroupManager { public static long getOpenGroupThreadID(String id, @NonNull Context context) { - final String groupID = GroupUtil.getEncodedOpenGroupId(id.getBytes()); - return getThreadIDFromGroupID(groupID, context); - } - - public static long getRSSFeedThreadID(String id, @NonNull Context context) { - final String groupID = GroupUtil.getEncodedRSSFeedId(id.getBytes()); + final String groupID = GroupUtil.getEncodedOpenGroupID(id); return getThreadIDFromGroupID(groupID, context); } @@ -60,7 +56,7 @@ public class GroupManager { @NonNull Set admins) { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); - String id = GroupUtil.getEncodedId(database.allocateGroupId(), mms); + String id = GroupUtil.getEncodedGroupID(database.allocateGroupId()); return createGroup(id, context, members, avatar, name, mms, admins); } @@ -74,7 +70,7 @@ public class GroupManager { { final byte[] avatarBytes = BitmapUtil.toByteArray(avatar); final GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); - final String groupId = GroupUtil.getEncodedId(id.getBytes(), mms); + final String groupId = GroupUtil.getEncodedGroupID(id.getBytes()); final Recipient groupRecipient = Recipient.from(context, Address.Companion.fromSerialized(groupId), false); final Set
memberAddresses = getMemberAddresses(members); final Set
adminAddresses = getMemberAddresses(admins); @@ -101,16 +97,7 @@ public class GroupManager { @Nullable Bitmap avatar, @Nullable String name) { - final String groupID = GroupUtil.getEncodedOpenGroupId(id.getBytes()); - return createLokiGroup(groupID, context, avatar, name); - } - - public static @NonNull GroupActionResult createRSSFeed(@NonNull String id, - @NonNull Context context, - @Nullable Bitmap avatar, - @Nullable String name) - { - final String groupID = GroupUtil.getEncodedRSSFeedId(id.getBytes()); + final String groupID = GroupUtil.getEncodedOpenGroupID(id); return createLokiGroup(groupID, context, avatar, name); } @@ -188,41 +175,37 @@ public class GroupManager { @Nullable byte[] avatar, @NonNull Set
admins) { - try { - Attachment avatarAttachment = null; - Address groupAddress = Address.Companion.fromSerialized(groupId); - Recipient groupRecipient = Recipient.from(context, groupAddress, false); + Attachment avatarAttachment = null; + Address groupAddress = Address.Companion.fromSerialized(groupId); + Recipient groupRecipient = Recipient.from(context, groupAddress, false); - List numbers = new LinkedList<>(); - for (Address member : members) { - numbers.add(member.serialize()); - } - - List adminNumbers = new LinkedList<>(); - for (Address admin : admins) { - adminNumbers.add(admin.serialize()); - } - - GroupContext.Builder groupContextBuilder = GroupContext.newBuilder() - .setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId))) - .setType(GroupContext.Type.UPDATE) - .addAllMembers(numbers) - .addAllAdmins(adminNumbers); - if (groupName != null) groupContextBuilder.setName(groupName); - GroupContext groupContext = groupContextBuilder.build(); - - if (avatar != null) { - Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory(); - avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null, null); - } - - OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0, null, Collections.emptyList(), Collections.emptyList()); - long threadId = MessageSender.send(context, outgoingMessage, -1, false, null); - - return new GroupActionResult(groupRecipient, threadId); - } catch (IOException e) { - throw new AssertionError(e); + List numbers = new LinkedList<>(); + for (Address member : members) { + numbers.add(member.serialize()); } + + List adminNumbers = new LinkedList<>(); + for (Address admin : admins) { + adminNumbers.add(admin.serialize()); + } + + GroupContext.Builder groupContextBuilder = GroupContext.newBuilder() + .setId(ByteString.copyFrom(GroupUtil.getDecodedGroupIDAsData(groupId.getBytes()))) + .setType(GroupContext.Type.UPDATE) + .addAllMembers(numbers) + .addAllAdmins(adminNumbers); + if (groupName != null) groupContextBuilder.setName(groupName); + GroupContext groupContext = groupContextBuilder.build(); + + if (avatar != null) { + Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory(); + avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null, null); + } + + OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0, null, Collections.emptyList(), Collections.emptyList()); + long threadId = MessageSender.send(context, outgoingMessage, -1, false, null); + + return new GroupActionResult(groupRecipient, threadId); } private static Set
getMemberAddresses(Collection recipients) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/impl/SqlCipherMigrationConstraint.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/impl/SqlCipherMigrationConstraint.java index 8e0c230c01..32fa84b6f5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/impl/SqlCipherMigrationConstraint.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/impl/SqlCipherMigrationConstraint.java @@ -5,7 +5,7 @@ import android.app.job.JobInfo; import androidx.annotation.NonNull; import org.thoughtcrime.securesms.jobmanager.Constraint; -import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.session.libsession.utilities.TextSecurePreferences; public class SqlCipherMigrationConstraint implements Constraint { diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java index 6d0f45d375..e3da6ab56a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java @@ -11,9 +11,6 @@ import com.google.android.mms.pdu_alt.PduPart; import com.google.android.mms.pdu_alt.RetrieveConf; import org.thoughtcrime.securesms.ApplicationContext; -import org.session.libsession.messaging.sending_receiving.attachments.Attachment; -import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; -import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult; @@ -27,17 +24,21 @@ import org.thoughtcrime.securesms.mms.IncomingMediaMessage; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.mms.MmsRadioException; import org.thoughtcrime.securesms.mms.PartParser; -import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.service.KeyCachingService; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; import org.session.libsignal.libsignal.DuplicateMessageException; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.LegacyMessageException; import org.session.libsignal.libsignal.NoSessionException; import org.session.libsignal.libsignal.util.guava.Optional; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; +import org.session.libsession.messaging.threads.Address; +import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.HashSet; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 7957b0130e..7bde6ca224 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -8,11 +8,14 @@ import androidx.annotation.WorkerThread; import com.annimon.stream.Collectors; import com.annimon.stream.Stream; -import org.thoughtcrime.securesms.ApplicationContext; import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment; -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; +import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.Address; +import org.session.libsession.utilities.GroupUtil; + +import org.thoughtcrime.securesms.ApplicationContext; +import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.NoSuchMessageException; @@ -28,10 +31,8 @@ import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage; import org.thoughtcrime.securesms.mms.OutgoingMediaMessage; -import org.session.libsession.messaging.threads.recipients.Recipient; import org.thoughtcrime.securesms.transport.RetryLaterException; import org.thoughtcrime.securesms.transport.UndeliverableMessageException; -import org.thoughtcrime.securesms.util.GroupUtil; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.SignalServiceMessageSender; import org.session.libsignal.service.api.crypto.UnidentifiedAccessPair; @@ -261,7 +262,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { GroupContext groupContext = groupMessage.getGroupContext(); SignalServiceAttachment avatar = attachmentPointers.isEmpty() ? null : attachmentPointers.get(0); SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE; - SignalServiceGroup group = new SignalServiceGroup(type, GroupUtil.getDecodedId(groupId), groupType, groupContext.getName(), groupContext.getMembersList(), avatar, groupContext.getAdminsList()); + SignalServiceGroup group = new SignalServiceGroup(type, GroupUtil.getDecodedGroupIDAsData(groupId.getBytes()), groupType, groupContext.getName(), groupContext.getMembersList(), avatar, groupContext.getAdminsList()); SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder() .withTimestamp(message.getSentTimeMillis()) .withExpiration(message.getRecipient().getExpireMessages()) @@ -270,7 +271,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { return messageSender.sendMessage(messageId, addresses, unidentifiedAccess, groupDataMessage); } else { - SignalServiceGroup group = new SignalServiceGroup(GroupUtil.getDecodedId(groupId), groupType); + SignalServiceGroup group = new SignalServiceGroup(GroupUtil.getDecodedGroupIDAsData(groupId.getBytes()), groupType); SignalServiceDataMessage groupMessage = SignalServiceDataMessage.newBuilder() .withTimestamp(message.getSentTimeMillis()) .asGroupMessage(group) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupUpdateJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupUpdateJob.java index 78b7b435c9..080bf08aad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupUpdateJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupUpdateJob.java @@ -3,18 +3,19 @@ package org.thoughtcrime.securesms.jobs; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.session.libsession.messaging.threads.Address; +import org.session.libsession.messaging.threads.GroupRecord; +import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.utilities.GroupUtil; + +import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.GroupDatabase; -import org.session.libsession.messaging.threads.GroupRecord; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.session.libsession.messaging.threads.recipients.Recipient; -import org.thoughtcrime.securesms.util.GroupUtil; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.SignalServiceMessageSender; import org.session.libsignal.service.api.crypto.UntrustedIdentityException; @@ -68,7 +69,7 @@ public class PushGroupUpdateJob extends BaseJob implements InjectableType { @Override public @NonNull Data serialize() { return new Data.Builder().putString(KEY_SOURCE, source) - .putString(KEY_GROUP_ID, GroupUtil.getEncodedId(groupId, false)) + .putString(KEY_GROUP_ID, GroupUtil.getEncodedGroupID(groupId)) .build(); } @@ -80,7 +81,7 @@ public class PushGroupUpdateJob extends BaseJob implements InjectableType { @Override public void onRun() throws IOException, UntrustedIdentityException { GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); - Optional record = groupDatabase.getGroup(GroupUtil.getEncodedId(groupId, false)); + Optional record = groupDatabase.getGroup(GroupUtil.getEncodedGroupID(groupId)); SignalServiceAttachment avatar = null; if (record == null) { @@ -114,7 +115,7 @@ public class PushGroupUpdateJob extends BaseJob implements InjectableType { .withName(record.get().getTitle()) .build(); - Address groupAddress = Address.Companion.fromSerialized(GroupUtil.getEncodedId(groupId, false)); + Address groupAddress = Address.Companion.fromSerialized(GroupUtil.getEncodedGroupID(groupId)); Recipient groupRecipient = Recipient.from(context, groupAddress, false); SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder() @@ -142,13 +143,9 @@ public class PushGroupUpdateJob extends BaseJob implements InjectableType { public static final class Factory implements Job.Factory { @Override public @NonNull PushGroupUpdateJob create(@NonNull Parameters parameters, @NonNull org.thoughtcrime.securesms.jobmanager.Data data) { - try { - return new PushGroupUpdateJob(parameters, - data.getString(KEY_SOURCE), - GroupUtil.getDecodedId(data.getString(KEY_GROUP_ID))); - } catch (IOException e) { - throw new AssertionError(e); - } + return new PushGroupUpdateJob(parameters, + data.getString(KEY_SOURCE), + GroupUtil.getDecodedGroupIDAsData(data.getString(KEY_GROUP_ID).getBytes())); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java index 462870ea28..790c4886e6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java @@ -8,10 +8,11 @@ import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.session.libsignal.service.api.SignalServiceMessageReceiver; import org.session.libsignal.service.api.push.exceptions.PushNetworkException; +import org.session.libsession.utilities.TextSecurePreferences; + import java.io.IOException; import javax.inject.Inject; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/RequestGroupInfoJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/RequestGroupInfoJob.java index fdb8a1edb3..e4c02834ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/RequestGroupInfoJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/RequestGroupInfoJob.java @@ -2,14 +2,15 @@ package org.thoughtcrime.securesms.jobs; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; +import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.Address; +import org.session.libsession.utilities.GroupUtil; + +import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; -import org.thoughtcrime.securesms.util.GroupUtil; -import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsignal.service.api.SignalServiceMessageSender; import org.session.libsignal.service.api.crypto.UntrustedIdentityException; import org.session.libsignal.service.api.messages.SignalServiceDataMessage; @@ -59,7 +60,7 @@ public class RequestGroupInfoJob extends BaseJob implements InjectableType { @Override public @NonNull Data serialize() { return new Data.Builder().putString(KEY_SOURCE, source) - .putString(KEY_GROUP_ID, GroupUtil.getEncodedId(groupId, false)) + .putString(KEY_GROUP_ID, GroupUtil.getEncodedGroupID(groupId)) .build(); } @@ -98,13 +99,9 @@ public class RequestGroupInfoJob extends BaseJob implements InjectableType { @Override public @NonNull RequestGroupInfoJob create(@NonNull Parameters parameters, @NonNull Data data) { - try { - return new RequestGroupInfoJob(parameters, - data.getString(KEY_SOURCE), - GroupUtil.getDecodedId(data.getString(KEY_GROUP_ID))); - } catch (IOException e) { - throw new AssertionError(e); - } + return new RequestGroupInfoJob(parameters, + data.getString(KEY_SOURCE), + GroupUtil.getDecodedGroupIDAsData(data.getString(KEY_GROUP_ID).getBytes())); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java index 8d7223ec02..140d59bb8b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/RetrieveProfileAvatarJob.java @@ -7,6 +7,7 @@ import android.text.TextUtils; import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.messaging.contacts.avatars.AvatarHelper; import org.session.libsession.utilities.Util; import org.thoughtcrime.securesms.jobmanager.Data; @@ -17,7 +18,6 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.RecipientDatabase; import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.profiles.AvatarHelper; import org.session.libsignal.service.api.SignalServiceMessageReceiver; import org.session.libsignal.service.api.push.exceptions.PushNetworkException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/TypingSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/TypingSendJob.java index 957be32428..3d37b88b2d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/TypingSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/TypingSendJob.java @@ -10,9 +10,6 @@ import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.logging.Log; -import org.session.libsession.messaging.threads.recipients.Recipient; -import org.thoughtcrime.securesms.util.GroupUtil; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.SignalServiceMessageSender; import org.session.libsignal.service.api.crypto.UnidentifiedAccessPair; @@ -20,6 +17,10 @@ import org.session.libsignal.service.api.messages.SignalServiceTypingMessage; import org.session.libsignal.service.api.messages.SignalServiceTypingMessage.Action; import org.session.libsignal.service.api.push.SignalServiceAddress; +import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.utilities.GroupUtil; +import org.session.libsession.utilities.TextSecurePreferences; + import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -89,7 +90,7 @@ public class TypingSendJob extends BaseJob implements InjectableType { if (recipient.isGroupRecipient()) { recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.getAddress().toGroupString(), false); - groupId = Optional.of(GroupUtil.getDecodedId(recipient.getAddress().toGroupString())); + groupId = Optional.of(GroupUtil.getDecodedGroupIDAsData(recipient.getAddress().toGroupString().getBytes())); } List addresses = Stream.of(recipients).map(r -> new SignalServiceAddress(r.getAddress().serialize())).toList(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index e24762bdf6..2b9434c7d7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -26,7 +26,6 @@ import org.thoughtcrime.securesms.stickers.StickerRemoteUri; import org.thoughtcrime.securesms.stickers.StickerUrl; import org.thoughtcrime.securesms.util.Hex; import org.thoughtcrime.securesms.util.MediaUtil; -import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.Pair; import org.session.libsignal.libsignal.util.guava.Optional; @@ -38,6 +37,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil.OpenGraph; import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.utilities.concurrent.SignalExecutors; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/logging/LogFile.java b/app/src/main/java/org/thoughtcrime/securesms/logging/LogFile.java index 8fbf8c3a78..53c4305666 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/logging/LogFile.java +++ b/app/src/main/java/org/thoughtcrime/securesms/logging/LogFile.java @@ -2,8 +2,8 @@ package org.thoughtcrime.securesms.logging; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.util.Conversions; -import org.thoughtcrime.securesms.util.Util; +import org.session.libsession.utilities.Conversions; +import org.session.libsession.utilities.Util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/DisplayNameActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/DisplayNameActivity.kt index 477b25b9f4..23bfcc6268 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/DisplayNameActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/DisplayNameActivity.kt @@ -12,7 +12,7 @@ import network.loki.messenger.R import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.service.api.crypto.ProfileCipher class DisplayNameActivity : BaseActionBarActivity() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index 6b36be6eda..a25d3157e1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -41,10 +41,10 @@ import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegat import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests -import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.thoughtcrime.securesms.util.TextSecurePreferences.getBooleanPreference -import org.thoughtcrime.securesms.util.TextSecurePreferences.setBooleanPreference -import org.thoughtcrime.securesms.util.Util +import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences.getBooleanPreference +import org.session.libsession.utilities.TextSecurePreferences.setBooleanPreference +import org.session.libsession.utilities.Util import org.session.libsignal.service.loki.api.fileserver.FileServerAPI import org.session.libsignal.service.loki.protocol.mentions.MentionsManager import org.session.libsignal.service.loki.protocol.meta.SessionMetaProtocol @@ -89,7 +89,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe private val publicKey: String get() { val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this) - val userPublicKey = TextSecurePreferences.getLocalNumber(this) + val userPublicKey = TextSecurePreferences.getLocalNumber(this)!! return masterPublicKey ?: userPublicKey } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt index 7ed3cf18d6..4957af909d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt @@ -12,9 +12,10 @@ import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo import org.thoughtcrime.securesms.loki.views.FakeChatView import org.thoughtcrime.securesms.service.KeyCachingService -import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.Util +import org.session.libsession.utilities.TextSecurePreferences + class LandingActivity : BaseActionBarActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt index 7c86dec593..a09bb03048 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/PNModeActivity.kt @@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo import org.thoughtcrime.securesms.loki.utilities.show import org.thoughtcrime.securesms.loki.views.GlowViewUtilities import org.thoughtcrime.securesms.loki.views.PNModeView -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences class PNModeActivity : BaseActionBarActivity() { private var selectedOptionView: PNModeView? = null diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/QRCodeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/QRCodeActivity.kt index 0ae7e33fd5..82cd704001 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/QRCodeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/QRCodeActivity.kt @@ -25,7 +25,7 @@ import org.thoughtcrime.securesms.loki.utilities.QRCodeUtilities import org.thoughtcrime.securesms.loki.utilities.toPx import org.session.libsession.messaging.threads.recipients.Recipient import org.thoughtcrime.securesms.util.FileProviderUtil -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.service.loki.utilities.PublicKeyValidation import java.io.File import java.io.FileOutputStream @@ -56,7 +56,7 @@ class QRCodeActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperF val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this) val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this) val targetHexEncodedPublicKey = if (hexEncodedPublicKey == masterHexEncodedPublicKey) userHexEncodedPublicKey else hexEncodedPublicKey - val recipient = Recipient.from(this, Address.fromSerialized(targetHexEncodedPublicKey), false) + val recipient = Recipient.from(this, Address.fromSerialized(targetHexEncodedPublicKey!!), false) val intent = Intent(this, ConversationActivity::class.java) intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address) intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA)) @@ -106,7 +106,7 @@ class ViewMyQRCodeFragment : Fragment() { private val hexEncodedPublicKey: String get() { val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext()) - val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext()) + val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext())!! return masterHexEncodedPublicKey ?: userHexEncodedPublicKey } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt index e49345c60f..b9c8175d7a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt @@ -14,15 +14,12 @@ import android.widget.Toast import kotlinx.android.synthetic.main.activity_recovery_phrase_restore.* import network.loki.messenger.R import org.thoughtcrime.securesms.BaseActionBarActivity -import org.thoughtcrime.securesms.crypto.IdentityKeyUtil -import org.session.libsession.messaging.threads.Address -import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.loki.utilities.KeyPairUtilities import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.Hex -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.KeyHelper import org.session.libsignal.service.loki.crypto.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RegisterActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RegisterActivity.kt index f9010ba72b..9af309ba0a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RegisterActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RegisterActivity.kt @@ -19,13 +19,10 @@ import com.goterl.lazycode.lazysodium.utils.KeyPair import kotlinx.android.synthetic.main.activity_register.* import network.loki.messenger.R import org.thoughtcrime.securesms.BaseActionBarActivity -import org.thoughtcrime.securesms.crypto.IdentityKeyUtil -import org.session.libsession.messaging.threads.Address -import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.loki.utilities.KeyPairUtilities import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.ecc.ECKeyPair import org.session.libsignal.libsignal.util.KeyHelper import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt index b9549ed294..07d8d8f9db 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/SeedActivity.kt @@ -15,7 +15,7 @@ import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.thoughtcrime.securesms.loki.utilities.getColorWithID -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.service.loki.crypto.MnemonicCodec import org.session.libsignal.service.loki.utilities.hexEncodedPrivateKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/BackgroundPollWorker.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/BackgroundPollWorker.kt index 1a9bde5286..35c06402e5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/BackgroundPollWorker.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/BackgroundPollWorker.kt @@ -10,7 +10,7 @@ import nl.komponents.kovenant.functional.map import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobs.PushContentReceiveJob import org.thoughtcrime.securesms.logging.Log -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.service.api.messages.SignalServiceEnvelope import org.session.libsignal.service.loki.api.SnodeAPI import java.util.concurrent.TimeUnit @@ -67,7 +67,7 @@ class BackgroundPollWorker(val context: Context, params: WorkerParameters) : Wor val promises = mutableListOf>() // Private chats - val userPublicKey = TextSecurePreferences.getLocalNumber(context) + val userPublicKey = TextSecurePreferences.getLocalNumber(context)!! val privateChatsPromise = SnodeAPI.shared.getMessages(userPublicKey).map { envelopes -> envelopes.forEach { PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it), false) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt index 2df244c2b1..edfcbe6526 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt @@ -10,8 +10,8 @@ import org.thoughtcrime.securesms.database.DatabaseContentProviders import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.groups.GroupManager import org.thoughtcrime.securesms.util.BitmapUtil -import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.thoughtcrime.securesms.util.Util +import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.Util import org.session.libsignal.service.loki.api.opengroups.PublicChatInfo import org.session.libsignal.service.loki.api.opengroups.PublicChat import kotlin.jvm.Throws diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt index 7a56427cc4..edc811f550 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatPoller.kt @@ -16,7 +16,7 @@ import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol import org.session.libsession.utilities.successBackground import org.session.libsession.messaging.threads.recipients.Recipient -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.guava.Optional import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer import org.session.libsignal.service.api.messages.SignalServiceContent @@ -40,7 +40,7 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh public var isCaughtUp = false // region Convenience - private val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) + private val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)!! private var displayNameUpdatees = setOf() private val api: PublicChatAPI diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt index 1303c47309..7c4a53f6d7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt @@ -6,7 +6,7 @@ import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import org.thoughtcrime.securesms.jobs.PushContentReceiveJob import org.thoughtcrime.securesms.notifications.NotificationChannels -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.service.api.messages.SignalServiceEnvelope import org.session.libsignal.service.internal.util.Base64 @@ -50,7 +50,7 @@ class PushNotificationService : FirebaseMessagingService() { override fun onDeletedMessages() { org.thoughtcrime.securesms.logging.Log.d("Loki", "Called onDeletedMessages.") super.onDeletedMessages() - val token = TextSecurePreferences.getFCMToken(this) + val token = TextSecurePreferences.getFCMToken(this)!! val userPublicKey = TextSecurePreferences.getLocalNumber(this) ?: return LokiPushNotificationManager.register(token, userPublicKey, this, true) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt index 8c92734435..99240626f2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiUserDatabase.kt @@ -10,7 +10,7 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.loki.utilities.get import org.thoughtcrime.securesms.loki.utilities.insertOrUpdate import org.session.libsession.messaging.threads.recipients.Recipient -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.service.loki.database.LokiUserDatabaseProtocol class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/KeyPairMigrationSuccessBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/KeyPairMigrationSuccessBottomSheet.kt index cc7f1dcb61..21ab2c5f34 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/KeyPairMigrationSuccessBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/KeyPairMigrationSuccessBottomSheet.kt @@ -16,7 +16,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import kotlinx.android.synthetic.main.fragment_key_pair_migration_success_bottom_sheet.* import network.loki.messenger.R -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences class KeyPairMigrationSuccessBottomSheet : BottomSheetDialogFragment() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/MultiDeviceRemovalBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/MultiDeviceRemovalBottomSheet.kt index 72a798082b..0bc634a6d5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/MultiDeviceRemovalBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/dialogs/MultiDeviceRemovalBottomSheet.kt @@ -16,7 +16,7 @@ import android.widget.Toast import kotlinx.android.synthetic.main.fragment_multi_device_removal_bottom_sheet.* import network.loki.messenger.R import org.thoughtcrime.securesms.loki.utilities.getColorWithID -import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.session.libsession.utilities.TextSecurePreferences import java.text.SimpleDateFormat import java.util.* diff --git a/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt b/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt index 6998fa6c19..f52d06b4c5 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt @@ -15,6 +15,7 @@ object GroupUtil { const val MMS_GROUP_PREFIX = "__signal_mms_group__!" const val OPEN_GROUP_PREFIX = "__loki_public_chat_group__!" + @JvmStatic fun getEncodedOpenGroupID(groupID: String): String { return OPEN_GROUP_PREFIX + groupID } @@ -53,6 +54,7 @@ object GroupUtil { return groupID.toString() } + @JvmStatic fun getDecodedGroupID(groupID: ByteArray): String { val encodedGroupID = groupID.toString() if (encodedGroupID.split("!").count() > 1) { @@ -61,6 +63,7 @@ object GroupUtil { return encodedGroupID.split("!")[0] } + @JvmStatic fun getDecodedGroupIDAsData(groupID: ByteArray): ByteArray { return getDecodedGroupID(groupID).toByteArray() } @@ -69,6 +72,7 @@ object GroupUtil { return groupId.startsWith(CLOSED_GROUP_PREFIX) || groupId.startsWith(MMS_GROUP_PREFIX) || groupId.startsWith(OPEN_GROUP_PREFIX) } + @JvmStatic fun isMmsGroup(groupId: String): Boolean { return groupId.startsWith(MMS_GROUP_PREFIX) } diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 3e47b8d19c..0656554fbb 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -56,7 +56,7 @@ object TextSecurePreferences { const val MMS_USER_AGENT = "pref_mms_user_agent" private const val MMS_CUSTOM_USER_AGENT = "pref_custom_mms_user_agent" private const val THREAD_TRIM_ENABLED = "pref_trim_threads" - private const val LOCAL_NUMBER_PREF = "pref_local_number" + const val LOCAL_NUMBER_PREF = "pref_local_number" private const val VERIFYING_STATE_PREF = "pref_verifying" const val REGISTERED_GCM_PREF = "pref_gcm_registered" private const val GCM_PASSWORD_PREF = "pref_gcm_password" @@ -76,7 +76,7 @@ object TextSecurePreferences { private const val SHOW_INVITE_REMINDER_PREF = "pref_show_invite_reminder" const val MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size" - private const val LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id" + const val LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id" private const val SIGNED_PREKEY_REGISTERED_PREF = "pref_signed_prekey_registered" private const val WIFI_SMS_PREF = "pref_wifi_sms" @@ -103,10 +103,10 @@ object TextSecurePreferences { private const val MULTI_DEVICE_PROVISIONED_PREF = "pref_multi_device" const val DIRECT_CAPTURE_CAMERA_ID = "pref_direct_capture_camera_id" private const val ALWAYS_RELAY_CALLS_PREF = "pref_turn_only" - private const val PROFILE_KEY_PREF = "pref_profile_key" - private const val PROFILE_NAME_PREF = "pref_profile_name" - private const val PROFILE_AVATAR_ID_PREF = "pref_profile_avatar_id" - private const val PROFILE_AVATAR_URL_PREF = "pref_profile_avatar_url" + const val PROFILE_KEY_PREF = "pref_profile_key" + const val PROFILE_NAME_PREF = "pref_profile_name" + const val PROFILE_AVATAR_ID_PREF = "pref_profile_avatar_id" + 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 UNAUTHORIZED_RECEIVED = "pref_unauthorized_received" @@ -160,7 +160,7 @@ object TextSecurePreferences { private const val MEDIA_KEYBOARD_MODE = "pref_media_keyboard_mode" // region FCM - private const val IS_USING_FCM = "pref_is_using_fcm" + 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 HAS_SEEN_PN_MODE_SHEET = "pref_has_seen_pn_mode_sheet" @@ -212,18 +212,22 @@ object TextSecurePreferences { setLongPreference(context, SCREEN_LOCK_TIMEOUT, value) } + @JvmStatic fun setBackupPassphrase(context: Context, passphrase: String?) { setStringPreference(context, BACKUP_PASSPHRASE, passphrase) } + @JvmStatic fun getBackupPassphrase(context: Context): String? { return getStringPreference(context, BACKUP_PASSPHRASE, null) } + @JvmStatic fun setEncryptedBackupPassphrase(context: Context, encryptedPassphrase: String?) { setStringPreference(context, ENCRYPTED_BACKUP_PASSPHRASE, encryptedPassphrase) } + @JvmStatic fun getEncryptedBackupPassphrase(context: Context): String? { return getStringPreference(context, ENCRYPTED_BACKUP_PASSPHRASE, null) } @@ -287,34 +291,42 @@ object TextSecurePreferences { return getBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, false) } + @JvmStatic fun setAttachmentEncryptedSecret(context: Context, secret: String) { setStringPreference(context, ATTACHMENT_ENCRYPTED_SECRET, secret) } + @JvmStatic fun setAttachmentUnencryptedSecret(context: Context, secret: String?) { setStringPreference(context, ATTACHMENT_UNENCRYPTED_SECRET, secret) } + @JvmStatic fun getAttachmentEncryptedSecret(context: Context): String? { return getStringPreference(context, ATTACHMENT_ENCRYPTED_SECRET, null) } + @JvmStatic fun getAttachmentUnencryptedSecret(context: Context): String? { return getStringPreference(context, ATTACHMENT_UNENCRYPTED_SECRET, null) } + @JvmStatic fun setDatabaseEncryptedSecret(context: Context, secret: String) { setStringPreference(context, DATABASE_ENCRYPTED_SECRET, secret) } + @JvmStatic fun setDatabaseUnencryptedSecret(context: Context, secret: String?) { setStringPreference(context, DATABASE_UNENCRYPTED_SECRET, secret) } + @JvmStatic fun getDatabaseUnencryptedSecret(context: Context): String? { return getStringPreference(context, DATABASE_UNENCRYPTED_SECRET, null) } + @JvmStatic fun getDatabaseEncryptedSecret(context: Context): String? { return getStringPreference(context, DATABASE_ENCRYPTED_SECRET, null) } @@ -327,6 +339,7 @@ object TextSecurePreferences { return getBooleanPreference(context, SUCCESSFUL_DIRECTORY_PREF, false) } + @JvmStatic fun setUnauthorizedReceived(context: Context, value: Boolean) { setBooleanPreference(context, UNAUTHORIZED_RECEIVED, value) } @@ -335,6 +348,7 @@ object TextSecurePreferences { return getBooleanPreference(context, UNAUTHORIZED_RECEIVED, false) } + @JvmStatic fun isIncognitoKeyboardEnabled(context: Context): Boolean { return getBooleanPreference(context, INCOGNITO_KEYBORAD_PREF, true) } @@ -358,6 +372,7 @@ object TextSecurePreferences { setBooleanPreference(context, TYPING_INDICATORS, enabled) } + @JvmStatic fun isLinkPreviewsEnabled(context: Context): Boolean { return getBooleanPreference(context, LINK_PREVIEWS, false) } @@ -371,6 +386,7 @@ object TextSecurePreferences { return getBooleanPreference(context, GIF_GRID_LAYOUT, false) } + @JvmStatic fun setIsGifSearchInGridLayout(context: Context, isGrid: Boolean) { setBooleanPreference(context, GIF_GRID_LAYOUT, isGrid) } @@ -427,6 +443,7 @@ object TextSecurePreferences { return getBooleanPreference(context, ALWAYS_RELAY_CALLS_PREF, false) } + @JvmStatic fun isFcmDisabled(context: Context): Boolean { return getBooleanPreference(context, GCM_DISABLED_PREF, false) } @@ -443,10 +460,12 @@ object TextSecurePreferences { setBooleanPreference(context, WEBRTC_CALLING_PREF, enabled) } + @JvmStatic fun setDirectCaptureCameraId(context: Context, value: Int) { setIntegerPrefrence(context, DIRECT_CAPTURE_CAMERA_ID, value) } + @JvmStatic fun getDirectCaptureCameraId(context: Context): Int { return getIntegerPreference(context, DIRECT_CAPTURE_CAMERA_ID, Camera.CameraInfo.CAMERA_FACING_FRONT) } @@ -455,6 +474,7 @@ object TextSecurePreferences { setBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, value) } + @JvmStatic fun isMultiDevice(context: Context): Boolean { return getBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, false) } @@ -566,6 +586,7 @@ object TextSecurePreferences { return null } + @JvmStatic fun isUniversalUnidentifiedAccess(context: Context): Boolean { return getBooleanPreference(context, UNIVERSAL_UNIDENTIFIED_ACCESS, false) } @@ -642,6 +663,7 @@ object TextSecurePreferences { removePreference(context, LOCAL_NUMBER_PREF) } + @JvmStatic fun getPushServerPassword(context: Context): String? { return getStringPreference(context, GCM_PASSWORD_PREF, null) } @@ -650,6 +672,7 @@ object TextSecurePreferences { setStringPreference(context, GCM_PASSWORD_PREF, password) } + @JvmStatic fun getSignalingKey(context: Context): String? { return getStringPreference(context, SIGNALING_KEY_PREF, null) } @@ -671,6 +694,7 @@ object TextSecurePreferences { setBooleanPreference(context, DISABLE_PASSPHRASE_PREF, disabled) } + @JvmStatic fun getUseCustomMmsc(context: Context): Boolean { val legacy: Boolean = isLegacyUseLocalApnsEnabled(context) return getBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, legacy) @@ -680,6 +704,7 @@ object TextSecurePreferences { setBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, value) } + @JvmStatic fun getMmscUrl(context: Context): String? { return getStringPreference(context, MMSC_HOST_PREF, "") } @@ -688,6 +713,7 @@ object TextSecurePreferences { setStringPreference(context, MMSC_HOST_PREF, mmsc) } + @JvmStatic fun getUseCustomMmscProxy(context: Context): Boolean { val legacy: Boolean = isLegacyUseLocalApnsEnabled(context) return getBooleanPreference(context, MMSC_CUSTOM_PROXY_PREF, legacy) @@ -697,6 +723,7 @@ object TextSecurePreferences { setBooleanPreference(context, MMSC_CUSTOM_PROXY_PREF, value) } + @JvmStatic fun getMmscProxy(context: Context): String? { return getStringPreference(context, MMSC_PROXY_HOST_PREF, "") } @@ -705,6 +732,7 @@ object TextSecurePreferences { setStringPreference(context, MMSC_PROXY_HOST_PREF, value) } + @JvmStatic fun getUseCustomMmscProxyPort(context: Context): Boolean { val legacy: Boolean = isLegacyUseLocalApnsEnabled(context) return getBooleanPreference(context, MMSC_CUSTOM_PROXY_PORT_PREF, legacy) @@ -714,6 +742,7 @@ object TextSecurePreferences { setBooleanPreference(context, MMSC_CUSTOM_PROXY_PORT_PREF, value) } + @JvmStatic fun getMmscProxyPort(context: Context): String? { return getStringPreference(context, MMSC_PROXY_PORT_PREF, "") } @@ -722,6 +751,7 @@ object TextSecurePreferences { setStringPreference(context, MMSC_PROXY_PORT_PREF, value) } + @JvmStatic fun getUseCustomMmscUsername(context: Context): Boolean { val legacy: Boolean = isLegacyUseLocalApnsEnabled(context) return getBooleanPreference(context, MMSC_CUSTOM_USERNAME_PREF, legacy) @@ -731,6 +761,7 @@ object TextSecurePreferences { setBooleanPreference(context, MMSC_CUSTOM_USERNAME_PREF, value) } + @JvmStatic fun getMmscUsername(context: Context): String? { return getStringPreference(context, MMSC_USERNAME_PREF, "") } @@ -739,6 +770,7 @@ object TextSecurePreferences { setStringPreference(context, MMSC_USERNAME_PREF, value) } + @JvmStatic fun getUseCustomMmscPassword(context: Context): Boolean { val legacy: Boolean = isLegacyUseLocalApnsEnabled(context) return getBooleanPreference(context, MMSC_CUSTOM_PASSWORD_PREF, legacy) @@ -748,6 +780,7 @@ object TextSecurePreferences { setBooleanPreference(context, MMSC_CUSTOM_PASSWORD_PREF, value) } + @JvmStatic fun getMmscPassword(context: Context): String? { return getStringPreference(context, MMSC_PASSWORD_PREF, "") } @@ -822,6 +855,7 @@ object TextSecurePreferences { setBooleanPreference(context, VERIFYING_STATE_PREF, verifying) } + @JvmStatic fun isPushRegistered(context: Context): Boolean { return getBooleanPreference(context, REGISTERED_GCM_PREF, false) } @@ -1048,35 +1082,43 @@ object TextSecurePreferences { setBooleanPreference(context, NEEDS_MESSAGE_PULL, needsMessagePull) } + @JvmStatic fun hasSeenStickerIntroTooltip(context: Context): Boolean { return getBooleanPreference(context, SEEN_STICKER_INTRO_TOOLTIP, false) } + @JvmStatic fun setHasSeenStickerIntroTooltip(context: Context, seenStickerTooltip: Boolean) { setBooleanPreference(context, SEEN_STICKER_INTRO_TOOLTIP, seenStickerTooltip) } + @JvmStatic fun setMediaKeyboardMode(context: Context, mode: MediaKeyboardMode) { setStringPreference(context, MEDIA_KEYBOARD_MODE, mode.name) } + @JvmStatic fun getMediaKeyboardMode(context: Context): MediaKeyboardMode { val name = getStringPreference(context, MEDIA_KEYBOARD_MODE, MediaKeyboardMode.EMOJI.name)!! return MediaKeyboardMode.valueOf(name) } + @JvmStatic fun setBooleanPreference(context: Context, key: String?, value: Boolean) { getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply() } + @JvmStatic fun getBooleanPreference(context: Context, key: String?, defaultValue: Boolean): Boolean { return getDefaultSharedPreferences(context).getBoolean(key, defaultValue) } + @JvmStatic fun setStringPreference(context: Context, key: String?, value: String?) { getDefaultSharedPreferences(context).edit().putString(key, value).apply() } + @JvmStatic fun getStringPreference(context: Context, key: String, defaultValue: String?): String? { return getDefaultSharedPreferences(context).getString(key, defaultValue) } @@ -1207,10 +1249,12 @@ 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) } @@ -1262,94 +1306,7 @@ object TextSecurePreferences { } // endregion - /* TODO - // region Backup related - fun getBackupRecords(context: Context): List { - val preferences = getDefaultSharedPreferences(context) - val prefsFileName: String - prefsFileName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - getDefaultSharedPreferencesName(context) - } else { - context.packageName + "_preferences" - } - val prefList: LinkedList = LinkedList() - addBackupEntryInt(prefList, preferences, prefsFileName, LOCAL_REGISTRATION_ID_PREF) - addBackupEntryString(prefList, preferences, prefsFileName, LOCAL_NUMBER_PREF) - addBackupEntryString(prefList, preferences, prefsFileName, PROFILE_NAME_PREF) - addBackupEntryString(prefList, preferences, prefsFileName, PROFILE_AVATAR_URL_PREF) - addBackupEntryInt(prefList, preferences, prefsFileName, PROFILE_AVATAR_ID_PREF) - addBackupEntryString(prefList, preferences, prefsFileName, PROFILE_KEY_PREF) - addBackupEntryBoolean(prefList, preferences, prefsFileName, IS_USING_FCM) - return prefList - } - private fun addBackupEntryString( - outPrefList: MutableList, - prefs: SharedPreferences, - prefFileName: String, - prefKey: String, - ) { - val value = prefs.getString(prefKey, null) - if (value == null) { - logBackupEntry(prefKey, false) - return - } - outPrefList.add(BackupProtos.SharedPreference.newBuilder() - .setFile(prefFileName) - .setKey(prefKey) - .setValue(value) - .build()) - logBackupEntry(prefKey, true) - } - - private fun addBackupEntryInt( - outPrefList: MutableList, - prefs: SharedPreferences, - prefFileName: String, - prefKey: String, - ) { - val value = prefs.getInt(prefKey, -1) - if (value == -1) { - logBackupEntry(prefKey, false) - return - } - outPrefList.add(BackupProtos.SharedPreference.newBuilder() - .setFile(prefFileName) - .setKey(PREF_PREFIX_TYPE_INT + prefKey) // The prefix denotes the type of the preference. - .setValue(value.toString()) - .build()) - logBackupEntry(prefKey, true) - } - - private fun addBackupEntryBoolean( - outPrefList: MutableList, - prefs: SharedPreferences, - prefFileName: String, - prefKey: String, - ) { - if (!prefs.contains(prefKey)) { - logBackupEntry(prefKey, false) - return - } - outPrefList.add(BackupProtos.SharedPreference.newBuilder() - .setFile(prefFileName) - .setKey(PREF_PREFIX_TYPE_BOOLEAN + prefKey) // The prefix denotes the type of the preference. - .setValue(prefs.getBoolean(prefKey, false).toString()) - .build()) - logBackupEntry(prefKey, true) - } - - private fun logBackupEntry(prefName: String, wasIncluded: Boolean) { - val sb = StringBuilder() - sb.append("Backup preference ") - sb.append(if (wasIncluded) "+ " else "- ") - sb.append('\"').append(prefName).append("\" ") - if (!wasIncluded) { - sb.append("(is empty and not included)") - } - Log.d(TAG, sb.toString()) - } // endregion - */ // NEVER rename these -- they're persisted by name enum class MediaKeyboardMode { diff --git a/libsession/src/main/java/org/session/libsession/utilities/Util.kt b/libsession/src/main/java/org/session/libsession/utilities/Util.kt index fc23e1d82a..50feeb5319 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Util.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Util.kt @@ -1,8 +1,12 @@ package org.session.libsession.utilities import android.annotation.SuppressLint +import android.annotation.TargetApi +import android.app.ActivityManager import android.content.Context import android.net.Uri +import android.os.Build.VERSION +import android.os.Build.VERSION_CODES import android.os.Handler import android.os.Looper import android.provider.Telephony @@ -13,6 +17,7 @@ import java.io.* import java.nio.charset.StandardCharsets import java.security.SecureRandom import java.util.* +import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.ThreadPoolExecutor import java.util.concurrent.TimeUnit @@ -63,6 +68,27 @@ object Util { getHandler()?.postDelayed(runnable, delayMillis) } + @JvmStatic + fun runOnMainSync(runnable: Runnable) { + if (isMainThread()) { + runnable.run() + } else { + val sync = CountDownLatch(1) + runOnMain(Runnable { + try { + runnable.run() + } finally { + sync.countDown() + } + }) + try { + sync.await() + } catch (ie: InterruptedException) { + throw java.lang.AssertionError(ie) + } + } + } + @JvmStatic fun cancelRunnableOnMain(runnable: Runnable) { getHandler()?.removeCallbacks(runnable) @@ -248,6 +274,7 @@ object Util { return Base64.encodeBytes(secret) } + @JvmStatic fun getSecretBytes(size: Int): ByteArray { val secret = ByteArray(size) getSecureRandom().nextBytes(secret) @@ -274,4 +301,17 @@ object Util { return collection == null || collection.isEmpty() } + @JvmStatic + @TargetApi(VERSION_CODES.KITKAT) + fun isLowMemory(context: Context): Boolean { + val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + return VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice || + activityManager.largeMemoryClass <= 64 + } + + @JvmStatic + fun getRandomElement(elements: Array): T { + return elements[SecureRandom().nextInt(elements.size)] + } + } \ No newline at end of file