Search in sources :

Example 36 with Stopwatch

use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.

the class MediaRepository method getMediaInBucket.

@WorkerThread
@NonNull
private List<Media> getMediaInBucket(@NonNull Context context, @NonNull String bucketId) {
    Stopwatch stopwatch = new Stopwatch("getMediaInBucket");
    List<Media> images = getMediaInBucket(context, bucketId, Images.Media.EXTERNAL_CONTENT_URI, true);
    List<Media> videos = getMediaInBucket(context, bucketId, Video.Media.EXTERNAL_CONTENT_URI, false);
    List<Media> media = new ArrayList<>(images.size() + videos.size());
    stopwatch.split("post fetch");
    media.addAll(images);
    media.addAll(videos);
    Collections.sort(media, (o1, o2) -> Long.compare(o2.getDate(), o1.getDate()));
    stopwatch.split("post sort");
    stopwatch.stop(TAG);
    return media;
}
Also used : Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) ArrayList(java.util.ArrayList) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 37 with Stopwatch

use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.

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)

Example 38 with Stopwatch

use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.

the class ConversationListFragment method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setHasOptionsMenu(true);
    startupStopwatch = new Stopwatch("startup");
}
Also used : Stopwatch(org.thoughtcrime.securesms.util.Stopwatch)

Example 39 with Stopwatch

use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.

the class ConversationListDataSource method load.

@Override
@NonNull
public List<Conversation> load(int start, int length, @NonNull CancellationSignal cancellationSignal) {
    Stopwatch stopwatch = new Stopwatch("load(" + start + ", " + length + "), " + getClass().getSimpleName());
    List<Conversation> conversations = new ArrayList<>(length);
    List<Recipient> recipients = new LinkedList<>();
    try (ConversationReader reader = new ConversationReader(getCursor(start, length))) {
        ThreadRecord record;
        while ((record = reader.getNext()) != null && !cancellationSignal.isCanceled()) {
            conversations.add(new Conversation(record));
            recipients.add(record.getRecipient());
        }
    }
    stopwatch.split("cursor");
    ApplicationDependencies.getRecipientCache().addToCache(recipients);
    stopwatch.split("cache-recipients");
    stopwatch.stop(TAG);
    return conversations;
}
Also used : ConversationReader(org.thoughtcrime.securesms.conversationlist.model.ConversationReader) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) ArrayList(java.util.ArrayList) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Conversation(org.thoughtcrime.securesms.conversationlist.model.Conversation) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) NonNull(androidx.annotation.NonNull)

Example 40 with Stopwatch

use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.

the class ConversationDataSource method load.

@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
    Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
    MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
    MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
    stopwatch.split("message");
    try {
        if (record != null) {
            List<Mention> mentions;
            if (messageId.isMms()) {
                mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
            } else {
                mentions = Collections.emptyList();
            }
            stopwatch.split("mentions");
            List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
            record = ReactionHelper.recordWithReactions(record, reactions);
            stopwatch.split("reactions");
            if (messageId.isMms()) {
                List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
                if (attachments.size() > 0) {
                    record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
                }
            }
            stopwatch.split("attachments");
            return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
        } else {
            return null;
        }
    } finally {
        stopwatch.stop(TAG);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) Mention(org.thoughtcrime.securesms.database.model.Mention) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) Nullable(androidx.annotation.Nullable)

Aggregations

Stopwatch (org.thoughtcrime.securesms.util.Stopwatch)42 NonNull (androidx.annotation.NonNull)20 IOException (java.io.IOException)16 Nullable (androidx.annotation.Nullable)14 Context (android.content.Context)12 ArrayList (java.util.ArrayList)12 Log (org.signal.core.util.logging.Log)12 WorkerThread (androidx.annotation.WorkerThread)10 List (java.util.List)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 Util (org.thoughtcrime.securesms.util.Util)10 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 LinkedList (java.util.LinkedList)8 Set (java.util.Set)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 Cursor (android.database.Cursor)6