2015-09-22 00:41:27 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
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;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
2015-09-30 23:19:50 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2018-05-22 09:13:10 +00:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
2015-09-22 00:41:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
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;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public class RefreshAttributesJob extends BaseJob implements InjectableType {
|
2018-08-09 14:15:43 +00:00
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public static final String KEY = "RefreshAttributesJob";
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
@Inject SignalServiceAccountManager signalAccountManager;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
public RefreshAttributesJob() {
|
|
|
|
this(new Job.Parameters.Builder()
|
|
|
|
.addConstraint(NetworkConstraint.KEY)
|
|
|
|
.setQueue("RefreshAttributesJob")
|
|
|
|
.build());
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 15:56:35 +00:00
|
|
|
private RefreshAttributesJob(@NonNull Job.Parameters parameters) {
|
|
|
|
super(parameters);
|
2015-09-22 00:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-03-28 15:56:35 +00:00
|
|
|
public @NonNull Data serialize() {
|
|
|
|
return Data.EMPTY;
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-03-28 15:56:35 +00:00
|
|
|
public @NonNull String getFactoryKey() {
|
|
|
|
return KEY;
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
@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());
|
2015-09-22 00:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public boolean onShouldRetry(@NonNull Exception e) {
|
2015-09-22 00:41:27 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-09-22 00:41:27 +00:00
|
|
|
}
|