session-android/src/org/thoughtcrime/securesms/jobs/RefreshAttributesJob.java

84 lines
2.9 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.jobs;
import android.support.annotation.NonNull;
2018-10-11 23:45:22 +00:00
import org.thoughtcrime.securesms.ApplicationContext;
2019-03-28 15:56:35 +00:00
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
2018-08-01 15:09:24 +00:00
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.dependencies.InjectableType;
2018-05-22 09:13:10 +00:00
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
import java.io.IOException;
import javax.inject.Inject;
2019-03-28 15:56:35 +00:00
public class RefreshAttributesJob extends BaseJob implements InjectableType {
2019-03-28 15:56:35 +00:00
public static final String KEY = "RefreshAttributesJob";
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
2019-03-28 15:56:35 +00:00
@Inject SignalServiceAccountManager signalAccountManager;
2019-03-28 15:56:35 +00:00
public RefreshAttributesJob() {
this(new Job.Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue("RefreshAttributesJob")
.build());
}
2019-03-28 15:56:35 +00:00
private RefreshAttributesJob(@NonNull Job.Parameters parameters) {
super(parameters);
}
@Override
2019-03-28 15:56:35 +00:00
public @NonNull Data serialize() {
return Data.EMPTY;
}
@Override
2019-03-28 15:56:35 +00:00
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public void onRun() throws IOException {
2018-05-22 09:13:10 +00:00
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
2019-01-24 11:04:28 +00:00
boolean fetchesMessages = TextSecurePreferences.isFcmDisabled(context);
2018-05-22 09:13:10 +00:00
String pin = TextSecurePreferences.getRegistrationLockPin(context);
byte[] unidentifiedAccessKey = UnidentifiedAccessUtil.getSelfUnidentifiedAccessKey(context);
boolean universalUnidentifiedAccess = TextSecurePreferences.isUniversalUnidentifiedAccess(context);
2019-01-17 23:36:53 +00:00
signalAccountManager.setAccountAttributes(null, registrationId, fetchesMessages, pin,
2018-05-22 09:13:10 +00:00
unidentifiedAccessKey, universalUnidentifiedAccess);
2018-10-11 23:45:22 +00:00
ApplicationContext.getInstance(context)
.getJobManager()
2019-03-28 15:56:35 +00:00
.add(new RefreshUnidentifiedDeliveryAbilityJob());
}
@Override
public boolean onShouldRetry(@NonNull Exception e) {
return e instanceof NetworkFailureException;
}
@Override
public void onCanceled() {
Log.w(TAG, "Failed to update account attributes!");
}
2019-03-28 15:56:35 +00:00
public static class Factory implements Job.Factory<RefreshAttributesJob> {
@Override
public @NonNull RefreshAttributesJob create(@NonNull Parameters parameters, @NonNull org.thoughtcrime.securesms.jobmanager.Data data) {
return new RefreshAttributesJob(parameters);
}
}
}