Search in sources :

Example 36 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class RegistrationRepository method registerAccountInternal.

@WorkerThread
private void registerAccountInternal(@NonNull RegistrationData registrationData, @NonNull VerifyAccountResponse response, @Nullable String pin, @Nullable KbsPinData kbsData) throws IOException {
    ACI aci = ACI.parseOrThrow(response.getUuid());
    PNI pni = PNI.parseOrThrow(response.getPni());
    boolean hasPin = response.isStorageCapable();
    SignalStore.account().setAci(aci);
    SignalStore.account().setPni(pni);
    ApplicationDependencies.getProtocolStore().aci().sessions().archiveAllSessions();
    ApplicationDependencies.getProtocolStore().pni().sessions().archiveAllSessions();
    SenderKeyUtil.clearAllState(context);
    SignalServiceAccountManager accountManager = AccountManagerFactory.createAuthenticated(context, aci, pni, registrationData.getE164(), SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.getPassword());
    SignalServiceAccountDataStoreImpl aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
    SignalServiceAccountDataStoreImpl pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
    generateAndRegisterPreKeys(ServiceIdType.ACI, accountManager, aciProtocolStore, SignalStore.account().aciPreKeys());
    generateAndRegisterPreKeys(ServiceIdType.PNI, accountManager, pniProtocolStore, SignalStore.account().pniPreKeys());
    if (registrationData.isFcm()) {
        accountManager.setGcmId(Optional.fromNullable(registrationData.getFcmToken()));
    }
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    RecipientId selfId = Recipient.externalPush(aci, registrationData.getE164(), true).getId();
    recipientDatabase.setProfileSharing(selfId, true);
    recipientDatabase.markRegisteredOrThrow(selfId, aci);
    recipientDatabase.setPni(selfId, pni);
    recipientDatabase.setProfileKey(selfId, registrationData.getProfileKey());
    ApplicationDependencies.getRecipientCache().clearSelf();
    SignalStore.account().setE164(registrationData.getE164());
    SignalStore.account().setFcmToken(registrationData.getFcmToken());
    SignalStore.account().setFcmEnabled(registrationData.isFcm());
    long now = System.currentTimeMillis();
    saveOwnIdentityKey(selfId, aciProtocolStore, now);
    saveOwnIdentityKey(selfId, pniProtocolStore, now);
    SignalStore.account().setServicePassword(registrationData.getPassword());
    SignalStore.account().setRegistered(true);
    TextSecurePreferences.setPromptedPushRegistration(context, true);
    TextSecurePreferences.setUnauthorizedReceived(context, false);
    PinState.onRegistration(context, kbsData, pin, hasPin);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ACI(org.whispersystems.signalservice.api.push.ACI) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PNI(org.whispersystems.signalservice.api.push.PNI) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) WorkerThread(androidx.annotation.WorkerThread)

Example 37 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class RegistrationRepository method findExistingProfileKey.

@WorkerThread
@Nullable
private static ProfileKey findExistingProfileKey(@NonNull String e164number) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    Optional<RecipientId> recipient = recipientDatabase.getByE164(e164number);
    if (recipient.isPresent()) {
        return ProfileKeyUtil.profileKeyOrNull(Recipient.resolved(recipient.get()).getProfileKey());
    }
    return null;
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 38 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class RecipientUtil method isMessageRequestAccepted.

/**
 * If true, the new message request UI does not need to be shown, and it's safe to send read
 * receipts.
 *
 * Note that this does not imply that a user has explicitly accepted a message request -- it could
 * also be the case that the thread in question is for a system contact or something of the like.
 */
@WorkerThread
public static boolean isMessageRequestAccepted(@NonNull Context context, long threadId) {
    if (threadId < 0) {
        return true;
    }
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Recipient threadRecipient = threadDatabase.getRecipientForThreadId(threadId);
    if (threadRecipient == null) {
        return true;
    }
    return isMessageRequestAccepted(context, threadId, threadRecipient);
}
Also used : ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread)

Example 39 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class RecipientUtil method toSignalServiceAddress.

/**
 * This method will do it's best to craft a fully-populated {@link SignalServiceAddress} based on
 * the provided recipient. This includes performing a possible network request if no UUID is
 * available. If the request to get a UUID fails or the user is not registered, an IOException is thrown.
 */
@WorkerThread
@NonNull
public static SignalServiceAddress toSignalServiceAddress(@NonNull Context context, @NonNull Recipient recipient) throws IOException {
    recipient = recipient.resolve();
    if (!recipient.getServiceId().isPresent() && !recipient.getE164().isPresent()) {
        throw new AssertionError(recipient.getId() + " - No UUID or phone number!");
    }
    if (!recipient.getServiceId().isPresent()) {
        Log.i(TAG, recipient.getId() + " is missing a UUID...");
        RegisteredState state = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
        recipient = Recipient.resolved(recipient.getId());
        Log.i(TAG, "Successfully performed a UUID fetch for " + recipient.getId() + ". Registered: " + state);
    }
    if (recipient.hasServiceId()) {
        return new SignalServiceAddress(recipient.requireServiceId(), Optional.fromNullable(recipient.resolve().getE164().orNull()));
    } else {
        throw new NotFoundException(recipient.getId() + " is not registered!");
    }
}
Also used : RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 40 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class ShareRepository method getResolvedInternal.

@WorkerThread
@Nullable
private ShareData getResolvedInternal(@NonNull List<Uri> uris) throws IOException {
    Context context = ApplicationDependencies.getApplication();
    Map<Uri, String> mimeTypes = Stream.of(uris).map(uri -> new Pair<>(uri, getMimeType(context, uri, null))).filter(p -> MediaUtil.isImageType(p.second) || MediaUtil.isVideoType(p.second)).collect(Collectors.toMap(p -> p.first, p -> p.second));
    if (mimeTypes.isEmpty()) {
        return null;
    }
    List<Media> media = new ArrayList<>(mimeTypes.size());
    for (Map.Entry<Uri, String> entry : mimeTypes.entrySet()) {
        Uri uri = entry.getKey();
        String mimeType = entry.getValue();
        InputStream stream;
        try {
            stream = context.getContentResolver().openInputStream(uri);
            if (stream == null) {
                throw new IOException("Failed to open stream!");
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to open: " + uri);
            continue;
        }
        long size = getSize(context, uri);
        Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
        long duration = getDuration(context, uri);
        Uri blobUri = BlobProvider.getInstance().forData(stream, size).withMimeType(mimeType).createForSingleSessionOnDisk(context);
        media.add(new Media(blobUri, mimeType, System.currentTimeMillis(), dimens.first, dimens.second, size, duration, false, false, Optional.of(Media.ALL_MEDIA_BUCKET_ID), Optional.absent(), Optional.absent()));
        if (media.size() >= MediaSendConstants.MAX_PUSH) {
            Log.w(TAG, "Exceeded the attachment limit! Skipping the rest.");
            break;
        }
    }
    if (media.size() > 0) {
        boolean isMmsSupported = Stream.of(media).allMatch(m -> isMmsSupported(context, asUriAttachment(m.getUri(), m.getMimeType(), m.getSize())));
        return ShareData.forMedia(media, isMmsSupported);
    } else {
        return null;
    }
}
Also used : Context(android.content.Context) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) Context(android.content.Context) Stream(com.annimon.stream.Stream) PackageManager(android.content.pm.PackageManager) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) Pair(android.util.Pair) WorkerThread(androidx.annotation.WorkerThread) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) ArrayList(java.util.ArrayList) Manifest(android.Manifest) TransportOption(org.thoughtcrime.securesms.TransportOption) Media(org.thoughtcrime.securesms.mediasend.Media) Map(java.util.Map) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) ContextCompat(androidx.core.content.ContextCompat) UriUtil(org.thoughtcrime.securesms.util.UriUtil) Cursor(android.database.Cursor) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) Collectors(com.annimon.stream.Collectors) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) IOException(java.io.IOException) OpenableColumns(android.provider.OpenableColumns) Optional(org.whispersystems.libsignal.util.guava.Optional) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) TransportOptions(org.thoughtcrime.securesms.TransportOptions) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) MediaSendConstants(org.thoughtcrime.securesms.mediasend.MediaSendConstants) Attachment(org.thoughtcrime.securesms.attachments.Attachment) InputStream(java.io.InputStream) InputStream(java.io.InputStream) Media(org.thoughtcrime.securesms.mediasend.Media) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Uri(android.net.Uri) Map(java.util.Map) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)204 NonNull (androidx.annotation.NonNull)77 IOException (java.io.IOException)45 Recipient (org.thoughtcrime.securesms.recipients.Recipient)41 Nullable (androidx.annotation.Nullable)26 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)23 Cursor (android.database.Cursor)22 ArrayList (java.util.ArrayList)22 Context (android.content.Context)20 Uri (android.net.Uri)18 LinkedList (java.util.LinkedList)15 List (java.util.List)15 HashMap (java.util.HashMap)14 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)14 Stream (com.annimon.stream.Stream)13 Log (org.signal.core.util.logging.Log)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)11 Bitmap (android.graphics.Bitmap)10 Collections (java.util.Collections)10