Search in sources :

Example 1 with MultiDeviceVerifiedUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob in project Signal-Android by WhisperSystems.

the class VerifyDisplayFragment method updateVerifyButton.

private void updateVerifyButton(boolean verified, boolean update) {
    currentVerifiedState = verified;
    if (verified) {
        verifyButton.setText(R.string.verify_display_fragment__clear_verification);
    } else {
        verifyButton.setText(R.string.verify_display_fragment__mark_as_verified);
    }
    if (update) {
        final RecipientId recipientId = recipient.getId();
        final Context context = requireContext().getApplicationContext();
        SignalExecutors.BOUNDED.execute(() -> {
            try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
                if (verified) {
                    Log.i(TAG, "Saving identity: " + recipientId);
                    ApplicationDependencies.getProtocolStore().aci().identities().saveIdentityWithoutSideEffects(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.VERIFIED, false, System.currentTimeMillis(), true);
                } else {
                    ApplicationDependencies.getProtocolStore().aci().identities().setVerified(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.DEFAULT);
                }
                ApplicationDependencies.getJobManager().add(new MultiDeviceVerifiedUpdateJob(recipientId, remoteIdentity, verified ? IdentityDatabase.VerifiedStatus.VERIFIED : IdentityDatabase.VerifiedStatus.DEFAULT));
                StorageSyncHelper.scheduleSyncForDataChange();
                IdentityUtil.markIdentityVerified(context, recipient.get(), verified, false);
            }
        });
    }
}
Also used : Context(android.content.Context) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock)

Example 2 with MultiDeviceVerifiedUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_multiDeviceVerifiedUpdateJob.

@Test
public void migrate_multiDeviceVerifiedUpdateJob() throws Exception {
    JobData testData = new JobData("MultiDeviceVerifiedUpdateJob", "__MULTI_DEVICE_VERIFIED_UPDATE__", new Data.Builder().putString("destination", "+16101234567").putString("identity_key", "abcd").putInt("verified_status", 1).putLong("timestamp", 123).build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("MultiDeviceVerifiedUpdateJob", converted.getFactoryKey());
    assertEquals("__MULTI_DEVICE_VERIFIED_UPDATE__", converted.getQueueKey());
    assertEquals("abcd", converted.getData().getString("identity_key"));
    assertEquals(1, converted.getData().getInt("verified_status"));
    assertEquals(123, converted.getData().getLong("timestamp"));
    assertEquals("1", converted.getData().getString("destination"));
    new MultiDeviceVerifiedUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MultiDeviceVerifiedUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob in project Signal-Android by signalapp.

the class RecipientIdJobMigrationTest method migrate_multiDeviceVerifiedUpdateJob.

@Test
public void migrate_multiDeviceVerifiedUpdateJob() throws Exception {
    JobData testData = new JobData("MultiDeviceVerifiedUpdateJob", "__MULTI_DEVICE_VERIFIED_UPDATE__", new Data.Builder().putString("destination", "+16101234567").putString("identity_key", "abcd").putInt("verified_status", 1).putLong("timestamp", 123).build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("MultiDeviceVerifiedUpdateJob", converted.getFactoryKey());
    assertEquals("__MULTI_DEVICE_VERIFIED_UPDATE__", converted.getQueueKey());
    assertEquals("abcd", converted.getData().getString("identity_key"));
    assertEquals(1, converted.getData().getInt("verified_status"));
    assertEquals(123, converted.getData().getLong("timestamp"));
    assertEquals("1", converted.getData().getString("destination"));
    new MultiDeviceVerifiedUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with MultiDeviceVerifiedUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob in project Signal-Android by signalapp.

the class VerifyDisplayFragment method updateVerifyButton.

private void updateVerifyButton(boolean verified, boolean update) {
    currentVerifiedState = verified;
    if (verified) {
        verifyButton.setText(R.string.verify_display_fragment__clear_verification);
    } else {
        verifyButton.setText(R.string.verify_display_fragment__mark_as_verified);
    }
    if (update) {
        final RecipientId recipientId = recipient.getId();
        final Context context = requireContext().getApplicationContext();
        SignalExecutors.BOUNDED.execute(() -> {
            try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
                if (verified) {
                    Log.i(TAG, "Saving identity: " + recipientId);
                    ApplicationDependencies.getProtocolStore().aci().identities().saveIdentityWithoutSideEffects(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.VERIFIED, false, System.currentTimeMillis(), true);
                } else {
                    ApplicationDependencies.getProtocolStore().aci().identities().setVerified(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.DEFAULT);
                }
                ApplicationDependencies.getJobManager().add(new MultiDeviceVerifiedUpdateJob(recipientId, remoteIdentity, verified ? IdentityDatabase.VerifiedStatus.VERIFIED : IdentityDatabase.VerifiedStatus.DEFAULT));
                StorageSyncHelper.scheduleSyncForDataChange();
                IdentityUtil.markIdentityVerified(context, recipient.get(), verified, false);
            }
        });
    }
}
Also used : Context(android.content.Context) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock)

Aggregations

MultiDeviceVerifiedUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob)4 Application (android.app.Application)2 Context (android.content.Context)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JobData (org.thoughtcrime.securesms.jobmanager.JobMigration.JobData)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 SignalSessionLock (org.whispersystems.signalservice.api.SignalSessionLock)2