From d948f743c26c42a3f4f94ce2332a7ba24f5ed5fc Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 4 May 2020 20:48:32 +0800 Subject: [PATCH] Do not stop dream service if dream activity is relaunching Currently DreamActivity doesn't handle any configuration changes, and does not set fixed orientation. So the decor view will be detached if the activity is relaunching for configuration changes. Though it also works by making DreamActivity support handling the changes, all implementations of DreamService may need to add the corresponding handling. So this fix only keeps the service alive for compatibility. Fixes: 154474768 Test: atest DreamManagerServiceTests#testDreamNotFinishAfterRotation Test: Enter Settings > Display > Screen saver, press "Start now". The dream service should not be stopped after device rotated. Change-Id: I454f75d06c4539258eeafd8794a3cb03e0276163 --- core/java/android/service/dreams/DreamService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index 337027ef5bc99..c43a9b0699e1b 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -1076,8 +1076,12 @@ public class DreamService extends Service implements Window.Callback { @Override public void onViewDetachedFromWindow(View v) { - mActivity = null; - finish(); + if (mActivity == null || !mActivity.isChangingConfigurations()) { + // Only stop the dream if the view is not detached by relaunching + // activity for configuration changes. + mActivity = null; + finish(); + } } }); }