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-06-19 22:02:10 -07:00
|
|
|
import org.thoughtcrime.securesms.DeviceListActivity;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
|
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
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;
|
2014-11-11 19:57:53 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
|
|
|
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;
|
|
|
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
|
|
|
import org.thoughtcrime.securesms.push.TextSecurePushTrustStore;
|
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;
|
|
|
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
|
|
|
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
|
|
|
import org.whispersystems.textsecure.api.TextSecureMessageReceiver;
|
|
|
|
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
2015-01-25 17:43:24 -08:00
|
|
|
import org.whispersystems.textsecure.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,
|
2015-09-21 17:41:27 -07:00
|
|
|
DeviceListActivity.DeviceListFragment.class,
|
|
|
|
RefreshAttributesJob.class})
|
2014-11-11 19:57:53 -08:00
|
|
|
public class TextSecureCommunicationModule {
|
|
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
public TextSecureCommunicationModule(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Provides TextSecureAccountManager provideTextSecureAccountManager() {
|
2015-09-09 13:54:29 -07:00
|
|
|
return new TextSecureAccountManager(BuildConfig.TEXTSECURE_URL,
|
2014-11-11 19:57:53 -08:00
|
|
|
new TextSecurePushTrustStore(context),
|
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
2015-09-09 13:54:29 -07:00
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Provides TextSecureMessageSenderFactory provideTextSecureMessageSenderFactory() {
|
|
|
|
return new TextSecureMessageSenderFactory() {
|
|
|
|
@Override
|
2015-07-06 17:36:49 -07:00
|
|
|
public TextSecureMessageSender create() {
|
2015-09-09 13:54:29 -07:00
|
|
|
return new TextSecureMessageSender(BuildConfig.TEXTSECURE_URL,
|
2015-03-03 11:44:49 -08:00
|
|
|
new TextSecurePushTrustStore(context),
|
|
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
|
|
TextSecurePreferences.getPushServerPassword(context),
|
2015-07-06 17:36:49 -07:00
|
|
|
new TextSecureAxolotlStore(context),
|
2015-09-09 13:54:29 -07:00
|
|
|
BuildConfig.USER_AGENT,
|
2015-08-13 00:39:08 +01:00
|
|
|
Optional.<TextSecureMessageSender.EventListener>of(new SecurityEventListener(context)));
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Provides TextSecureMessageReceiver provideTextSecureMessageReceiver() {
|
2015-09-09 13:54:29 -07:00
|
|
|
return new TextSecureMessageReceiver(BuildConfig.TEXTSECURE_URL,
|
2015-01-25 17:43:24 -08:00
|
|
|
new TextSecurePushTrustStore(context),
|
2015-09-09 13:54:29 -07:00
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
BuildConfig.USER_AGENT);
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static interface TextSecureMessageSenderFactory {
|
2015-07-06 17:36:49 -07:00
|
|
|
public TextSecureMessageSender 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
|
|
|
}
|