diff options
| author | 2023-04-20 11:35:28 +0000 | |
|---|---|---|
| committer | 2023-04-20 11:35:28 +0000 | |
| commit | c3e257fc007faaa4ab3f1a297fe2a4b0fc85f58a (patch) | |
| tree | afa19af1375bfd8828a5fcf7d87c857b3d6c2a93 | |
| parent | ee3afca596291830937b82398d7397039049dadc (diff) | |
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
| -rw-r--r-- | core/java/android/service/wallpaper/WallpaperService.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 9d3d70d4a8f7..8d84e4413635 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -2738,7 +2738,12 @@ public abstract class WallpaperService extends Service { engineWrapper.destroy(); } 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(); } |