Search in sources :

Example 76 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class FullBackupImporter method processAvatar.

private static void processAvatar(@NonNull Context context, @NonNull SQLiteDatabase db, @NonNull BackupProtos.Avatar avatar, @NonNull BackupRecordInputStream inputStream) throws IOException {
    if (avatar.hasRecipientId()) {
        RecipientId recipientId = RecipientId.from(avatar.getRecipientId());
        inputStream.readAttachmentTo(AvatarHelper.getOutputStream(context, recipientId, false), avatar.getLength());
    } else {
        if (avatar.hasName() && SqlUtil.tableExists(db, "recipient_preferences")) {
            Log.w(TAG, "Avatar is missing a recipientId. Clearing signal_profile_avatar (legacy) so it can be fetched later.");
            db.execSQL("UPDATE recipient_preferences SET signal_profile_avatar = NULL WHERE recipient_ids = ?", new String[] { avatar.getName() });
        } else if (avatar.hasName() && SqlUtil.tableExists(db, "recipient")) {
            Log.w(TAG, "Avatar is missing a recipientId. Clearing signal_profile_avatar so it can be fetched later.");
            db.execSQL("UPDATE recipient SET signal_profile_avatar = NULL WHERE phone = ?", new String[] { avatar.getName() });
        } else {
            Log.w(TAG, "Avatar is missing a recipientId. Skipping avatar restore.");
        }
        inputStream.readAttachmentTo(new ByteArrayOutputStream(), avatar.getLength());
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 77 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class VoiceNoteMediaController method getClipType.

@NonNull
private static VoiceNotePlaybackState.ClipType getClipType(@Nullable Bundle mediaExtras) {
    long messageId = -1L;
    RecipientId senderId = RecipientId.UNKNOWN;
    long messagePosition = -1L;
    long threadId = -1L;
    RecipientId threadRecipientId = RecipientId.UNKNOWN;
    long timestamp = -1L;
    if (mediaExtras != null) {
        messageId = mediaExtras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID, -1L);
        messagePosition = mediaExtras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_POSITION, -1L);
        threadId = mediaExtras.getLong(VoiceNoteMediaItemFactory.EXTRA_THREAD_ID, -1L);
        timestamp = mediaExtras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_TIMESTAMP, -1L);
        String serializedSenderId = mediaExtras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID);
        if (serializedSenderId != null) {
            senderId = RecipientId.from(serializedSenderId);
        }
        String serializedThreadRecipientId = mediaExtras.getString(VoiceNoteMediaItemFactory.EXTRA_THREAD_RECIPIENT_ID);
        if (serializedThreadRecipientId != null) {
            threadRecipientId = RecipientId.from(serializedThreadRecipientId);
        }
    }
    if (messageId != -1L) {
        return new VoiceNotePlaybackState.ClipType.Message(messageId, senderId, threadRecipientId, messagePosition, threadId, timestamp);
    } else {
        return VoiceNotePlaybackState.ClipType.Draft.INSTANCE;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Message(android.os.Message) NonNull(androidx.annotation.NonNull)

Example 78 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class VerifyDisplayFragment method initializeFingerprint.

private void initializeFingerprint() {
    RecipientId recipientId = getArguments().getParcelable(RECIPIENT_ID);
    IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
    IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
    this.localIdentity = localIdentityParcelable.get();
    this.recipient = Recipient.live(recipientId);
    this.remoteIdentity = remoteIdentityParcelable.get();
    int version;
    byte[] localId;
    byte[] remoteId;
    // noinspection WrongThread
    Recipient resolved = recipient.resolve();
    if (FeatureFlags.verifyV2() && resolved.getServiceId().isPresent()) {
        Log.i(TAG, "Using UUID (version 2).");
        version = 2;
        localId = Recipient.self().requireServiceId().toByteArray();
        remoteId = resolved.requireServiceId().toByteArray();
    } else if (!FeatureFlags.verifyV2() && resolved.getE164().isPresent()) {
        Log.i(TAG, "Using E164 (version 1).");
        version = 1;
        localId = Recipient.self().requireE164().getBytes();
        remoteId = resolved.requireE164().getBytes();
    } else {
        Log.w(TAG, String.format(Locale.ENGLISH, "Could not show proper verification! verifyV2: %s, hasUuid: %s, hasE164: %s", FeatureFlags.verifyV2(), resolved.getServiceId().isPresent(), resolved.getE164().isPresent()));
        new MaterialAlertDialogBuilder(requireContext()).setMessage(getString(R.string.VerifyIdentityActivity_you_must_first_exchange_messages_in_order_to_view, resolved.getDisplayName(requireContext()))).setPositiveButton(android.R.string.ok, (dialog, which) -> requireActivity().finish()).setOnDismissListener(dialog -> {
            requireActivity().finish();
            dialog.dismiss();
        }).show();
        return;
    }
    this.recipient.observe(this, this::setRecipientText);
    SimpleTask.run(() -> new NumericFingerprintGenerator(5200).createFor(version, localId, localIdentity, remoteId, remoteIdentity), fingerprint -> {
        if (getActivity() == null)
            return;
        VerifyDisplayFragment.this.fingerprint = fingerprint;
        setFingerprintViews(fingerprint, true);
        initializeOptionsMenu();
    });
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ReentrantSessionLock(org.thoughtcrime.securesms.crypto.ReentrantSessionLock) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) TypeEvaluator(android.animation.TypeEvaluator) MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ThreadUtil(org.signal.core.util.ThreadUtil) ViewGroup(android.view.ViewGroup) IdentityKey(org.whispersystems.libsignal.IdentityKey) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) Toolbar(androidx.appcompat.widget.Toolbar) Context(android.content.Context) ContextMenu(android.view.ContextMenu) Util(org.thoughtcrime.securesms.util.Util) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) MenuItem(android.view.MenuItem) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) FingerprintVersionMismatchException(org.whispersystems.libsignal.fingerprint.FingerprintVersionMismatchException) Charset(java.nio.charset.Charset) MenuInflater(android.view.MenuInflater) QrCode(org.thoughtcrime.securesms.qr.QrCode) Toast(android.widget.Toast) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) TextSwitcher(android.widget.TextSwitcher) ViewTreeObserver(android.view.ViewTreeObserver) ValueAnimator(android.animation.ValueAnimator) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint)

Example 79 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId 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 80 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class UsernameUtil method fetchAciForUsername.

@WorkerThread
@NonNull
public static Optional<ServiceId> fetchAciForUsername(@NonNull String username) {
    Optional<RecipientId> localId = SignalDatabase.recipients().getByUsername(username);
    if (localId.isPresent()) {
        Recipient recipient = Recipient.resolved(localId.get());
        if (recipient.getServiceId().isPresent()) {
            Log.i(TAG, "Found username locally -- using associated UUID.");
            return recipient.getServiceId();
        } else {
            Log.w(TAG, "Found username locally, but it had no associated UUID! Clearing it.");
            SignalDatabase.recipients().clearUsernameIfExists(username);
        }
    }
    try {
        Log.d(TAG, "No local user with this username. Searching remotely.");
        SignalServiceProfile profile = ApplicationDependencies.getSignalServiceMessageReceiver().retrieveProfileByUsername(username, Optional.absent(), Locale.getDefault());
        return Optional.fromNullable(profile.getAci());
    } catch (IOException e) {
        return Optional.absent();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)154 NonNull (androidx.annotation.NonNull)70 Recipient (org.thoughtcrime.securesms.recipients.Recipient)70 List (java.util.List)34 ArrayList (java.util.ArrayList)33 Nullable (androidx.annotation.Nullable)32 Context (android.content.Context)31 Log (org.signal.core.util.logging.Log)31 IOException (java.io.IOException)30 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)29 WorkerThread (androidx.annotation.WorkerThread)28 Stream (com.annimon.stream.Stream)27 LinkedList (java.util.LinkedList)25 ContentValues (android.content.ContentValues)24 Cursor (android.database.Cursor)24 Collections (java.util.Collections)24 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)24 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)23 Optional (org.whispersystems.libsignal.util.guava.Optional)22 HashSet (java.util.HashSet)21