2015-09-22 00:41:27 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2015-09-30 23:19:50 +00:00
|
|
|
import org.thoughtcrime.redphone.signaling.RedPhoneAccountAttributes;
|
|
|
|
import org.thoughtcrime.redphone.signaling.RedPhoneAccountManager;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2015-09-22 00:41:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.whispersystems.jobqueue.JobParameters;
|
|
|
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2015-09-30 23:19:50 +00:00
|
|
|
public class RefreshAttributesJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
public static final long serialVersionUID = 1L;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
|
|
|
|
2016-11-09 17:37:40 +00:00
|
|
|
@Inject transient SignalServiceAccountManager signalAccountManager;
|
2016-03-23 17:34:41 +00:00
|
|
|
@Inject transient RedPhoneAccountManager redPhoneAccountManager;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
public RefreshAttributesJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withPersistence()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
|
|
|
.withWakeLock(true)
|
2016-11-09 17:37:40 +00:00
|
|
|
.withGroupId(RefreshAttributesJob.class.getName())
|
2015-09-22 00:41:27 +00:00
|
|
|
.create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException {
|
2016-11-09 17:37:40 +00:00
|
|
|
String signalingKey = TextSecurePreferences.getSignalingKey(context);
|
|
|
|
String gcmRegistrationId = TextSecurePreferences.getGcmRegistrationId(context);
|
|
|
|
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
|
|
|
|
boolean video = TextSecurePreferences.isWebrtcCallingEnabled(context);
|
2015-09-30 23:19:50 +00:00
|
|
|
|
2016-11-09 17:37:40 +00:00
|
|
|
String token = signalAccountManager.getAccountVerificationToken();
|
2015-09-22 00:41:27 +00:00
|
|
|
|
2015-09-30 23:19:50 +00:00
|
|
|
redPhoneAccountManager.createAccount(token, new RedPhoneAccountAttributes(signalingKey, gcmRegistrationId));
|
2016-11-09 17:37:40 +00:00
|
|
|
signalAccountManager.setAccountAttributes(signalingKey, registrationId, true, video);
|
2015-09-22 00:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
return e instanceof NetworkFailureException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "Failed to update account attributes!");
|
|
|
|
}
|
|
|
|
}
|