diff options
| author | 2023-12-07 20:20:22 +0000 | |
|---|---|---|
| committer | 2023-12-12 07:58:01 +0000 | |
| commit | e94b29da2776ae634de0eec8e68a5514a1a37585 (patch) | |
| tree | 4749e5f182a9b6499456de8ecb82e4d290747eba | |
| parent | 7c182fd40f957d4d938e08bb1c04b330873946a0 (diff) | |
Avoid consecutive onVisibilityChanged calls
Calling directly onVisibilityChanged(...) from
WallpaperService#updateSurface bypasses the check that the visibility
actually changed. Instead we use doVisibilityChanged(...), which is a
wrapper to onVisibilityChanged that checks that the visibility actually
changed.
This prevents a bug that triggers two consecutive calls to
onVisibilitychanged(false). One of the call comes from engine.attach ->
updateSurface, the other one from picker -> resizePreview ->
updateSurface.
Flag: ACONFIG com.android.window.flags.no_consecutive_visibility_events DEVELOPMENT
Bug: 285631818
Bug: 313527496 (to be verified)
Test: manually check onVisibilityChanged(false) logs
Test: treehugger
Change-Id: I4fc189cdb9d4b4de36d88fe27ad651ddf0b40449
| -rw-r--r-- | core/java/android/service/wallpaper/WallpaperService.java | 47 | ||||
| -rw-r--r-- | core/java/android/window/flags/wallpaper_manager.aconfig | 7 |
2 files changed, 36 insertions, 18 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 54116a2749e0..692dad49ec89 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -26,6 +26,8 @@ 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 com.android.window.flags.Flags.noConsecutiveVisibilityEvents; + import android.animation.AnimationHandler; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -1431,27 +1433,36 @@ public abstract class WallpaperService extends Service { } if (didSurface && !mReportedVisible) { - // This wallpaper is currently invisible, but its - // surface has changed. At this point let's tell it - // again that it is invisible in case the report about - // the surface caused it to start running. We really - // don't want wallpapers running when not visible. if (mIsCreating) { - // Some wallpapers will ignore this call if they - // had previously been told they were invisble, - // so if we are creating a new surface then toggle - // the state to get them to notice. - if (DEBUG) Log.v(TAG, "onVisibilityChanged(true) at surface: " - + this); - Trace.beginSection("WPMS.Engine.onVisibilityChanged-true"); - onVisibilityChanged(true); + // The surface has been created, but the wallpaper isn't visible. + // Trigger onVisibilityChanged(true) then onVisibilityChanged(false) + // to make sure the wallpaper is stopped even after the events + // onSurfaceCreated() and onSurfaceChanged(). + if (noConsecutiveVisibilityEvents()) { + if (DEBUG) Log.v(TAG, "toggling doVisibilityChanged"); + Trace.beginSection("WPMS.Engine.doVisibilityChanged-true"); + doVisibilityChanged(true); + Trace.endSection(); + Trace.beginSection("WPMS.Engine.doVisibilityChanged-false"); + doVisibilityChanged(false); + Trace.endSection(); + } else { + if (DEBUG) { + Log.v(TAG, "onVisibilityChanged(true) at surface: " + this); + } + Trace.beginSection("WPMS.Engine.onVisibilityChanged-true"); + onVisibilityChanged(true); + Trace.endSection(); + } + } + if (!noConsecutiveVisibilityEvents()) { + if (DEBUG) { + Log.v(TAG, "onVisibilityChanged(false) at surface: " + this); + } + Trace.beginSection("WPMS.Engine.onVisibilityChanged-false"); + onVisibilityChanged(false); Trace.endSection(); } - if (DEBUG) Log.v(TAG, "onVisibilityChanged(false) at surface: " - + this); - Trace.beginSection("WPMS.Engine.onVisibilityChanged-false"); - onVisibilityChanged(false); - Trace.endSection(); } } finally { mIsCreating = false; diff --git a/core/java/android/window/flags/wallpaper_manager.aconfig b/core/java/android/window/flags/wallpaper_manager.aconfig index f03c993a9c66..ea9da96496c7 100644 --- a/core/java/android/window/flags/wallpaper_manager.aconfig +++ b/core/java/android/window/flags/wallpaper_manager.aconfig @@ -13,3 +13,10 @@ flag { description: "Support storing different wallpaper crops for different display dimensions. Only effective after rebooting." bug: "281648899" } + +flag { + name: "no_consecutive_visibility_events" + namespace: "systemui" + description: "Prevent the system from sending consecutive onVisibilityChanged(false) events." + bug: "285631818" +}
\ No newline at end of file |