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

Commit cf320c95 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expose transform surface control in wallpaper service" into main

parents 685b13aa 6594c021
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -321,6 +321,14 @@ public class WallpaperManager {
    public static final String COMMAND_LOCKSCREEN_TAP =
    public static final String COMMAND_LOCKSCREEN_TAP =
            "android.wallpaper.lockscreen_tap";
            "android.wallpaper.lockscreen_tap";


    /**
     * Command for {@link #sendWallpaperCommand}: reported when the surface control that could be
     * used to transform the wallpaper is available
     * @hide
     */
    public static final String COMMAND_TRANSFORM_SURFACE_CONTROL =
            "android.wallpaper.transform_surface_control";

    /**
    /**
     * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID.
     * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID.
     * @hide
     * @hide
+10 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,16 @@ flag {
  }
  }
}
}


flag {
  name: "enable_wallpaper_transform_surface_control_command"
  namespace: "systemui"
  description: "Enables sending SurfaceControl to onCommand that could be used to transform the wallpaper"
  bug: "399077623"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
flag {
  name: "accurate_wallpaper_downsampling"
  name: "accurate_wallpaper_downsampling"
  namespace: "systemui"
  namespace: "systemui"
+39 −4
Original line number Original line Diff line number Diff line
@@ -18,7 +18,9 @@ package android.service.wallpaper;


import static android.app.Flags.FLAG_LIVE_WALLPAPER_CONTENT_HANDLING;
import static android.app.Flags.FLAG_LIVE_WALLPAPER_CONTENT_HANDLING;
import static android.app.Flags.liveWallpaperContentHandling;
import static android.app.Flags.liveWallpaperContentHandling;
import static android.app.Flags.enableWallpaperTransformSurfaceControlCommand;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_FREEZE;
import static android.app.WallpaperManager.COMMAND_TRANSFORM_SURFACE_CONTROL;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WallpaperManager.COMMAND_UNFREEZE;
import static android.app.WallpaperManager.SetWallpaperFlags;
import static android.app.WallpaperManager.SetWallpaperFlags;
import static android.graphics.Matrix.MSCALE_X;
import static android.graphics.Matrix.MSCALE_X;
@@ -374,11 +376,16 @@ public abstract class WallpaperService extends Service {
        private float mPreviousWallpaperDimAmount = mWallpaperDimAmount;
        private float mPreviousWallpaperDimAmount = mWallpaperDimAmount;
        private float mDefaultDimAmount = 0.05f;
        private float mDefaultDimAmount = 0.05f;
        SurfaceControl mBbqSurfaceControl;
        SurfaceControl mBbqSurfaceControl;
        // Surface control that could be used to apply transformation to the wallpaper
        // The hiearchy is the following:
        //   mSurfaceControl <- mTransformSurfaceControl <- mBbqSurfaceControl
        SurfaceControl mTransformSurfaceControl;
        BLASTBufferQueue mBlastBufferQueue;
        BLASTBufferQueue mBlastBufferQueue;
        IBinder mBbqApplyToken = new Binder();
        IBinder mBbqApplyToken = new Binder();
        private SurfaceControl mScreenshotSurfaceControl;
        private SurfaceControl mScreenshotSurfaceControl;
        private Point mScreenshotSize = new Point();
        private Point mScreenshotSize = new Point();


        private final boolean mEnableTransformSurfaceControlCommand;
        private final boolean mDisableDrawWakeLock;
        private final boolean mDisableDrawWakeLock;


        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
@@ -568,6 +575,7 @@ public abstract class WallpaperService extends Service {
        public Engine(Supplier<Long> clockFunction, Handler handler) {
        public Engine(Supplier<Long> clockFunction, Handler handler) {
            mClockFunction = clockFunction;
            mClockFunction = clockFunction;
            mHandler = handler;
            mHandler = handler;
            mEnableTransformSurfaceControlCommand = enableWallpaperTransformSurfaceControlCommand();
            mDisableDrawWakeLock = CompatChanges.isChangeEnabled(DISABLE_DRAW_WAKE_LOCK_WALLPAPER)
            mDisableDrawWakeLock = CompatChanges.isChangeEnabled(DISABLE_DRAW_WAKE_LOCK_WALLPAPER)
                    && disableDrawWakeLock();
                    && disableDrawWakeLock();
        }
        }
@@ -1331,11 +1339,20 @@ public abstract class WallpaperService extends Service {
                            (mDisplay.getInstallOrientation() + mDisplay.getRotation()) % 4);
                            (mDisplay.getInstallOrientation() + mDisplay.getRotation()) % 4);
                        mSurfaceControl.setTransformHint(transformHint);
                        mSurfaceControl.setTransformHint(transformHint);
                        if (mBbqSurfaceControl == null) {
                        if (mBbqSurfaceControl == null) {
                            if (mEnableTransformSurfaceControlCommand) {
                                mTransformSurfaceControl = new SurfaceControl.Builder()
                                        .setName("Wallpaper Transform wrapper")
                                        .setHidden(false)
                                        .setParent(mSurfaceControl)
                                        .setCallsite("Wallpaper#relayout")
                                        .build();
                            }
                            mBbqSurfaceControl = new SurfaceControl.Builder()
                            mBbqSurfaceControl = new SurfaceControl.Builder()
                                    .setName("Wallpaper BBQ wrapper")
                                    .setName("Wallpaper BBQ wrapper")
                                    .setHidden(false)
                                    .setHidden(false)
                                    .setBLASTLayer()
                                    .setBLASTLayer()
                                    .setParent(mSurfaceControl)
                                    .setParent(mEnableTransformSurfaceControlCommand
                                            ? mTransformSurfaceControl : mSurfaceControl)
                                    .setCallsite("Wallpaper#relayout")
                                    .setCallsite("Wallpaper#relayout")
                                    .build();
                                    .build();
                            SurfaceControl.Transaction transaction =
                            SurfaceControl.Transaction transaction =
@@ -1348,6 +1365,10 @@ public abstract class WallpaperService extends Service {
                            }
                            }
                            transaction.setDefaultFrameRateCompatibility(mBbqSurfaceControl,
                            transaction.setDefaultFrameRateCompatibility(mBbqSurfaceControl,
                                    frameRateCompat).apply();
                                    frameRateCompat).apply();
                            if (mEnableTransformSurfaceControlCommand) {
                                // TODO: b/406967924 - remove after creating public APIs
                                sendTransformSurfaceControl();
                            }
                        }
                        }
                        // Propagate transform hint from WM, so we can use the right hint for the
                        // Propagate transform hint from WM, so we can use the right hint for the
                        // first frame.
                        // first frame.
@@ -1551,6 +1572,12 @@ public abstract class WallpaperService extends Service {
            }
            }
        }
        }


        private void sendTransformSurfaceControl() {
            final Bundle extras = new Bundle();
            extras.putParcelable(COMMAND_TRANSFORM_SURFACE_CONTROL, mTransformSurfaceControl);
            onCommand(COMMAND_TRANSFORM_SURFACE_CONTROL, 0, 0, 0, extras, false);
        }

        private void resizePreview(Rect position) {
        private void resizePreview(Rect position) {
            if (position != null) {
            if (position != null) {
                mSurfaceHolder.setFixedSize(position.width(), position.height());
                mSurfaceHolder.setFixedSize(position.width(), position.height());
@@ -2218,7 +2245,8 @@ public abstract class WallpaperService extends Service {
            if (mScreenshotSurfaceControl != null) {
            if (mScreenshotSurfaceControl != null) {
                new SurfaceControl.Transaction()
                new SurfaceControl.Transaction()
                        .remove(mScreenshotSurfaceControl)
                        .remove(mScreenshotSurfaceControl)
                        .show(mBbqSurfaceControl)
                        .show(mEnableTransformSurfaceControlCommand
                                ? mTransformSurfaceControl : mBbqSurfaceControl)
                        .apply();
                        .apply();
                mScreenshotSurfaceControl = null;
                mScreenshotSurfaceControl = null;
            }
            }
@@ -2315,7 +2343,8 @@ public abstract class WallpaperService extends Service {
            // Place on top everything else.
            // Place on top everything else.
            t.setLayer(mScreenshotSurfaceControl, Integer.MAX_VALUE);
            t.setLayer(mScreenshotSurfaceControl, Integer.MAX_VALUE);
            t.show(mScreenshotSurfaceControl);
            t.show(mScreenshotSurfaceControl);
            t.hide(mBbqSurfaceControl);
            t.hide(mEnableTransformSurfaceControlCommand
                    ? mTransformSurfaceControl : mBbqSurfaceControl);
            t.apply();
            t.apply();


            return true;
            return true;
@@ -2388,10 +2417,16 @@ public abstract class WallpaperService extends Service {
                        mBlastBufferQueue.destroy();
                        mBlastBufferQueue.destroy();
                        mBlastBufferQueue = null;
                        mBlastBufferQueue = null;
                    }
                    }
                    final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
                    if (mBbqSurfaceControl != null) {
                    if (mBbqSurfaceControl != null) {
                        new SurfaceControl.Transaction().remove(mBbqSurfaceControl).apply();
                        t.remove(mBbqSurfaceControl);
                        mBbqSurfaceControl = null;
                        mBbqSurfaceControl = null;
                    }
                    }
                    if (mTransformSurfaceControl != null) {
                        t.remove(mTransformSurfaceControl);
                        mTransformSurfaceControl = null;
                    }
                    t.apply();
                    mCreated = false;
                    mCreated = false;
                }
                }