Add MainThread annotations to WallpaperService callbacks

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
This commit is contained in:
Aurélien Pomini
2022-11-07 19:43:57 +00:00
parent f9033ef598
commit 4602a88ae8
3 changed files with 33 additions and 16 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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. <em>It is very important that a wallpaper only use
* CPU while it is visible.</em>.
*/
@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