51 lines
1.5 KiB
Java
51 lines
1.5 KiB
Java
|
package org.thoughtcrime.securesms.jobs;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.util.Log;
|
||
|
|
||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||
|
import org.whispersystems.jobqueue.JobParameters;
|
||
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||
|
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
||
|
import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
import javax.inject.Inject;
|
||
|
|
||
|
public class RefreshAttributesJob extends ContextJob {
|
||
|
|
||
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
||
|
|
||
|
@Inject TextSecureAccountManager accountManager;
|
||
|
|
||
|
public RefreshAttributesJob(Context context) {
|
||
|
super(context, JobParameters.newBuilder()
|
||
|
.withPersistence()
|
||
|
.withRequirement(new NetworkRequirement(context))
|
||
|
.withWakeLock(true)
|
||
|
.create());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAdded() {}
|
||
|
|
||
|
@Override
|
||
|
public void onRun() throws IOException {
|
||
|
String signalingKey = TextSecurePreferences.getSignalingKey(context);
|
||
|
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
|
||
|
|
||
|
accountManager.setAccountAttributes(signalingKey, registrationId, true);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean onShouldRetry(Exception e) {
|
||
|
return e instanceof NetworkFailureException;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onCanceled() {
|
||
|
Log.w(TAG, "Failed to update account attributes!");
|
||
|
}
|
||
|
}
|