2015-09-21 17:41:27 -07:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-09-21 17:41:27 -07:00
|
|
|
|
2015-09-30 16:19:50 -07:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2018-06-18 12:27:04 -07:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
|
2015-09-21 17:41:27 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
2015-09-21 17:41:27 -07:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2017-04-19 21:55:44 -07:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2015-09-21 17:41:27 -07:00
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2015-09-30 16:19:50 -07:00
|
|
|
public class RefreshAttributesJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
public static final long serialVersionUID = 1L;
|
2015-09-21 17:41:27 -07:00
|
|
|
|
|
|
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
@Inject transient SignalServiceAccountManager signalAccountManager;
|
2015-09-21 17:41:27 -07:00
|
|
|
|
|
|
|
public RefreshAttributesJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withPersistence()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
2017-04-19 21:55:44 -07:00
|
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS)
|
2016-11-09 09:37:40 -08:00
|
|
|
.withGroupId(RefreshAttributesJob.class.getName())
|
2015-09-21 17:41:27 -07:00
|
|
|
.create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException {
|
2018-03-01 09:51:37 -08:00
|
|
|
String signalingKey = TextSecurePreferences.getSignalingKey(context);
|
|
|
|
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
|
|
|
|
boolean fetchesMessages = TextSecurePreferences.isGcmDisabled(context);
|
|
|
|
String pin = TextSecurePreferences.getRegistrationLockPin(context);
|
2015-09-30 16:19:50 -07:00
|
|
|
|
2018-03-01 09:51:37 -08:00
|
|
|
signalAccountManager.setAccountAttributes(signalingKey, registrationId, fetchesMessages, pin);
|
2015-09-21 17:41:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
return e instanceof NetworkFailureException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "Failed to update account attributes!");
|
|
|
|
}
|
|
|
|
}
|