From 784a9ec804b9733e60f45f9afcd55a79ed9bca8f Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Thu, 20 Apr 2023 11:35:28 +0000 Subject: Check for nullness in WallpaperService onDestroy There are cases where the WallpaperService API is misused and an instance is created manually. In those cases, onCreate is not called as expected, but onDestroy is. As mBackgroundThread was being created `onCreate`, it ended up being null in onDestroy. Adding a null check to avoid breaking those places. Bug: 275361339 Test: androidx.wear.watchface.editor.EditorSessionTest#commitWithPreviewImage Change-Id: I89076da179493fa282f3e59895cfa4f4bfb6bdfc Merged-In: I89076da179493fa282f3e59895cfa4f4bfb6bdfc --- core/java/android/service/wallpaper/WallpaperService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 8f1fc1b9348e..5fab6678b938 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -2610,7 +2610,12 @@ public abstract class WallpaperService extends Service { mActiveEngines.get(i).detach(); } mActiveEngines.clear(); - mBackgroundThread.quitSafely(); + 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 + // if here we don't take into consideration this scenario. + mBackgroundThread.quitSafely(); + } Trace.endSection(); } -- cgit v1.2.3-59-g8ed1b