Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee665262 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato Committed by Android (Google) Code Review
Browse files

Merge "Change name of screenshot from the connected display" into main

parents 75e2eb72 de57acb8
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Display;

import androidx.concurrent.futures.CallbackToFutureAdapter;
import androidx.exifinterface.media.ExifInterface;
@@ -64,6 +65,9 @@ public class ImageExporter {

    // ex: 'Screenshot_20201215-090626.png'
    private static final String FILENAME_PATTERN = "Screenshot_%1$tY%<tm%<td-%<tH%<tM%<tS.%2$s";
    // ex: 'Screenshot_20201215-090626-display-1.png'
    private static final String CONNECTED_DISPLAY_FILENAME_PATTERN =
            "Screenshot_%1$tY%<tm%<td-%<tH%<tM%<tS-display-%2$d.%3$s";
    private static final String SCREENSHOTS_PATH = Environment.DIRECTORY_PICTURES
            + File.separator + Environment.DIRECTORY_SCREENSHOTS;

@@ -145,12 +149,12 @@ public class ImageExporter {
     *
     * @param executor the thread for execution
     * @param bitmap the bitmap to export
     *
     * @param displayId the display id the bitmap comes from.
     * @return a listenable future result
     */
    public ListenableFuture<Result> export(Executor executor, UUID requestId, Bitmap bitmap,
            UserHandle owner) {
        return export(executor, requestId, bitmap, ZonedDateTime.now(), owner);
            UserHandle owner, int displayId) {
        return export(executor, requestId, bitmap, ZonedDateTime.now(), owner, displayId);
    }

    /**
@@ -162,10 +166,10 @@ public class ImageExporter {
     * @return a listenable future result
     */
    ListenableFuture<Result> export(Executor executor, UUID requestId, Bitmap bitmap,
            ZonedDateTime captureTime, UserHandle owner) {
            ZonedDateTime captureTime, UserHandle owner, int displayId) {

        final Task task = new Task(mResolver, requestId, bitmap, captureTime, mCompressFormat,
                mQuality, /* publish */ true, owner, mFlags);
                mQuality, /* publish */ true, owner, mFlags, displayId);

        return CallbackToFutureAdapter.getFuture(
                (completer) -> {
@@ -218,7 +222,7 @@ public class ImageExporter {

        Task(ContentResolver resolver, UUID requestId, Bitmap bitmap, ZonedDateTime captureTime,
                CompressFormat format, int quality, boolean publish, UserHandle owner,
                FeatureFlags flags) {
                FeatureFlags flags, int displayId) {
            mResolver = resolver;
            mRequestId = requestId;
            mBitmap = bitmap;
@@ -226,7 +230,7 @@ public class ImageExporter {
            mFormat = format;
            mQuality = quality;
            mOwner = owner;
            mFileName = createFilename(mCaptureTime, mFormat);
            mFileName = createFilename(mCaptureTime, mFormat, displayId);
            mPublish = publish;
            mFlags = flags;
        }
@@ -371,9 +375,13 @@ public class ImageExporter {
    }

    @VisibleForTesting
    static String createFilename(ZonedDateTime time, CompressFormat format) {
    static String createFilename(ZonedDateTime time, CompressFormat format, int displayId) {
        if (displayId == Display.DEFAULT_DISPLAY) {
            return String.format(FILENAME_PATTERN, time, fileExtension(format));
        }
        return String.format(CONNECTED_DISPLAY_FILENAME_PATTERN, time, displayId,
            fileExtension(format));
    }

    static ContentValues createMetadata(ZonedDateTime captureTime, CompressFormat format,
            String fileName) {
+3 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.Process;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.ScrollCaptureResponse;
import android.view.View;
import android.widget.ImageView;
@@ -403,9 +404,10 @@ public class LongScreenshotActivity extends Activity {
        updateImageDimensions();

        mOutputBitmap = renderBitmap(drawable, bounds);
        // TODO(b/298931528): Add support for long screenshot on external displays.
        ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
                mBackgroundExecutor, UUID.randomUUID(), mOutputBitmap, ZonedDateTime.now(),
                mScreenshotUserHandle);
                mScreenshotUserHandle, Display.DEFAULT_DISPLAY);
        exportFuture.addListener(() -> onExportCompleted(action, exportFuture), mUiExecutor);
    }

+2 −1
Original line number Diff line number Diff line
@@ -147,7 +147,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {

            // Call synchronously here since already on a background thread.
            ListenableFuture<ImageExporter.Result> future =
                    mImageExporter.export(Runnable::run, requestId, image, mParams.owner);
                    mImageExporter.export(Runnable::run, requestId, image, mParams.owner,
                            mParams.displayId);
            ImageExporter.Result result = future.get();
            Log.d(TAG, "Saved screenshot: " + result);
            final Uri uri = result.uri;
+2 −0
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ public class ScreenshotController {
        public ScreenshotController.ActionsReadyListener mActionsReadyListener;
        public ScreenshotController.QuickShareActionReadyListener mQuickShareActionsReadyListener;
        public UserHandle owner;
        public int displayId;

        void clearImage() {
            image = null;
@@ -1020,6 +1021,7 @@ public class ScreenshotController {
        data.mActionsReadyListener = actionsReadyListener;
        data.mQuickShareActionsReadyListener = quickShareActionsReadyListener;
        data.owner = owner;
        data.displayId = mDisplayId;

        if (mSaveInBgTask != null) {
            // just log success/failure for the pre-existing screenshot
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.RenderNode;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.UserHandle;
import android.view.Display;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@@ -116,8 +117,8 @@ final class AppClipsViewModel extends ViewModel {
            Bitmap screenshotBitmap = renderBitmap(screenshotDrawable, bounds);

            // Export and save the screenshot in background.
            ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
                    mBgExecutor, UUID.randomUUID(), screenshotBitmap, user);
            ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(mBgExecutor,
                    UUID.randomUUID(), screenshotBitmap, user, Display.DEFAULT_DISPLAY);

            // Get the result and update state on main thread.
            exportFuture.addListener(() -> {
Loading