Merge "Fix launching ActivityGroup with ActivityEmbedding" into tm-qpr-dev

This commit is contained in:
Chris Li
2022-11-03 02:17:30 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 2 deletions

View File

@@ -1873,6 +1873,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
@Override @Override
public void onActivityPreCreated(@NonNull Activity activity, public void onActivityPreCreated(@NonNull Activity activity,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
if (activity.isChild()) {
// Skip Activity that is child of another Activity (ActivityGroup) because it's
// window will just be a child of the parent Activity window.
return;
}
synchronized (mLock) { synchronized (mLock) {
final IBinder activityToken = activity.getActivityToken(); final IBinder activityToken = activity.getActivityToken();
final IBinder initialTaskFragmentToken = final IBinder initialTaskFragmentToken =
@@ -1904,6 +1909,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
@Override @Override
public void onActivityPostCreated(@NonNull Activity activity, public void onActivityPostCreated(@NonNull Activity activity,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
if (activity.isChild()) {
// Skip Activity that is child of another Activity (ActivityGroup) because it's
// window will just be a child of the parent Activity window.
return;
}
// Calling after Activity#onCreate is complete to allow the app launch something // Calling after Activity#onCreate is complete to allow the app launch something
// first. In case of a configured placeholder activity we want to make sure // first. In case of a configured placeholder activity we want to make sure
// that we don't launch it if an activity itself already requested something to be // that we don't launch it if an activity itself already requested something to be
@@ -1921,6 +1931,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
@Override @Override
public void onActivityConfigurationChanged(@NonNull Activity activity) { public void onActivityConfigurationChanged(@NonNull Activity activity) {
if (activity.isChild()) {
// Skip Activity that is child of another Activity (ActivityGroup) because it's
// window will just be a child of the parent Activity window.
return;
}
synchronized (mLock) { synchronized (mLock) {
final TransactionRecord transactionRecord = mTransactionManager final TransactionRecord transactionRecord = mTransactionManager
.startNewTransaction(); .startNewTransaction();
@@ -1934,6 +1949,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
@Override @Override
public void onActivityPostDestroyed(@NonNull Activity activity) { public void onActivityPostDestroyed(@NonNull Activity activity) {
if (activity.isChild()) {
// Skip Activity that is child of another Activity (ActivityGroup) because it's
// window will just be a child of the parent Activity window.
return;
}
synchronized (mLock) { synchronized (mLock) {
SplitController.this.onActivityDestroyed(activity); SplitController.this.onActivityDestroyed(activity);
} }
@@ -1969,7 +1989,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
if (who instanceof Activity) { if (who instanceof Activity) {
// We will check if the new activity should be split with the activity that launched // We will check if the new activity should be split with the activity that launched
// it. // it.
launchingActivity = (Activity) who; final Activity activity = (Activity) who;
// For Activity that is child of another Activity (ActivityGroup), treat the parent
// Activity as the launching one because it's window will just be a child of the
// parent Activity window.
launchingActivity = activity.isChild() ? activity.getParent() : activity;
if (isInPictureInPicture(launchingActivity)) { if (isInPictureInPicture(launchingActivity)) {
// We don't embed activity when it is in PIP. // We don't embed activity when it is in PIP.
return super.onStartActivity(who, intent, options); return super.onStartActivity(who, intent, options);

View File

@@ -227,7 +227,7 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
final TaskFragmentContainer curSecondaryContainer = mController.getContainerWithActivity( final TaskFragmentContainer curSecondaryContainer = mController.getContainerWithActivity(
secondaryActivity); secondaryActivity);
TaskFragmentContainer containerToAvoid = primaryContainer; TaskFragmentContainer containerToAvoid = primaryContainer;
if (curSecondaryContainer != null if (curSecondaryContainer != null && curSecondaryContainer != primaryContainer
&& (rule.shouldClearTop() || primaryContainer.isAbove(curSecondaryContainer))) { && (rule.shouldClearTop() || primaryContainer.isAbove(curSecondaryContainer))) {
// Do not reuse the current TaskFragment if the rule is to clear top, or if it is below // Do not reuse the current TaskFragment if the rule is to clear top, or if it is below
// the primary TaskFragment. // the primary TaskFragment.