75 lines
2.3 KiB
Java
75 lines
2.3 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
|
import org.thoughtcrime.securesms.jobmanager.Data;
|
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
|
import org.thoughtcrime.securesms.logging.Log;
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
public class RemoteConfigRefreshJob extends BaseJob {
|
|
|
|
private static final String TAG = Log.tag(RemoteConfigRefreshJob.class);
|
|
|
|
public static final String KEY = "RemoteConfigRefreshJob";
|
|
|
|
public RemoteConfigRefreshJob() {
|
|
this(new Job.Parameters.Builder()
|
|
.setQueue("RemoteConfigRefreshJob")
|
|
.setMaxInstances(1)
|
|
.addConstraint(NetworkConstraint.KEY)
|
|
.setMaxAttempts(Parameters.UNLIMITED)
|
|
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
|
.build());
|
|
}
|
|
|
|
private RemoteConfigRefreshJob(@NonNull Parameters parameters) {
|
|
super(parameters);
|
|
}
|
|
|
|
@Override
|
|
public @NonNull Data serialize() {
|
|
return Data.EMPTY;
|
|
}
|
|
|
|
@Override
|
|
public @NonNull String getFactoryKey() {
|
|
return KEY;
|
|
}
|
|
|
|
@Override
|
|
protected void onRun() throws Exception {
|
|
if (!TextSecurePreferences.isPushRegistered(context)) {
|
|
Log.w(TAG, "Not registered. Skipping.");
|
|
return;
|
|
}
|
|
|
|
Map<String, Object> config = ApplicationDependencies.getSignalServiceAccountManager().getRemoteConfig();
|
|
FeatureFlags.update(config);
|
|
}
|
|
|
|
@Override
|
|
protected boolean onShouldRetry(@NonNull Exception e) {
|
|
return e instanceof PushNetworkException;
|
|
}
|
|
|
|
@Override
|
|
public void onFailure() {
|
|
}
|
|
|
|
public static final class Factory implements Job.Factory<RemoteConfigRefreshJob> {
|
|
@Override
|
|
public @NonNull RemoteConfigRefreshJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
|
return new RemoteConfigRefreshJob(parameters);
|
|
}
|
|
}
|
|
}
|