Search in sources :

Example 1 with StorageSyncJob

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

the class RegistrationUtil method maybeMarkRegistrationComplete.

/**
 * There's several events where a registration may or may not be considered complete based on what
 * path a user has taken. This will only truly mark registration as complete if all of the
 * requirements are met.
 */
public static void maybeMarkRegistrationComplete(@NonNull Context context) {
    if (!SignalStore.registrationValues().isRegistrationComplete() && SignalStore.account().isRegistered() && !Recipient.self().getProfileName().isEmpty() && (SignalStore.kbsValues().hasPin() || SignalStore.kbsValues().hasOptedOut())) {
        Log.i(TAG, "Marking registration completed.", new Throwable());
        SignalStore.registrationValues().setRegistrationComplete();
        ApplicationDependencies.getJobManager().startChain(new StorageSyncJob()).then(new DirectoryRefreshJob(false)).enqueue();
    } else if (!SignalStore.registrationValues().isRegistrationComplete()) {
        Log.i(TAG, "Registration is not yet complete.", new Throwable());
    }
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)

Example 2 with StorageSyncJob

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

the class RegistrationLockFragment method handleSuccessfulPinEntry.

@Override
protected void handleSuccessfulPinEntry(@NonNull String pin) {
    SignalStore.pinValues().setKeyboardType(getPinEntryKeyboardType());
    SimpleTask.run(() -> {
        SignalStore.onboarding().clearAll();
        Stopwatch stopwatch = new Stopwatch("RegistrationLockRestore");
        ApplicationDependencies.getJobManager().runSynchronously(new StorageAccountRestoreJob(), StorageAccountRestoreJob.LIFESPAN);
        stopwatch.split("AccountRestore");
        ApplicationDependencies.getJobManager().runSynchronously(new StorageSyncJob(), TimeUnit.SECONDS.toMillis(10));
        stopwatch.split("ContactRestore");
        try {
            FeatureFlags.refreshSync();
        } catch (IOException e) {
            Log.w(TAG, "Failed to refresh flags.", e);
        }
        stopwatch.split("FeatureFlags");
        stopwatch.stop(TAG);
        return null;
    }, none -> {
        cancelSpinning(pinButton);
        SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), RegistrationLockFragmentDirections.actionSuccessfulRegistration());
    });
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) StorageAccountRestoreJob(org.thoughtcrime.securesms.jobs.StorageAccountRestoreJob) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) IOException(java.io.IOException)

Example 3 with StorageSyncJob

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

the class DirectoryHelper method refreshDirectoryFor.

@WorkerThread
public static RegisteredState refreshDirectoryFor(@NonNull Context context, @NonNull Recipient recipient, boolean notifyOfNewUsers) throws IOException {
    Stopwatch stopwatch = new Stopwatch("single");
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    RegisteredState originalRegisteredState = recipient.resolve().getRegistered();
    RegisteredState newRegisteredState;
    if (recipient.hasServiceId() && !recipient.hasE164()) {
        boolean isRegistered = ApplicationDependencies.getSignalServiceAccountManager().isIdentifierRegistered(recipient.requireServiceId());
        stopwatch.split("aci-network");
        if (isRegistered) {
            boolean idChanged = recipientDatabase.markRegistered(recipient.getId(), recipient.requireServiceId());
            if (idChanged) {
                Log.w(TAG, "ID changed during refresh by UUID.");
            }
        } else {
            recipientDatabase.markUnregistered(recipient.getId());
        }
        stopwatch.split("aci-disk");
        stopwatch.stop(TAG);
        return isRegistered ? RegisteredState.REGISTERED : RegisteredState.NOT_REGISTERED;
    }
    if (!recipient.getE164().isPresent()) {
        Log.w(TAG, "No ACI or E164?");
        return RegisteredState.NOT_REGISTERED;
    }
    DirectoryResult result = ContactDiscoveryV2.getDirectoryResult(context, recipient.getE164().get());
    stopwatch.split("e164-network");
    if (result.getNumberRewrites().size() > 0) {
        Log.i(TAG, "[getDirectoryResult] Need to rewrite some numbers.");
        recipientDatabase.updatePhoneNumbers(result.getNumberRewrites());
    }
    if (result.getRegisteredNumbers().size() > 0) {
        ACI aci = result.getRegisteredNumbers().values().iterator().next();
        if (aci != null) {
            boolean idChanged = recipientDatabase.markRegistered(recipient.getId(), aci);
            if (idChanged) {
                recipient = Recipient.resolved(recipientDatabase.getByServiceId(aci).get());
            }
        } else {
            Log.w(TAG, "Registered number set had a null ACI!");
        }
    } else if (recipient.hasServiceId() && recipient.isRegistered() && hasCommunicatedWith(recipient)) {
        if (ApplicationDependencies.getSignalServiceAccountManager().isIdentifierRegistered(recipient.requireServiceId())) {
            recipientDatabase.markRegistered(recipient.getId(), recipient.requireServiceId());
        } else {
            recipientDatabase.markUnregistered(recipient.getId());
        }
        stopwatch.split("e164-unlisted-network");
    } else {
        recipientDatabase.markUnregistered(recipient.getId());
    }
    if (Permissions.hasAll(context, Manifest.permission.WRITE_CONTACTS)) {
        updateContactsDatabase(context, Collections.singletonList(recipient.getId()), false, result.getNumberRewrites());
    }
    newRegisteredState = result.getRegisteredNumbers().size() > 0 ? RegisteredState.REGISTERED : RegisteredState.NOT_REGISTERED;
    if (newRegisteredState != originalRegisteredState) {
        ApplicationDependencies.getJobManager().add(new MultiDeviceContactUpdateJob());
        ApplicationDependencies.getJobManager().add(new StorageSyncJob());
        if (notifyOfNewUsers && newRegisteredState == RegisteredState.REGISTERED && recipient.resolve().isSystemContact()) {
            notifyNewUsers(context, Collections.singletonList(recipient.getId()));
        }
        StorageSyncHelper.scheduleSyncForDataChange();
    }
    stopwatch.split("e164-disk");
    stopwatch.stop(TAG);
    return newRegisteredState;
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) ACI(org.whispersystems.signalservice.api.push.ACI) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with StorageSyncJob

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

the class AccountRecordMigrationJob method performMigration.

@Override
public void performMigration() {
    if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null) {
        Log.w(TAG, "Not registered!");
        return;
    }
    SignalDatabase.recipients().markNeedsSync(Recipient.self().getId());
    ApplicationDependencies.getJobManager().add(new StorageSyncJob());
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob)

Example 5 with StorageSyncJob

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

the class PinRestoreRepository method submitPin.

void submitPin(@NonNull String pin, @NonNull TokenData tokenData, @NonNull Callback<PinResultData> callback) {
    executor.execute(() -> {
        try {
            Stopwatch stopwatch = new Stopwatch("PinSubmission");
            KbsPinData kbsData = KbsRepository.restoreMasterKey(pin, tokenData.getEnclave(), tokenData.getBasicAuth(), tokenData.getTokenResponse());
            PinState.onSignalPinRestore(ApplicationDependencies.getApplication(), Objects.requireNonNull(kbsData), pin);
            stopwatch.split("MasterKey");
            ApplicationDependencies.getJobManager().runSynchronously(new StorageAccountRestoreJob(), StorageAccountRestoreJob.LIFESPAN);
            stopwatch.split("AccountRestore");
            ApplicationDependencies.getJobManager().runSynchronously(new StorageSyncJob(), TimeUnit.SECONDS.toMillis(10));
            stopwatch.split("ContactRestore");
            stopwatch.stop(TAG);
            callback.onComplete(new PinResultData(PinResult.SUCCESS, tokenData));
        } catch (IOException e) {
            callback.onComplete(new PinResultData(PinResult.NETWORK_ERROR, tokenData));
        } catch (KeyBackupSystemNoDataException e) {
            callback.onComplete(new PinResultData(PinResult.LOCKED, tokenData));
        } catch (KeyBackupSystemWrongPinException e) {
            callback.onComplete(new PinResultData(PinResult.INCORRECT, TokenData.withResponse(tokenData, e.getTokenResponse())));
        }
    });
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) StorageAccountRestoreJob(org.thoughtcrime.securesms.jobs.StorageAccountRestoreJob) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) IOException(java.io.IOException) KeyBackupSystemNoDataException(org.whispersystems.signalservice.api.KeyBackupSystemNoDataException)

Aggregations

StorageSyncJob (org.thoughtcrime.securesms.jobs.StorageSyncJob)6 Stopwatch (org.thoughtcrime.securesms.util.Stopwatch)3 IOException (java.io.IOException)2 StorageAccountRestoreJob (org.thoughtcrime.securesms.jobs.StorageAccountRestoreJob)2 WorkerThread (androidx.annotation.WorkerThread)1 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1 RegisteredState (org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState)1 JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)1 DirectoryRefreshJob (org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)1 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)1 MultiDeviceKeysUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceKeysUpdateJob)1 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)1 KeyBackupSystemNoDataException (org.whispersystems.signalservice.api.KeyBackupSystemNoDataException)1 ACI (org.whispersystems.signalservice.api.push.ACI)1