mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-29 04:55:15 +00:00
ea0945d406
// FREEBIE
131 lines
6.1 KiB
Java
131 lines
6.1 KiB
Java
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
import android.content.Context;
|
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
|
import org.thoughtcrime.securesms.DeviceListFragment;
|
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
|
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
|
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
|
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
|
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
|
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
|
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
|
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
|
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
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;
|
|
|
|
import dagger.Module;
|
|
import dagger.Provides;
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
CreateSignedPreKeyJob.class,
|
|
DeliveryReceiptJob.class,
|
|
PushGroupSendJob.class,
|
|
PushTextSendJob.class,
|
|
PushMediaSendJob.class,
|
|
AttachmentDownloadJob.class,
|
|
RefreshPreKeysJob.class,
|
|
MessageRetrievalService.class,
|
|
PushNotificationReceiveJob.class,
|
|
MultiDeviceContactUpdateJob.class,
|
|
MultiDeviceGroupUpdateJob.class,
|
|
MultiDeviceReadUpdateJob.class,
|
|
MultiDeviceBlockedUpdateJob.class,
|
|
DeviceListFragment.class,
|
|
RefreshAttributesJob.class,
|
|
GcmRefreshJob.class,
|
|
RequestGroupInfoJob.class,
|
|
PushGroupUpdateJob.class,
|
|
AvatarDownloadJob.class,
|
|
RotateSignedPreKeyJob.class,
|
|
WebRtcCallService.class})
|
|
public class SignalCommunicationModule {
|
|
|
|
private final Context context;
|
|
private final SignalServiceNetworkAccess networkAccess;
|
|
|
|
public SignalCommunicationModule(Context context, SignalServiceNetworkAccess networkAccess) {
|
|
this.context = context;
|
|
this.networkAccess = networkAccess;
|
|
}
|
|
|
|
@Provides SignalServiceAccountManager provideSignalAccountManager() {
|
|
return new SignalServiceAccountManager(networkAccess.getConfiguration(context),
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
BuildConfig.USER_AGENT);
|
|
}
|
|
|
|
@Provides
|
|
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
|
|
return new SignalMessageSenderFactory() {
|
|
@Override
|
|
public SignalServiceMessageSender create() {
|
|
return new SignalServiceMessageSender(networkAccess.getConfiguration(context),
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
new SignalProtocolStoreImpl(context),
|
|
BuildConfig.USER_AGENT,
|
|
Optional.fromNullable(MessageRetrievalService.getPipe()),
|
|
Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
|
|
}
|
|
};
|
|
}
|
|
|
|
@Provides SignalServiceMessageReceiver provideSignalMessageReceiver() {
|
|
return new SignalServiceMessageReceiver(networkAccess.getConfiguration(context),
|
|
new DynamicCredentialsProvider(context),
|
|
BuildConfig.USER_AGENT);
|
|
}
|
|
|
|
public static interface SignalMessageSenderFactory {
|
|
public SignalServiceMessageSender create();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|