2014-11-11 19:57:53 -08:00
|
|
|
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-10-05 15:23:33 -07:00
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
2015-05-14 18:14:42 -07:00
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.thoughtcrime.securesms.CreateProfileActivity;
|
2015-11-19 10:21:19 -08:00
|
|
|
import org.thoughtcrime.securesms.DeviceListFragment;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
2019-07-22 10:41:50 +10:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.gcm.FcmService;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob;
|
2016-12-20 09:55:52 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
2019-01-24 03:04:28 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.FcmRefreshJob;
|
2016-08-26 16:53:23 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
2015-05-29 16:23:47 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2015-06-22 14:49:04 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
2017-08-25 12:00:52 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
2016-02-19 17:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
2016-11-20 14:50:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
2015-04-15 10:58:29 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
2015-09-21 17:41:27 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshUnidentifiedDeliveryAbilityJob;
|
2016-11-20 14:50:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
2017-08-14 18:11:13 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
2017-05-19 18:01:40 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
2018-05-22 02:13:10 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateCertificateJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
|
2017-01-06 09:19:58 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
2018-05-22 02:13:10 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
|
2017-09-15 22:38:53 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
2019-06-24 14:10:09 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2018-03-01 09:51:37 -08:00
|
|
|
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
2016-12-29 20:54:05 -08:00
|
|
|
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
2018-10-15 13:27:21 -07:00
|
|
|
import org.thoughtcrime.securesms.service.IncomingMessageObserver;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
2019-06-04 11:45:29 +10:00
|
|
|
import org.thoughtcrime.securesms.util.RealtimeSleepTimer;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
|
|
|
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
2018-09-10 08:40:00 -07:00
|
|
|
import org.whispersystems.signalservice.api.util.SleepTimer;
|
|
|
|
import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.whispersystems.signalservice.api.websocket.ConnectivityListener;
|
2014-11-11 19:57:53 -08:00
|
|
|
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
|
|
|
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
|
|
CreateSignedPreKeyJob.class,
|
|
|
|
PushGroupSendJob.class,
|
|
|
|
PushTextSendJob.class,
|
|
|
|
PushMediaSendJob.class,
|
|
|
|
AttachmentDownloadJob.class,
|
2015-01-25 17:43:24 -08:00
|
|
|
RefreshPreKeysJob.class,
|
2018-10-15 13:27:21 -07:00
|
|
|
IncomingMessageObserver.class,
|
2015-05-29 16:23:47 -07:00
|
|
|
PushNotificationReceiveJob.class,
|
2015-06-19 22:02:10 -07:00
|
|
|
MultiDeviceContactUpdateJob.class,
|
2015-06-22 14:49:04 -07:00
|
|
|
MultiDeviceGroupUpdateJob.class,
|
2016-02-19 17:07:41 -08:00
|
|
|
MultiDeviceReadUpdateJob.class,
|
2016-08-26 16:53:23 -07:00
|
|
|
MultiDeviceBlockedUpdateJob.class,
|
2015-11-19 10:21:19 -08:00
|
|
|
DeviceListFragment.class,
|
2015-09-30 16:19:50 -07:00
|
|
|
RefreshAttributesJob.class,
|
2019-01-24 03:04:28 -08:00
|
|
|
FcmRefreshJob.class,
|
2016-11-20 14:50:41 -08:00
|
|
|
RequestGroupInfoJob.class,
|
2016-12-20 09:55:52 -08:00
|
|
|
PushGroupUpdateJob.class,
|
2017-01-06 09:19:58 -08:00
|
|
|
AvatarDownloadJob.class,
|
2016-11-09 09:37:40 -08:00
|
|
|
RotateSignedPreKeyJob.class,
|
2017-05-19 18:01:40 -07:00
|
|
|
WebRtcCallService.class,
|
2017-06-06 18:03:09 -07:00
|
|
|
RetrieveProfileJob.class,
|
2017-08-08 16:37:15 -07:00
|
|
|
MultiDeviceVerifiedUpdateJob.class,
|
2017-08-14 18:11:13 -07:00
|
|
|
CreateProfileActivity.class,
|
2017-08-25 12:00:52 -07:00
|
|
|
RetrieveProfileAvatarJob.class,
|
2017-09-15 22:38:53 -07:00
|
|
|
MultiDeviceProfileKeyUpdateJob.class,
|
2017-09-21 11:27:53 -07:00
|
|
|
SendReadReceiptJob.class,
|
2018-10-05 15:23:33 -07:00
|
|
|
AppProtectionPreferenceFragment.class,
|
2019-01-24 03:04:28 -08:00
|
|
|
FcmService.class,
|
2018-05-22 02:13:10 -07:00
|
|
|
RotateCertificateJob.class,
|
2018-10-11 16:45:22 -07:00
|
|
|
SendDeliveryReceiptJob.class,
|
|
|
|
RotateProfileKeyJob.class,
|
|
|
|
MultiDeviceConfigurationUpdateJob.class,
|
2018-10-29 15:14:31 -07:00
|
|
|
RefreshUnidentifiedDeliveryAbilityJob.class,
|
2018-12-07 18:31:39 -08:00
|
|
|
TypingSendJob.class,
|
2019-06-06 10:39:24 +10:00
|
|
|
AttachmentUploadJob.class,
|
|
|
|
PushDecryptJob.class})
|
2016-12-20 09:55:52 -08:00
|
|
|
public class SignalCommunicationModule {
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
private static final String TAG = SignalCommunicationModule.class.getSimpleName();
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
private final Context context;
|
|
|
|
private final SignalServiceNetworkAccess networkAccess;
|
|
|
|
|
|
|
|
private SignalServiceAccountManager accountManager;
|
|
|
|
private SignalServiceMessageSender messageSender;
|
|
|
|
private SignalServiceMessageReceiver messageReceiver;
|
2016-12-20 09:55:52 -08:00
|
|
|
|
2016-12-29 20:54:05 -08:00
|
|
|
public SignalCommunicationModule(Context context, SignalServiceNetworkAccess networkAccess) {
|
2017-01-11 15:37:51 -08:00
|
|
|
this.context = context;
|
|
|
|
this.networkAccess = networkAccess;
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceAccountManager provideSignalAccountManager() {
|
|
|
|
if (this.accountManager == null) {
|
|
|
|
this.accountManager = new SignalServiceAccountManager(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.accountManager;
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
@Provides
|
2019-06-28 16:08:27 +10:00
|
|
|
public synchronized SignalServiceMessageSender provideSignalMessageSender() {
|
2017-09-15 22:38:53 -07:00
|
|
|
if (this.messageSender == null) {
|
|
|
|
this.messageSender = new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
new SignalProtocolStoreImpl(context),
|
|
|
|
BuildConfig.USER_AGENT,
|
2018-05-22 02:13:10 -07:00
|
|
|
TextSecurePreferences.isMultiDevice(context),
|
2018-10-15 13:27:21 -07:00
|
|
|
Optional.fromNullable(IncomingMessageObserver.getPipe()),
|
2018-05-22 02:13:10 -07:00
|
|
|
Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()),
|
2019-06-11 16:27:00 +10:00
|
|
|
Optional.of(new SecurityEventListener(context)),
|
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
2019-06-12 11:41:50 +10:00
|
|
|
DatabaseFactory.getLokiAPIDatabase(context),
|
2019-07-22 09:38:12 +10:00
|
|
|
DatabaseFactory.getLokiThreadDatabase(context),
|
2019-06-24 14:10:09 +10:00
|
|
|
DatabaseFactory.getLokiMessageFriendRequestDatabase(context),
|
2019-07-22 10:41:50 +10:00
|
|
|
DatabaseFactory.getLokiPreKeyBundleDatabase(context),
|
|
|
|
new TextSecureSessionStore(context));
|
2017-10-10 09:14:53 -07:00
|
|
|
} else {
|
2018-05-22 02:13:10 -07:00
|
|
|
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
|
|
|
|
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
2014-11-11 19:57:53 -08:00
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
return this.messageSender;
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
|
|
|
if (this.messageReceiver == null) {
|
2019-01-24 03:04:28 -08:00
|
|
|
SleepTimer sleepTimer = TextSecurePreferences.isFcmDisabled(context) ? new RealtimeSleepTimer(context) : new UptimeSleepTimer();
|
2018-09-10 08:40:00 -07:00
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
this.messageReceiver = new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
2017-11-15 16:29:00 -08:00
|
|
|
BuildConfig.USER_AGENT,
|
2018-09-10 08:40:00 -07:00
|
|
|
new PipeConnectivityListener(),
|
|
|
|
sleepTimer);
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.messageReceiver;
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2018-10-15 13:27:21 -07:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceNetworkAccess provideSignalServiceNetworkAccess() {
|
|
|
|
return networkAccess;
|
|
|
|
}
|
|
|
|
|
2015-01-25 17:43:24 -08:00
|
|
|
private static class DynamicCredentialsProvider implements CredentialsProvider {
|
|
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
private DynamicCredentialsProvider(Context context) {
|
|
|
|
this.context = context.getApplicationContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUser() {
|
|
|
|
return TextSecurePreferences.getLocalNumber(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPassword() {
|
|
|
|
return TextSecurePreferences.getPushServerPassword(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSignalingKey() {
|
|
|
|
return TextSecurePreferences.getSignalingKey(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
private class PipeConnectivityListener implements ConnectivityListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnected() {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onConnected()");
|
2017-11-15 16:29:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnecting() {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onConnecting()");
|
2017-11-15 16:29:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisconnected() {
|
|
|
|
Log.w(TAG, "onDisconnected()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailure() {
|
|
|
|
Log.w(TAG, "onAuthenticationFailure()");
|
|
|
|
TextSecurePreferences.setUnauthorizedReceived(context, true);
|
|
|
|
EventBus.getDefault().post(new ReminderUpdateEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|