2014-07-25 22:14:29 +00: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;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-01-11 23:37:51 +00:00
|
|
|
import android.os.AsyncTask;
|
2017-02-14 06:55:06 +00:00
|
|
|
import android.os.Build;
|
2017-01-08 17:43:43 +00:00
|
|
|
import android.support.multidex.MultiDexApplication;
|
2017-01-11 23:37:51 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.google.android.gms.security.ProviderInstaller;
|
2015-05-21 19:30:18 +00:00
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.PRNGFixes;
|
2014-11-12 03:57:53 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2016-12-20 17:55:52 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule;
|
2016-03-12 01:07:22 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
2014-11-12 05:11:57 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
2017-03-06 20:10:26 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
2014-11-12 05:11:57 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.persistence.EncryptingJobSerializer;
|
2014-11-14 23:44:49 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider;
|
2015-08-24 22:24:31 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirementProvider;
|
2014-11-14 23:44:49 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.requirements.ServiceRequirementProvider;
|
2016-12-30 04:54:05 +00:00
|
|
|
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
2017-01-06 17:19:58 +00:00
|
|
|
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
2016-08-16 03:23:56 +00:00
|
|
|
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
2017-01-06 17:19:58 +00:00
|
|
|
import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener;
|
2017-02-26 22:36:43 +00:00
|
|
|
import org.thoughtcrime.securesms.service.UpdateApkRefreshListener;
|
2014-07-25 22:14:29 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-11-09 17:37:40 +00:00
|
|
|
import org.webrtc.PeerConnectionFactory;
|
2017-03-21 17:23:16 +00:00
|
|
|
import org.webrtc.voiceengine.WebRtcAudioManager;
|
|
|
|
import org.webrtc.voiceengine.WebRtcAudioUtils;
|
2014-08-04 23:15:13 +00:00
|
|
|
import org.whispersystems.jobqueue.JobManager;
|
2014-11-12 03:57:53 +00:00
|
|
|
import org.whispersystems.jobqueue.dependencies.DependencyInjector;
|
2014-11-14 23:44:49 +00:00
|
|
|
import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
|
|
|
|
import org.whispersystems.libsignal.util.AndroidSignalProtocolLogger;
|
2014-07-25 22:14:29 +00:00
|
|
|
|
2017-03-21 17:23:16 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2017-03-17 17:28:06 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2014-11-12 03:57:53 +00:00
|
|
|
import dagger.ObjectGraph;
|
|
|
|
|
2014-07-25 22:14:29 +00: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
|
|
|
|
*/
|
2017-01-08 17:43:43 +00:00
|
|
|
public class ApplicationContext extends MultiDexApplication implements DependencyInjector {
|
2014-07-25 22:14:29 +00:00
|
|
|
|
2017-01-11 23:37:51 +00:00
|
|
|
private static final String TAG = ApplicationContext.class.getName();
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
private ExpiringMessageManager expiringMessageManager;
|
|
|
|
private JobManager jobManager;
|
|
|
|
private ObjectGraph objectGraph;
|
2014-07-25 22:14:29 +00:00
|
|
|
|
2015-08-24 22:24:31 +00:00
|
|
|
private MediaNetworkRequirementProvider mediaNetworkRequirementProvider = new MediaNetworkRequirementProvider();
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
public static ApplicationContext getInstance(Context context) {
|
|
|
|
return (ApplicationContext)context.getApplicationContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2015-05-21 19:30:18 +00:00
|
|
|
super.onCreate();
|
2014-07-25 22:14:29 +00:00
|
|
|
initializeRandomNumberFix();
|
2015-03-02 16:25:19 +00:00
|
|
|
initializeLogging();
|
2014-11-12 03:57:53 +00:00
|
|
|
initializeDependencyInjection();
|
2014-07-25 22:14:29 +00:00
|
|
|
initializeJobManager();
|
2016-08-16 03:23:56 +00:00
|
|
|
initializeExpiringMessageManager();
|
2014-07-25 22:14:29 +00:00
|
|
|
initializeGcmCheck();
|
2016-03-12 01:07:22 +00:00
|
|
|
initializeSignedPreKeyCheck();
|
2017-01-06 17:19:58 +00:00
|
|
|
initializePeriodicTasks();
|
2017-01-11 23:37:51 +00:00
|
|
|
initializeCircumvention();
|
2017-03-06 20:10:26 +00:00
|
|
|
initializeSetVideoCapable();
|
2017-03-21 17:23:16 +00:00
|
|
|
initializeWebRtc();
|
2014-07-25 22:14:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 03:57:53 +00:00
|
|
|
@Override
|
|
|
|
public void injectDependencies(Object object) {
|
|
|
|
if (object instanceof InjectableType) {
|
|
|
|
objectGraph.inject(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
public JobManager getJobManager() {
|
|
|
|
return jobManager;
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
public ExpiringMessageManager getExpiringMessageManager() {
|
|
|
|
return expiringMessageManager;
|
|
|
|
}
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
private void initializeRandomNumberFix() {
|
|
|
|
PRNGFixes.apply();
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:25:19 +00:00
|
|
|
private void initializeLogging() {
|
2016-03-23 17:34:41 +00:00
|
|
|
SignalProtocolLoggerProvider.setProvider(new AndroidSignalProtocolLogger());
|
2015-03-02 16:25:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
private void initializeJobManager() {
|
2014-11-12 05:11:57 +00:00
|
|
|
this.jobManager = JobManager.newBuilder(this)
|
|
|
|
.withName("TextSecureJobs")
|
|
|
|
.withDependencyInjector(this)
|
2014-11-17 00:15:12 +00:00
|
|
|
.withJobSerializer(new EncryptingJobSerializer())
|
2014-11-14 23:44:49 +00:00
|
|
|
.withRequirementProviders(new MasterSecretRequirementProvider(this),
|
|
|
|
new ServiceRequirementProvider(this),
|
2015-08-24 22:24:31 +00:00
|
|
|
new NetworkRequirementProvider(this),
|
|
|
|
mediaNetworkRequirementProvider)
|
2014-11-12 05:11:57 +00:00
|
|
|
.withConsumerThreads(5)
|
|
|
|
.build();
|
2014-07-25 22:14:29 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 22:24:31 +00:00
|
|
|
public void notifyMediaControlEvent() {
|
|
|
|
mediaNetworkRequirementProvider.notifyMediaControlEvent();
|
|
|
|
}
|
|
|
|
|
2014-11-12 03:57:53 +00:00
|
|
|
private void initializeDependencyInjection() {
|
2016-12-30 04:54:05 +00:00
|
|
|
this.objectGraph = ObjectGraph.create(new SignalCommunicationModule(this, new SignalServiceNetworkAccess(this)),
|
2014-11-12 03:57:53 +00:00
|
|
|
new AxolotlStorageModule(this));
|
|
|
|
}
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
private void initializeGcmCheck() {
|
2017-03-06 19:50:51 +00:00
|
|
|
if (TextSecurePreferences.isPushRegistered(this)) {
|
2017-03-17 17:28:06 +00:00
|
|
|
long nextSetTime = TextSecurePreferences.getGcmRegistrationIdLastSetTime(this) + TimeUnit.HOURS.toMillis(6);
|
|
|
|
|
|
|
|
if (TextSecurePreferences.getGcmRegistrationId(this) == null || nextSetTime <= System.currentTimeMillis()) {
|
|
|
|
this.jobManager.add(new GcmRefreshJob(this));
|
|
|
|
}
|
2014-07-25 22:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 01:07:22 +00:00
|
|
|
private void initializeSignedPreKeyCheck() {
|
|
|
|
if (!TextSecurePreferences.isSignedPreKeyRegistered(this)) {
|
|
|
|
jobManager.add(new CreateSignedPreKeyJob(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
private void initializeExpiringMessageManager() {
|
|
|
|
this.expiringMessageManager = new ExpiringMessageManager(this);
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:19:58 +00:00
|
|
|
private void initializePeriodicTasks() {
|
|
|
|
RotateSignedPreKeyListener.schedule(this);
|
|
|
|
DirectoryRefreshListener.schedule(this);
|
2017-02-26 22:36:43 +00:00
|
|
|
|
|
|
|
if (BuildConfig.PLAY_STORE_DISABLED) {
|
|
|
|
UpdateApkRefreshListener.schedule(this);
|
|
|
|
}
|
2017-01-06 17:19:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 20:10:26 +00:00
|
|
|
private void initializeSetVideoCapable() {
|
2017-03-14 20:24:24 +00:00
|
|
|
if (TextSecurePreferences.isPushRegistered(this) &&
|
|
|
|
!TextSecurePreferences.isWebrtcCallingEnabled(this))
|
|
|
|
{
|
2017-03-06 20:10:26 +00:00
|
|
|
TextSecurePreferences.setWebrtcCallingEnabled(this, true);
|
|
|
|
jobManager.add(new RefreshAttributesJob(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 17:23:16 +00:00
|
|
|
private void initializeWebRtc() {
|
2017-04-12 22:12:13 +00:00
|
|
|
Set<String> HARDWARE_AEC_WHITELIST = new HashSet<String>() {{
|
2017-03-21 17:23:16 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
Set<String> OPEN_SL_ES_BLACKLIST = new HashSet<String>() {{
|
|
|
|
add("MI 4LTE"); // Xiami Mi4 #6241
|
2017-04-26 17:25:31 +00:00
|
|
|
add("Nexus 5"); // Nexus 5 #6432
|
2017-04-27 18:38:49 +00:00
|
|
|
add("LG-D852"); // LG G3 #6432
|
2017-03-21 17:23:16 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
2017-04-12 22:12:13 +00:00
|
|
|
if (HARDWARE_AEC_WHITELIST.contains(Build.MODEL)) {
|
|
|
|
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(false);
|
|
|
|
} else {
|
2017-03-21 17:23:16 +00:00
|
|
|
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPEN_SL_ES_BLACKLIST.contains(Build.MODEL)) {
|
|
|
|
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 23:37:51 +00:00
|
|
|
private void initializeCircumvention() {
|
2017-03-21 17:23:16 +00:00
|
|
|
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
|
2017-01-11 23:37:51 +00:00
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
if (new SignalServiceNetworkAccess(ApplicationContext.this).isCensored(ApplicationContext.this)) {
|
|
|
|
try {
|
|
|
|
ProviderInstaller.installIfNeeded(ApplicationContext.this);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
Log.w(TAG, t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-21 17:23:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
else task.execute();
|
2017-01-11 23:37:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 22:14:29 +00:00
|
|
|
}
|