use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class ConversationDataSource method load.
@Override
@NonNull
public List<ConversationMessage> load(int start, int length, @NonNull CancellationSignal cancellationSignal) {
Stopwatch stopwatch = new Stopwatch("load(" + start + ", " + length + "), thread " + threadId);
MmsSmsDatabase db = SignalDatabase.mmsSms();
List<MessageRecord> records = new ArrayList<>(length);
MentionHelper mentionHelper = new MentionHelper();
AttachmentHelper attachmentHelper = new AttachmentHelper();
ReactionHelper reactionHelper = new ReactionHelper();
try (MmsSmsDatabase.Reader reader = MmsSmsDatabase.readerFor(db.getConversation(threadId, start, length))) {
MessageRecord record;
while ((record = reader.getNext()) != null && !cancellationSignal.isCanceled()) {
records.add(record);
mentionHelper.add(record);
reactionHelper.add(record);
attachmentHelper.add(record);
}
}
if (messageRequestData.includeWarningUpdateMessage() && (start + length >= size())) {
records.add(new InMemoryMessageRecord.NoGroupsInCommon(threadId, messageRequestData.isGroup()));
}
if (showUniversalExpireTimerUpdate) {
records.add(new InMemoryMessageRecord.UniversalExpireTimerUpdate(threadId));
}
stopwatch.split("messages");
mentionHelper.fetchMentions(context);
stopwatch.split("mentions");
reactionHelper.fetchReactions(context);
stopwatch.split("reactions");
records = reactionHelper.buildUpdatedModels(context, records);
stopwatch.split("reaction-models");
attachmentHelper.fetchAttachments(context);
stopwatch.split("attachments");
records = attachmentHelper.buildUpdatedModels(context, records);
stopwatch.split("attachment-models");
List<ConversationMessage> messages = Stream.of(records).map(m -> ConversationMessageFactory.createWithUnresolvedData(context, m, mentionHelper.getMentions(m.getId()))).toList();
stopwatch.split("conversion");
stopwatch.stop(TAG);
return messages;
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by WhisperSystems.
the class CreateGroupActivity method handleNextPressed.
private void handleNextPressed() {
Stopwatch stopwatch = new Stopwatch("Recipient Refresh");
SimpleProgressDialog.DismissibleDialog dismissibleDialog = SimpleProgressDialog.showDelayed(this);
SimpleTask.run(getLifecycle(), () -> {
List<RecipientId> ids = contactsFragment.getSelectedContacts().stream().map(selectedContact -> selectedContact.getOrCreateRecipientId(this)).collect(Collectors.toList());
List<Recipient> resolved = Recipient.resolvedList(ids);
stopwatch.split("resolve");
Set<Recipient> registeredChecks = resolved.stream().filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN).collect(Collectors.toSet());
Log.i(TAG, "Need to do " + registeredChecks.size() + " registration checks.");
for (Recipient recipient : registeredChecks) {
try {
DirectoryHelper.refreshDirectoryFor(this, recipient, false);
} catch (IOException e) {
Log.w(TAG, "Failed to refresh registered status for " + recipient.getId(), e);
}
}
if (registeredChecks.size() > 0) {
resolved = Recipient.resolvedList(ids);
}
stopwatch.split("registered");
List<Recipient> recipientsAndSelf = new ArrayList<>(resolved);
recipientsAndSelf.add(Recipient.self().resolve());
boolean neededRefresh = false;
if (!SignalStore.internalValues().gv2DoNotCreateGv2Groups()) {
try {
neededRefresh = GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf);
} catch (IOException e) {
Log.w(TAG, "Failed to refresh all recipient capabilities.", e);
}
}
if (neededRefresh) {
resolved = Recipient.resolvedList(ids);
}
stopwatch.split("capabilities");
Pair<Boolean, List<RecipientId>> result;
boolean gv2 = Stream.of(recipientsAndSelf).allMatch(r -> r.getGroupsV2Capability() == Recipient.Capability.SUPPORTED);
if (!gv2 && Stream.of(resolved).anyMatch(r -> !r.hasE164())) {
Log.w(TAG, "Invalid GV1 group...");
ids = Collections.emptyList();
result = Pair.create(false, ids);
} else {
result = Pair.create(true, ids);
}
stopwatch.split("gv1-check");
return result;
}, result -> {
dismissibleDialog.dismiss();
stopwatch.stop(TAG);
if (result.first) {
startActivityForResult(AddGroupDetailsActivity.newIntent(this, result.second), REQUEST_CODE_ADD_DETAILS);
} else {
new AlertDialog.Builder(this).setMessage(R.string.CreateGroupActivity_some_contacts_cannot_be_in_legacy_groups).setPositiveButton(android.R.string.ok, (d, w) -> d.dismiss()).show();
}
});
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.
the class CameraXUtil method transformByteArray.
private static byte[] transformByteArray(@NonNull byte[] data, @Nullable Rect cropRect, int rotation, boolean flip) throws IOException {
Stopwatch stopwatch = new Stopwatch("transform");
Bitmap in;
if (cropRect != null) {
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(data, 0, data.length, false);
in = decoder.decodeRegion(cropRect, new BitmapFactory.Options());
decoder.recycle();
stopwatch.split("crop");
} else {
in = BitmapFactory.decodeByteArray(data, 0, data.length);
}
Bitmap out = in;
if (rotation != 0 || flip) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
if (flip) {
matrix.postScale(-1, 1);
matrix.postTranslate(in.getWidth(), 0);
}
out = Bitmap.createBitmap(in, 0, 0, in.getWidth(), in.getHeight(), matrix, true);
}
byte[] transformedData = toJpegBytes(out);
stopwatch.split("transcode");
in.recycle();
out.recycle();
stopwatch.stop(TAG);
return transformedData;
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.
the class Camera1Fragment method onCaptureClicked.
private void onCaptureClicked() {
orderEnforcer.reset();
Stopwatch fastCaptureTimer = new Stopwatch("Capture");
camera.capture((jpegData, frontFacing) -> {
fastCaptureTimer.split("captured");
Transformation<Bitmap> transformation = frontFacing ? new MultiTransformation<>(new CenterCrop(), new FlipTransformation()) : new CenterCrop();
GlideApp.with(this).asBitmap().load(jpegData).transform(transformation).override(cameraPreview.getWidth(), cameraPreview.getHeight()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
fastCaptureTimer.split("transform");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resource.compress(Bitmap.CompressFormat.JPEG, 80, stream);
fastCaptureTimer.split("compressed");
byte[] data = stream.toByteArray();
fastCaptureTimer.split("bytes");
fastCaptureTimer.stop(TAG);
controller.onImageCaptured(data, resource.getWidth(), resource.getHeight());
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
controller.onCameraError();
}
});
});
}
use of org.thoughtcrime.securesms.util.Stopwatch in project Signal-Android by signalapp.
the class SubmitDebugLogRepository method submitLogInternal.
@WorkerThread
@NonNull
private Optional<String> submitLogInternal(long untilTime, @NonNull List<LogLine> prefixLines, @Nullable byte[] trace) {
String traceUrl = null;
if (trace != null) {
try {
traceUrl = uploadContent("application/octet-stream", RequestBody.create(MediaType.get("application/octet-stream"), trace));
} catch (IOException e) {
Log.w(TAG, "Error during trace upload.", e);
return Optional.absent();
}
}
StringBuilder prefixStringBuilder = new StringBuilder();
for (LogLine line : prefixLines) {
switch(line.getPlaceholderType()) {
case NONE:
prefixStringBuilder.append(line.getText()).append('\n');
break;
case TRACE:
prefixStringBuilder.append(traceUrl).append('\n');
break;
}
}
try {
Stopwatch stopwatch = new Stopwatch("log-upload");
ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
Uri gzipUri = BlobProvider.getInstance().forData(new ParcelFileDescriptor.AutoCloseInputStream(fds[0]), 0).withMimeType("application/gzip").createForSingleSessionOnDiskAsync(context, null, null);
OutputStream gzipOutput = new GZIPOutputStream(new ParcelFileDescriptor.AutoCloseOutputStream(fds[1]));
gzipOutput.write(prefixStringBuilder.toString().getBytes());
stopwatch.split("front-matter");
try (LogDatabase.Reader reader = LogDatabase.getInstance(context).getAllBeforeTime(untilTime)) {
while (reader.hasNext()) {
gzipOutput.write(reader.next().getBytes());
gzipOutput.write("\n".getBytes());
}
} catch (IllegalStateException e) {
Log.e(TAG, "Failed to read row!", e);
return Optional.absent();
}
StreamUtil.close(gzipOutput);
stopwatch.split("body");
String logUrl = uploadContent("application/gzip", new RequestBody() {
@Override
@NonNull
public MediaType contentType() {
return MediaType.get("application/gzip");
}
@Override
public long contentLength() {
return BlobProvider.getInstance().calculateFileSize(context, gzipUri);
}
@Override
public void writeTo(@NonNull BufferedSink sink) throws IOException {
Source source = Okio.source(BlobProvider.getInstance().getStream(context, gzipUri));
sink.writeAll(source);
}
});
stopwatch.split("upload");
stopwatch.stop(TAG);
BlobProvider.getInstance().delete(context, gzipUri);
return Optional.of(logUrl);
} catch (IOException e) {
Log.w(TAG, "Error during log upload.", e);
return Optional.absent();
}
}
Aggregations