2014-11-11 19:57:53 -08:00
|
|
|
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-11-15 16:29:00 -08:00
|
|
|
import android.util.Log;
|
2014-11-11 19:57:53 -08:00
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.greenrobot.eventbus.EventBus;
|
2015-05-14 18:14:42 -07:00
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.thoughtcrime.securesms.CreateProfileActivity;
|
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;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
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;
|
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;
|
2017-08-25 12:00:52 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
2017-09-21 11:27:53 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadReceiptUpdateJob;
|
2016-02-19 17:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
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-08-14 18:11:13 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
2017-05-19 18:01:40 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
2017-01-06 09:19:58 -08:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
2017-09-15 22:38:53 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
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;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
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;
|
2017-11-15 16:29:00 -08:00
|
|
|
import org.whispersystems.signalservice.api.websocket.ConnectivityListener;
|
2014-11-11 19:57:53 -08:00
|
|
|
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
|
|
|
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
|
|
CreateSignedPreKeyJob.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,
|
2016-11-09 09:37:40 -08:00
|
|
|
RotateSignedPreKeyJob.class,
|
2017-05-19 18:01:40 -07:00
|
|
|
WebRtcCallService.class,
|
2017-06-06 18:03:09 -07:00
|
|
|
RetrieveProfileJob.class,
|
2017-08-08 16:37:15 -07:00
|
|
|
MultiDeviceVerifiedUpdateJob.class,
|
2017-08-14 18:11:13 -07:00
|
|
|
CreateProfileActivity.class,
|
2017-08-25 12:00:52 -07:00
|
|
|
RetrieveProfileAvatarJob.class,
|
2017-09-15 22:38:53 -07:00
|
|
|
MultiDeviceProfileKeyUpdateJob.class,
|
2017-09-21 11:27:53 -07:00
|
|
|
SendReadReceiptJob.class,
|
|
|
|
MultiDeviceReadReceiptUpdateJob.class})
|
2016-12-20 09:55:52 -08:00
|
|
|
public class SignalCommunicationModule {
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
private static final String TAG = SignalCommunicationModule.class.getSimpleName();
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
private final Context context;
|
|
|
|
private final SignalServiceNetworkAccess networkAccess;
|
|
|
|
|
|
|
|
private SignalServiceAccountManager accountManager;
|
|
|
|
private SignalServiceMessageSender messageSender;
|
|
|
|
private SignalServiceMessageReceiver messageReceiver;
|
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
|
|
|
}
|
|
|
|
|
2017-09-15 22:38:53 -07: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-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2016-12-20 09:55:52 -08:00
|
|
|
@Provides
|
2017-09-15 22:38:53 -07:00
|
|
|
synchronized SignalServiceMessageSender provideSignalMessageSender() {
|
|
|
|
if (this.messageSender == null) {
|
|
|
|
this.messageSender = new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
|
|
|
new SignalProtocolStoreImpl(context),
|
|
|
|
BuildConfig.USER_AGENT,
|
|
|
|
Optional.fromNullable(MessageRetrievalService.getPipe()),
|
2017-10-10 09:14:53 -07:00
|
|
|
Optional.of(new SecurityEventListener(context)));
|
|
|
|
} else {
|
|
|
|
this.messageSender.setMessagePipe(MessageRetrievalService.getPipe());
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
2014-11-11 19:57:53 -08:00
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
return this.messageSender;
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
@Provides
|
|
|
|
synchronized SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
|
|
|
if (this.messageReceiver == null) {
|
|
|
|
this.messageReceiver = new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
|
|
|
new DynamicCredentialsProvider(context),
|
2017-11-15 16:29:00 -08:00
|
|
|
BuildConfig.USER_AGENT,
|
|
|
|
new PipeConnectivityListener());
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.messageReceiver;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 16:29:00 -08:00
|
|
|
private class PipeConnectivityListener implements ConnectivityListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnected() {
|
|
|
|
Log.w(TAG, "onConnected()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConnecting() {
|
|
|
|
Log.w(TAG, "onConnecting()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisconnected() {
|
|
|
|
Log.w(TAG, "onDisconnected()");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailure() {
|
|
|
|
Log.w(TAG, "onAuthenticationFailure()");
|
|
|
|
TextSecurePreferences.setUnauthorizedReceived(context, true);
|
|
|
|
EventBus.getDefault().post(new ReminderUpdateEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-11 19:57:53 -08:00
|
|
|
}
|