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

79 lines
2.8 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
2018-10-11 23:45:22 +00:00
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.jobmanager.SafeData;
2018-08-01 15:09:24 +00:00
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.jobmanager.JobParameters;
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;
import androidx.work.Data;
2018-11-27 20:34:42 +00:00
import androidx.work.WorkerParameters;
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;
2018-11-27 20:34:42 +00:00
public RefreshAttributesJob(@NonNull Context context, @NonNull WorkerParameters workerParameters) {
super(context, workerParameters);
}
public RefreshAttributesJob(Context context) {
super(context, JobParameters.newBuilder()
.withNetworkRequirement()
.withGroupId(RefreshAttributesJob.class.getName())
.create());
}
@Override
protected void initialize(@NonNull SafeData data) {
}
@Override
protected @NonNull Data serialize(@NonNull Data.Builder dataBuilder) {
return dataBuilder.build();
}
@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()
.add(new RefreshUnidentifiedDeliveryAbilityJob(context));
}
@Override
public boolean onShouldRetry(Exception e) {
return e instanceof NetworkFailureException;
}
@Override
public void onCanceled() {
Log.w(TAG, "Failed to update account attributes!");
}
}