From 762dfd156619072e8f74dafaf055b6f0bf7ab2d5 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 10 Oct 2016 17:44:48 -0700 Subject: [PATCH] Ignore wallpaper relaunch timeout during shutdown Because of course during system shutdown, the wallpaper service won't actually get relaunched. Sometimes shutdown can take long enough that this timeout kicks, so we need to avoid clearing the live wallpaper state spuriously. For simplicity we just check at "would have timed out now" time rather than try to distinguish between the shutdown case and a genuine crash that raced with the shutdown broadcast. Bug 32020355 Change-Id: I9335b2c0214b4c750ef950fed157d186aa670176 --- .../server/wallpaper/WallpaperManagerService.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 5f6800a8d0f2..760e298693d4 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -480,6 +480,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { WallpaperData mLastWallpaper; IWallpaperManagerCallback mKeyguardListener; boolean mWaitingForUnlock; + boolean mShuttingDown; /** * ID of the current wallpaper, changed every time anything sets a wallpaper. @@ -607,6 +608,14 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { private Runnable mResetRunnable = () -> { synchronized (mLock) { + if (mShuttingDown) { + // Don't expect wallpaper services to relaunch during shutdown + if (DEBUG) { + Slog.i(TAG, "Ignoring relaunch timeout during shutdown"); + } + return; + } + if (!mWallpaper.wallpaperUpdating && mWallpaper.userId == mCurrentUserId) { Slog.w(TAG, "Wallpaper reconnect timed out, " @@ -867,6 +876,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { public WallpaperManagerService(Context context) { if (DEBUG) Slog.v(TAG, "WallpaperService startup"); mContext = context; + mShuttingDown = false; mImageWallpaper = ComponentName.unflattenFromString( context.getResources().getString(R.string.image_wallpaper_component)); mIWindowManager = IWindowManager.Stub.asInterface( @@ -931,6 +941,21 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { } }, userFilter); + final IntentFilter shutdownFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) { + if (DEBUG) { + Slog.i(TAG, "Shutting down"); + } + synchronized (mLock) { + mShuttingDown = true; + } + } + } + }, shutdownFilter); + try { ActivityManagerNative.getDefault().registerUserSwitchObserver( new IUserSwitchObserver.Stub() { -- 2.11.0