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

Commit 1d796d30 authored by Chen Bai's avatar Chen Bai
Browse files

draw-wakelock: disable DRAW_WAKE_LOCK for wallpaper

Note: this replicate the logic in ViewRootImpl by ag/27815016
DRAW_WAKE_LOCK is an internal wakelock that is acquired per frame while
DOZE. It was added for ambient transition and per-minute
screen change. However, an loop transition animation could extend the
wakelock infiintely which drains the battery. Since Wear SystemUI now
can manage the animation allowing window by itself, DRAW_WAKE_LOCK will
be disabled starting U.

Flag: android.view.flags.disable_draw_wake_lock
Test: go/verification-limit-aod-animation
Bug: 349153669
Bug: 361433696
Change-Id: I524df9b572824adc6efc67a78d3436592025cd4b
parent 07e4d42b
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.graphics.Matrix.MSKEW_X;
import static android.graphics.Matrix.MSKEW_Y;
import static android.view.View.SYSTEM_UI_FLAG_VISIBLE;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static android.view.flags.Flags.disableDrawWakeLock;

import static com.android.window.flags.Flags.FLAG_OFFLOAD_COLOR_EXTRACTION;
import static com.android.window.flags.Flags.noDuplicateSurfaceDestroyedEvents;
@@ -51,6 +52,7 @@ import android.app.WallpaperManager;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
@@ -207,6 +209,15 @@ public abstract class WallpaperService extends Service {
    // TODO (b/287037772) remove this flag and the forceReport argument in reportVisibility
    private boolean mIsWearOs;

    /**
     * This change disables the {@code DRAW_WAKE_LOCK}, an internal wakelock acquired per-frame
     * duration display DOZE. It was added to allow animation during AOD. This wakelock consumes
     * battery severely if the animation is too heavy, so, it will be removed.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    private static final long DISABLE_DRAW_WAKE_LOCK_WALLPAPER = 361433696L;

    /**
     * Wear products currently force a slight scaling transition to wallpapers
     * when the QSS is opened. However, on Wear 6 (SDK 35) and above, 1P watch faces
@@ -362,6 +373,8 @@ public abstract class WallpaperService extends Service {
        private SurfaceControl mScreenshotSurfaceControl;
        private Point mScreenshotSize = new Point();

        private final boolean mDisableDrawWakeLock;

        final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
            {
                mRequestedFormat = PixelFormat.RGBX_8888;
@@ -406,6 +419,9 @@ public abstract class WallpaperService extends Service {
            }

            private void prepareToDraw() {
                if (mDisableDrawWakeLock) {
                    return;
                }
                if (mDisplayState == Display.STATE_DOZE) {
                    try {
                        mSession.pokeDrawLock(mWindow);
@@ -546,6 +562,8 @@ public abstract class WallpaperService extends Service {
        public Engine(Supplier<Long> clockFunction, Handler handler) {
            mClockFunction = clockFunction;
            mHandler = handler;
            mDisableDrawWakeLock = CompatChanges.isChangeEnabled(DISABLE_DRAW_WAKE_LOCK_WALLPAPER)
                    && disableDrawWakeLock();
        }

        /**