Loading core/java/android/service/wallpaper/WallpaperService.java +56 −33 Original line number Diff line number Diff line Loading @@ -170,6 +170,7 @@ public abstract class WallpaperService extends Service { Float.NEGATIVE_INFINITY); private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000; private static final int PROCESS_LOCAL_COLORS_INTERVAL_MS = 1000; private static final boolean ENABLE_WALLPAPER_DIMMING = SystemProperties.getBoolean("persist.debug.enable_wallpaper_dimming", true); Loading Loading @@ -275,9 +276,13 @@ public abstract class WallpaperService extends Service { MotionEvent mPendingMove; boolean mIsInAmbientMode; // Needed for throttling onComputeColors. // used to throttle onComputeColors private long mLastColorInvalidation; private final Runnable mNotifyColorsChanged = this::notifyColorsChanged; // used to throttle processLocalColors private long mLastProcessLocalColorsTimestamp; private AtomicBoolean mProcessLocalColorsPending = new AtomicBoolean(false); private final Supplier<Long> mClockFunction; private final Handler mHandler; Loading Loading @@ -1591,7 +1596,26 @@ public abstract class WallpaperService extends Service { processLocalColors(xOffset, xOffsetStep); } /** * Thread-safe util to call {@link #processLocalColorsInternal} with a minimum interval of * {@link #PROCESS_LOCAL_COLORS_INTERVAL_MS} between two calls. */ private void processLocalColors(float xOffset, float xOffsetStep) { if (mProcessLocalColorsPending.compareAndSet(false, true)) { final long now = mClockFunction.get(); final long timeSinceLastColorProcess = now - mLastProcessLocalColorsTimestamp; final long timeToWait = Math.max(0, PROCESS_LOCAL_COLORS_INTERVAL_MS - timeSinceLastColorProcess); mHandler.postDelayed(() -> { mLastProcessLocalColorsTimestamp = now + timeToWait; mProcessLocalColorsPending.set(false); processLocalColorsInternal(xOffset, xOffsetStep); }, timeToWait); } } private void processLocalColorsInternal(float xOffset, float xOffsetStep) { // implemented by the wallpaper if (supportsLocalColorExtraction()) return; if (DEBUG) { Loading Loading @@ -1625,7 +1649,7 @@ public abstract class WallpaperService extends Service { float finalXOffsetStep = xOffsetStep; float finalXOffset = xOffset; mHandler.post(() -> { Trace.beginSection("WallpaperService#processLocalColors"); resetWindowPages(); int xPage = xCurrentPage; Loading Loading @@ -1658,7 +1682,6 @@ public abstract class WallpaperService extends Service { current = mWindowPages[xPage]; updatePage(current, xPage, xPages, finalXOffsetStep); Trace.endSection(); }); } private void initWindowPages(EngineWindowPage[] windowPages, float step) { Loading Loading
core/java/android/service/wallpaper/WallpaperService.java +56 −33 Original line number Diff line number Diff line Loading @@ -170,6 +170,7 @@ public abstract class WallpaperService extends Service { Float.NEGATIVE_INFINITY); private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000; private static final int PROCESS_LOCAL_COLORS_INTERVAL_MS = 1000; private static final boolean ENABLE_WALLPAPER_DIMMING = SystemProperties.getBoolean("persist.debug.enable_wallpaper_dimming", true); Loading Loading @@ -275,9 +276,13 @@ public abstract class WallpaperService extends Service { MotionEvent mPendingMove; boolean mIsInAmbientMode; // Needed for throttling onComputeColors. // used to throttle onComputeColors private long mLastColorInvalidation; private final Runnable mNotifyColorsChanged = this::notifyColorsChanged; // used to throttle processLocalColors private long mLastProcessLocalColorsTimestamp; private AtomicBoolean mProcessLocalColorsPending = new AtomicBoolean(false); private final Supplier<Long> mClockFunction; private final Handler mHandler; Loading Loading @@ -1591,7 +1596,26 @@ public abstract class WallpaperService extends Service { processLocalColors(xOffset, xOffsetStep); } /** * Thread-safe util to call {@link #processLocalColorsInternal} with a minimum interval of * {@link #PROCESS_LOCAL_COLORS_INTERVAL_MS} between two calls. */ private void processLocalColors(float xOffset, float xOffsetStep) { if (mProcessLocalColorsPending.compareAndSet(false, true)) { final long now = mClockFunction.get(); final long timeSinceLastColorProcess = now - mLastProcessLocalColorsTimestamp; final long timeToWait = Math.max(0, PROCESS_LOCAL_COLORS_INTERVAL_MS - timeSinceLastColorProcess); mHandler.postDelayed(() -> { mLastProcessLocalColorsTimestamp = now + timeToWait; mProcessLocalColorsPending.set(false); processLocalColorsInternal(xOffset, xOffsetStep); }, timeToWait); } } private void processLocalColorsInternal(float xOffset, float xOffsetStep) { // implemented by the wallpaper if (supportsLocalColorExtraction()) return; if (DEBUG) { Loading Loading @@ -1625,7 +1649,7 @@ public abstract class WallpaperService extends Service { float finalXOffsetStep = xOffsetStep; float finalXOffset = xOffset; mHandler.post(() -> { Trace.beginSection("WallpaperService#processLocalColors"); resetWindowPages(); int xPage = xCurrentPage; Loading Loading @@ -1658,7 +1682,6 @@ public abstract class WallpaperService extends Service { current = mWindowPages[xPage]; updatePage(current, xPage, xPages, finalXOffsetStep); Trace.endSection(); }); } private void initWindowPages(EngineWindowPage[] windowPages, float step) { Loading