Make DreamService detach on DreamActivity onDestroy

Currently DreamService.onDestroy is called whenever the DreamActivity is being destroyed. This causes issues with the lifecycle of the dream
window, because the DreamService is destroyed before
onDetachedFromWindow is called.

In this CL, we change the implementation of onActivityDestroyed to
detach the DreamService instead of destroy it immediately. This is a
more gentle way to achieve the same result.

Bug: 243385408
Bug: 266668856
Bug: 270913936
Test: atest DreamServiceManagerTests
Test: atest DreamServiceTests
Test: atest DreamOverlayTest
Change-Id: Iadb7880faabf54f70a64c76c6e3e267fde9c42dd
This commit is contained in:
Galia Peycheva
2023-01-20 11:02:21 +00:00
parent b436b2f183
commit 3f6a4e9d5c
2 changed files with 3 additions and 2 deletions

View File

@@ -70,7 +70,7 @@ public class DreamActivity extends Activity {
@Override
public void onDestroy() {
if (mCallback != null && !isFinishing()) {
if (mCallback != null) {
mCallback.onActivityDestroyed();
}

View File

@@ -1588,7 +1588,8 @@ public class DreamService extends Service implements Window.Callback {
// If DreamActivity is destroyed, wake up from Dream.
void onActivityDestroyed() {
mActivity = null;
onDestroy();
mWindow = null;
detach();
}
}