mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 13:58:25 +00:00
clean
This commit is contained in:
parent
48c0df0621
commit
543019f93c
@ -25,7 +25,8 @@ import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -54,10 +54,12 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment;
|
||||
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import org.thoughtcrime.securesms.components.MediaView;
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord;
|
||||
import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
@ -66,13 +68,10 @@ import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.util.AttachmentUtil;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
@ -7,9 +7,9 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.session.libsession.utilities.Hex;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Hex;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
|
@ -10,7 +10,7 @@ import android.media.MediaRecorder;
|
||||
import android.os.Build;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@ -36,8 +36,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.thoughtcrime.securesms.attachments.AttachmentServer;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,8 @@ import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.BackupDirSelector;
|
||||
import org.thoughtcrime.securesms.util.BackupUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -25,7 +25,7 @@ import org.thoughtcrime.securesms.logging.Log
|
||||
import org.thoughtcrime.securesms.loki.database.LokiAPIDatabase
|
||||
import org.thoughtcrime.securesms.loki.database.LokiBackupFilesDatabase
|
||||
import org.thoughtcrime.securesms.util.BackupUtil
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.session.libsession.utilities.Util
|
||||
import org.session.libsignal.libsignal.kdf.HKDFv3
|
||||
import org.session.libsignal.libsignal.util.ByteUtil
|
||||
import java.io.*
|
||||
|
@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||
import org.thoughtcrime.securesms.events.PartProgressEvent;
|
||||
import org.thoughtcrime.securesms.mms.DocumentSlide;
|
||||
import org.thoughtcrime.securesms.mms.SlideClickListener;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
public class DocumentView extends FrameLayout {
|
||||
|
@ -6,7 +6,7 @@ import androidx.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -7,7 +7,7 @@ import android.util.AttributeSet;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
|
||||
public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKeyboardShownListener {
|
||||
private InputView current;
|
||||
|
@ -29,8 +29,8 @@ import android.view.Surface;
|
||||
import android.view.View;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
|
@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.service.loki.protocol.shelved.multidevice.MultiDeviceProtocol;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -192,7 +192,7 @@ import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.PushCharacterCalculator;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Util; // Cannot be modified
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.contacts.Contact;
|
||||
|
@ -20,7 +20,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.LimitedInputStream;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -31,7 +31,7 @@ import org.session.libsignal.libsignal.ecc.ECPublicKey;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.session.libsession.utilities.Base64;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
@ -19,7 +19,7 @@ package org.thoughtcrime.securesms.crypto;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.session.libsession.utilities.Hex;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.InvalidKeyException;
|
||||
import org.session.libsignal.libsignal.ecc.Curve;
|
||||
import org.session.libsignal.libsignal.ecc.ECPublicKey;
|
||||
|
@ -20,7 +20,7 @@ import android.content.ContentValues;
|
||||
|
||||
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
public class ContentValuesBuilder {
|
||||
|
||||
|
@ -965,7 +965,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
notifyConversationListeners(threadId);
|
||||
DatabaseFactory.getThreadDatabase(context).update(threadId, true);
|
||||
|
||||
if (org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider(context)) {
|
||||
if (Util.isDefaultSmsProvider(context)) {
|
||||
DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, 1);
|
||||
}
|
||||
|
||||
@ -1433,10 +1433,10 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
byte[]transactionIdBytes = null;
|
||||
|
||||
if (!TextUtils.isEmpty(contentLocation))
|
||||
contentLocationBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(contentLocation);
|
||||
contentLocationBytes = Util.toIsoBytes(contentLocation);
|
||||
|
||||
if (!TextUtils.isEmpty(transactionId))
|
||||
transactionIdBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(transactionId);
|
||||
transactionIdBytes = Util.toIsoBytes(transactionId);
|
||||
|
||||
SlideDeck slideDeck = new SlideDeck(context, new MmsNotificationAttachment(status, messageSize));
|
||||
|
||||
|
@ -27,9 +27,9 @@ import net.sqlcipher.database.SQLiteQueryBuilder;
|
||||
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -9,7 +9,7 @@ import net.sqlcipher.Cursor;
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -46,6 +46,7 @@ import org.session.libsession.messaging.threads.Address;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.utilities.JsonUtils;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -616,7 +617,7 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
groupRecipient = Recipient.from(context, message.getGroupId(), true);
|
||||
}
|
||||
|
||||
boolean unread = (org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider(context) ||
|
||||
boolean unread = (Util.isDefaultSmsProvider(context) ||
|
||||
message.isSecureMessage() || message.isGroup() || message.isPreKeyBundle()) &&
|
||||
!message.isIdentityUpdate() && !message.isIdentityDefault() && !message.isIdentityVerified();
|
||||
|
||||
|
@ -22,7 +22,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||
import org.thoughtcrime.securesms.stickers.BlessedPacks;
|
||||
import org.thoughtcrime.securesms.stickers.StickerPackInstallEvent;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
|
@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.glide.cache;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -11,7 +11,8 @@ import org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.FullSpec;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.JobSpec;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.JobStorage;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -14,9 +14,10 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.stickers.StickerUrl;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -10,7 +10,7 @@ import android.text.TextUtils;
|
||||
|
||||
import org.thoughtcrime.securesms.net.RequestController;
|
||||
import org.thoughtcrime.securesms.util.Debouncer;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
|
@ -189,8 +189,6 @@ class BackupRestoreViewModel(application: Application): AndroidViewModel(applica
|
||||
TextSecurePreferences.setRestorationTime(context, System.currentTimeMillis())
|
||||
TextSecurePreferences.setHasViewedSeed(context, true)
|
||||
TextSecurePreferences.setHasSeenWelcomeScreen(context, true)
|
||||
TextSecurePreferences.setHasSeenMultiDeviceRemovalSheet(context)
|
||||
TextSecurePreferences.setHasSeenLightThemeIntroSheet(context)
|
||||
val application = ApplicationContext.getInstance(context)
|
||||
application.setUpStorageAPIIfNeeded()
|
||||
application.setUpP2PAPIIfNeeded()
|
||||
|
@ -152,8 +152,6 @@ class PNModeActivity : BaseActionBarActivity() {
|
||||
}
|
||||
TextSecurePreferences.setHasSeenWelcomeScreen(this, true)
|
||||
TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == fcmOptionView))
|
||||
TextSecurePreferences.setHasSeenMultiDeviceRemovalSheet(this)
|
||||
TextSecurePreferences.setHasSeenLightThemeIntroSheet(this)
|
||||
val application = ApplicationContext.getInstance(this)
|
||||
application.setUpStorageAPIIfNeeded()
|
||||
application.setUpP2PAPIIfNeeded()
|
||||
|
@ -27,7 +27,6 @@ import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.RotateAnimation;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.load.MultiTransformation;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
@ -38,7 +37,7 @@ import com.bumptech.glide.request.transition.Transition;
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Stopwatch;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
|
||||
|
@ -18,7 +18,7 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.SingleLiveEvent;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -35,7 +35,7 @@ import com.google.android.mms.pdu_alt.RetrieveConf;
|
||||
|
||||
import org.thoughtcrime.securesms.providers.MmsBodyProvider;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -43,7 +43,7 @@ import org.apache.http.impl.client.LaxRedirectStrategy;
|
||||
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.thoughtcrime.securesms.database.ApnDatabase;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TelephonyUtil;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
|
@ -9,7 +9,7 @@ import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -33,7 +33,8 @@ import com.google.android.mms.pdu_alt.SendConf;
|
||||
|
||||
import org.thoughtcrime.securesms.providers.MmsBodyProvider;
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -6,7 +6,8 @@ import com.google.android.mms.pdu_alt.PduBody;
|
||||
import com.google.android.mms.pdu_alt.PduPart;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.service.loki.api.fileserver.FileServerAPI;
|
||||
|
||||
public class PushMediaConstraints extends MediaConstraints {
|
||||
|
@ -4,7 +4,7 @@ import android.os.AsyncTask;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -38,10 +38,7 @@ import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier;
|
||||
import org.session.libsignal.service.api.messages.SignalServiceGroup;
|
||||
import org.session.libsignal.service.internal.push.SignalServiceProtos;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.session.libsession.messaging.sending_receiving.contacts.Contact;
|
||||
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
||||
@ -60,12 +57,11 @@ import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.IncomingMessageObserver;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.SpanUtil;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsignal.service.internal.util.Util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
@ -27,7 +27,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient.*;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsignal.libsignal.logging.Log;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import com.annimon.stream.Stream;
|
||||
import com.annimon.stream.function.Consumer;
|
||||
|
||||
import org.thoughtcrime.securesms.util.LRUCache;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.security.SecureRandom;
|
||||
|
@ -17,7 +17,7 @@ import com.google.zxing.qrcode.QRCodeReader;
|
||||
import org.thoughtcrime.securesms.components.camera.CameraView;
|
||||
import org.thoughtcrime.securesms.components.camera.CameraView.PreviewFrame;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -39,7 +39,7 @@ import org.thoughtcrime.securesms.DummyActivity;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.jobs.MmsReceiveJob;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
public class MmsListener extends BroadcastReceiver {
|
||||
|
||||
|
@ -26,7 +26,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.jobs.SmsReceiveJob;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
public class SmsListener extends BroadcastReceiver {
|
||||
|
||||
|
@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.util.FileProviderUtil;
|
||||
import org.thoughtcrime.securesms.util.FileUtils;
|
||||
import org.session.libsession.utilities.Hex;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -12,9 +12,11 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
@ -22,6 +22,8 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -4,6 +4,8 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
/**
|
||||
* Implementation of {@link androidx.lifecycle.LiveData} that will handle closing the contained
|
||||
* {@link Closeable} when the value changes.
|
||||
|
@ -1,230 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
import org.session.libsignal.service.api.messages.SignalServiceGroup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
import static org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext;
|
||||
|
||||
public class GroupUtil {
|
||||
// TODO: Remove this file
|
||||
// private static final String ENCODED_CLOSED_GROUP_PREFIX = "__textsecure_group__!";
|
||||
// private static final String ENCODED_MMS_GROUP_PREFIX = "__signal_mms_group__!";
|
||||
// private static final String ENCODED_OPEN_GROUP_PREFIX = "__loki_public_chat_group__!";
|
||||
// private static final String ENCODED_RSS_FEED_GROUP_PREFIX = "__loki_rss_feed_group__!";
|
||||
// private static final String TAG = GroupUtil.class.getSimpleName();
|
||||
//
|
||||
// public static String getEncodedId(SignalServiceGroup group) {
|
||||
// byte[] groupId = group.getGroupId();
|
||||
// if (group.getGroupType() == SignalServiceGroup.GroupType.PUBLIC_CHAT) {
|
||||
// return getEncodedOpenGroupId(groupId);
|
||||
// } else if (group.getGroupType() == SignalServiceGroup.GroupType.RSS_FEED) {
|
||||
// return getEncodedRSSFeedId(groupId);
|
||||
// }
|
||||
// return getEncodedId(groupId, false);
|
||||
// }
|
||||
//
|
||||
// public static String getEncodedId(byte[] groupId, boolean mms) {
|
||||
// return (mms ? ENCODED_MMS_GROUP_PREFIX : ENCODED_CLOSED_GROUP_PREFIX) + Hex.toStringCondensed(groupId);
|
||||
// }
|
||||
//
|
||||
// public static String getEncodedOpenGroupId(byte[] groupId) {
|
||||
// return ENCODED_OPEN_GROUP_PREFIX + Hex.toStringCondensed(groupId);
|
||||
// }
|
||||
//
|
||||
// public static String getEncodedRSSFeedId(byte[] groupId) {
|
||||
// return ENCODED_RSS_FEED_GROUP_PREFIX + Hex.toStringCondensed(groupId);
|
||||
// }
|
||||
//
|
||||
// public static byte[] getDecodedId(String groupId) throws IOException {
|
||||
// if (!isEncodedGroup(groupId)) {
|
||||
// throw new IOException("Invalid encoding");
|
||||
// }
|
||||
//
|
||||
// return Hex.fromStringCondensed(groupId.split("!", 2)[1]);
|
||||
// }
|
||||
//
|
||||
// public static String getDecodedStringId(String groupId) throws IOException {
|
||||
// byte[] id = getDecodedId(groupId);
|
||||
// return new String(id);
|
||||
// }
|
||||
//
|
||||
// public static boolean isEncodedGroup(@NonNull String groupId) {
|
||||
// return groupId.startsWith(ENCODED_CLOSED_GROUP_PREFIX) || groupId.startsWith(ENCODED_MMS_GROUP_PREFIX) || groupId.startsWith(ENCODED_OPEN_GROUP_PREFIX) || groupId.startsWith(ENCODED_RSS_FEED_GROUP_PREFIX);
|
||||
// }
|
||||
//
|
||||
// public static boolean isMmsGroup(@NonNull String groupId) {
|
||||
// return groupId.startsWith(ENCODED_MMS_GROUP_PREFIX);
|
||||
// }
|
||||
//
|
||||
// public static boolean isOpenGroup(@NonNull String groupId) {
|
||||
// return groupId.startsWith(ENCODED_OPEN_GROUP_PREFIX);
|
||||
// }
|
||||
//
|
||||
// public static boolean isRSSFeed(@NonNull String groupId) {
|
||||
// return groupId.startsWith(ENCODED_RSS_FEED_GROUP_PREFIX);
|
||||
// }
|
||||
//
|
||||
// public static boolean isClosedGroup(@NonNull String groupId) {
|
||||
// return groupId.startsWith(ENCODED_CLOSED_GROUP_PREFIX);
|
||||
// }
|
||||
//
|
||||
// @WorkerThread
|
||||
// public static Optional<OutgoingGroupMediaMessage> createGroupLeaveMessage(@NonNull Context context, @NonNull Recipient groupRecipient) {
|
||||
// String encodedGroupId = groupRecipient.getAddress().toGroupString();
|
||||
// GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
||||
//
|
||||
// if (!groupDatabase.isActive(encodedGroupId)) {
|
||||
// Log.w(TAG, "Group has already been left.");
|
||||
// return Optional.absent();
|
||||
// }
|
||||
//
|
||||
// ByteString decodedGroupId;
|
||||
// try {
|
||||
// decodedGroupId = ByteString.copyFrom(getDecodedId(encodedGroupId));
|
||||
// } catch (IOException e) {
|
||||
// Log.w(TAG, "Failed to decode group ID.", e);
|
||||
// return Optional.absent();
|
||||
// }
|
||||
//
|
||||
// GroupContext groupContext = GroupContext.newBuilder()
|
||||
// .setId(decodedGroupId)
|
||||
// .setType(GroupContext.Type.QUIT)
|
||||
// .build();
|
||||
//
|
||||
// return Optional.of(new OutgoingGroupMediaMessage(groupRecipient, groupContext, null, System.currentTimeMillis(), 0, null, Collections.emptyList(), Collections.emptyList()));
|
||||
// }
|
||||
//
|
||||
// public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup) {
|
||||
// if (encodedGroup == null) {
|
||||
// return new GroupDescription(context, null);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
||||
// return new GroupDescription(context, groupContext);
|
||||
// } catch (IOException e) {
|
||||
// Log.w(TAG, e);
|
||||
// return new GroupDescription(context, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static class GroupDescription {
|
||||
//
|
||||
// @NonNull private final Context context;
|
||||
// @Nullable private final GroupContext groupContext;
|
||||
// private final List<Recipient> newMembers;
|
||||
// private final List<Recipient> removedMembers;
|
||||
// private boolean wasCurrentUserRemoved;
|
||||
//
|
||||
// public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) {
|
||||
// this.context = context.getApplicationContext();
|
||||
// this.groupContext = groupContext;
|
||||
//
|
||||
// this.newMembers = new LinkedList<>();
|
||||
// this.removedMembers = new LinkedList<>();
|
||||
// this.wasCurrentUserRemoved = false;
|
||||
//
|
||||
// if (groupContext != null) {
|
||||
// List<String> newMembers = groupContext.getNewMembersList();
|
||||
// for (String member : newMembers) {
|
||||
// this.newMembers.add(this.toRecipient(member));
|
||||
// }
|
||||
//
|
||||
// List<String> removedMembers = groupContext.getRemovedMembersList();
|
||||
// for (String member : removedMembers) {
|
||||
// this.removedMembers.add(this.toRecipient(member));
|
||||
// }
|
||||
//
|
||||
// // If we were the one that quit then we need to leave the group (only relevant for slave
|
||||
// // devices in a multi device context)
|
||||
// if (!removedMembers.isEmpty()) {
|
||||
// String masterPublicKeyOrNull = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||
// String masterPublicKey = masterPublicKeyOrNull != null ? masterPublicKeyOrNull : TextSecurePreferences.getLocalNumber(context);
|
||||
// wasCurrentUserRemoved = removedMembers.contains(masterPublicKey);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private Recipient toRecipient(String hexEncodedPublicKey) {
|
||||
// Address address = Address.Companion.fromSerialized(hexEncodedPublicKey);
|
||||
// return Recipient.from(context, address, false);
|
||||
// }
|
||||
//
|
||||
// public String toString(Recipient sender) {
|
||||
// if (wasCurrentUserRemoved) {
|
||||
// return context.getString(R.string.GroupUtil_you_were_removed_from_group);
|
||||
// }
|
||||
//
|
||||
// StringBuilder description = new StringBuilder();
|
||||
// description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.toShortString()));
|
||||
//
|
||||
// if (groupContext == null) {
|
||||
// return description.toString();
|
||||
// }
|
||||
//
|
||||
// String title = groupContext.getName();
|
||||
//
|
||||
// if (!newMembers.isEmpty()) {
|
||||
// description.append("\n");
|
||||
// description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_joined_the_group,
|
||||
// newMembers.size(), toString(newMembers)));
|
||||
// }
|
||||
//
|
||||
// if (!removedMembers.isEmpty()) {
|
||||
// description.append("\n");
|
||||
// description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_removed_from_the_group,
|
||||
// removedMembers.size(), toString(removedMembers)));
|
||||
// }
|
||||
//
|
||||
// if (title != null && !title.trim().isEmpty()) {
|
||||
// String separator = (!newMembers.isEmpty() || !removedMembers.isEmpty()) ? " " : "\n";
|
||||
// description.append(separator);
|
||||
// description.append(context.getString(R.string.GroupUtil_group_name_is_now, title));
|
||||
// }
|
||||
//
|
||||
// return description.toString();
|
||||
// }
|
||||
//
|
||||
// public void addListener(RecipientModifiedListener listener) {
|
||||
// if (!this.newMembers.isEmpty()) {
|
||||
// for (Recipient member : this.newMembers) {
|
||||
// member.addListener(listener);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private String toString(List<Recipient> recipients) {
|
||||
// String result = "";
|
||||
//
|
||||
// for (int i=0;i<recipients.size();i++) {
|
||||
// result += recipients.get(i).toShortString();
|
||||
//
|
||||
// if (i != recipients.size() -1 )
|
||||
// result += ", ";
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
}
|
@ -22,6 +22,8 @@ import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
|
||||
/**
|
||||
* An input stream, which limits its data size. This stream is
|
||||
|
@ -1,45 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import android.database.ContentObserver;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.database.ObservableContent;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/**
|
||||
* Implementation of {@link androidx.lifecycle.LiveData} that will handle closing the contained
|
||||
* {@link Closeable} when the value changes.
|
||||
*/
|
||||
public class ObservingLiveData<E extends ObservableContent> extends MutableLiveData<E> {
|
||||
|
||||
private ContentObserver observer;
|
||||
|
||||
@Override
|
||||
public void setValue(E value) {
|
||||
E previous = getValue();
|
||||
|
||||
if (previous != null) {
|
||||
previous.unregisterContentObserver(observer);
|
||||
Util.close(previous);
|
||||
}
|
||||
|
||||
value.registerContentObserver(observer);
|
||||
|
||||
super.setValue(value);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
E value = getValue();
|
||||
|
||||
if (value != null) {
|
||||
value.unregisterContentObserver(observer);
|
||||
Util.close(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerContentObserver(@NonNull ContentObserver observer) {
|
||||
this.observer = observer;
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@ import java.lang.ref.WeakReference
|
||||
import java.text.SimpleDateFormat
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
import org.session.libsession.utilities.Util
|
||||
|
||||
/**
|
||||
* Saves attachment files to an external storage using [MediaStore] API.
|
||||
* Requires [android.Manifest.permission.WRITE_EXTERNAL_STORAGE] on API 28 and below.
|
||||
|
@ -16,72 +16,31 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Typeface;
|
||||
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;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
|
||||
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||
|
||||
import org.session.libsession.utilities.Base64;
|
||||
import org.session.libsession.utilities.LinkedBlockingLifoQueue;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.components.ComposeText;
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingLegacyMmsConnection;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import network.loki.messenger.BuildConfig;
|
||||
|
||||
public class Util {
|
||||
private static final String TAG = Util.class.getSimpleName();
|
||||
|
||||
private static volatile Handler handler;
|
||||
|
||||
public static <T> List<T> asList(T... elements) {
|
||||
List<T> result = new LinkedList<>();
|
||||
Collections.addAll(result, elements);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String join(String[] list, String delimiter) {
|
||||
return join(Arrays.asList(list), delimiter);
|
||||
@ -101,32 +60,6 @@ public class Util {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String join(long[] list, String delimeter) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int j=0;j<list.length;j++) {
|
||||
if (j != 0) sb.append(delimeter);
|
||||
sb.append(list[j]);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static ExecutorService newSingleThreadedLifoExecutor() {
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingLifoQueue<Runnable>());
|
||||
|
||||
executor.execute(() -> {
|
||||
// Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||
});
|
||||
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(EncodedStringValue[] value) {
|
||||
return value == null || value.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(ComposeText value) {
|
||||
return value == null || value.getText() == null || TextUtils.isEmpty(value.getTextTrimmed());
|
||||
}
|
||||
@ -135,19 +68,6 @@ public class Util {
|
||||
return collection == null || collection.isEmpty();
|
||||
}
|
||||
|
||||
public static <K, V> V getOrDefault(@NonNull Map<K, V> map, K key, V defaultValue) {
|
||||
return map.containsKey(key) ? map.get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public static String getFirstNonEmpty(String... values) {
|
||||
for (String value : values) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static <E> List<List<E>> chunk(@NonNull List<E> list, int chunkSize) {
|
||||
List<List<E>> chunks = new ArrayList<>(list.size() / chunkSize);
|
||||
|
||||
@ -159,78 +79,12 @@ public class Util {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public static CharSequence getBoldedString(String value) {
|
||||
SpannableString spanned = new SpannableString(value);
|
||||
spanned.setSpan(new StyleSpan(Typeface.BOLD), 0,
|
||||
spanned.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
return spanned;
|
||||
}
|
||||
|
||||
public static @NonNull String toIsoString(byte[] bytes) {
|
||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public static byte[] toIsoBytes(String isoString) {
|
||||
return isoString.getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public static byte[] toUtf8Bytes(String utf8String) {
|
||||
return utf8String.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void wait(Object lock, long timeout) {
|
||||
try {
|
||||
lock.wait(timeout);
|
||||
} catch (InterruptedException ie) {
|
||||
throw new AssertionError(ie);
|
||||
}
|
||||
}
|
||||
|
||||
public static void close(Closeable closeable) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static long getStreamLength(InputStream in) throws IOException {
|
||||
byte[] buffer = new byte[4096];
|
||||
int totalSize = 0;
|
||||
|
||||
int read;
|
||||
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
totalSize += read;
|
||||
}
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
public static boolean isOwnNumber(Context context, Address address) {
|
||||
if (address.isGroup()) return false;
|
||||
|
||||
return TextSecurePreferences.getLocalNumber(context).equals(address.serialize());
|
||||
}
|
||||
|
||||
public static void readFully(InputStream in, byte[] buffer) throws IOException {
|
||||
readFully(in, buffer, buffer.length);
|
||||
}
|
||||
|
||||
public static void readFully(InputStream in, byte[] buffer, int len) throws IOException {
|
||||
int offset = 0;
|
||||
|
||||
for (;;) {
|
||||
int read = in.read(buffer, offset, len - offset);
|
||||
if (read == -1) throw new EOFException("Stream ended early");
|
||||
|
||||
if (read + offset < len) offset += read;
|
||||
else return;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] readFully(InputStream in) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
@ -249,27 +103,6 @@ public class Util {
|
||||
return new String(readFully(in));
|
||||
}
|
||||
|
||||
public static long copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
long total = 0;
|
||||
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
total += read;
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
public static Optional<String> getSimCountryIso(Context context) {
|
||||
String simCountryIso = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso();
|
||||
return Optional.fromNullable(simCountryIso != null ? simCountryIso.toUpperCase() : null);
|
||||
}
|
||||
|
||||
public static <T> List<List<T>> partition(List<T> list, int partitionSize) {
|
||||
List<List<T>> results = new LinkedList<>();
|
||||
|
||||
@ -282,57 +115,6 @@ public class Util {
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<String> split(String source, String delimiter) {
|
||||
List<String> results = new LinkedList<>();
|
||||
|
||||
if (TextUtils.isEmpty(source)) {
|
||||
return results;
|
||||
}
|
||||
|
||||
String[] elements = source.split(delimiter);
|
||||
Collections.addAll(results, elements);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public static byte[][] split(byte[] input, int firstLength, int secondLength) {
|
||||
byte[][] parts = new byte[2][];
|
||||
|
||||
parts[0] = new byte[firstLength];
|
||||
System.arraycopy(input, 0, parts[0], 0, firstLength);
|
||||
|
||||
parts[1] = new byte[secondLength];
|
||||
System.arraycopy(input, firstLength, parts[1], 0, secondLength);
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
public static byte[] combine(byte[]... elements) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
for (byte[] element : elements) {
|
||||
baos.write(element);
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] trim(byte[] input, int length) {
|
||||
byte[] result = new byte[length];
|
||||
System.arraycopy(input, 0, result, 0, result.length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static boolean isDefaultSmsProvider(Context context){
|
||||
return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* The app version.
|
||||
* <p>
|
||||
@ -358,158 +140,8 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSecret(int size) {
|
||||
byte[] secret = getSecretBytes(size);
|
||||
return Base64.encodeBytes(secret);
|
||||
}
|
||||
|
||||
public static byte[] getSecretBytes(int size) {
|
||||
byte[] secret = new byte[size];
|
||||
getSecureRandom().nextBytes(secret);
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static SecureRandom getSecureRandom() {
|
||||
return new SecureRandom();
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
public static boolean isMmsCapable(Context context) {
|
||||
return (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) || OutgoingLegacyMmsConnection.isConnectionPossible(context);
|
||||
}
|
||||
|
||||
public static boolean isMainThread() {
|
||||
return Looper.myLooper() == Looper.getMainLooper();
|
||||
}
|
||||
|
||||
public static void assertMainThread() {
|
||||
if (!isMainThread()) {
|
||||
throw new AssertionError("Main-thread assertion failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void postToMain(final @NonNull Runnable runnable) {
|
||||
getHandler().post(runnable);
|
||||
}
|
||||
|
||||
public static void runOnMain(final @NonNull Runnable runnable) {
|
||||
if (isMainThread()) runnable.run();
|
||||
else getHandler().post(runnable);
|
||||
}
|
||||
|
||||
public static void runOnMainDelayed(final @NonNull Runnable runnable, long delayMillis) {
|
||||
getHandler().postDelayed(runnable, delayMillis);
|
||||
}
|
||||
|
||||
public static void cancelRunnableOnMain(@NonNull Runnable runnable) {
|
||||
getHandler().removeCallbacks(runnable);
|
||||
}
|
||||
|
||||
public static void runOnMainSync(final @NonNull Runnable runnable) {
|
||||
if (isMainThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
final CountDownLatch sync = new CountDownLatch(1);
|
||||
runOnMain(() -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
sync.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
sync.await();
|
||||
} catch (InterruptedException ie) {
|
||||
throw new AssertionError(ie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getRandomElement(T[] elements) {
|
||||
return elements[new SecureRandom().nextInt(elements.length)];
|
||||
}
|
||||
|
||||
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
||||
return a == b || (a != null && a.equals(b));
|
||||
}
|
||||
|
||||
public static int hashCode(@Nullable Object... objects) {
|
||||
return Arrays.hashCode(objects);
|
||||
}
|
||||
|
||||
public static @Nullable Uri uri(@Nullable String uri) {
|
||||
if (uri == null) return null;
|
||||
else return Uri.parse(uri);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.KITKAT)
|
||||
public static boolean isLowMemory(Context context) {
|
||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
|
||||
return (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) ||
|
||||
activityManager.getLargeMemoryClass() <= 64;
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
public static @Nullable String readTextFromClipboard(@NonNull Context context) {
|
||||
{
|
||||
ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
if (clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) {
|
||||
return clipboardManager.getPrimaryClip().getItemAt(0).getText().toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTextToClipboard(@NonNull Context context, @NonNull String text) {
|
||||
{
|
||||
ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboardManager.setPrimaryClip(ClipData.newPlainText("Safety numbers", text));
|
||||
}
|
||||
}
|
||||
|
||||
public static int toIntExact(long value) {
|
||||
if ((int)value != value) {
|
||||
throw new ArithmeticException("integer overflow");
|
||||
}
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
public static boolean isStringEquals(String first, String second) {
|
||||
if (first == null) return second == null;
|
||||
return first.equals(second);
|
||||
}
|
||||
|
||||
public static boolean isEquals(@Nullable Long first, long second) {
|
||||
return first != null && first == second;
|
||||
}
|
||||
|
||||
public static String getPrettyFileSize(long sizeBytes) {
|
||||
if (sizeBytes <= 0) return "0";
|
||||
|
||||
String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
|
||||
int digitGroups = (int) (Math.log10(sizeBytes) / Math.log10(1024));
|
||||
|
||||
return new DecimalFormat("#,##0.#").format(sizeBytes/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
|
||||
}
|
||||
|
||||
private static Handler getHandler() {
|
||||
if (handler == null) {
|
||||
synchronized (Util.class) {
|
||||
if (handler == null) {
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
public class WakeLockUtil {
|
||||
|
@ -10,7 +10,7 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.session.libsignal.libsignal.util.guava.Function;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
|
@ -10,7 +10,7 @@ import androidx.annotation.Nullable;
|
||||
import org.thoughtcrime.securesms.crypto.AttachmentSecret;
|
||||
import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream;
|
||||
import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
package org.session.libsession.utilities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
@ -10,17 +10,13 @@ import androidx.core.app.NotificationCompat
|
||||
import org.session.libsession.R
|
||||
import org.session.libsession.utilities.preferences.NotificationPrivacyPreference
|
||||
import org.session.libsignal.libsignal.logging.Log
|
||||
import org.session.libsignal.libsignal.util.Medium
|
||||
import org.session.libsignal.service.internal.util.Base64
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
|
||||
object TextSecurePreferences {
|
||||
private val TAG = TextSecurePreferences::class.simpleName
|
||||
|
||||
const val IDENTITY_PREF = "pref_choose_identity"
|
||||
const val CHANGE_PASSPHRASE_PREF = "pref_change_passphrase"
|
||||
const val DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase"
|
||||
const val THEME_PREF = "pref_theme"
|
||||
const val LANGUAGE_PREF = "pref_language"
|
||||
@ -40,20 +36,16 @@ object TextSecurePreferences {
|
||||
|
||||
private const val LAST_VERSION_CODE_PREF = "last_version_code"
|
||||
private const val LAST_EXPERIENCE_VERSION_PREF = "last_experience_version_code"
|
||||
private const val EXPERIENCE_DISMISSED_PREF = "experience_dismissed"
|
||||
const val RINGTONE_PREF = "pref_key_ringtone"
|
||||
const val VIBRATE_PREF = "pref_key_vibrate"
|
||||
private const val NOTIFICATION_PREF = "pref_key_enable_notifications"
|
||||
const val LED_COLOR_PREF = "pref_led_color"
|
||||
const val LED_BLINK_PREF = "pref_led_blink"
|
||||
private const val LED_BLINK_PREF_CUSTOM = "pref_led_blink_custom"
|
||||
const val ALL_MMS_PREF = "pref_all_mms"
|
||||
const val ALL_SMS_PREF = "pref_all_sms"
|
||||
const val PASSPHRASE_TIMEOUT_INTERVAL_PREF = "pref_timeout_interval"
|
||||
const val PASSPHRASE_TIMEOUT_PREF = "pref_timeout_passphrase"
|
||||
const val SCREEN_SECURITY_PREF = "pref_screen_security"
|
||||
private const val ENTER_SENDS_PREF = "pref_enter_sends"
|
||||
private const val ENTER_PRESENT_PREF = "pref_enter_key"
|
||||
private const val SMS_DELIVERY_REPORT_PREF = "pref_delivery_report_sms"
|
||||
const val MMS_USER_AGENT = "pref_mms_user_agent"
|
||||
private const val MMS_CUSTOM_USER_AGENT = "pref_custom_mms_user_agent"
|
||||
@ -63,39 +55,23 @@ object TextSecurePreferences {
|
||||
const val REGISTERED_GCM_PREF = "pref_gcm_registered"
|
||||
private const val GCM_PASSWORD_PREF = "pref_gcm_password"
|
||||
private const val SEEN_WELCOME_SCREEN_PREF = "pref_seen_welcome_screen"
|
||||
private const val PROMPTED_PUSH_REGISTRATION_PREF = "pref_prompted_push_registration"
|
||||
private const val PROMPTED_DEFAULT_SMS_PREF = "pref_prompted_default_sms"
|
||||
private const val PROMPTED_OPTIMIZE_DOZE_PREF = "pref_prompted_optimize_doze"
|
||||
private const val PROMPTED_SHARE_PREF = "pref_prompted_share"
|
||||
private const val SIGNALING_KEY_PREF = "pref_signaling_key"
|
||||
private const val DIRECTORY_FRESH_TIME_PREF = "pref_directory_refresh_time"
|
||||
private const val UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time"
|
||||
private const val UPDATE_APK_DOWNLOAD_ID = "pref_update_apk_download_id"
|
||||
private const val UPDATE_APK_DIGEST = "pref_update_apk_digest"
|
||||
private const val SIGNED_PREKEY_ROTATION_TIME_PREF = "pref_signed_pre_key_rotation_time"
|
||||
|
||||
private const val IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications"
|
||||
private const val SHOW_INVITE_REMINDER_PREF = "pref_show_invite_reminder"
|
||||
const val MESSAGE_BODY_TEXT_SIZE_PREF = "pref_message_body_text_size"
|
||||
|
||||
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"
|
||||
|
||||
private const val GCM_DISABLED_PREF = "pref_gcm_disabled"
|
||||
private const val GCM_REGISTRATION_ID_PREF = "pref_gcm_registration_id"
|
||||
private const val GCM_REGISTRATION_ID_VERSION_PREF = "pref_gcm_registration_id_version"
|
||||
private const val GCM_REGISTRATION_ID_TIME_PREF = "pref_gcm_registration_id_last_set_time"
|
||||
private const val WEBSOCKET_REGISTERED_PREF = "pref_websocket_registered"
|
||||
private const val RATING_LATER_PREF = "pref_rating_later"
|
||||
private const val RATING_ENABLED_PREF = "pref_rating_enabled"
|
||||
private const val SIGNED_PREKEY_FAILURE_COUNT_PREF = "pref_signed_prekey_failure_count"
|
||||
|
||||
const val REPEAT_ALERTS_PREF = "pref_repeat_alerts"
|
||||
const val NOTIFICATION_PRIVACY_PREF = "pref_notification_privacy"
|
||||
const val NOTIFICATION_PRIORITY_PREF = "pref_notification_priority"
|
||||
const val NEW_CONTACTS_NOTIFICATIONS = "pref_enable_new_contacts_notifications"
|
||||
const val WEBRTC_CALLING_PREF = "pref_webrtc_calling"
|
||||
|
||||
const val MEDIA_DOWNLOAD_MOBILE_PREF = "pref_media_download_mobile"
|
||||
const val MEDIA_DOWNLOAD_WIFI_PREF = "pref_media_download_wifi"
|
||||
@ -104,7 +80,6 @@ object TextSecurePreferences {
|
||||
const val SYSTEM_EMOJI_PREF = "pref_system_emoji"
|
||||
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"
|
||||
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"
|
||||
@ -112,7 +87,6 @@ object TextSecurePreferences {
|
||||
const val READ_RECEIPTS_PREF = "pref_read_receipts"
|
||||
const val INCOGNITO_KEYBORAD_PREF = "pref_incognito_keyboard"
|
||||
private const val UNAUTHORIZED_RECEIVED = "pref_unauthorized_received"
|
||||
private const val SUCCESSFUL_DIRECTORY_PREF = "pref_successful_directory"
|
||||
|
||||
private const val DATABASE_ENCRYPTED_SECRET = "pref_database_encrypted_secret"
|
||||
private const val DATABASE_UNENCRYPTED_SECRET = "pref_database_unencrypted_secret"
|
||||
@ -120,10 +94,6 @@ object TextSecurePreferences {
|
||||
private const val ATTACHMENT_UNENCRYPTED_SECRET = "pref_attachment_unencrypted_secret"
|
||||
private const val NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration"
|
||||
|
||||
private const val NEXT_PRE_KEY_ID = "pref_next_pre_key_id"
|
||||
private const val ACTIVE_SIGNED_PRE_KEY_ID = "pref_active_signed_pre_key_id"
|
||||
private const val NEXT_SIGNED_PRE_KEY_ID = "pref_next_signed_pre_key_id"
|
||||
|
||||
const val BACKUP_ENABLED = "pref_backup_enabled_v3"
|
||||
private const val BACKUP_PASSPHRASE = "pref_backup_passphrase"
|
||||
private const val ENCRYPTED_BACKUP_PASSPHRASE = "pref_encrypted_backup_passphrase"
|
||||
@ -134,9 +104,6 @@ object TextSecurePreferences {
|
||||
const val SCREEN_LOCK = "pref_android_screen_lock"
|
||||
const val SCREEN_LOCK_TIMEOUT = "pref_android_screen_lock_timeout"
|
||||
|
||||
private const val LAST_FULL_CONTACT_SYNC_TIME = "pref_last_full_contact_sync_time"
|
||||
private const val NEEDS_FULL_CONTACT_SYNC = "pref_needs_full_contact_sync"
|
||||
|
||||
private const val LOG_ENCRYPTED_SECRET = "pref_log_encrypted_secret"
|
||||
private const val LOG_UNENCRYPTED_SECRET = "pref_log_unencrypted_secret"
|
||||
|
||||
@ -145,11 +112,7 @@ object TextSecurePreferences {
|
||||
|
||||
private const val NEEDS_MESSAGE_PULL = "pref_needs_message_pull"
|
||||
|
||||
private const val UNIDENTIFIED_ACCESS_CERTIFICATE_ROTATION_TIME_PREF = "pref_unidentified_access_certificate_rotation_time"
|
||||
private const val UNIDENTIFIED_ACCESS_CERTIFICATE = "pref_unidentified_access_certificate"
|
||||
const val UNIVERSAL_UNIDENTIFIED_ACCESS = "pref_universal_unidentified_access"
|
||||
const val SHOW_UNIDENTIFIED_DELIVERY_INDICATORS = "pref_show_unidentifed_delivery_indicators"
|
||||
private const val UNIDENTIFIED_DELIVERY_ENABLED = "pref_unidentified_delivery_enabled"
|
||||
|
||||
const val TYPING_INDICATORS = "pref_typing_indicators"
|
||||
|
||||
@ -165,7 +128,6 @@ object TextSecurePreferences {
|
||||
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"
|
||||
|
||||
|
||||
@JvmStatic
|
||||
@ -264,36 +226,6 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, BACKUP_SAVE_DIR, null)
|
||||
}
|
||||
|
||||
fun getNextPreKeyId(context: Context): Int {
|
||||
return getIntegerPreference(context, NEXT_PRE_KEY_ID, SecureRandom().nextInt(Medium.MAX_VALUE))
|
||||
}
|
||||
|
||||
fun setNextPreKeyId(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, NEXT_PRE_KEY_ID, value)
|
||||
}
|
||||
|
||||
fun getNextSignedPreKeyId(context: Context): Int {
|
||||
return getIntegerPreference(context, NEXT_SIGNED_PRE_KEY_ID, SecureRandom().nextInt(Medium.MAX_VALUE))
|
||||
}
|
||||
|
||||
fun setNextSignedPreKeyId(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, NEXT_SIGNED_PRE_KEY_ID, value)
|
||||
}
|
||||
|
||||
fun getActiveSignedPreKeyId(context: Context): Int {
|
||||
return getIntegerPreference(context, ACTIVE_SIGNED_PRE_KEY_ID, -1)
|
||||
}
|
||||
|
||||
fun setActiveSignedPreKeyId(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, ACTIVE_SIGNED_PRE_KEY_ID, value)
|
||||
}
|
||||
|
||||
// TODO
|
||||
// fun setNeedsSqlCipherMigration(context: Context, value: Boolean) {
|
||||
// setBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, value)
|
||||
// org.greenrobot.eventbus.EventBus.getDefault().post(SqlCipherNeedsMigrationEvent())
|
||||
// }
|
||||
|
||||
@JvmStatic
|
||||
fun getNeedsSqlCipherMigration(context: Context): Boolean {
|
||||
return getBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, false)
|
||||
@ -339,23 +271,11 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, DATABASE_ENCRYPTED_SECRET, null)
|
||||
}
|
||||
|
||||
fun setHasSuccessfullyRetrievedDirectory(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, SUCCESSFUL_DIRECTORY_PREF, value)
|
||||
}
|
||||
|
||||
fun hasSuccessfullyRetrievedDirectory(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SUCCESSFUL_DIRECTORY_PREF, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setUnauthorizedReceived(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, UNAUTHORIZED_RECEIVED, value)
|
||||
}
|
||||
|
||||
fun isUnauthorizedRecieved(context: Context): Boolean {
|
||||
return getBooleanPreference(context, UNAUTHORIZED_RECEIVED, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isIncognitoKeyboardEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, INCOGNITO_KEYBORAD_PREF, true)
|
||||
@ -449,27 +369,11 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, MESSAGE_BODY_TEXT_SIZE_PREF, "16")!!.toInt()
|
||||
}
|
||||
|
||||
fun isTurnOnly(context: Context): Boolean {
|
||||
return getBooleanPreference(context, ALWAYS_RELAY_CALLS_PREF, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isFcmDisabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, GCM_DISABLED_PREF, false)
|
||||
}
|
||||
|
||||
fun setFcmDisabled(context: Context, disabled: Boolean) {
|
||||
setBooleanPreference(context, GCM_DISABLED_PREF, disabled)
|
||||
}
|
||||
|
||||
fun isWebrtcCallingEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, WEBRTC_CALLING_PREF, false)
|
||||
}
|
||||
|
||||
fun setWebrtcCallingEnabled(context: Context, enabled: Boolean) {
|
||||
setBooleanPreference(context, WEBRTC_CALLING_PREF, enabled)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setDirectCaptureCameraId(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, DIRECT_CAPTURE_CAMERA_ID, value)
|
||||
@ -480,57 +384,21 @@ object TextSecurePreferences {
|
||||
return getIntegerPreference(context, DIRECT_CAPTURE_CAMERA_ID, Camera.CameraInfo.CAMERA_FACING_FRONT)
|
||||
}
|
||||
|
||||
fun setMultiDevice(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isMultiDevice(context: Context): Boolean {
|
||||
return getBooleanPreference(context, MULTI_DEVICE_PROVISIONED_PREF, false)
|
||||
}
|
||||
|
||||
fun setSignedPreKeyFailureCount(context: Context, value: Int) {
|
||||
setIntegerPrefrence(context, SIGNED_PREKEY_FAILURE_COUNT_PREF, value)
|
||||
}
|
||||
|
||||
fun getSignedPreKeyFailureCount(context: Context): Int {
|
||||
return getIntegerPreference(context, SIGNED_PREKEY_FAILURE_COUNT_PREF, 0)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getNotificationPrivacy(context: Context): NotificationPrivacyPreference {
|
||||
return NotificationPrivacyPreference(getStringPreference(context, NOTIFICATION_PRIVACY_PREF, "all"))
|
||||
}
|
||||
|
||||
fun isNewContactsNotificationEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, NEW_CONTACTS_NOTIFICATIONS, true)
|
||||
}
|
||||
|
||||
fun getRatingLaterTimestamp(context: Context): Long {
|
||||
return getLongPreference(context, RATING_LATER_PREF, 0)
|
||||
}
|
||||
|
||||
fun setRatingLaterTimestamp(context: Context, timestamp: Long) {
|
||||
setLongPreference(context, RATING_LATER_PREF, timestamp)
|
||||
}
|
||||
|
||||
fun isRatingEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, RATING_ENABLED_PREF, true)
|
||||
}
|
||||
|
||||
fun setRatingEnabled(context: Context, enabled: Boolean) {
|
||||
setBooleanPreference(context, RATING_ENABLED_PREF, enabled)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isWebsocketRegistered(context: Context): Boolean {
|
||||
return getBooleanPreference(context, WEBSOCKET_REGISTERED_PREF, false)
|
||||
}
|
||||
|
||||
fun setWebsocketRegistered(context: Context, registered: Boolean) {
|
||||
setBooleanPreference(context, WEBSOCKET_REGISTERED_PREF, registered)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isWifiSmsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, WIFI_SMS_PREF, false)
|
||||
@ -546,18 +414,6 @@ object TextSecurePreferences {
|
||||
}
|
||||
}
|
||||
|
||||
fun setRepeatAlertsCount(context: Context, count: Int) {
|
||||
setStringPreference(context, REPEAT_ALERTS_PREF, count.toString())
|
||||
}
|
||||
|
||||
fun isSignedPreKeyRegistered(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SIGNED_PREKEY_REGISTERED_PREF, false)
|
||||
}
|
||||
|
||||
fun setSignedPreKeyRegistered(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, SIGNED_PREKEY_REGISTERED_PREF, value)
|
||||
}
|
||||
|
||||
fun getLocalRegistrationId(context: Context): Int {
|
||||
return getIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, 0)
|
||||
}
|
||||
@ -566,52 +422,16 @@ object TextSecurePreferences {
|
||||
setIntegerPrefrence(context, LOCAL_REGISTRATION_ID_PREF, registrationId)
|
||||
}
|
||||
|
||||
fun removeLocalRegistrationId(context: Context) {
|
||||
removePreference(context, LOCAL_REGISTRATION_ID_PREF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isInThreadNotifications(context: Context): Boolean {
|
||||
return getBooleanPreference(context, IN_THREAD_NOTIFICATION_PREF, true)
|
||||
}
|
||||
|
||||
fun getUnidentifiedAccessCertificateRotationTime(context: Context): Long {
|
||||
return getLongPreference(context, UNIDENTIFIED_ACCESS_CERTIFICATE_ROTATION_TIME_PREF, 0L)
|
||||
}
|
||||
|
||||
fun setUnidentifiedAccessCertificateRotationTime(context: Context, value: Long) {
|
||||
setLongPreference(context, UNIDENTIFIED_ACCESS_CERTIFICATE_ROTATION_TIME_PREF, value)
|
||||
}
|
||||
|
||||
fun setUnidentifiedAccessCertificate(context: Context, value: ByteArray?) {
|
||||
setStringPreference(context, UNIDENTIFIED_ACCESS_CERTIFICATE, Base64.encodeBytes(value))
|
||||
}
|
||||
|
||||
fun getUnidentifiedAccessCertificate(context: Context): ByteArray? {
|
||||
try {
|
||||
val result = getStringPreference(context, UNIDENTIFIED_ACCESS_CERTIFICATE, null)
|
||||
if (result != null) {
|
||||
return Base64.decode(result)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isUniversalUnidentifiedAccess(context: Context): Boolean {
|
||||
return getBooleanPreference(context, UNIVERSAL_UNIDENTIFIED_ACCESS, false)
|
||||
}
|
||||
|
||||
fun isShowUnidentifiedDeliveryIndicatorsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SHOW_UNIDENTIFIED_DELIVERY_INDICATORS, false)
|
||||
}
|
||||
|
||||
fun setIsUnidentifiedDeliveryEnabled(context: Context, enabled: Boolean) {
|
||||
setBooleanPreference(context, UNIDENTIFIED_DELIVERY_ENABLED, enabled)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isUnidentifiedDeliveryEnabled(context: Context): Boolean {
|
||||
// Loki - Always enable unidentified sender
|
||||
@ -619,22 +439,6 @@ object TextSecurePreferences {
|
||||
// return getBooleanPreference(context, UNIDENTIFIED_DELIVERY_ENABLED, true);
|
||||
}
|
||||
|
||||
fun getSignedPreKeyRotationTime(context: Context): Long {
|
||||
return getLongPreference(context, SIGNED_PREKEY_ROTATION_TIME_PREF, 0L)
|
||||
}
|
||||
|
||||
fun setSignedPreKeyRotationTime(context: Context, value: Long) {
|
||||
setLongPreference(context, SIGNED_PREKEY_ROTATION_TIME_PREF, value)
|
||||
}
|
||||
|
||||
fun getDirectoryRefreshTime(context: Context): Long {
|
||||
return getLongPreference(context, DIRECTORY_FRESH_TIME_PREF, 0L)
|
||||
}
|
||||
|
||||
fun setDirectoryRefreshTime(context: Context, value: Long) {
|
||||
setLongPreference(context, DIRECTORY_FRESH_TIME_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getUpdateApkRefreshTime(context: Context): Long {
|
||||
return getLongPreference(context, UPDATE_APK_REFRESH_TIME_PREF, 0L)
|
||||
@ -683,19 +487,11 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, GCM_PASSWORD_PREF, null)
|
||||
}
|
||||
|
||||
fun setPushServerPassword(context: Context, password: String?) {
|
||||
setStringPreference(context, GCM_PASSWORD_PREF, password)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getSignalingKey(context: Context): String? {
|
||||
return getStringPreference(context, SIGNALING_KEY_PREF, null)
|
||||
}
|
||||
|
||||
fun isEnterImeKeyEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, ENTER_PRESENT_PREF, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isEnterSendsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, ENTER_SENDS_PREF, false)
|
||||
@ -716,113 +512,61 @@ object TextSecurePreferences {
|
||||
return getBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, legacy)
|
||||
}
|
||||
|
||||
fun setUseCustomMmsc(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MMSC_CUSTOM_HOST_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmscUrl(context: Context): String? {
|
||||
return getStringPreference(context, MMSC_HOST_PREF, "")
|
||||
}
|
||||
|
||||
fun setMmscUrl(context: Context, mmsc: String?) {
|
||||
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)
|
||||
}
|
||||
|
||||
fun setUseCustomMmscProxy(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MMSC_CUSTOM_PROXY_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmscProxy(context: Context): String? {
|
||||
return getStringPreference(context, MMSC_PROXY_HOST_PREF, "")
|
||||
}
|
||||
|
||||
fun setMmscProxy(context: Context, value: String?) {
|
||||
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)
|
||||
}
|
||||
|
||||
fun setUseCustomMmscProxyPort(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MMSC_CUSTOM_PROXY_PORT_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmscProxyPort(context: Context): String? {
|
||||
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "")
|
||||
}
|
||||
|
||||
fun setMmscProxyPort(context: Context, value: String?) {
|
||||
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)
|
||||
}
|
||||
|
||||
fun setUseCustomMmscUsername(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MMSC_CUSTOM_USERNAME_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmscUsername(context: Context): String? {
|
||||
return getStringPreference(context, MMSC_USERNAME_PREF, "")
|
||||
}
|
||||
|
||||
fun setMmscUsername(context: Context, value: String?) {
|
||||
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)
|
||||
}
|
||||
|
||||
fun setUseCustomMmscPassword(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, MMSC_CUSTOM_PASSWORD_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmscPassword(context: Context): String? {
|
||||
return getStringPreference(context, MMSC_PASSWORD_PREF, "")
|
||||
}
|
||||
|
||||
fun setMmscPassword(context: Context, value: String?) {
|
||||
setStringPreference(context, MMSC_PASSWORD_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMmsUserAgent(context: Context, defaultUserAgent: String): String {
|
||||
val useCustom: Boolean = getBooleanPreference(context, MMS_CUSTOM_USER_AGENT, false)
|
||||
return if (useCustom) getStringPreference(context, MMS_USER_AGENT, defaultUserAgent)!! else defaultUserAgent
|
||||
}
|
||||
|
||||
fun getIdentityContactUri(context: Context): String? {
|
||||
return getStringPreference(context, IDENTITY_PREF, null)
|
||||
}
|
||||
|
||||
fun setIdentityContactUri(context: Context, identityUri: String?) {
|
||||
setStringPreference(context, IDENTITY_PREF, identityUri)
|
||||
}
|
||||
|
||||
fun setScreenSecurityEnabled(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, SCREEN_SECURITY_PREF, value)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isScreenSecurityEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SCREEN_SECURITY_PREF, true)
|
||||
@ -843,22 +587,10 @@ object TextSecurePreferences {
|
||||
}
|
||||
}
|
||||
|
||||
fun getLastExperienceVersionCode(context: Context): Int {
|
||||
return getIntegerPreference(context, LAST_EXPERIENCE_VERSION_PREF, 0)
|
||||
}
|
||||
|
||||
fun setLastExperienceVersionCode(context: Context, versionCode: Int) {
|
||||
setIntegerPrefrence(context, LAST_EXPERIENCE_VERSION_PREF, versionCode)
|
||||
}
|
||||
|
||||
fun getExperienceDismissedVersionCode(context: Context): Int {
|
||||
return getIntegerPreference(context, EXPERIENCE_DISMISSED_PREF, 0)
|
||||
}
|
||||
|
||||
fun setExperienceDismissedVersionCode(context: Context, versionCode: Int) {
|
||||
setIntegerPrefrence(context, EXPERIENCE_DISMISSED_PREF, versionCode)
|
||||
}
|
||||
|
||||
fun getTheme(context: Context): String? {
|
||||
return getStringPreference(context, THEME_PREF, "light")
|
||||
}
|
||||
@ -868,24 +600,11 @@ object TextSecurePreferences {
|
||||
return getBooleanPreference(context, VERIFYING_STATE_PREF, false)
|
||||
}
|
||||
|
||||
fun setVerifying(context: Context, verifying: Boolean) {
|
||||
setBooleanPreference(context, VERIFYING_STATE_PREF, verifying)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isPushRegistered(context: Context): Boolean {
|
||||
return getBooleanPreference(context, REGISTERED_GCM_PREF, false)
|
||||
}
|
||||
|
||||
fun setPushRegistered(context: Context, registered: Boolean) {
|
||||
Log.i(TAG, "Setting push registered: $registered")
|
||||
setBooleanPreference(context, REGISTERED_GCM_PREF, registered)
|
||||
}
|
||||
|
||||
fun isShowInviteReminders(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SHOW_INVITE_REMINDER_PREF, true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isPassphraseTimeoutEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PASSPHRASE_TIMEOUT_PREF, false)
|
||||
@ -896,19 +615,11 @@ object TextSecurePreferences {
|
||||
return getIntegerPreference(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, 5 * 60)
|
||||
}
|
||||
|
||||
fun setPassphraseTimeoutInterval(context: Context, interval: Int) {
|
||||
setIntegerPrefrence(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, interval)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLanguage(context: Context): String? {
|
||||
return getStringPreference(context, LANGUAGE_PREF, "zz")
|
||||
}
|
||||
|
||||
fun setLanguage(context: Context, language: String?) {
|
||||
setStringPreference(context, LANGUAGE_PREF, language)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isSmsDeliveryReportsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, SMS_DELIVERY_REPORT_PREF, false)
|
||||
@ -923,46 +634,6 @@ object TextSecurePreferences {
|
||||
setBooleanPreference(context, SEEN_WELCOME_SCREEN_PREF, value)
|
||||
}
|
||||
|
||||
fun hasPromptedPushRegistration(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, false)
|
||||
}
|
||||
|
||||
fun setPromptedPushRegistration(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, value)
|
||||
}
|
||||
|
||||
fun hasPromptedDefaultSmsProvider(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PROMPTED_DEFAULT_SMS_PREF, false)
|
||||
}
|
||||
|
||||
fun setPromptedDefaultSmsProvider(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, PROMPTED_DEFAULT_SMS_PREF, value)
|
||||
}
|
||||
|
||||
fun setPromptedOptimizeDoze(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, PROMPTED_OPTIMIZE_DOZE_PREF, value)
|
||||
}
|
||||
|
||||
fun hasPromptedOptimizeDoze(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PROMPTED_OPTIMIZE_DOZE_PREF, false)
|
||||
}
|
||||
|
||||
fun hasPromptedShare(context: Context): Boolean {
|
||||
return getBooleanPreference(context, PROMPTED_SHARE_PREF, false)
|
||||
}
|
||||
|
||||
fun setPromptedShare(context: Context, value: Boolean) {
|
||||
setBooleanPreference(context, PROMPTED_SHARE_PREF, value)
|
||||
}
|
||||
|
||||
fun isInterceptAllMmsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, ALL_MMS_PREF, true)
|
||||
}
|
||||
|
||||
fun isInterceptAllSmsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, ALL_SMS_PREF, true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isNotificationsEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, NOTIFICATION_PREF, true)
|
||||
@ -1012,10 +683,6 @@ object TextSecurePreferences {
|
||||
return getStringPreference(context, LED_BLINK_PREF_CUSTOM, "500,2000")
|
||||
}
|
||||
|
||||
fun setNotificationLedPatternCustom(context: Context, pattern: String?) {
|
||||
setStringPreference(context, LED_BLINK_PREF_CUSTOM, pattern)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isThreadLengthTrimmingEnabled(context: Context): Boolean {
|
||||
return getBooleanPreference(context, THREAD_TRIM_ENABLED, false)
|
||||
@ -1050,22 +717,6 @@ object TextSecurePreferences {
|
||||
return getStringSetPreference(context, key, HashSet(Arrays.asList(*context.resources.getStringArray(defaultValuesRes))))
|
||||
}
|
||||
|
||||
fun getLastFullContactSyncTime(context: Context): Long {
|
||||
return getLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, 0)
|
||||
}
|
||||
|
||||
fun setLastFullContactSyncTime(context: Context, timestamp: Long) {
|
||||
setLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, timestamp)
|
||||
}
|
||||
|
||||
fun needsFullContactSync(context: Context): Boolean {
|
||||
return getBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, false)
|
||||
}
|
||||
|
||||
fun setNeedsFullContactSync(context: Context, needsSync: Boolean) {
|
||||
setBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, needsSync)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLogEncryptedSecret(context: Context, base64Secret: String?) {
|
||||
setStringPreference(context, LOG_ENCRYPTED_SECRET, base64Secret)
|
||||
@ -1191,30 +842,6 @@ object TextSecurePreferences {
|
||||
}
|
||||
|
||||
// region Loki
|
||||
fun getBackgroundPollTime(context: Context): Long {
|
||||
return getLongPreference(context, "background_poll_time", 0L)
|
||||
}
|
||||
|
||||
fun setBackgroundPollTime(context: Context, backgroundPollTime: Long) {
|
||||
setLongPreference(context, "background_poll_time", backgroundPollTime)
|
||||
}
|
||||
|
||||
fun getOpenGroupBackgroundPollTime(context: Context): Long {
|
||||
return getLongPreference(context, "public_chat_background_poll_time", 0L)
|
||||
}
|
||||
|
||||
fun setOpenGroupBackgroundPollTime(context: Context, backgroundPollTime: Long) {
|
||||
setLongPreference(context, "public_chat_background_poll_time", backgroundPollTime)
|
||||
}
|
||||
|
||||
fun isChatSetUp(context: Context, id: String): Boolean {
|
||||
return getBooleanPreference(context, "is_chat_set_up?chat=$id", false)
|
||||
}
|
||||
|
||||
fun markChatSetUp(context: Context, id: String) {
|
||||
setBooleanPreference(context, "is_chat_set_up?chat=$id", true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMasterHexEncodedPublicKey(context: Context): String? {
|
||||
return getStringPreference(context, "master_hex_encoded_public_key", null)
|
||||
@ -1232,14 +859,6 @@ object TextSecurePreferences {
|
||||
setBooleanPreference(context, "has_viewed_seed", hasViewedSeed)
|
||||
}
|
||||
|
||||
fun setNeedsDatabaseReset(context: Context, resetDatabase: Boolean) {
|
||||
getDefaultSharedPreferences(context).edit().putBoolean("database_reset", resetDatabase).commit()
|
||||
}
|
||||
|
||||
fun getNeedsDatabaseReset(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "database_reset", false)
|
||||
}
|
||||
|
||||
fun setWasUnlinked(context: Context, value: Boolean) {
|
||||
// We do it this way so that it gets persisted in storage straight away
|
||||
getDefaultSharedPreferences(context).edit().putBoolean("database_reset_unpair", value).commit()
|
||||
@ -1265,14 +884,6 @@ object TextSecurePreferences {
|
||||
return getLongPreference(context, "restoration_time", 0)
|
||||
}
|
||||
|
||||
fun getHasSeenOpenGroupSuggestionSheet(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_seen_open_group_suggestion_sheet", false)
|
||||
}
|
||||
|
||||
fun setHasSeenOpenGroupSuggestionSheet(context: Context) {
|
||||
setBooleanPreference(context, "has_seen_open_group_suggestion_sheet", true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLastProfilePictureUpload(context: Context): Long {
|
||||
return getLongPreference(context, "last_profile_picture_upload", 0)
|
||||
@ -1298,22 +909,6 @@ object TextSecurePreferences {
|
||||
getDefaultSharedPreferences(context).edit().clear().commit()
|
||||
}
|
||||
|
||||
fun getHasSeenMultiDeviceRemovalSheet(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_seen_multi_device_removal_sheet", false)
|
||||
}
|
||||
|
||||
fun setHasSeenMultiDeviceRemovalSheet(context: Context) {
|
||||
setBooleanPreference(context, "has_seen_multi_device_removal_sheet", true)
|
||||
}
|
||||
|
||||
fun hasSeenLightThemeIntroSheet(context: Context): Boolean {
|
||||
return getBooleanPreference(context, "has_seen_light_theme_intro_sheet", false)
|
||||
}
|
||||
|
||||
fun setHasSeenLightThemeIntroSheet(context: Context) {
|
||||
setBooleanPreference(context, "has_seen_light_theme_intro_sheet", true)
|
||||
}
|
||||
|
||||
fun getLastSnodePoolRefreshDate(context: Context?): Long {
|
||||
return getLongPreference(context!!, "last_snode_pool_refresh_date", 0)
|
||||
}
|
||||
@ -1322,14 +917,6 @@ object TextSecurePreferences {
|
||||
setLongPreference(context!!, "last_snode_pool_refresh_date", date.time)
|
||||
}
|
||||
|
||||
fun getLastKeyPairMigrationNudge(context: Context?): Long {
|
||||
return getLongPreference(context!!, "last_key_pair_migration_nudge", 0)
|
||||
}
|
||||
|
||||
fun setLastKeyPairMigrationNudge(context: Context?, newValue: Long) {
|
||||
setLongPreference(context!!, "last_key_pair_migration_nudge", newValue)
|
||||
}
|
||||
|
||||
fun getIsMigratingKeyPair(context: Context?): Boolean {
|
||||
return getBooleanPreference(context!!, "is_migrating_key_pair", false)
|
||||
}
|
||||
@ -1338,7 +925,6 @@ object TextSecurePreferences {
|
||||
fun setIsMigratingKeyPair(context: Context?, newValue: Boolean) {
|
||||
setBooleanPreference(context!!, "is_migrating_key_pair", newValue)
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@ import org.session.libsignal.libsignal.logging.Log
|
||||
import java.io.*
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.SecureRandom
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.ExecutorService
|
||||
@ -43,16 +44,16 @@ object Util {
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun copy(`in`: InputStream, out: OutputStream): Long {
|
||||
fun copy(`in`: InputStream, out: OutputStream?): Long {
|
||||
val buffer = ByteArray(8192)
|
||||
var read: Int
|
||||
var total: Long = 0
|
||||
while (`in`.read(buffer).also { read = it } != -1) {
|
||||
out.write(buffer, 0, read)
|
||||
out?.write(buffer, 0, read)
|
||||
total += read.toLong()
|
||||
}
|
||||
`in`.close()
|
||||
out.close()
|
||||
out?.close()
|
||||
return total
|
||||
}
|
||||
|
||||
@ -327,4 +328,39 @@ object Util {
|
||||
return spanned
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun clamp(value: Int, min: Int, max: Int): Int {
|
||||
return Math.min(Math.max(value, min), max)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun combine(vararg elements: ByteArray?): ByteArray? {
|
||||
return try {
|
||||
val baos = ByteArrayOutputStream()
|
||||
for (element in elements) {
|
||||
baos.write(element)
|
||||
}
|
||||
baos.toByteArray()
|
||||
} catch (e: IOException) {
|
||||
throw java.lang.AssertionError(e)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun split(input: ByteArray?, firstLength: Int, secondLength: Int): Array<ByteArray?> {
|
||||
val parts = arrayOfNulls<ByteArray>(2)
|
||||
parts[0] = ByteArray(firstLength)
|
||||
System.arraycopy(input, 0, parts[0], 0, firstLength)
|
||||
parts[1] = ByteArray(secondLength)
|
||||
System.arraycopy(input, firstLength, parts[1], 0, secondLength)
|
||||
return parts
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getPrettyFileSize(sizeBytes: Long): String {
|
||||
if (sizeBytes <= 0) return "0"
|
||||
val units = arrayOf("B", "kB", "MB", "GB", "TB")
|
||||
val digitGroups = (Math.log10(sizeBytes.toDouble()) / Math.log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.#").format(sizeBytes / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user