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

Commit 936cdf20 authored by Will Osborn's avatar Will Osborn Committed by Android (Google) Code Review
Browse files

Merge "Update display density of Task thumbnails" into main

parents 241d7a1c a8cbe69d
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.window;

import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
@@ -30,6 +31,7 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.WindowInsetsController;

@@ -74,6 +76,7 @@ public class TaskSnapshot implements Parcelable {
    private final boolean mIsTranslucent;
    private final boolean mHasImeSurface;
    private final int mUiMode;
    private final int mDensityDpi;
    // Must be one of the named color spaces, otherwise, always use SRGB color space.
    private final ColorSpace mColorSpace;
    private int mInternalReferences;
@@ -110,7 +113,7 @@ public class TaskSnapshot implements Parcelable {
            Rect contentInsets, Rect letterboxInsets, boolean isLowResolution,
            boolean isRealSnapshot, int windowingMode,
            @WindowInsetsController.Appearance int appearance, boolean isTranslucent,
            boolean hasImeSurface, int uiMode) {
            boolean hasImeSurface, int uiMode, @IntRange(from = 1) int densityDpi) {
        mId = id;
        mCaptureTime = captureTime;
        mTopActivityComponent = topActivityComponent;
@@ -129,6 +132,7 @@ public class TaskSnapshot implements Parcelable {
        mIsTranslucent = isTranslucent;
        mHasImeSurface = hasImeSurface;
        mUiMode = uiMode;
        mDensityDpi = densityDpi;
    }

    private TaskSnapshot(Parcel source) {
@@ -152,6 +156,8 @@ public class TaskSnapshot implements Parcelable {
        mIsTranslucent = source.readBoolean();
        mHasImeSurface = source.readBoolean();
        mUiMode = source.readInt();
        int densityDpi = source.readInt();
        mDensityDpi = densityDpi > 0 ? densityDpi : DisplayMetrics.DENSITY_DEVICE_STABLE;
    }

    /**
@@ -296,6 +302,13 @@ public class TaskSnapshot implements Parcelable {
        return mUiMode;
    }

    /**
     * @return The pixel density the screenshot was taken in.
     */
    public int getDensityDpi() {
        return mDensityDpi;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -319,6 +332,7 @@ public class TaskSnapshot implements Parcelable {
        dest.writeBoolean(mIsTranslucent);
        dest.writeBoolean(mHasImeSurface);
        dest.writeInt(mUiMode);
        dest.writeInt(mDensityDpi);
        synchronized (this) {
            if ((mInternalReferences & REFERENCE_WRITE_TO_PARCEL) != 0) {
                mWriteToParcelCount--;
@@ -359,7 +373,8 @@ public class TaskSnapshot implements Parcelable {
                + " mHasImeSurface=" + mHasImeSurface
                + " mInternalReferences=" + mInternalReferences
                + " mWriteToParcelCount=" + mWriteToParcelCount
                + " mUiMode=" + Integer.toHexString(mUiMode);
                + " mUiMode=" + Integer.toHexString(mUiMode)
                + " mDensityDpi=" + mDensityDpi;
    }

    /**
@@ -431,6 +446,7 @@ public class TaskSnapshot implements Parcelable {
        private boolean mHasImeSurface;
        private int mPixelFormat;
        private int mUiMode;
        private int mDensityDpi = DisplayMetrics.DENSITY_DEVICE_STABLE;

        public Builder setId(long id) {
            mId = id;
@@ -514,13 +530,22 @@ public class TaskSnapshot implements Parcelable {
        }

        /**
         * Sets the original uiMode while capture
         * Sets the original uiMode while capturing
         */
        public Builder setUiMode(int uiMode) {
            mUiMode = uiMode;
            return this;
        }

        /**
         * Sets the original density while capturing. Throws IllegalArgumentException if
         * densityDpi is outside the range (0,100000) (exclusive).
         */
        public Builder setDensityDpi(@IntRange(from = 1) int densityDpi) {
            mDensityDpi = densityDpi;
            return this;
        }

        public int getPixelFormat() {
            return mPixelFormat;
        }
@@ -551,7 +576,8 @@ public class TaskSnapshot implements Parcelable {
                    mAppearance,
                    mIsTranslucent,
                    mHasImeSurface,
                    mUiMode);
                    mUiMode,
                    mDensityDpi);

        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -357,6 +357,6 @@ public class StartingSurfaceDrawerTests extends ShellTestCase {
                Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
                false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
                0 /* systemUiVisibility */, false /* isTranslucent */,
                hasImeSurface /* hasImeSurface */, 0 /* uiMode */);
                hasImeSurface /* hasImeSurface */, 0 /* uiMode */, 300 /* densityDpi */);
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ class ActivityTaskManagerThumbnailLoaderTest : SysuiTestCase() {
                /* height= */ 100,
                HardwareBuffer.RGBA_8888,
                /* layers= */ 1,
                /* usage= */ HardwareBuffer.USAGE_CPU_READ_OFTEN
                /* usage= */ HardwareBuffer.USAGE_CPU_READ_OFTEN,
            ),
            ColorSpace.get(ColorSpace.Named.SRGB),
            Configuration.ORIENTATION_PORTRAIT,
@@ -103,6 +103,7 @@ class ActivityTaskManagerThumbnailLoaderTest : SysuiTestCase() {
            /* appearance= */ 0,
            /* isTranslucent= */ false,
            /* hasImeSurface= */ false,
            /* uiMode */ 0
            /* uiMode */ 0,
            /* densityDpi */ 300,
        )
}
+13 −2
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ data class ThumbnailData(
    }

    companion object {
        private const val TAG = "ThumbnailData"

        private fun makeThumbnail(snapshot: TaskSnapshot): Bitmap {
            var thumbnail: Bitmap? = null
            try {
@@ -55,13 +57,22 @@ data class ThumbnailData(
                // TODO(b/157562905): Workaround for a crash when we get a snapshot without this
                // state
                Log.e(
                    "ThumbnailData",
                    TAG,
                    "Unexpected snapshot without USAGE_GPU_SAMPLED_IMAGE: " +
                        "${snapshot.hardwareBuffer}",
                    ex,
                )
            }

            if (snapshot.densityDpi > 0 && thumbnail?.density != snapshot.densityDpi) {
                Log.d(
                    TAG,
                    "Updating thumbnail.density from " +
                        thumbnail?.density +
                        " to " +
                        snapshot.densityDpi,
                )
                thumbnail?.density = snapshot.densityDpi
            }
            return thumbnail
                ?: Bitmap.createBitmap(snapshot.taskSize.x, snapshot.taskSize.y, ARGB_8888).apply {
                    eraseColor(Color.BLACK)
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ message TaskSnapshotProto {
  int32 letterbox_inset_right = 19;
  int32 letterbox_inset_bottom = 20;
  int32 ui_mode = 21;
  int32 density_dpi = 22;
}

// Persistent letterboxing configurations
Loading