2014-07-25 15:14:29 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2020-03-27 16:36:24 -03:00
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Build;
|
2019-06-30 00:45:59 -04:00
|
|
|
|
2020-03-27 16:36:24 -03:00
|
|
|
import androidx.annotation.NonNull;
|
2020-09-01 19:13:35 -04:00
|
|
|
import androidx.annotation.Nullable;
|
2020-12-20 14:45:51 -05:00
|
|
|
import androidx.annotation.WorkerThread;
|
2019-10-07 15:43:36 -03:00
|
|
|
import androidx.appcompat.app.AppCompatDelegate;
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.multidex.MultiDexApplication;
|
2017-01-11 15:37:51 -08:00
|
|
|
|
|
|
|
import com.google.android.gms.security.ProviderInstaller;
|
2015-05-21 12:30:18 -07:00
|
|
|
|
2019-05-01 09:00:26 -07:00
|
|
|
import org.conscrypt.Conscrypt;
|
2021-09-15 16:46:34 -04:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
2019-05-01 09:00:26 -07:00
|
|
|
import org.signal.aesgcmprovider.AesGcmProvider;
|
2020-12-04 18:31:58 -05:00
|
|
|
import org.signal.core.util.concurrent.SignalExecutors;
|
|
|
|
import org.signal.core.util.logging.AndroidLogger;
|
|
|
|
import org.signal.core.util.logging.Log;
|
2020-12-20 00:44:26 -05:00
|
|
|
import org.signal.core.util.tracing.Tracer;
|
2020-09-01 19:13:35 -04:00
|
|
|
import org.signal.glide.SignalGlideCodecs;
|
2022-03-24 13:23:23 -04:00
|
|
|
import org.signal.libsignal.protocol.logging.SignalProtocolLoggerProvider;
|
2020-02-11 19:56:16 -08:00
|
|
|
import org.signal.ringrtc.CallManager;
|
2021-07-20 13:08:52 -03:00
|
|
|
import org.thoughtcrime.securesms.avatar.AvatarPickerStorage;
|
2021-11-18 12:36:52 -05:00
|
|
|
import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider;
|
|
|
|
import org.thoughtcrime.securesms.crypto.DatabaseSecretProvider;
|
2021-07-23 07:39:16 -04:00
|
|
|
import org.thoughtcrime.securesms.database.LogDatabase;
|
2022-01-21 18:11:49 -05:00
|
|
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
2022-02-23 13:16:25 -05:00
|
|
|
import org.thoughtcrime.securesms.database.SqlCipherLibraryLoader;
|
2019-07-15 11:12:26 -04:00
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencyProvider;
|
2021-04-19 10:36:33 -03:00
|
|
|
import org.thoughtcrime.securesms.emoji.EmojiSource;
|
2022-02-23 13:16:25 -05:00
|
|
|
import org.thoughtcrime.securesms.emoji.JumboEmoji;
|
2019-05-31 17:12:41 -04:00
|
|
|
import org.thoughtcrime.securesms.gcm.FcmJobService;
|
2022-03-04 13:30:22 -05:00
|
|
|
import org.thoughtcrime.securesms.jobs.CheckServiceReachabilityJob;
|
2016-03-11 17:07:22 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
2021-04-19 10:36:33 -03:00
|
|
|
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob;
|
2021-05-26 10:47:14 -03:00
|
|
|
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob;
|
2019-01-24 03:04:28 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.FcmRefreshJob;
|
2022-02-24 13:40:28 -04:00
|
|
|
import org.thoughtcrime.securesms.jobs.FontDownloaderJob;
|
2022-03-11 09:45:07 -05:00
|
|
|
import org.thoughtcrime.securesms.jobs.GroupV2UpdateSelfProfileKeyJob;
|
2018-07-06 17:28:58 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2021-11-23 14:06:37 -05:00
|
|
|
import org.thoughtcrime.securesms.jobs.ProfileUploadJob;
|
2018-10-05 15:23:33 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
2020-02-19 14:16:31 -05:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
2020-06-12 10:22:46 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
2022-02-23 13:16:25 -05:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveReleaseChannelJob;
|
2021-11-10 11:33:00 -04:00
|
|
|
import org.thoughtcrime.securesms.jobs.SubscriptionKeepAliveJob;
|
2020-09-08 18:03:56 -04:00
|
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
2018-07-26 10:10:46 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger;
|
2021-07-19 18:30:04 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.PersistentLogger;
|
2021-02-10 14:01:11 -04:00
|
|
|
import org.thoughtcrime.securesms.messageprocessingalarm.MessageProcessReceiver;
|
2019-07-29 19:02:40 -04:00
|
|
|
import org.thoughtcrime.securesms.migrations.ApplicationMigrations;
|
2021-12-10 15:31:46 -05:00
|
|
|
import org.thoughtcrime.securesms.mms.SignalGlideComponents;
|
2022-02-23 13:16:25 -05:00
|
|
|
import org.thoughtcrime.securesms.mms.SignalGlideModule;
|
2018-08-06 12:20:24 -04:00
|
|
|
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
2019-02-25 17:47:30 -08:00
|
|
|
import org.thoughtcrime.securesms.providers.BlobProvider;
|
2021-05-05 12:49:18 -04:00
|
|
|
import org.thoughtcrime.securesms.ratelimit.RateLimitUtil;
|
2021-11-23 14:06:37 -05:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2020-04-23 12:03:23 -04:00
|
|
|
import org.thoughtcrime.securesms.registration.RegistrationUtil;
|
2019-10-29 19:32:23 -07:00
|
|
|
import org.thoughtcrime.securesms.ringrtc.RingRtcLogger;
|
2017-01-06 09:19:58 -08:00
|
|
|
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
2018-10-15 13:27:21 -07:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
2018-02-26 09:58:18 -08:00
|
|
|
import org.thoughtcrime.securesms.service.LocalBackupListener;
|
2018-05-22 02:13:10 -07:00
|
|
|
import org.thoughtcrime.securesms.service.RotateSenderCertificateListener;
|
2017-01-06 09:19:58 -08:00
|
|
|
import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener;
|
2017-02-26 14:36:43 -08:00
|
|
|
import org.thoughtcrime.securesms.service.UpdateApkRefreshListener;
|
2022-02-23 13:16:25 -05:00
|
|
|
import org.thoughtcrime.securesms.service.webrtc.AndroidTelecomUtil;
|
2020-03-18 16:31:45 -04:00
|
|
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
2021-02-08 15:37:45 -05:00
|
|
|
import org.thoughtcrime.securesms.util.AppForegroundObserver;
|
2020-12-20 14:45:51 -05:00
|
|
|
import org.thoughtcrime.securesms.util.AppStartup;
|
2020-11-11 15:14:54 -04:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2019-12-19 17:41:21 -05:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
2021-08-04 10:01:14 -04:00
|
|
|
import org.thoughtcrime.securesms.util.SignalLocalMetrics;
|
2020-12-04 18:31:58 -05:00
|
|
|
import org.thoughtcrime.securesms.util.SignalUncaughtExceptionHandler;
|
2014-07-25 15:14:29 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2020-09-08 18:03:56 -04:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2021-01-13 17:33:14 -05:00
|
|
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
2019-03-25 17:23:38 -03:00
|
|
|
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper;
|
2014-07-25 15:14:29 -07:00
|
|
|
|
2021-12-08 13:22:36 -05:00
|
|
|
import java.net.SocketException;
|
|
|
|
import java.net.SocketTimeoutException;
|
2019-05-01 09:00:26 -07:00
|
|
|
import java.security.Security;
|
2017-03-17 10:28:06 -07:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2021-12-08 13:22:36 -05:00
|
|
|
import io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException;
|
|
|
|
import io.reactivex.rxjava3.exceptions.UndeliverableException;
|
2021-07-08 11:41:26 -04:00
|
|
|
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
|
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
2021-12-08 13:22:36 -05:00
|
|
|
import rxdogtag2.RxDogTag;
|
2021-07-08 11:41:26 -04:00
|
|
|
|
2014-07-25 15:14:29 -07:00
|
|
|
/**
|
|
|
|
* Will be called once when the TextSecure process is created.
|
|
|
|
*
|
|
|
|
* We're using this as an insertion point to patch up the Android PRNG disaster,
|
|
|
|
* to initialize the job manager, and to check for GCM registration freshness.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2021-02-08 15:37:45 -05:00
|
|
|
public class ApplicationContext extends MultiDexApplication implements AppForegroundObserver.Listener {
|
2014-07-25 15:14:29 -07:00
|
|
|
|
2021-03-29 18:37:22 -04:00
|
|
|
private static final String TAG = Log.tag(ApplicationContext.class);
|
2017-01-11 15:37:51 -08:00
|
|
|
|
2021-04-13 14:49:32 -04:00
|
|
|
private PersistentLogger persistentLogger;
|
2014-07-25 15:14:29 -07:00
|
|
|
|
|
|
|
public static ApplicationContext getInstance(Context context) {
|
|
|
|
return (ApplicationContext)context.getApplicationContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2020-12-10 11:45:15 -05:00
|
|
|
Tracer.getInstance().start("Application#onCreate()");
|
2021-01-06 15:31:33 -05:00
|
|
|
AppStartup.getInstance().onApplicationCreate();
|
2021-08-04 10:01:14 -04:00
|
|
|
SignalLocalMetrics.ColdStart.start();
|
2020-12-20 00:44:26 -05:00
|
|
|
|
2020-06-22 17:01:40 -07:00
|
|
|
long startTime = System.currentTimeMillis();
|
2020-12-10 11:45:15 -05:00
|
|
|
|
2020-12-20 00:44:26 -05:00
|
|
|
if (FeatureFlags.internalUser()) {
|
|
|
|
Tracer.getInstance().setMaxBufferSize(35_000);
|
|
|
|
}
|
|
|
|
|
2018-10-04 09:09:04 -07:00
|
|
|
super.onCreate();
|
2020-12-10 11:45:15 -05:00
|
|
|
|
2021-01-06 15:31:33 -05:00
|
|
|
AppStartup.getInstance().addBlocking("security-provider", this::initializeSecurityProvider)
|
2021-11-18 12:36:52 -05:00
|
|
|
.addBlocking("sqlcipher-init", () -> {
|
|
|
|
SqlCipherLibraryLoader.load();
|
|
|
|
SignalDatabase.init(this,
|
|
|
|
DatabaseSecretProvider.getOrCreateDatabaseSecret(this),
|
|
|
|
AttachmentSecretProvider.getInstance(this).getOrCreateAttachmentSecret());
|
|
|
|
})
|
2021-01-06 15:31:33 -05:00
|
|
|
.addBlocking("logging", () -> {
|
2021-07-08 11:41:26 -04:00
|
|
|
initializeLogging();
|
|
|
|
Log.i(TAG, "onCreate()");
|
2021-01-06 15:31:33 -05:00
|
|
|
})
|
|
|
|
.addBlocking("crash-handling", this::initializeCrashHandling)
|
2021-12-08 13:22:36 -05:00
|
|
|
.addBlocking("rx-init", this::initializeRx)
|
2021-09-15 16:46:34 -04:00
|
|
|
.addBlocking("event-bus", () -> EventBus.builder().logNoSubscriberMessages(false).installDefaultEventBus())
|
2021-01-06 15:31:33 -05:00
|
|
|
.addBlocking("app-dependencies", this::initializeAppDependencies)
|
2021-02-16 14:22:50 -05:00
|
|
|
.addBlocking("notification-channels", () -> NotificationChannels.create(this))
|
2021-01-06 15:31:33 -05:00
|
|
|
.addBlocking("first-launch", this::initializeFirstEverAppLaunch)
|
|
|
|
.addBlocking("app-migrations", this::initializeApplicationMigrations)
|
|
|
|
.addBlocking("ring-rtc", this::initializeRingRtc)
|
|
|
|
.addBlocking("mark-registration", () -> RegistrationUtil.maybeMarkRegistrationComplete(this))
|
2021-02-08 15:37:45 -05:00
|
|
|
.addBlocking("lifecycle-observer", () -> ApplicationDependencies.getAppForegroundObserver().addListener(this))
|
2021-01-12 02:05:53 -05:00
|
|
|
.addBlocking("message-retriever", this::initializeMessageRetrieval)
|
2021-01-06 15:31:33 -05:00
|
|
|
.addBlocking("dynamic-theme", () -> DynamicTheme.setDefaultDayNightMode(this))
|
|
|
|
.addBlocking("vector-compat", () -> {
|
|
|
|
if (Build.VERSION.SDK_INT < 21) {
|
|
|
|
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
|
|
|
}
|
|
|
|
})
|
2021-02-02 16:42:47 -05:00
|
|
|
.addBlocking("proxy-init", () -> {
|
|
|
|
if (SignalStore.proxy().isProxyEnabled()) {
|
|
|
|
Log.w(TAG, "Proxy detected. Enabling Conscrypt.setUseEngineSocketByDefault()");
|
|
|
|
Conscrypt.setUseEngineSocketByDefault(true);
|
|
|
|
}
|
|
|
|
})
|
2021-02-24 16:04:58 -05:00
|
|
|
.addBlocking("blob-provider", this::initializeBlobProvider)
|
2021-04-14 18:49:31 -04:00
|
|
|
.addBlocking("feature-flags", FeatureFlags::init)
|
2021-12-10 15:31:46 -05:00
|
|
|
.addBlocking("glide", () -> SignalGlideModule.setRegisterGlideComponents(new SignalGlideComponents()))
|
2021-07-20 13:08:52 -03:00
|
|
|
.addNonBlocking(this::cleanAvatarStorage)
|
2021-01-06 15:31:33 -05:00
|
|
|
.addNonBlocking(this::initializeRevealableMessageManager)
|
2021-05-14 14:03:35 -04:00
|
|
|
.addNonBlocking(this::initializePendingRetryReceiptManager)
|
2021-11-17 15:08:28 -05:00
|
|
|
.addNonBlocking(this::initializeFcmCheck)
|
2022-02-01 14:09:04 -05:00
|
|
|
.addNonBlocking(CreateSignedPreKeyJob::enqueueIfNeeded)
|
2021-01-06 15:31:33 -05:00
|
|
|
.addNonBlocking(this::initializePeriodicTasks)
|
|
|
|
.addNonBlocking(this::initializeCircumvention)
|
|
|
|
.addNonBlocking(this::initializePendingMessages)
|
|
|
|
.addNonBlocking(this::initializeCleanup)
|
|
|
|
.addNonBlocking(this::initializeGlideCodecs)
|
|
|
|
.addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary)
|
|
|
|
.addNonBlocking(StorageSyncHelper::scheduleRoutineSync)
|
|
|
|
.addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop())
|
2021-04-19 10:36:33 -03:00
|
|
|
.addNonBlocking(EmojiSource::refresh)
|
2021-09-03 16:32:16 -04:00
|
|
|
.addNonBlocking(() -> ApplicationDependencies.getGiphyMp4Cache().onAppStart(this))
|
2021-11-23 14:06:37 -05:00
|
|
|
.addNonBlocking(this::ensureProfileUploaded)
|
2022-02-24 13:40:28 -04:00
|
|
|
.addNonBlocking(() -> ApplicationDependencies.getExpireStoriesManager().scheduleIfNecessary())
|
2021-05-05 12:49:18 -04:00
|
|
|
.addPostRender(() -> RateLimitUtil.retryAllRateLimitedMessages(this))
|
2021-01-06 15:31:33 -05:00
|
|
|
.addPostRender(this::initializeExpiringMessageManager)
|
2021-05-12 14:58:19 -04:00
|
|
|
.addPostRender(() -> SignalStore.settings().setDefaultSms(Util.isDefaultSmsProvider(this)))
|
2021-05-26 10:47:14 -03:00
|
|
|
.addPostRender(() -> DownloadLatestEmojiDataJob.scheduleIfNecessary(this))
|
|
|
|
.addPostRender(EmojiSearchIndexDownloadJob::scheduleIfNecessary)
|
2021-11-18 12:36:52 -05:00
|
|
|
.addPostRender(() -> SignalDatabase.messageLog().trimOldMessages(System.currentTimeMillis(), FeatureFlags.retryRespondMaxAge()))
|
2022-01-21 10:31:43 -05:00
|
|
|
.addPostRender(() -> JumboEmoji.updateCurrentVersion(this))
|
2022-02-02 10:45:04 -05:00
|
|
|
.addPostRender(RetrieveReleaseChannelJob::enqueue)
|
2022-02-23 13:16:25 -05:00
|
|
|
.addPostRender(() -> AndroidTelecomUtil.registerPhoneAccount())
|
2022-02-24 13:40:28 -04:00
|
|
|
.addPostRender(() -> ApplicationDependencies.getJobManager().add(new FontDownloaderJob()))
|
2022-03-04 13:30:22 -05:00
|
|
|
.addPostRender(CheckServiceReachabilityJob::enqueueIfNecessary)
|
2022-03-11 09:45:07 -05:00
|
|
|
.addPostRender(GroupV2UpdateSelfProfileKeyJob::enqueueForGroupsIfNecessary)
|
2021-01-06 15:31:33 -05:00
|
|
|
.execute();
|
2020-11-09 09:29:11 -05:00
|
|
|
|
2020-06-22 17:01:40 -07:00
|
|
|
Log.d(TAG, "onCreate() took " + (System.currentTimeMillis() - startTime) + " ms");
|
2021-08-04 10:01:14 -04:00
|
|
|
SignalLocalMetrics.ColdStart.onApplicationCreateFinished();
|
2020-12-10 11:45:15 -05:00
|
|
|
Tracer.getInstance().end("Application#onCreate()");
|
2018-07-06 17:28:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-08 15:37:45 -05:00
|
|
|
public void onForeground() {
|
2020-12-20 14:45:51 -05:00
|
|
|
long startTime = System.currentTimeMillis();
|
2018-07-06 17:28:58 -07:00
|
|
|
Log.i(TAG, "App is now visible.");
|
2020-12-20 14:45:51 -05:00
|
|
|
|
2021-10-08 15:18:52 -04:00
|
|
|
ApplicationDependencies.getFrameRateTracker().start();
|
2021-01-08 11:31:35 -05:00
|
|
|
ApplicationDependencies.getMegaphoneRepository().onAppForegrounded();
|
2021-10-21 16:32:25 -04:00
|
|
|
ApplicationDependencies.getDeadlockDetector().start();
|
2021-11-10 11:33:00 -04:00
|
|
|
SubscriptionKeepAliveJob.launchSubscriberIdKeepAliveJobIfNecessary();
|
2020-12-20 14:45:51 -05:00
|
|
|
|
|
|
|
SignalExecutors.BOUNDED.execute(() -> {
|
|
|
|
FeatureFlags.refreshIfNecessary();
|
|
|
|
ApplicationDependencies.getRecipientCache().warmUp();
|
|
|
|
RetrieveProfileJob.enqueueRoutineFetchIfNecessary(this);
|
|
|
|
executePendingContactSync();
|
|
|
|
KeyCachingService.onAppForegrounded(this);
|
2021-01-04 18:39:48 -05:00
|
|
|
ApplicationDependencies.getShakeToReport().enable();
|
2020-12-20 14:45:51 -05:00
|
|
|
checkBuildExpiration();
|
|
|
|
});
|
|
|
|
|
|
|
|
Log.d(TAG, "onStart() took " + (System.currentTimeMillis() - startTime) + " ms");
|
2018-07-06 17:28:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-08 15:37:45 -05:00
|
|
|
public void onBackground() {
|
2018-07-06 17:28:58 -07:00
|
|
|
Log.i(TAG, "App is no longer visible.");
|
2018-10-15 13:27:21 -07:00
|
|
|
KeyCachingService.onAppBackgrounded(this);
|
2020-05-27 15:04:45 -04:00
|
|
|
ApplicationDependencies.getMessageNotifier().clearVisibleThread();
|
2021-10-08 15:18:52 -04:00
|
|
|
ApplicationDependencies.getFrameRateTracker().stop();
|
2021-01-04 18:39:48 -05:00
|
|
|
ApplicationDependencies.getShakeToReport().disable();
|
2021-10-08 15:18:52 -04:00
|
|
|
ApplicationDependencies.getDeadlockDetector().stop();
|
2014-07-25 15:14:29 -07:00
|
|
|
}
|
|
|
|
|
2018-07-26 10:10:46 -04:00
|
|
|
public PersistentLogger getPersistentLogger() {
|
|
|
|
return persistentLogger;
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:03:56 -04:00
|
|
|
public void checkBuildExpiration() {
|
|
|
|
if (Util.getTimeUntilBuildExpiry() <= 0 && !SignalStore.misc().isClientDeprecated()) {
|
|
|
|
Log.w(TAG, "Build expired!");
|
2020-09-09 10:22:22 -04:00
|
|
|
SignalStore.misc().markClientDeprecated();
|
2020-09-08 18:03:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 09:00:26 -07:00
|
|
|
private void initializeSecurityProvider() {
|
|
|
|
try {
|
|
|
|
Class.forName("org.signal.aesgcmprovider.AesGcmCipher");
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
Log.e(TAG, "Failed to find AesGcmCipher class");
|
|
|
|
throw new ProviderInitializationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
int aesPosition = Security.insertProviderAt(new AesGcmProvider(), 1);
|
|
|
|
Log.i(TAG, "Installed AesGcmProvider: " + aesPosition);
|
|
|
|
|
|
|
|
if (aesPosition < 0) {
|
|
|
|
Log.e(TAG, "Failed to install AesGcmProvider()");
|
|
|
|
throw new ProviderInitializationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
int conscryptPosition = Security.insertProviderAt(Conscrypt.newProvider(), 2);
|
|
|
|
Log.i(TAG, "Installed Conscrypt provider: " + conscryptPosition);
|
|
|
|
|
|
|
|
if (conscryptPosition < 0) {
|
|
|
|
Log.w(TAG, "Did not install Conscrypt provider. May already be present.");
|
|
|
|
}
|
2014-07-25 15:14:29 -07:00
|
|
|
}
|
|
|
|
|
2015-03-02 08:25:19 -08:00
|
|
|
private void initializeLogging() {
|
2021-07-23 07:39:16 -04:00
|
|
|
persistentLogger = new PersistentLogger(this);
|
2021-04-14 14:38:29 -04:00
|
|
|
org.signal.core.util.logging.Log.initialize(FeatureFlags::internalUser, new AndroidLogger(), persistentLogger);
|
2018-07-26 10:10:46 -04:00
|
|
|
|
|
|
|
SignalProtocolLoggerProvider.setProvider(new CustomSignalProtocolLogger());
|
2021-07-23 07:39:16 -04:00
|
|
|
|
2021-10-04 15:52:17 -04:00
|
|
|
SignalExecutors.UNBOUNDED.execute(() -> {
|
|
|
|
Log.blockUntilAllWritesFinished();
|
|
|
|
LogDatabase.getInstance(this).trimToSize();
|
|
|
|
});
|
2018-07-26 10:10:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeCrashHandling() {
|
|
|
|
final Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler();
|
2020-01-10 01:08:39 -05:00
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new SignalUncaughtExceptionHandler(originalHandler));
|
2015-03-02 08:25:19 -08:00
|
|
|
}
|
|
|
|
|
2021-12-08 13:22:36 -05:00
|
|
|
private void initializeRx() {
|
|
|
|
RxDogTag.install();
|
|
|
|
RxJavaPlugins.setInitIoSchedulerHandler(schedulerSupplier -> Schedulers.from(SignalExecutors.BOUNDED_IO, true, false));
|
|
|
|
RxJavaPlugins.setInitComputationSchedulerHandler(schedulerSupplier -> Schedulers.from(SignalExecutors.BOUNDED, true, false));
|
|
|
|
RxJavaPlugins.setErrorHandler(e -> {
|
|
|
|
boolean wasWrapped = false;
|
|
|
|
while ((e instanceof UndeliverableException || e instanceof AssertionError || e instanceof OnErrorNotImplementedException) && e.getCause() != null) {
|
|
|
|
wasWrapped = true;
|
|
|
|
e = e.getCause();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasWrapped && (e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof InterruptedException)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
|
|
|
|
if (uncaughtExceptionHandler == null) {
|
|
|
|
uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-29 19:02:40 -04:00
|
|
|
private void initializeApplicationMigrations() {
|
2019-10-15 15:47:54 -04:00
|
|
|
ApplicationMigrations.onApplicationCreate(this, ApplicationDependencies.getJobManager());
|
2019-07-29 19:02:40 -04:00
|
|
|
}
|
|
|
|
|
2018-10-15 13:27:21 -07:00
|
|
|
public void initializeMessageRetrieval() {
|
2020-07-21 10:38:42 -04:00
|
|
|
ApplicationDependencies.getIncomingMessageObserver();
|
2018-10-15 13:27:21 -07:00
|
|
|
}
|
|
|
|
|
2019-07-15 11:12:26 -04:00
|
|
|
private void initializeAppDependencies() {
|
2021-02-02 16:42:47 -05:00
|
|
|
ApplicationDependencies.init(this, new ApplicationDependencyProvider(this));
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2019-09-05 14:39:18 -04:00
|
|
|
private void initializeFirstEverAppLaunch() {
|
|
|
|
if (TextSecurePreferences.getFirstInstallVersion(this) == -1) {
|
2021-11-18 12:36:52 -05:00
|
|
|
if (!SignalDatabase.databaseFileExists(this) || VersionTracker.getDaysSinceFirstInstalled(this) < 365) {
|
2019-09-05 14:39:18 -04:00
|
|
|
Log.i(TAG, "First ever app launch!");
|
2020-02-20 01:01:14 -05:00
|
|
|
AppInitialization.onFirstEverAppLaunch(this);
|
2019-09-05 14:39:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Log.i(TAG, "Setting first install version to " + BuildConfig.CANONICAL_VERSION_CODE);
|
|
|
|
TextSecurePreferences.setFirstInstallVersion(this, BuildConfig.CANONICAL_VERSION_CODE);
|
2021-01-13 17:33:14 -05:00
|
|
|
} else if (!TextSecurePreferences.isPasswordDisabled(this) && VersionTracker.getDaysSinceFirstInstalled(this) < 90) {
|
|
|
|
Log.i(TAG, "Detected a new install that doesn't have passphrases disabled -- assuming bad initialization.");
|
|
|
|
AppInitialization.onRepairFirstEverAppLaunch(this);
|
2021-01-27 10:10:26 -05:00
|
|
|
} else if (!TextSecurePreferences.isPasswordDisabled(this) && VersionTracker.getDaysSinceFirstInstalled(this) < 912) {
|
|
|
|
Log.i(TAG, "Detected a not-recent install that doesn't have passphrases disabled -- disabling now.");
|
|
|
|
TextSecurePreferences.setPasswordDisabled(this, true);
|
2019-09-05 14:39:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 15:08:28 -05:00
|
|
|
private void initializeFcmCheck() {
|
|
|
|
if (SignalStore.account().isRegistered()) {
|
|
|
|
long nextSetTime = SignalStore.account().getFcmTokenLastSetTime() + TimeUnit.HOURS.toMillis(6);
|
2017-03-17 10:28:06 -07:00
|
|
|
|
2021-11-17 15:08:28 -05:00
|
|
|
if (SignalStore.account().getFcmToken() == null || nextSetTime <= System.currentTimeMillis()) {
|
2019-10-15 15:47:54 -04:00
|
|
|
ApplicationDependencies.getJobManager().add(new FcmRefreshJob());
|
2017-03-17 10:28:06 -07:00
|
|
|
}
|
2014-07-25 15:14:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void initializeExpiringMessageManager() {
|
2021-04-13 14:49:32 -04:00
|
|
|
ApplicationDependencies.getExpiringMessageManager().checkSchedule();
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
|
2019-06-11 02:18:45 -04:00
|
|
|
private void initializeRevealableMessageManager() {
|
2021-04-13 14:49:32 -04:00
|
|
|
ApplicationDependencies.getViewOnceMessageManager().scheduleIfNecessary();
|
2019-06-11 02:18:45 -04:00
|
|
|
}
|
|
|
|
|
2021-05-14 14:03:35 -04:00
|
|
|
private void initializePendingRetryReceiptManager() {
|
|
|
|
ApplicationDependencies.getPendingRetryReceiptManager().scheduleIfNecessary();
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:19:58 -08:00
|
|
|
private void initializePeriodicTasks() {
|
|
|
|
RotateSignedPreKeyListener.schedule(this);
|
|
|
|
DirectoryRefreshListener.schedule(this);
|
2018-02-26 09:58:18 -08:00
|
|
|
LocalBackupListener.schedule(this);
|
2018-05-22 02:13:10 -07:00
|
|
|
RotateSenderCertificateListener.schedule(this);
|
2021-02-10 14:01:11 -04:00
|
|
|
MessageProcessReceiver.startOrUpdateAlarm(this);
|
2017-02-26 14:36:43 -08:00
|
|
|
|
|
|
|
if (BuildConfig.PLAY_STORE_DISABLED) {
|
|
|
|
UpdateApkRefreshListener.schedule(this);
|
|
|
|
}
|
2017-01-06 09:19:58 -08:00
|
|
|
}
|
|
|
|
|
2019-10-15 10:29:05 -07:00
|
|
|
private void initializeRingRtc() {
|
2017-07-21 16:29:03 -07:00
|
|
|
try {
|
2020-02-11 19:56:16 -08:00
|
|
|
CallManager.initialize(this, new RingRtcLogger());
|
2017-07-21 16:29:03 -07:00
|
|
|
} catch (UnsatisfiedLinkError e) {
|
2020-02-11 19:56:16 -08:00
|
|
|
throw new AssertionError("Unable to load ringrtc library", e);
|
2017-03-21 10:23:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:45:51 -05:00
|
|
|
@WorkerThread
|
2017-01-11 15:37:51 -08:00
|
|
|
private void initializeCircumvention() {
|
2021-11-17 15:08:28 -05:00
|
|
|
if (ApplicationDependencies.getSignalServiceNetworkAccess().isCensored()) {
|
2020-12-20 14:45:51 -05:00
|
|
|
try {
|
|
|
|
ProviderInstaller.installIfNeeded(ApplicationContext.this);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
Log.w(TAG, t);
|
2017-01-11 15:37:51 -08:00
|
|
|
}
|
2020-12-20 14:45:51 -05:00
|
|
|
}
|
2017-01-11 15:37:51 -08:00
|
|
|
}
|
|
|
|
|
2021-11-23 14:06:37 -05:00
|
|
|
private void ensureProfileUploaded() {
|
|
|
|
if (SignalStore.account().isRegistered() && !SignalStore.registrationValues().hasUploadedProfile() && !Recipient.self().getProfileName().isEmpty()) {
|
|
|
|
Log.w(TAG, "User has a profile, but has not uploaded one. Uploading now.");
|
|
|
|
ApplicationDependencies.getJobManager().add(new ProfileUploadJob());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:28:58 -07:00
|
|
|
private void executePendingContactSync() {
|
|
|
|
if (TextSecurePreferences.needsFullContactSync(this)) {
|
2019-10-15 15:47:54 -04:00
|
|
|
ApplicationDependencies.getJobManager().add(new MultiDeviceContactUpdateJob(true));
|
2018-07-06 17:28:58 -07:00
|
|
|
}
|
|
|
|
}
|
2018-10-05 15:23:33 -07:00
|
|
|
|
|
|
|
private void initializePendingMessages() {
|
|
|
|
if (TextSecurePreferences.getNeedsMessagePull(this)) {
|
|
|
|
Log.i(TAG, "Scheduling a message fetch.");
|
2019-05-31 17:12:41 -04:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
FcmJobService.schedule(this);
|
|
|
|
} else {
|
2021-02-10 14:01:11 -04:00
|
|
|
ApplicationDependencies.getJobManager().add(new PushNotificationReceiveJob());
|
2019-05-31 17:12:41 -04:00
|
|
|
}
|
2018-10-05 15:23:33 -07:00
|
|
|
TextSecurePreferences.setNeedsMessagePull(this, false);
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 16:45:22 -07:00
|
|
|
|
2020-12-20 14:45:51 -05:00
|
|
|
@WorkerThread
|
2019-02-25 17:47:30 -08:00
|
|
|
private void initializeBlobProvider() {
|
2021-02-24 16:04:58 -05:00
|
|
|
BlobProvider.getInstance().initialize(this);
|
2019-02-25 17:47:30 -08:00
|
|
|
}
|
2019-03-25 17:23:38 -03:00
|
|
|
|
2021-07-20 13:08:52 -03:00
|
|
|
@WorkerThread
|
|
|
|
private void cleanAvatarStorage() {
|
|
|
|
AvatarPickerStorage.cleanOrphans(this);
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:45:51 -05:00
|
|
|
@WorkerThread
|
2020-01-08 15:56:51 -05:00
|
|
|
private void initializeCleanup() {
|
2021-11-18 12:36:52 -05:00
|
|
|
int deleted = SignalDatabase.attachments().deleteAbandonedPreuploadedAttachments();
|
2020-12-20 14:45:51 -05:00
|
|
|
Log.i(TAG, "Deleted " + deleted + " abandoned attachments.");
|
2020-01-08 15:56:51 -05:00
|
|
|
}
|
|
|
|
|
2020-09-01 19:13:35 -04:00
|
|
|
private void initializeGlideCodecs() {
|
|
|
|
SignalGlideCodecs.setLogProvider(new org.signal.glide.Log.Provider() {
|
|
|
|
@Override
|
|
|
|
public void v(@NonNull String tag, @NonNull String message) {
|
|
|
|
Log.v(tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void d(@NonNull String tag, @NonNull String message) {
|
|
|
|
Log.d(tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void i(@NonNull String tag, @NonNull String message) {
|
|
|
|
Log.i(tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void w(@NonNull String tag, @NonNull String message) {
|
|
|
|
Log.w(tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void e(@NonNull String tag, @NonNull String message, @Nullable Throwable throwable) {
|
|
|
|
Log.e(tag, message, throwable);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-25 17:23:38 -03:00
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(Context base) {
|
2022-01-21 18:11:49 -05:00
|
|
|
DynamicLanguageContextWrapper.updateContext(base);
|
|
|
|
super.attachBaseContext(base);
|
2019-03-25 17:23:38 -03:00
|
|
|
}
|
2019-05-01 09:00:26 -07:00
|
|
|
|
|
|
|
private static class ProviderInitializationException extends RuntimeException {
|
|
|
|
}
|
2014-07-25 15:14:29 -07:00
|
|
|
}
|