mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
2c4c0f1349
Fixes #6703 // FREEBIE
56 lines
1.9 KiB
Java
56 lines
1.9 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
import org.whispersystems.jobqueue.JobParameters;
|
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
|
|
|
import java.io.IOException;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
public class RefreshAttributesJob extends ContextJob implements InjectableType {
|
|
|
|
public static final long serialVersionUID = 1L;
|
|
|
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
|
|
|
@Inject transient SignalServiceAccountManager signalAccountManager;
|
|
|
|
public RefreshAttributesJob(Context context) {
|
|
super(context, JobParameters.newBuilder()
|
|
.withPersistence()
|
|
.withRequirement(new NetworkRequirement(context))
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS)
|
|
.withGroupId(RefreshAttributesJob.class.getName())
|
|
.create());
|
|
}
|
|
|
|
@Override
|
|
public void onAdded() {}
|
|
|
|
@Override
|
|
public void onRun() throws IOException {
|
|
String signalingKey = TextSecurePreferences.getSignalingKey(context);
|
|
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
|
|
boolean fetchesMessages = TextSecurePreferences.isGcmDisabled(context);
|
|
|
|
signalAccountManager.setAccountAttributes(signalingKey, registrationId, fetchesMessages);
|
|
}
|
|
|
|
@Override
|
|
public boolean onShouldRetry(Exception e) {
|
|
return e instanceof NetworkFailureException;
|
|
}
|
|
|
|
@Override
|
|
public void onCanceled() {
|
|
Log.w(TAG, "Failed to update account attributes!");
|
|
}
|
|
}
|