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

Commit e94b29da authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Ching-Sung Li
Browse files

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
parent 7c182fd4
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -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,28 +1433,37 @@ 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);
                                // 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 (DEBUG) Log.v(TAG, "onVisibilityChanged(false) at surface: "
                                        + this);
                            }
                            if (!noConsecutiveVisibilityEvents()) {
                                if (DEBUG) {
                                    Log.v(TAG, "onVisibilityChanged(false) at surface: " + this);
                                }
                                Trace.beginSection("WPMS.Engine.onVisibilityChanged-false");
                                onVisibilityChanged(false);
                                Trace.endSection();
                            }
                        }
                    } finally {
                        mIsCreating = false;
                        mSurfaceCreated = true;
+7 −0
Original line number Diff line number Diff line
@@ -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