Merge "Using LaunchActivity when possible" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-08-23 11:13:09 +00:00
committed by Android (Google) Code Review

View File

@@ -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 client Target client handler.
* @param token Target activity token. * @param token Target activity token.
* @param includeLaunching Indicate to also find the {@link ActivityClientRecord} in launching * @param includeLaunching Indicate to find the {@link ActivityClientRecord} in launching
* activity list. It should be noted that there is no activity in * activity list.
* <p>Note that there is no {@link android.app.Activity} instance in
* {@link ActivityClientRecord} from the launching activity list. * {@link ActivityClientRecord} from the launching activity list.
* @return The {@link ActivityClientRecord} instance that corresponds to the provided token. * @return The {@link ActivityClientRecord} instance that corresponds to the provided token.
*/ */
@NonNull ActivityClientRecord getActivityClientRecord( @NonNull ActivityClientRecord getActivityClientRecord(
@NonNull ClientTransactionHandler client, IBinder token, boolean includeLaunching) { @NonNull ClientTransactionHandler client, IBinder token, boolean includeLaunching) {
ActivityClientRecord r = client.getActivityClient(token); ActivityClientRecord r = null;
if (r != null) { // Check launching Activity first to prevent race condition that activity instance has not
if (client.getActivity(token) == null) { // 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 " throw new IllegalArgumentException("Activity must not be null to execute "
+ "transaction item"); + "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) { if (r == null) {
throw new IllegalArgumentException("Activity client record must not be null to execute " throw new IllegalArgumentException("Activity client record must not be null to execute "
+ "transaction item"); + "transaction item");
} }
// We don't need to check the activity of launching activity client records because they
// have not been launched yet.
return r; return r;
} }
} }