2014-11-12 04:57:53 +01:00
|
|
|
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-10-06 00:23:33 +02:00
|
|
|
|
2020-12-02 13:01:04 +01:00
|
|
|
import org.session.libsignal.libsignal.util.guava.Optional;
|
|
|
|
import org.session.libsignal.service.api.SignalServiceAccountManager;
|
|
|
|
import org.session.libsignal.service.api.SignalServiceMessageReceiver;
|
|
|
|
import org.session.libsignal.service.api.SignalServiceMessageSender;
|
|
|
|
import org.session.libsignal.service.api.util.CredentialsProvider;
|
|
|
|
import org.session.libsignal.service.api.util.SleepTimer;
|
|
|
|
import org.session.libsignal.service.api.util.UptimeSleepTimer;
|
|
|
|
import org.session.libsignal.service.api.websocket.ConnectivityListener;
|
2020-01-16 04:35:51 +01:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
2016-03-23 18:34:41 +01:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob;
|
2016-12-20 18:55:52 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
2016-08-27 01:53:23 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
2015-05-30 01:23:47 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2015-06-22 23:49:04 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
2017-08-25 21:00:52 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
2016-02-20 02:07:41 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
2019-04-17 16:21:30 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackOperationJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackSyncJob;
|
2017-06-07 03:03:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
2016-11-20 23:50:41 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
2015-04-15 19:58:29 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
2015-09-22 02:41:27 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RefreshUnidentifiedDeliveryAbilityJob;
|
2016-11-20 23:50:41 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
2017-08-15 03:11:13 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
2017-05-20 03:01:40 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
2018-05-22 11:13:10 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateCertificateJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
|
2017-01-06 18:19:58 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
2018-05-22 11:13:10 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
|
2017-09-16 07:38:53 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
2019-04-17 16:21:30 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.StickerDownloadJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.StickerPackDownloadJob;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
2019-04-17 16:21:30 +02:00
|
|
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
2019-06-24 06:10:09 +02:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2020-07-15 06:26:20 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation;
|
2020-08-07 01:20:22 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.protocol.shelved.MultiDeviceOpenGroupUpdateJob;
|
2018-03-01 18:51:37 +01:00
|
|
|
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
2019-10-24 08:16:53 +02:00
|
|
|
import org.thoughtcrime.securesms.push.MessageSenderEventListener;
|
2016-12-30 05:54:05 +01:00
|
|
|
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
2018-10-15 22:27:21 +02:00
|
|
|
import org.thoughtcrime.securesms.service.IncomingMessageObserver;
|
2019-04-17 16:21:30 +02:00
|
|
|
import org.thoughtcrime.securesms.stickers.StickerPackPreviewRepository;
|
|
|
|
import org.thoughtcrime.securesms.stickers.StickerRemoteUriLoader;
|
2019-06-04 03:45:29 +02:00
|
|
|
import org.thoughtcrime.securesms.util.RealtimeSleepTimer;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
2019-08-07 08:48:54 +02:00
|
|
|
import network.loki.messenger.BuildConfig;
|
2014-11-12 04:57:53 +01:00
|
|
|
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
|
|
CreateSignedPreKeyJob.class,
|
|
|
|
PushGroupSendJob.class,
|
|
|
|
PushTextSendJob.class,
|
|
|
|
PushMediaSendJob.class,
|
|
|
|
AttachmentDownloadJob.class,
|
2015-01-26 02:43:24 +01:00
|
|
|
RefreshPreKeysJob.class,
|
2018-10-15 22:27:21 +02:00
|
|
|
IncomingMessageObserver.class,
|
2015-05-30 01:23:47 +02:00
|
|
|
PushNotificationReceiveJob.class,
|
2015-06-20 07:02:10 +02:00
|
|
|
MultiDeviceContactUpdateJob.class,
|
2015-06-22 23:49:04 +02:00
|
|
|
MultiDeviceGroupUpdateJob.class,
|
2016-02-20 02:07:41 +01:00
|
|
|
MultiDeviceReadUpdateJob.class,
|
2016-08-27 01:53:23 +02:00
|
|
|
MultiDeviceBlockedUpdateJob.class,
|
2015-10-01 01:19:50 +02:00
|
|
|
RefreshAttributesJob.class,
|
2016-11-20 23:50:41 +01:00
|
|
|
RequestGroupInfoJob.class,
|
2016-12-20 18:55:52 +01:00
|
|
|
PushGroupUpdateJob.class,
|
2017-01-06 18:19:58 +01:00
|
|
|
AvatarDownloadJob.class,
|
2016-11-09 18:37:40 +01:00
|
|
|
RotateSignedPreKeyJob.class,
|
2017-06-07 03:03:09 +02:00
|
|
|
RetrieveProfileJob.class,
|
2017-08-09 01:37:15 +02:00
|
|
|
MultiDeviceVerifiedUpdateJob.class,
|
2017-08-25 21:00:52 +02:00
|
|
|
RetrieveProfileAvatarJob.class,
|
2017-09-16 07:38:53 +02:00
|
|
|
MultiDeviceProfileKeyUpdateJob.class,
|
2017-09-21 20:27:53 +02:00
|
|
|
SendReadReceiptJob.class,
|
2018-10-06 00:23:33 +02:00
|
|
|
AppProtectionPreferenceFragment.class,
|
2018-05-22 11:13:10 +02:00
|
|
|
RotateCertificateJob.class,
|
2018-10-12 01:45:22 +02:00
|
|
|
SendDeliveryReceiptJob.class,
|
|
|
|
RotateProfileKeyJob.class,
|
|
|
|
MultiDeviceConfigurationUpdateJob.class,
|
2018-10-29 23:14:31 +01:00
|
|
|
RefreshUnidentifiedDeliveryAbilityJob.class,
|
2018-12-08 03:31:39 +01:00
|
|
|
TypingSendJob.class,
|
2019-06-06 02:39:24 +02:00
|
|
|
AttachmentUploadJob.class,
|
2019-08-07 08:48:54 +02:00
|
|
|
PushDecryptJob.class,
|
2019-04-17 16:21:30 +02:00
|
|
|
StickerDownloadJob.class,
|
|
|
|
StickerPackPreviewRepository.class,
|
|
|
|
StickerRemoteUriLoader.Factory.class,
|
|
|
|
StickerPackDownloadJob.class,
|
|
|
|
MultiDeviceStickerPackOperationJob.class,
|
|
|
|
MultiDeviceStickerPackSyncJob.class,
|
2019-10-24 08:16:53 +02:00
|
|
|
LinkPreviewRepository.class,
|
2020-02-25 01:28:56 +01:00
|
|
|
MultiDeviceOpenGroupUpdateJob.class})
|
2019-08-07 08:48:54 +02:00
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
public class SignalCommunicationModule {
|
|
|
|
|
2017-11-16 01:29:00 +01:00
|
|
|
private static final String TAG = SignalCommunicationModule.class.getSimpleName();
|
|
|
|
|
2017-09-16 07:38:53 +02:00
|
|
|
private final Context context;
|
|
|
|
private final SignalServiceNetworkAccess networkAccess;
|
|
|
|
|
|
|
|
private SignalServiceAccountManager accountManager;
|
|
|
|
private SignalServiceMessageSender messageSender;
|
|
|
|
private SignalServiceMessageReceiver messageReceiver;
|
2016-12-20 18:55:52 +01:00
|
|
|
|
2016-12-30 05:54:05 +01:00
|
|
|
public SignalCommunicationModule(Context context, SignalServiceNetworkAccess networkAccess) {
|
2017-01-12 00:37:51 +01:00
|
|
|
this.context = context;
|
|
|
|
this.networkAccess = networkAccess;
|
2020-12-07 02:41:03 +01:00
|
|
|
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:38:53 +02: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-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
@Provides
|
2019-06-28 08:08:27 +02:00
|
|
|
public synchronized SignalServiceMessageSender provideSignalMessageSender() {
|
2017-09-16 07:38:53 +02:00
|
|
|
if (this.messageSender == null) {
|
|
|
|
this.messageSender = new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
new SignalProtocolStoreImpl(context),
|
|
|
|
BuildConfig.USER_AGENT,
|
2018-05-22 11:13:10 +02:00
|
|
|
TextSecurePreferences.isMultiDevice(context),
|
2018-10-15 22:27:21 +02:00
|
|
|
Optional.fromNullable(IncomingMessageObserver.getPipe()),
|
2018-05-22 11:13:10 +02:00
|
|
|
Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()),
|
2019-10-24 08:16:53 +02:00
|
|
|
Optional.of(new MessageSenderEventListener(context)),
|
2019-06-11 08:27:00 +02:00
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
2019-06-12 03:41:50 +02:00
|
|
|
DatabaseFactory.getLokiAPIDatabase(context),
|
2020-08-10 07:29:36 +02:00
|
|
|
DatabaseFactory.getSSKDatabase(context),
|
2019-07-22 01:38:12 +02:00
|
|
|
DatabaseFactory.getLokiThreadDatabase(context),
|
2019-08-09 04:00:01 +02:00
|
|
|
DatabaseFactory.getLokiMessageDatabase(context),
|
2019-07-22 02:41:50 +02:00
|
|
|
DatabaseFactory.getLokiPreKeyBundleDatabase(context),
|
2020-07-15 06:26:20 +02:00
|
|
|
new SessionResetImplementation(context),
|
2020-01-16 04:35:51 +01:00
|
|
|
DatabaseFactory.getLokiUserDatabase(context),
|
2020-10-19 06:21:15 +02:00
|
|
|
DatabaseFactory.getGroupDatabase(context),
|
2020-01-16 04:35:51 +01:00
|
|
|
((ApplicationContext)context.getApplicationContext()).broadcaster);
|
2017-10-10 18:14:53 +02:00
|
|
|
} else {
|
2018-05-22 11:13:10 +02:00
|
|
|
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
|
|
|
|
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
|
2017-09-16 07:38:53 +02:00
|
|
|
}
|
2014-11-12 04:57:53 +01:00
|
|
|
|
2017-09-16 07:38:53 +02:00
|
|
|
return this.messageSender;
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:38:53 +02:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
|
|
|
if (this.messageReceiver == null) {
|
2019-01-24 12:04:28 +01:00
|
|
|
SleepTimer sleepTimer = TextSecurePreferences.isFcmDisabled(context) ? new RealtimeSleepTimer(context) : new UptimeSleepTimer();
|
2018-09-10 17:40:00 +02:00
|
|
|
|
2017-09-16 07:38:53 +02:00
|
|
|
this.messageReceiver = new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
2017-11-16 01:29:00 +01:00
|
|
|
BuildConfig.USER_AGENT,
|
2018-09-10 17:40:00 +02:00
|
|
|
new PipeConnectivityListener(),
|
|
|
|
sleepTimer);
|
2017-09-16 07:38:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.messageReceiver;
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2018-10-15 22:27:21 +02:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceNetworkAccess provideSignalServiceNetworkAccess() {
|
|
|
|
return networkAccess;
|
|
|
|
}
|
|
|
|
|
2015-01-26 02:43:24 +01: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-16 01:29:00 +01:00
|
|
|
private class PipeConnectivityListener implements ConnectivityListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnected() {
|
2018-08-02 15:25:33 +02:00
|
|
|
Log.i(TAG, "onConnected()");
|
2017-11-16 01:29:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnecting() {
|
2018-08-02 15:25:33 +02:00
|
|
|
Log.i(TAG, "onConnecting()");
|
2017-11-16 01:29:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisconnected() {
|
|
|
|
Log.w(TAG, "onDisconnected()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailure() {
|
|
|
|
Log.w(TAG, "onAuthenticationFailure()");
|
|
|
|
TextSecurePreferences.setUnauthorizedReceived(context, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|