mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-13 08:13:40 +00:00
42f1baaf61
We have to make some changes, and it's gotten to the point where maintaining it as a separate library is more hassle than it's worth, especially with Google releasing WorkManager as the preferred job scheduling library.
70 lines
2.6 KiB
Java
70 lines
2.6 KiB
Java
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
|
|
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
import org.whispersystems.libsignal.IdentityKeyPair;
|
|
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
public class RotateSignedPreKeyJob extends MasterSecretJob implements InjectableType {
|
|
|
|
private static final String TAG = RotateSignedPreKeyJob.class.getName();
|
|
|
|
@Inject transient SignalServiceAccountManager accountManager;
|
|
|
|
public RotateSignedPreKeyJob(Context context) {
|
|
super(context, JobParameters.newBuilder()
|
|
.withRequirement(new NetworkRequirement(context))
|
|
.withRequirement(new MasterSecretRequirement(context))
|
|
.withRetryCount(5)
|
|
.create());
|
|
}
|
|
|
|
@Override
|
|
public void onAdded() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onRun(MasterSecret masterSecret) throws Exception {
|
|
Log.w(TAG, "Rotating signed prekey...");
|
|
|
|
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
|
|
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
|
|
|
|
accountManager.setSignedPreKey(signedPreKeyRecord);
|
|
|
|
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
|
|
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
|
TextSecurePreferences.setSignedPreKeyFailureCount(context, 0);
|
|
|
|
ApplicationContext.getInstance(context)
|
|
.getJobManager()
|
|
.add(new CleanPreKeysJob(context));
|
|
}
|
|
|
|
@Override
|
|
public boolean onShouldRetryThrowable(Exception exception) {
|
|
return exception instanceof PushNetworkException;
|
|
}
|
|
|
|
@Override
|
|
public void onCanceled() {
|
|
TextSecurePreferences.setSignedPreKeyFailureCount(context, TextSecurePreferences.getSignedPreKeyFailureCount(context) + 1);
|
|
}
|
|
}
|