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.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;
|
2017-04-20 04:55:44 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
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;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
public RefreshAttributesJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withPersistence()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
2017-04-20 04:55:44 +00:00
|
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS)
|
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 {
|
2018-03-01 17:51:37 +00:00
|
|
|
String signalingKey = TextSecurePreferences.getSignalingKey(context);
|
|
|
|
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
|
|
|
|
boolean fetchesMessages = TextSecurePreferences.isGcmDisabled(context);
|
|
|
|
String pin = TextSecurePreferences.getRegistrationLockPin(context);
|
2015-09-30 23:19:50 +00:00
|
|
|
|
2018-03-01 17:51:37 +00:00
|
|
|
signalAccountManager.setAccountAttributes(signalingKey, registrationId, fetchesMessages, pin);
|
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!");
|
|
|
|
}
|
|
|
|
}
|