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

79 lines
2.7 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;
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() {
super(null, null);
}
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
String signalingKey = TextSecurePreferences.getSignalingKey(context);
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
boolean fetchesMessages = TextSecurePreferences.isGcmDisabled(context);
String pin = TextSecurePreferences.getRegistrationLockPin(context);
byte[] unidentifiedAccessKey = UnidentifiedAccessUtil.getSelfUnidentifiedAccessKey(context);
boolean universalUnidentifiedAccess = TextSecurePreferences.isUniversalUnidentifiedAccess(context);
signalAccountManager.setAccountAttributes(signalingKey, registrationId, fetchesMessages, pin,
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!");
}
}