2014-11-11 19:57:53 -08:00
|
|
|
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
2015-05-14 18:14:42 -07:00
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
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;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
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;
|
|
|
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
2015-09-30 16:19:50 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
2016-08-26 16:53:23 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
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;
|
2016-02-19 17:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
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;
|
2016-11-20 14:50:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
2017-01-06 09:19:58 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
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;
|
2015-01-25 17:43:24 -08:00
|
|
|
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
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;
|
2014-11-11 19:57:53 -08: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-25 17:43:24 -08:00
|
|
|
RefreshPreKeysJob.class,
|
2015-04-15 10:58:29 -07:00
|
|
|
MessageRetrievalService.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,
|
2016-11-20 14:50:41 -08:00
|
|
|
GcmRefreshJob.class,
|
|
|
|
RequestGroupInfoJob.class,
|
2016-12-20 09:55:52 -08:00
|
|
|
PushGroupUpdateJob.class,
|
2017-01-06 09:19:58 -08:00
|
|
|
AvatarDownloadJob.class,
|
|
|
|
RotateSignedPreKeyJob.class})
|
2016-12-20 09:55:52 -08:00
|
|
|
public class SignalCommunicationModule {
|
|
|
|
|
2017-01-11 15:37:51 -08:00
|
|
|
private final Context context;
|
|
|
|
private final SignalServiceNetworkAccess networkAccess;
|
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
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
@Provides SignalServiceAccountManager provideSignalAccountManager() {
|
2017-01-11 15:37:51 -08:00
|
|
|
return new SignalServiceAccountManager(networkAccess.getConfiguration(context),
|
2016-03-23 10:34:41 -07:00
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
@Provides
|
|
|
|
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
|
|
|
|
return new SignalMessageSenderFactory() {
|
2014-11-11 19:57:53 -08:00
|
|
|
@Override
|
2016-03-23 10:34:41 -07:00
|
|
|
public SignalServiceMessageSender create() {
|
2017-01-11 15:37:51 -08:00
|
|
|
return new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
2016-03-23 10:34:41 -07:00
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
|
|
new SignalProtocolStoreImpl(context),
|
|
|
|
BuildConfig.USER_AGENT,
|
2017-01-09 07:49:37 -08:00
|
|
|
Optional.fromNullable(MessageRetrievalService.getPipe()),
|
2016-03-23 10:34:41 -07:00
|
|
|
Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
@Provides SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
2017-01-11 15:37:51 -08:00
|
|
|
return new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
2016-12-20 09:55:52 -08:00
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
public static interface SignalMessageSenderFactory {
|
2016-03-23 10:34:41 -07:00
|
|
|
public SignalServiceMessageSender create();
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|