summaryrefslogtreecommitdiff
path: root/core/java/android/app/LocalActivityManager.java
diff options
context:
space:
mode:
authorChilun Huang <chilunhuang@google.com>2020-08-18 02:53:49 +0000
committerChilun <chilunhuang@google.com>2020-09-18 14:36:10 +0800
commitd5af95b56f232e120a7c824637d522d02b60efe4 (patch)
tree97e93556011ab781fc88aee2a5a66cf879c6ad32 /core/java/android/app/LocalActivityManager.java
parent48e000d788187714f799eb30df16a6a043b5a03e (diff)
Revert "Revert "Introduce ActivityTransactionItem and reduce null checks""
This reverts commit fd2be2c17882c7db2833ed35c2b4da975801e527. Reason for revert: Reland the CL This class is used for activity-targeting item to inherit, which encapsulate null checks of activity client record. This patch also change signature of ClientTransactionHandler#handle* and reduces null checks. In addition, add some null pointer checks after getActivityClient(). Also fix a typo in performStopActivityInner() and performDestroyActivity(). Bug: 127877792 Bug: 164982975 Test: atest frameworks/base/core/tests/coretests/src/android/app/servertransaction Test: atest ActivityThreadTest ActivityThreadClientTest Test: atest TransactionExecutorTests#testActivityItemNullRecordThrowsException Test: atest TransactionExecutorTests#testActivityItemExecute Test: atest CtsAppTestCases:LocalActivityManagerTest Change-Id: Ida612f1c8af7ecd7a04e69ade461403b8711508a
Diffstat (limited to 'core/java/android/app/LocalActivityManager.java')
-rw-r--r--core/java/android/app/LocalActivityManager.java43
1 files changed, 31 insertions, 12 deletions
diff --git a/core/java/android/app/LocalActivityManager.java b/core/java/android/app/LocalActivityManager.java
index 7cdf85e0a6b8..2e7c9f11ac66 100644
--- a/core/java/android/app/LocalActivityManager.java
+++ b/core/java/android/app/LocalActivityManager.java
@@ -49,6 +49,7 @@ public class LocalActivityManager {
private static final String TAG = "LocalActivityManager";
private static final boolean localLOGV = false;
+ // TODO(b/127877792): try to remove this and use {@code ActivityClientRecord} instead.
// Internal token for an Activity being managed by LocalActivityManager.
private static class LocalActivityRecord extends Binder {
LocalActivityRecord(String _id, Intent _intent) {
@@ -136,7 +137,7 @@ public class LocalActivityManager {
// startActivity() has not yet been called, so nothing to do.
return;
}
-
+
if (r.curState == INITIALIZING) {
// Get the lastNonConfigurationInstance for the activity
HashMap<String, Object> lastNonConfigurationInstances =
@@ -177,12 +178,13 @@ public class LocalActivityManager {
pendingActions = null;
}
- mActivityThread.handleStartActivity(r, pendingActions);
+ mActivityThread.handleStartActivity(clientRecord, pendingActions);
r.curState = STARTED;
if (desiredState == RESUMED) {
if (localLOGV) Log.v(TAG, r.id + ": resuming");
- mActivityThread.performResumeActivity(r, true, "moveToState-INITIALIZING");
+ mActivityThread.performResumeActivity(clientRecord, true,
+ "moveToState-INITIALIZING");
r.curState = RESUMED;
}
@@ -194,18 +196,25 @@ public class LocalActivityManager {
// group's state catches up.
return;
}
-
+
+ final ActivityClientRecord clientRecord = mActivityThread.getActivityClient(r);
+ if (clientRecord == null) {
+ Log.w(TAG, "Can't get activity record for " + r.id);
+ return;
+ }
+
switch (r.curState) {
case CREATED:
if (desiredState == STARTED) {
if (localLOGV) Log.v(TAG, r.id + ": restarting");
- mActivityThread.performRestartActivity(r, true /* start */);
+ mActivityThread.performRestartActivity(clientRecord, true /* start */);
r.curState = STARTED;
}
if (desiredState == RESUMED) {
if (localLOGV) Log.v(TAG, r.id + ": restarting and resuming");
- mActivityThread.performRestartActivity(r, true /* start */);
- mActivityThread.performResumeActivity(r, true, "moveToState-CREATED");
+ mActivityThread.performRestartActivity(clientRecord, true /* start */);
+ mActivityThread.performResumeActivity(clientRecord, true,
+ "moveToState-CREATED");
r.curState = RESUMED;
}
return;
@@ -214,7 +223,8 @@ public class LocalActivityManager {
if (desiredState == RESUMED) {
// Need to resume it...
if (localLOGV) Log.v(TAG, r.id + ": resuming");
- mActivityThread.performResumeActivity(r, true, "moveToState-STARTED");
+ mActivityThread.performResumeActivity(clientRecord, true,
+ "moveToState-STARTED");
r.instanceState = null;
r.curState = RESUMED;
}
@@ -352,7 +362,8 @@ public class LocalActivityManager {
ArrayList<ReferrerIntent> intents = new ArrayList<>(1);
intents.add(new ReferrerIntent(intent, mParent.getPackageName()));
if (localLOGV) Log.v(TAG, r.id + ": new intent");
- mActivityThread.handleNewIntent(r, intents);
+ final ActivityClientRecord clientRecord = mActivityThread.getActivityClient(r);
+ mActivityThread.handleNewIntent(clientRecord, intents);
r.intent = intent;
moveToState(r, mCurState);
if (mSingleMode) {
@@ -399,8 +410,11 @@ public class LocalActivityManager {
performPause(r, finish);
}
if (localLOGV) Log.v(TAG, r.id + ": destroying");
- mActivityThread.performDestroyActivity(r, finish, 0 /* configChanges */,
- false /* getNonConfigInstance */, "LocalActivityManager::performDestroy");
+ final ActivityClientRecord clientRecord = mActivityThread.getActivityClient(r);
+ if (clientRecord != null) {
+ mActivityThread.performDestroyActivity(clientRecord, finish, 0 /* configChanges */,
+ false /* getNonConfigInstance */, "LocalActivityManager::performDestroy");
+ }
r.activity = null;
r.window = null;
if (finish) {
@@ -664,7 +678,12 @@ public class LocalActivityManager {
for (int i=0; i<N; i++) {
LocalActivityRecord r = mActivityArray.get(i);
if (localLOGV) Log.v(TAG, r.id + ": destroying");
- mActivityThread.performDestroyActivity(r, finishing, 0 /* configChanges */,
+ final ActivityClientRecord clientRecord = mActivityThread.getActivityClient(r);
+ if (clientRecord == null) {
+ if (localLOGV) Log.v(TAG, r.id + ": no corresponding record");
+ continue;
+ }
+ mActivityThread.performDestroyActivity(clientRecord, finishing, 0 /* configChanges */,
false /* getNonConfigInstance */, "LocalActivityManager::dispatchDestroy");
}
mActivities.clear();