From 4602a88ae84a152f3b62fa9883668ac2498f5825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pomini?= Date: Mon, 7 Nov 2022 19:43:57 +0000 Subject: [PATCH] Add MainThread annotations to WallpaperService callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New CTS will enforce that the callback methods from WallpaperService are called by the main thread. Add the corresponding annotations to these methods. Test: atest CtsWallpaperTestCases Bug: 240112941 Change-Id: Ia63a401197f5dd8b2d32234357ffc2863150be31 --- core/api/current.txt | 30 +++++++++---------- core/api/system-current.txt | 2 +- .../service/wallpaper/WallpaperService.java | 17 +++++++++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index c8241066b2584..af1756dcc8027 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -39903,7 +39903,7 @@ package android.service.wallpaper { public abstract class WallpaperService extends android.app.Service { ctor public WallpaperService(); method public final android.os.IBinder onBind(android.content.Intent); - method public abstract android.service.wallpaper.WallpaperService.Engine onCreateEngine(); + method @MainThread public abstract android.service.wallpaper.WallpaperService.Engine onCreateEngine(); field public static final String SERVICE_INTERFACE = "android.service.wallpaper.WallpaperService"; field public static final String SERVICE_META_DATA = "android.service.wallpaper"; } @@ -39918,20 +39918,20 @@ package android.service.wallpaper { method public boolean isPreview(); method public boolean isVisible(); method public void notifyColorsChanged(); - method public void onApplyWindowInsets(android.view.WindowInsets); - method public android.os.Bundle onCommand(String, int, int, int, android.os.Bundle, boolean); - method @Nullable public android.app.WallpaperColors onComputeColors(); - method public void onCreate(android.view.SurfaceHolder); - method public void onDesiredSizeChanged(int, int); - method public void onDestroy(); - method public void onOffsetsChanged(float, float, float, float, int, int); - method public void onSurfaceChanged(android.view.SurfaceHolder, int, int, int); - method public void onSurfaceCreated(android.view.SurfaceHolder); - method public void onSurfaceDestroyed(android.view.SurfaceHolder); - method public void onSurfaceRedrawNeeded(android.view.SurfaceHolder); - method public void onTouchEvent(android.view.MotionEvent); - method public void onVisibilityChanged(boolean); - method public void onZoomChanged(@FloatRange(from=0.0f, to=1.0f) float); + method @MainThread public void onApplyWindowInsets(android.view.WindowInsets); + method @MainThread public android.os.Bundle onCommand(String, int, int, int, android.os.Bundle, boolean); + method @MainThread @Nullable public android.app.WallpaperColors onComputeColors(); + method @MainThread public void onCreate(android.view.SurfaceHolder); + method @MainThread public void onDesiredSizeChanged(int, int); + method @MainThread public void onDestroy(); + method @MainThread public void onOffsetsChanged(float, float, float, float, int, int); + method @MainThread public void onSurfaceChanged(android.view.SurfaceHolder, int, int, int); + method @MainThread public void onSurfaceCreated(android.view.SurfaceHolder); + method @MainThread public void onSurfaceDestroyed(android.view.SurfaceHolder); + method @MainThread public void onSurfaceRedrawNeeded(android.view.SurfaceHolder); + method @MainThread public void onTouchEvent(android.view.MotionEvent); + method @MainThread public void onVisibilityChanged(boolean); + method @MainThread public void onZoomChanged(@FloatRange(from=0.0f, to=1.0f) float); method public void setOffsetNotificationsEnabled(boolean); method public void setTouchEventsEnabled(boolean); } diff --git a/core/api/system-current.txt b/core/api/system-current.txt index ae6e58c7ed486..f05ae4745e956 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -12221,7 +12221,7 @@ package android.service.wallpaper { public class WallpaperService.Engine { method public boolean isInAmbientMode(); - method public void onAmbientModeChanged(boolean, long); + method @MainThread public void onAmbientModeChanged(boolean, long); } } diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 37fc9f288c3e4..98db0861179cf 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -31,6 +31,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.FloatRange; +import android.annotation.MainThread; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; @@ -655,6 +656,7 @@ public abstract class WallpaperService extends Service { * Called once to initialize the engine. After returning, the * engine's surface will be created by the framework. */ + @MainThread public void onCreate(SurfaceHolder surfaceHolder) { } @@ -663,6 +665,7 @@ public abstract class WallpaperService extends Service { * surface will be destroyed and this Engine object is no longer * valid. */ + @MainThread public void onDestroy() { } @@ -671,6 +674,7 @@ public abstract class WallpaperService extends Service { * hidden. It is very important that a wallpaper only use * CPU while it is visible.. */ + @MainThread public void onVisibilityChanged(boolean visible) { } @@ -681,6 +685,7 @@ public abstract class WallpaperService extends Service { * * @param insets Insets to apply. */ + @MainThread public void onApplyWindowInsets(WindowInsets insets) { } @@ -691,6 +696,7 @@ public abstract class WallpaperService extends Service { * user is interacting with, so if it is slow you will get fewer * move events. */ + @MainThread public void onTouchEvent(MotionEvent event) { } @@ -700,6 +706,7 @@ public abstract class WallpaperService extends Service { * call to {@link WallpaperManager#setWallpaperOffsets(IBinder, float, float) * WallpaperManager.setWallpaperOffsets()}. */ + @MainThread public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) { @@ -722,6 +729,7 @@ public abstract class WallpaperService extends Service { * @return If returning a result, create a Bundle and place the * result data in to it. Otherwise return null. */ + @MainThread public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) { return null; @@ -740,6 +748,7 @@ public abstract class WallpaperService extends Service { * @hide */ @SystemApi + @MainThread public void onAmbientModeChanged(boolean inAmbientMode, long animationDuration) { } @@ -747,6 +756,7 @@ public abstract class WallpaperService extends Service { * Called when an application has changed the desired virtual size of * the wallpaper. */ + @MainThread public void onDesiredSizeChanged(int desiredWidth, int desiredHeight) { } @@ -754,6 +764,7 @@ public abstract class WallpaperService extends Service { * Convenience for {@link SurfaceHolder.Callback#surfaceChanged * SurfaceHolder.Callback.surfaceChanged()}. */ + @MainThread public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @@ -761,6 +772,7 @@ public abstract class WallpaperService extends Service { * Convenience for {@link SurfaceHolder.Callback2#surfaceRedrawNeeded * SurfaceHolder.Callback.surfaceRedrawNeeded()}. */ + @MainThread public void onSurfaceRedrawNeeded(SurfaceHolder holder) { } @@ -768,6 +780,7 @@ public abstract class WallpaperService extends Service { * Convenience for {@link SurfaceHolder.Callback#surfaceCreated * SurfaceHolder.Callback.surfaceCreated()}. */ + @MainThread public void onSurfaceCreated(SurfaceHolder holder) { } @@ -775,6 +788,7 @@ public abstract class WallpaperService extends Service { * Convenience for {@link SurfaceHolder.Callback#surfaceDestroyed * SurfaceHolder.Callback.surfaceDestroyed()}. */ + @MainThread public void onSurfaceDestroyed(SurfaceHolder holder) { } @@ -785,6 +799,7 @@ public abstract class WallpaperService extends Service { * @param zoom the zoom level, between 0 indicating fully zoomed in and 1 indicating fully * zoomed out. */ + @MainThread public void onZoomChanged(@FloatRange(from = 0f, to = 1f) float zoom) { } @@ -834,6 +849,7 @@ public abstract class WallpaperService extends Service { * * @return Wallpaper colors. */ + @MainThread public @Nullable WallpaperColors onComputeColors() { return null; } @@ -2468,6 +2484,7 @@ public abstract class WallpaperService extends Service { * when the wallpaper is currently set as the active wallpaper and the user * is in the wallpaper picker viewing a preview of it as well. */ + @MainThread public abstract Engine onCreateEngine(); @Override