Merge "Synchronize access to mActiveEngines" into udc-dev am: 6c29630c2d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22966376

Change-Id: Ie3b047ae700ee9551b865dcaa7008ac9e49c8a39
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Marzia Favaro
2023-05-08 12:44:18 +00:00
committed by Automerger Merge Worker

View File

@@ -184,6 +184,7 @@ public abstract class WallpaperService extends Service {
private static final long DIMMING_ANIMATION_DURATION_MS = 300L; private static final long DIMMING_ANIMATION_DURATION_MS = 300L;
@GuardedBy("itself")
private final ArrayMap<IBinder, IWallpaperEngineWrapper> mActiveEngines = new ArrayMap<>(); private final ArrayMap<IBinder, IWallpaperEngineWrapper> mActiveEngines = new ArrayMap<>();
private Handler mBackgroundHandler; 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 they are visible, so we need to toggle the state to get their attention.
if (!mEngine.mDestroyed) { if (!mEngine.mDestroyed) {
mEngine.detach(); mEngine.detach();
synchronized (mActiveEngines) {
for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) { for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
if (engineWrapper.mEngine != null && engineWrapper.mEngine.mVisible) { if (engineWrapper.mEngine != null && engineWrapper.mEngine.mVisible) {
engineWrapper.mEngine.doVisibilityChanged(false); engineWrapper.mEngine.doVisibilityChanged(false);
@@ -2522,6 +2524,7 @@ public abstract class WallpaperService extends Service {
} }
} }
} }
}
public void updateScreenTurningOn(boolean isScreenTurningOn) { public void updateScreenTurningOn(boolean isScreenTurningOn) {
Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn, Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn,
@@ -2699,7 +2702,9 @@ public abstract class WallpaperService extends Service {
IWallpaperEngineWrapper engineWrapper = IWallpaperEngineWrapper engineWrapper =
new IWallpaperEngineWrapper(mTarget, conn, windowToken, windowType, new IWallpaperEngineWrapper(mTarget, conn, windowToken, windowType,
isPreview, reqWidth, reqHeight, padding, displayId, which); isPreview, reqWidth, reqHeight, padding, displayId, which);
synchronized (mActiveEngines) {
mActiveEngines.put(windowToken, engineWrapper); mActiveEngines.put(windowToken, engineWrapper);
}
if (DEBUG) { if (DEBUG) {
Slog.v(TAG, "IWallpaperServiceWrapper Attaching window token " + windowToken); Slog.v(TAG, "IWallpaperServiceWrapper Attaching window token " + windowToken);
} }
@@ -2708,7 +2713,10 @@ public abstract class WallpaperService extends Service {
@Override @Override
public void detach(IBinder windowToken) { public void detach(IBinder windowToken) {
IWallpaperEngineWrapper engineWrapper = mActiveEngines.remove(windowToken); IWallpaperEngineWrapper engineWrapper;
synchronized (mActiveEngines) {
engineWrapper = mActiveEngines.remove(windowToken);
}
if (engineWrapper == null) { if (engineWrapper == null) {
Log.w(TAG, "Engine for window token " + windowToken + " already detached"); Log.w(TAG, "Engine for window token " + windowToken + " already detached");
return; return;
@@ -2734,10 +2742,12 @@ public abstract class WallpaperService extends Service {
public void onDestroy() { public void onDestroy() {
Trace.beginSection("WPMS.onDestroy"); Trace.beginSection("WPMS.onDestroy");
super.onDestroy(); super.onDestroy();
synchronized (mActiveEngines) {
for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) { for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
engineWrapper.destroy(); engineWrapper.destroy();
} }
mActiveEngines.clear(); mActiveEngines.clear();
}
if (mBackgroundThread != null) { if (mBackgroundThread != null) {
// onDestroy might be called without a previous onCreate if WallpaperService was // onDestroy might be called without a previous onCreate if WallpaperService was
// instantiated manually. While this is a misuse of the API, some things break // instantiated manually. While this is a misuse of the API, some things break
@@ -2768,14 +2778,18 @@ public abstract class WallpaperService extends Service {
@Override @Override
protected void dump(FileDescriptor fd, PrintWriter out, String[] args) { protected void dump(FileDescriptor fd, PrintWriter out, String[] args) {
out.print("State of wallpaper "); out.print(this); out.println(":"); out.print("State of wallpaper "); out.print(this); out.println(":");
synchronized (mActiveEngines) {
for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) { for (IWallpaperEngineWrapper engineWrapper : mActiveEngines.values()) {
Engine engine = engineWrapper.mEngine; Engine engine = engineWrapper.mEngine;
if (engine == null) { if (engine == null) {
Slog.w(TAG, "Engine for wrapper " + engineWrapper + " not attached"); Slog.w(TAG, "Engine for wrapper " + engineWrapper + " not attached");
continue; continue;
} }
out.print(" Engine "); out.print(engine); out.println(":"); out.print(" Engine ");
out.print(engine);
out.println(":");
engine.dump(" ", fd, out, args); engine.dump(" ", fd, out, args);
} }
} }
} }
}