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

Commit 6c29630c authored by Marzia Favaro's avatar Marzia Favaro Committed by Android (Google) Code Review
Browse files

Merge "Synchronize access to mActiveEngines" into udc-dev

parents 6aecb91b a6e4644f
Loading
Loading
Loading
Loading
+31 −17
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ public abstract class WallpaperService extends Service {

    private static final long DIMMING_ANIMATION_DURATION_MS = 300L;

    @GuardedBy("itself")
    private final ArrayMap<IBinder, IWallpaperEngineWrapper> mActiveEngines = new ArrayMap<>();

    private Handler mBackgroundHandler;
@@ -2514,6 +2515,7 @@ public abstract class WallpaperService extends Service {
            // if they are visible, so we need to toggle the state to get their attention.
            if (!mEngine.mDestroyed) {
                mEngine.detach();
                synchronized (mActiveEngines) {
                    for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
                        if (engineWrapper.mEngine != null && engineWrapper.mEngine.mVisible) {
                            engineWrapper.mEngine.doVisibilityChanged(false);
@@ -2522,6 +2524,7 @@ public abstract class WallpaperService extends Service {
                    }
                }
            }
        }

        public void updateScreenTurningOn(boolean isScreenTurningOn) {
            Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn,
@@ -2699,7 +2702,9 @@ public abstract class WallpaperService extends Service {
            IWallpaperEngineWrapper engineWrapper =
                    new IWallpaperEngineWrapper(mTarget, conn, windowToken, windowType,
                            isPreview, reqWidth, reqHeight, padding, displayId, which);
            synchronized (mActiveEngines) {
                mActiveEngines.put(windowToken, engineWrapper);
            }
            if (DEBUG) {
                Slog.v(TAG, "IWallpaperServiceWrapper Attaching window token " + windowToken);
            }
@@ -2708,7 +2713,10 @@ public abstract class WallpaperService extends Service {

        @Override
        public void detach(IBinder windowToken) {
            IWallpaperEngineWrapper engineWrapper = mActiveEngines.remove(windowToken);
            IWallpaperEngineWrapper engineWrapper;
            synchronized (mActiveEngines) {
                engineWrapper = mActiveEngines.remove(windowToken);
            }
            if (engineWrapper == null) {
                Log.w(TAG, "Engine for window token " + windowToken + " already detached");
                return;
@@ -2734,10 +2742,12 @@ public abstract class WallpaperService extends Service {
    public void onDestroy() {
        Trace.beginSection("WPMS.onDestroy");
        super.onDestroy();
        synchronized (mActiveEngines) {
            for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
                engineWrapper.destroy();
            }
            mActiveEngines.clear();
        }
        if (mBackgroundThread != null) {
            // onDestroy might be called without a previous onCreate if WallpaperService was
            // instantiated manually. While this is a misuse of the API, some things break
@@ -2768,14 +2778,18 @@ public abstract class WallpaperService extends Service {
    @Override
    protected void dump(FileDescriptor fd, PrintWriter out, String[] args) {
        out.print("State of wallpaper "); out.print(this); out.println(":");
        synchronized (mActiveEngines) {
            for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
                Engine engine = engineWrapper.mEngine;
                if (engine == null) {
                    Slog.w(TAG, "Engine for wrapper " + engineWrapper + " not attached");
                    continue;
                }
            out.print("  Engine "); out.print(engine); out.println(":");
                out.print("  Engine ");
                out.print(engine);
                out.println(":");
                engine.dump("    ", fd, out, args);
            }
        }
    }
}