mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
WIP clean & make things compile
This commit is contained in:
parent
f7d898d5e3
commit
31d4deb354
@ -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.
|
||||
|
@ -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<BackupProtos.SharedPreference> {
|
||||
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<BackupProtos.SharedPreference> = LinkedList<BackupProtos.SharedPreference>()
|
||||
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<BackupProtos.SharedPreference>,
|
||||
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<BackupProtos.SharedPreference>,
|
||||
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<BackupProtos.SharedPreference>,
|
||||
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
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<String>, admins: Collection<String>) {
|
||||
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<String>, admins: Collection<String>, 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)
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Recipient> 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<Address> memberAddresses = getMemberAddresses(members);
|
||||
final Set<Address> 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<Address> 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<String> numbers = new LinkedList<>();
|
||||
for (Address member : members) {
|
||||
numbers.add(member.serialize());
|
||||
}
|
||||
|
||||
List<String> 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<String> numbers = new LinkedList<>();
|
||||
for (Address member : members) {
|
||||
numbers.add(member.serialize());
|
||||
}
|
||||
|
||||
List<String> 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<Address> getMemberAddresses(Collection<Recipient> recipients) {
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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<GroupRecord> record = groupDatabase.getGroup(GroupUtil.getEncodedId(groupId, false));
|
||||
Optional<GroupRecord> 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<PushGroupUpdateJob> {
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<SignalServiceAddress> addresses = Stream.of(recipients).map(r -> new SignalServiceAddress(r.getAddress().serialize())).toList();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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?) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<Promise<Unit, Exception>>()
|
||||
|
||||
// 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)
|
||||
|
@ -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
|
||||
|
@ -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<String>()
|
||||
|
||||
private val api: PublicChatAPI
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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.*
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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<SharedPreference> {
|
||||
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<SharedPreference> = LinkedList<SharedPreference>()
|
||||
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<SharedPreference>,
|
||||
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<SharedPreference>,
|
||||
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<SharedPreference>,
|
||||
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 {
|
||||
|
@ -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 <T> getRandomElement(elements: Array<T>): T {
|
||||
return elements[SecureRandom().nextInt(elements.size)]
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user