Make DreamActivity no history

The DreamActivity is tied to a DreamService. When the DreamActivity is
destroyed, so is the DreamService. If the DreamActivity is
consequently recreated by the WM, this leads to a ClassCastException
in the DreamActivity.onCreate method.

This CL makes the DreamActivity a noHistory activity, which prevents
it from being recreated after having been destroyed once. We also handle
the case where the callback in onCreate is null or of the wrong type and
finish the dream immediately if so.

Bug: 231602954
Test: atest DreamManagerServiceTests
Change-Id: I93637368374d9de90c588e2b0355ae7b66fb4167
This commit is contained in:
Galia Peycheva
2022-12-19 12:06:48 +01:00
parent 85a3f5050d
commit becfbaf25f
2 changed files with 7 additions and 5 deletions

View File

@@ -58,11 +58,13 @@ public class DreamActivity extends Activity {
setTitle(title);
}
final Bundle extras = getIntent().getExtras();
mCallback = (DreamService.DreamActivityCallbacks) extras.getBinder(EXTRA_CALLBACK);
if (mCallback != null) {
final Object callback = getIntent().getExtras().getBinder(EXTRA_CALLBACK);
if (callback instanceof DreamService.DreamActivityCallbacks) {
mCallback = (DreamService.DreamActivityCallbacks) callback;
mCallback.onActivityCreated(this);
} else {
mCallback = null;
finishAndRemoveTask();
}
}

View File

@@ -1495,7 +1495,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
a.persistableMode = ActivityInfo.PERSIST_NEVER;
a.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
a.colorMode = ActivityInfo.COLOR_MODE_DEFAULT;
a.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
a.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS | ActivityInfo.FLAG_NO_HISTORY;
a.resizeMode = RESIZE_MODE_UNRESIZEABLE;
a.configChanges = 0xffffffff;