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

Commit 5f2a7bd5 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Avoid sending two onSurfaceDestroyed() events

It has been observed that in some cases the onSurfaceDestroyed() event
could be sent twice, once from updateSurface and once from detach, while
onSurfaceCreated was only sent once. This is an issue since some
wallpapers (e.g. AndroidLiveWallpaperService subclasses) use
onSurfaceCreated and onSurfaceDestroyed to count the number of active
engines and pause or resume the wallpaper accordingly.

By creating a new flag mReportedSurfaceCreated, and setting it to true
right before onSurfaceCreated, and to false right before
onSurfaceDestroyed, and by checking its value before calling
onSurfaceDestroyed, we avoid calling onSurfaceDestroyed twice.

There is no need to add a check before calling onSurfaceCreated, the
mSurfaceCreated flag already avoids two consecutive onSurfaceCreated
calls.

Flag: com.android.window.flags.no_duplicate_surface_destroyed_events
Bug: 344461715
Test: treehugger, soak the flag and see if bug still exists
Change-Id: I0498d7689bd7636fb7c208f6fccdfba15df86440
parent 90e48229
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.view.View.SYSTEM_UI_FLAG_VISIBLE;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;

import static com.android.window.flags.Flags.FLAG_OFFLOAD_COLOR_EXTRACTION;
import static com.android.window.flags.Flags.noDuplicateSurfaceDestroyedEvents;
import static com.android.window.flags.Flags.noConsecutiveVisibilityEvents;
import static com.android.window.flags.Flags.noVisibilityEventOnDisplayStateChange;
import static com.android.window.flags.Flags.offloadColorExtraction;
@@ -255,6 +256,7 @@ public abstract class WallpaperService extends Service {
         */
        private boolean mIsScreenTurningOn;
        boolean mReportedVisible;
        boolean mReportedSurfaceCreated;
        boolean mDestroyed;
        // Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
        // after receiving WallpaperManager#COMMAND_UNFREEZE. COMMAND_FREEZE is fully applied once
@@ -1381,6 +1383,7 @@ public abstract class WallpaperService extends Service {
                        if (surfaceCreating) {
                            mIsCreating = true;
                            didSurface = true;
                            mReportedSurfaceCreated = true;
                            if (DEBUG) Log.v(TAG, "onSurfaceCreated("
                                    + mSurfaceHolder + "): " + this);
                            Trace.beginSection("WPMS.Engine.onSurfaceCreated");
@@ -2264,8 +2267,10 @@ public abstract class WallpaperService extends Service {
        }

        void reportSurfaceDestroyed() {
            if (mSurfaceCreated) {
            if ((!noDuplicateSurfaceDestroyedEvents() && mSurfaceCreated)
                    || (noDuplicateSurfaceDestroyedEvents() && mReportedSurfaceCreated)) {
                mSurfaceCreated = false;
                mReportedSurfaceCreated = false;
                mSurfaceHolder.ungetCallbacks();
                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
                if (callbacks != null) {
+10 −0
Original line number Diff line number Diff line
@@ -39,3 +39,13 @@ flag {
  description: "Prevent the system from sending visibility event on display state change."
  bug: "331725519"
}

flag {
  name: "no_duplicate_surface_destroyed_events"
  namespace: "systemui"
  description: "Prevent the system from sending onSurfaceDestroyed() twice."
  bug: "344461715"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}