summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2021-08-23 11:38:35 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-08-23 11:38:35 +0000
commit0917c90d041923d82efeeecc62aa215f7ec6ff7d (patch)
treecf1c5c5caf94927466659877c1fe73a26e21d45d /core/java
parent00a8be3e37f652bd52ceb6579bb15bf161fb33f2 (diff)
parent5da1d62387a80d80fa75b162e8a1a1ac688306c5 (diff)
Merge "Using LaunchActivity when possible" into sc-v2-dev am: a6a85a9be2 am: 5da1d62387
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15595469 Change-Id: I351006552864a7ceeccbbb71fff16f90b7555ae6
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/servertransaction/ActivityTransactionItem.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/core/java/android/app/servertransaction/ActivityTransactionItem.java b/core/java/android/app/servertransaction/ActivityTransactionItem.java
index a539812fa8c6..186f25deab67 100644
--- a/core/java/android/app/servertransaction/ActivityTransactionItem.java
+++ b/core/java/android/app/servertransaction/ActivityTransactionItem.java
@@ -59,36 +59,37 @@ public abstract class ActivityTransactionItem extends ClientTransactionItem {
}
/**
- * Get the {@link ActivityClientRecord} instance that corresponds to the provided token.
+ * Gets the {@link ActivityClientRecord} instance that corresponds to the provided token.
* @param client Target client handler.
* @param token Target activity token.
- * @param includeLaunching Indicate to also find the {@link ActivityClientRecord} in launching
- * activity list. It should be noted that there is no activity in
+ * @param includeLaunching Indicate to find the {@link ActivityClientRecord} in launching
+ * activity list.
+ * <p>Note that there is no {@link android.app.Activity} instance in
* {@link ActivityClientRecord} from the launching activity list.
* @return The {@link ActivityClientRecord} instance that corresponds to the provided token.
*/
@NonNull ActivityClientRecord getActivityClientRecord(
@NonNull ClientTransactionHandler client, IBinder token, boolean includeLaunching) {
- ActivityClientRecord r = client.getActivityClient(token);
- if (r != null) {
- if (client.getActivity(token) == null) {
+ ActivityClientRecord r = null;
+ // Check launching Activity first to prevent race condition that activity instance has not
+ // yet set to ActivityClientRecord.
+ if (includeLaunching) {
+ r = client.getLaunchingActivity(token);
+ }
+ // Then if we don't want to find launching Activity or the ActivityClientRecord doesn't
+ // exist in launching Activity list. The ActivityClientRecord should have been initialized
+ // and put in the Activity list.
+ if (r == null) {
+ r = client.getActivityClient(token);
+ if (r != null && client.getActivity(token) == null) {
throw new IllegalArgumentException("Activity must not be null to execute "
+ "transaction item");
}
- return r;
- }
- // The activity may not be launched yet. Fallback to check launching activity.
- if (includeLaunching) {
- r = client.getLaunchingActivity(token);
}
if (r == null) {
throw new IllegalArgumentException("Activity client record must not be null to execute "
+ "transaction item");
}
-
- // We don't need to check the activity of launching activity client records because they
- // have not been launched yet.
-
return r;
}
}