Search in sources :

Example 1 with SignalServiceAccountManager

use of org.whispersystems.signalservice.api.SignalServiceAccountManager in project Signal-Android by WhisperSystems.

the class RegistrationService method handleVoiceRegistrationIntent.

private void handleVoiceRegistrationIntent(Intent intent) {
    markAsVerifying(true);
    String number = intent.getStringExtra(NUMBER_EXTRA);
    String password = intent.getStringExtra(PASSWORD_EXTRA);
    String signalingKey = intent.getStringExtra(SIGNALING_KEY_EXTRA);
    boolean supportsGcm = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
    try {
        SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(this, number, password);
        handleCommonRegistration(accountManager, number, password, signalingKey, supportsGcm);
        markAsVerified(number, password, signalingKey);
        setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
        broadcastComplete(true);
    } catch (UnsupportedOperationException uoe) {
        Log.w("RegistrationService", uoe);
        setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
        broadcastComplete(false);
    } catch (IOException e) {
        Log.w("RegistrationService", e);
        setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
        broadcastComplete(false);
    }
}
Also used : SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) IOException(java.io.IOException)

Example 2 with SignalServiceAccountManager

use of org.whispersystems.signalservice.api.SignalServiceAccountManager in project Signal-Android by WhisperSystems.

the class RegistrationService method handleSmsRegistrationIntent.

private void handleSmsRegistrationIntent(Intent intent) {
    markAsVerifying(true);
    String number = intent.getStringExtra(NUMBER_EXTRA);
    boolean supportsGcm = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
    int registrationId = TextSecurePreferences.getLocalRegistrationId(this);
    boolean supportsVideo = TextSecurePreferences.isWebrtcCallingEnabled(this) || !supportsGcm;
    if (registrationId == 0) {
        registrationId = KeyHelper.generateRegistrationId(false);
        TextSecurePreferences.setLocalRegistrationId(this, registrationId);
    }
    try {
        String password = Util.getSecret(18);
        String signalingKey = Util.getSecret(52);
        initializeChallengeListener();
        setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
        SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(this, number, password);
        accountManager.requestSmsVerificationCode();
        setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
        String challenge = waitForChallenge();
        accountManager.verifyAccountWithCode(challenge, signalingKey, registrationId, true, supportsVideo, !supportsGcm);
        handleCommonRegistration(accountManager, number, password, signalingKey, supportsGcm);
        markAsVerified(number, password, signalingKey);
        setState(new RegistrationState(RegistrationState.STATE_COMPLETE, number));
        broadcastComplete(true);
    } catch (ExpectationFailedException efe) {
        Log.w("RegistrationService", efe);
        setState(new RegistrationState(RegistrationState.STATE_MULTI_REGISTERED, number));
        broadcastComplete(false);
    } catch (UnsupportedOperationException uoe) {
        Log.w("RegistrationService", uoe);
        setState(new RegistrationState(RegistrationState.STATE_GCM_UNSUPPORTED, number));
        broadcastComplete(false);
    } catch (AccountVerificationTimeoutException avte) {
        Log.w("RegistrationService", avte);
        setState(new RegistrationState(RegistrationState.STATE_TIMEOUT, number));
        broadcastComplete(false);
    } catch (IOException e) {
        Log.w("RegistrationService", e);
        setState(new RegistrationState(RegistrationState.STATE_NETWORK_ERROR, number));
        broadcastComplete(false);
    } finally {
        shutdownChallengeListener();
    }
}
Also used : ExpectationFailedException(org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) IOException(java.io.IOException)

Example 3 with SignalServiceAccountManager

use of org.whispersystems.signalservice.api.SignalServiceAccountManager in project Signal-Android by WhisperSystems.

the class DirectoryHelper method refreshDirectoryFor.

public static UserCapabilities refreshDirectoryFor(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Recipients recipients, @NonNull String localNumber) throws IOException {
    try {
        TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
        SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);
        String number = Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber());
        Optional<ContactTokenDetails> details = accountManager.getContact(number);
        if (details.isPresent()) {
            directory.setNumber(details.get(), true);
            RefreshResult result = updateContactsDatabase(context, localNumber, details.get());
            if (!result.getNewUsers().isEmpty() && TextSecurePreferences.isMultiDevice(context)) {
                ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceContactUpdateJob(context));
            }
            if (!result.isFresh()) {
                notifyNewUsers(context, masterSecret, result.getNewUsers());
            }
            return new UserCapabilities(Capability.SUPPORTED, details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED, details.get().isVideo() ? Capability.SUPPORTED : Capability.UNSUPPORTED);
        } else {
            ContactTokenDetails absent = new ContactTokenDetails();
            absent.setNumber(number);
            directory.setNumber(absent, false);
            return UserCapabilities.UNSUPPORTED;
        }
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
        return UserCapabilities.UNSUPPORTED;
    }
}
Also used : MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) TextSecureDirectory(org.thoughtcrime.securesms.database.TextSecureDirectory)

Aggregations

SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)3 IOException (java.io.IOException)2 TextSecureDirectory (org.thoughtcrime.securesms.database.TextSecureDirectory)1 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)1 ContactTokenDetails (org.whispersystems.signalservice.api.push.ContactTokenDetails)1 ExpectationFailedException (org.whispersystems.signalservice.api.push.exceptions.ExpectationFailedException)1 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)1