You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
6.3 KiB
Java
139 lines
6.3 KiB
Java
11 years ago
|
package org.thoughtcrime.securesms.dependencies;
|
||
|
|
||
|
import android.content.Context;
|
||
|
|
||
10 years ago
|
import org.thoughtcrime.securesms.BuildConfig;
|
||
10 years ago
|
import org.thoughtcrime.securesms.DeviceListFragment;
|
||
9 years ago
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
||
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
||
10 years ago
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
||
10 years ago
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
||
10 years ago
|
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
||
10 years ago
|
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
||
10 years ago
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||
11 years ago
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
||
9 years ago
|
import org.thoughtcrime.securesms.push.Censorship;
|
||
|
import org.thoughtcrime.securesms.push.SignalServiceTrustStore;
|
||
|
import org.thoughtcrime.securesms.push.CensorshipFrontingTrustStore;
|
||
11 years ago
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
||
10 years ago
|
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
||
11 years ago
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||
9 years ago
|
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;
|
||
9 years ago
|
import org.whispersystems.signalservice.api.push.TrustStore;
|
||
9 years ago
|
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
||
9 years ago
|
import org.whispersystems.signalservice.internal.push.SignalServiceUrl;
|
||
11 years ago
|
|
||
|
import dagger.Module;
|
||
|
import dagger.Provides;
|
||
|
|
||
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
||
|
CreateSignedPreKeyJob.class,
|
||
|
DeliveryReceiptJob.class,
|
||
|
PushGroupSendJob.class,
|
||
|
PushTextSendJob.class,
|
||
|
PushMediaSendJob.class,
|
||
|
AttachmentDownloadJob.class,
|
||
10 years ago
|
RefreshPreKeysJob.class,
|
||
10 years ago
|
MessageRetrievalService.class,
|
||
10 years ago
|
PushNotificationReceiveJob.class,
|
||
10 years ago
|
MultiDeviceContactUpdateJob.class,
|
||
10 years ago
|
MultiDeviceGroupUpdateJob.class,
|
||
9 years ago
|
MultiDeviceReadUpdateJob.class,
|
||
9 years ago
|
MultiDeviceBlockedUpdateJob.class,
|
||
10 years ago
|
DeviceListFragment.class,
|
||
10 years ago
|
RefreshAttributesJob.class,
|
||
9 years ago
|
GcmRefreshJob.class,
|
||
|
RequestGroupInfoJob.class,
|
||
9 years ago
|
PushGroupUpdateJob.class,
|
||
|
AvatarDownloadJob.class})
|
||
|
public class SignalCommunicationModule {
|
||
|
|
||
|
private final Context context;
|
||
|
private final SignalServiceUrl url;
|
||
|
private final TrustStore trustStore;
|
||
|
|
||
|
public SignalCommunicationModule(Context context) {
|
||
|
this.context = context;
|
||
|
|
||
|
if (Censorship.isCensored(context)) {
|
||
|
this.url = new SignalServiceUrl(BuildConfig.UNCENSORED_FRONTING_HOST, BuildConfig.CENSORED_REFLECTOR);
|
||
|
this.trustStore = new CensorshipFrontingTrustStore(context);
|
||
|
} else {
|
||
|
this.url = new SignalServiceUrl(BuildConfig.TEXTSECURE_URL, null);
|
||
|
this.trustStore = new SignalServiceTrustStore(context);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
@Provides SignalServiceAccountManager provideSignalAccountManager() {
|
||
|
return new SignalServiceAccountManager(this.url, this.trustStore,
|
||
9 years ago
|
TextSecurePreferences.getLocalNumber(context),
|
||
|
TextSecurePreferences.getPushServerPassword(context),
|
||
|
BuildConfig.USER_AGENT);
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
@Provides
|
||
|
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
|
||
|
return new SignalMessageSenderFactory() {
|
||
11 years ago
|
@Override
|
||
9 years ago
|
public SignalServiceMessageSender create() {
|
||
9 years ago
|
return new SignalServiceMessageSender(SignalCommunicationModule.this.url,
|
||
|
SignalCommunicationModule.this.trustStore,
|
||
9 years ago
|
TextSecurePreferences.getLocalNumber(context),
|
||
|
TextSecurePreferences.getPushServerPassword(context),
|
||
|
new SignalProtocolStoreImpl(context),
|
||
|
BuildConfig.USER_AGENT,
|
||
|
Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
|
||
11 years ago
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
9 years ago
|
@Provides SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
||
|
return new SignalServiceMessageReceiver(this.url, this.trustStore,
|
||
|
new DynamicCredentialsProvider(context),
|
||
|
BuildConfig.USER_AGENT);
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
public static interface SignalMessageSenderFactory {
|
||
9 years ago
|
public SignalServiceMessageSender create();
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
}
|