2015-09-22 00:41:27 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
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;
|
2018-08-09 14:15:43 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.SafeData;
|
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-06-18 19:27:04 +00:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
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;
|
|
|
|
|
2018-08-09 14:15:43 +00:00
|
|
|
import androidx.work.Data;
|
2018-11-27 20:34:42 +00:00
|
|
|
import androidx.work.WorkerParameters;
|
2018-08-09 14:15:43 +00:00
|
|
|
|
2015-09-30 23:19:50 +00:00
|
|
|
public class RefreshAttributesJob extends ContextJob implements InjectableType {
|
|
|
|
|
|
|
|
public static final long serialVersionUID = 1L;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
private static final String TAG = RefreshAttributesJob.class.getSimpleName();
|
|
|
|
|
2016-11-09 17:37:40 +00:00
|
|
|
@Inject transient SignalServiceAccountManager signalAccountManager;
|
2015-09-22 00:41:27 +00:00
|
|
|
|
2018-11-27 20:34:42 +00:00
|
|
|
public RefreshAttributesJob(@NonNull Context context, @NonNull WorkerParameters workerParameters) {
|
|
|
|
super(context, workerParameters);
|
2018-08-09 14:15:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 00:41:27 +00:00
|
|
|
public RefreshAttributesJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
2018-08-09 14:15:43 +00:00
|
|
|
.withNetworkRequirement()
|
2016-11-09 17:37:40 +00:00
|
|
|
.withGroupId(RefreshAttributesJob.class.getName())
|
2015-09-22 00:41:27 +00:00
|
|
|
.create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-09 14:15:43 +00:00
|
|
|
protected void initialize(@NonNull SafeData data) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected @NonNull Data serialize(@NonNull Data.Builder dataBuilder) {
|
|
|
|
return dataBuilder.build();
|
|
|
|
}
|
2015-09-22 00:41:27 +00:00
|
|
|
|
|
|
|
@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));
|
2015-09-22 00:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
|
|
|
return e instanceof NetworkFailureException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "Failed to update account attributes!");
|
|
|
|
}
|
|
|
|
}
|