2014-11-12 04:57:53 +01:00
|
|
|
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
2015-05-15 03:14:42 +02:00
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
2017-08-09 01:37:15 +02:00
|
|
|
import org.thoughtcrime.securesms.CreateProfileActivity;
|
2015-11-19 19:21:19 +01:00
|
|
|
import org.thoughtcrime.securesms.DeviceListFragment;
|
2016-03-23 18:34:41 +01:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
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;
|
|
|
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
2015-10-01 01:19:50 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
2016-08-27 01:53:23 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
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;
|
2016-02-20 02:07:41 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
2017-06-07 03:03:09 +02:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
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;
|
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;
|
2017-01-06 18:19:58 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
2016-12-30 05:54:05 +01:00
|
|
|
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
2015-01-26 02:43:24 +01:00
|
|
|
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
2016-11-09 18:37:40 +01:00
|
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
2014-11-12 04:57:53 +01:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-03-23 18:34:41 +01: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;
|
2014-11-12 04:57:53 +01:00
|
|
|
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
|
|
|
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
|
|
CreateSignedPreKeyJob.class,
|
|
|
|
DeliveryReceiptJob.class,
|
|
|
|
PushGroupSendJob.class,
|
|
|
|
PushTextSendJob.class,
|
|
|
|
PushMediaSendJob.class,
|
|
|
|
AttachmentDownloadJob.class,
|
2015-01-26 02:43:24 +01:00
|
|
|
RefreshPreKeysJob.class,
|
2015-04-15 19:58:29 +02:00
|
|
|
MessageRetrievalService.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-11-19 19:21:19 +01:00
|
|
|
DeviceListFragment.class,
|
2015-10-01 01:19:50 +02:00
|
|
|
RefreshAttributesJob.class,
|
2016-11-20 23:50:41 +01:00
|
|
|
GcmRefreshJob.class,
|
|
|
|
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-05-20 03:01:40 +02:00
|
|
|
WebRtcCallService.class,
|
2017-06-07 03:03:09 +02:00
|
|
|
RetrieveProfileJob.class,
|
2017-08-09 01:37:15 +02:00
|
|
|
MultiDeviceVerifiedUpdateJob.class,
|
2017-08-15 03:11:13 +02:00
|
|
|
CreateProfileActivity.class,
|
|
|
|
RetrieveProfileAvatarJob.class})
|
2016-12-20 18:55:52 +01:00
|
|
|
public class SignalCommunicationModule {
|
|
|
|
|
2017-01-12 00:37:51 +01:00
|
|
|
private final Context context;
|
|
|
|
private final SignalServiceNetworkAccess networkAccess;
|
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;
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
@Provides SignalServiceAccountManager provideSignalAccountManager() {
|
2017-01-12 00:37:51 +01:00
|
|
|
return new SignalServiceAccountManager(networkAccess.getConfiguration(context),
|
2016-03-23 18:34:41 +01:00
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
@Provides
|
|
|
|
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
|
|
|
|
return new SignalMessageSenderFactory() {
|
2014-11-12 04:57:53 +01:00
|
|
|
@Override
|
2016-03-23 18:34:41 +01:00
|
|
|
public SignalServiceMessageSender create() {
|
2017-01-12 00:37:51 +01:00
|
|
|
return new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
2016-03-23 18:34:41 +01:00
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
|
|
new SignalProtocolStoreImpl(context),
|
|
|
|
BuildConfig.USER_AGENT,
|
2017-01-09 16:49:37 +01:00
|
|
|
Optional.fromNullable(MessageRetrievalService.getPipe()),
|
2016-03-23 18:34:41 +01:00
|
|
|
Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
@Provides SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
2017-01-12 00:37:51 +01:00
|
|
|
return new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
2016-12-20 18:55:52 +01:00
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 18:55:52 +01:00
|
|
|
public static interface SignalMessageSenderFactory {
|
2016-03-23 18:34:41 +01:00
|
|
|
public SignalServiceMessageSender create();
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 04:57:53 +01:00
|
|
|
}
|