kopia lustrzana https://github.com/ryukoposting/Signal-Android
Remove two AsyncTasks.
rodzic
270606699b
commit
d651716d99
|
@ -60,6 +60,7 @@ import androidx.appcompat.widget.SwitchCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import org.signal.core.util.concurrent.SignalExecutors;
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||||
import org.thoughtcrime.securesms.components.camera.CameraView;
|
import org.thoughtcrime.securesms.components.camera.CameraView;
|
||||||
|
@ -79,7 +80,6 @@ import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||||
import org.thoughtcrime.securesms.util.DynamicDarkActionBarTheme;
|
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.IdentityUtil;
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
||||||
|
@ -617,36 +617,35 @@ public class VerifyIdentityActivity extends PassphraseRequiredActivity implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
|
||||||
new AsyncTask<Recipient, Void, Void>() {
|
final Recipient recipient = this.recipient.get();
|
||||||
@Override
|
final RecipientId recipientId = recipient.getId();
|
||||||
protected Void doInBackground(Recipient... params) {
|
|
||||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
|
||||||
if (isChecked) {
|
|
||||||
Log.i(TAG, "Saving identity: " + params[0].getId());
|
|
||||||
DatabaseFactory.getIdentityDatabase(getActivity())
|
|
||||||
.saveIdentity(params[0].getId(),
|
|
||||||
remoteIdentity,
|
|
||||||
VerifiedStatus.VERIFIED, false,
|
|
||||||
System.currentTimeMillis(), true);
|
|
||||||
} else {
|
|
||||||
DatabaseFactory.getIdentityDatabase(getActivity())
|
|
||||||
.setVerified(params[0].getId(),
|
|
||||||
remoteIdentity,
|
|
||||||
VerifiedStatus.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationDependencies.getJobManager()
|
SignalExecutors.BOUNDED.execute(() -> {
|
||||||
.add(new MultiDeviceVerifiedUpdateJob(recipient.getId(),
|
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||||
remoteIdentity,
|
if (isChecked) {
|
||||||
isChecked ? VerifiedStatus.VERIFIED :
|
Log.i(TAG, "Saving identity: " + recipientId);
|
||||||
VerifiedStatus.DEFAULT));
|
DatabaseFactory.getIdentityDatabase(getActivity())
|
||||||
StorageSyncHelper.scheduleSyncForDataChange();
|
.saveIdentity(recipientId,
|
||||||
|
remoteIdentity,
|
||||||
IdentityUtil.markIdentityVerified(getActivity(), recipient.get(), isChecked, false);
|
VerifiedStatus.VERIFIED, false,
|
||||||
|
System.currentTimeMillis(), true);
|
||||||
|
} else {
|
||||||
|
DatabaseFactory.getIdentityDatabase(getActivity())
|
||||||
|
.setVerified(recipientId,
|
||||||
|
remoteIdentity,
|
||||||
|
VerifiedStatus.DEFAULT);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
ApplicationDependencies.getJobManager()
|
||||||
|
.add(new MultiDeviceVerifiedUpdateJob(recipientId,
|
||||||
|
remoteIdentity,
|
||||||
|
isChecked ? VerifiedStatus.VERIFIED
|
||||||
|
: VerifiedStatus.DEFAULT));
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
|
|
||||||
|
IdentityUtil.markIdentityVerified(getActivity(), recipient, isChecked, false);
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient.get());
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
|
import org.signal.core.util.concurrent.SignalExecutors;
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.crypto.DatabaseSessionLock;
|
import org.thoughtcrime.securesms.crypto.DatabaseSessionLock;
|
||||||
|
@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.sms.OutgoingIdentityVerifiedMessage;
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||||
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||||
import org.whispersystems.libsignal.IdentityKey;
|
import org.whispersystems.libsignal.IdentityKey;
|
||||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||||
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
||||||
|
@ -41,25 +42,20 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IdentityUtil {
|
public final class IdentityUtil {
|
||||||
|
|
||||||
private static final String TAG = IdentityUtil.class.getSimpleName();
|
private IdentityUtil() {}
|
||||||
|
|
||||||
|
private static final String TAG = Log.tag(IdentityUtil.class);
|
||||||
|
|
||||||
public static ListenableFuture<Optional<IdentityRecord>> getRemoteIdentityKey(final Context context, final Recipient recipient) {
|
public static ListenableFuture<Optional<IdentityRecord>> getRemoteIdentityKey(final Context context, final Recipient recipient) {
|
||||||
final SettableFuture<Optional<IdentityRecord>> future = new SettableFuture<>();
|
final SettableFuture<Optional<IdentityRecord>> future = new SettableFuture<>();
|
||||||
|
final RecipientId recipientId = recipient.getId();
|
||||||
|
|
||||||
new AsyncTask<Recipient, Void, Optional<IdentityRecord>>() {
|
SimpleTask.run(SignalExecutors.BOUNDED,
|
||||||
@Override
|
() -> DatabaseFactory.getIdentityDatabase(context)
|
||||||
protected Optional<IdentityRecord> doInBackground(Recipient... recipient) {
|
.getIdentity(recipientId),
|
||||||
return DatabaseFactory.getIdentityDatabase(context)
|
future::set);
|
||||||
.getIdentity(recipient[0].getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Optional<IdentityRecord> result) {
|
|
||||||
future.set(result);
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
|
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue