Merge "Fix crash for cross-process embedding" into tm-dev

This commit is contained in:
Chris Li
2022-04-27 08:13:39 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 3 deletions

View File

@@ -591,8 +591,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {
* @see #isAllowedToEmbedActivityInTrustedMode(ActivityRecord)
*/
boolean isAllowedToBeEmbeddedInTrustedMode() {
final Predicate<ActivityRecord> callback = this::isAllowedToEmbedActivityInTrustedMode;
return forAllActivities(callback);
// Traverse all activities to see if any of them are not in the trusted mode.
final Predicate<ActivityRecord> callback = r -> !isAllowedToEmbedActivityInTrustedMode(r);
return !forAllActivities(callback);
}
/**

View File

@@ -1438,7 +1438,8 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
}
final WindowConfiguration requestedWindowConfig = requestedConfig.windowConfiguration;
final WindowConfiguration parentWindowConfig = parentConfig.windowConfiguration;
if (!parentWindowConfig.getBounds().contains(requestedWindowConfig.getBounds())) {
if (!requestedWindowConfig.getBounds().isEmpty()
&& !parentWindowConfig.getBounds().contains(requestedWindowConfig.getBounds())) {
String msg = "Permission Denial: " + func + " from pid="
+ Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+ " trying to apply bounds outside of parent for non-trusted host,"
@@ -1447,6 +1448,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
throw new SecurityException(msg);
}
if (requestedWindowConfig.getAppBounds() != null
&& !requestedWindowConfig.getAppBounds().isEmpty()
&& parentWindowConfig.getAppBounds() != null
&& !parentWindowConfig.getAppBounds().contains(
requestedWindowConfig.getAppBounds())) {

View File

@@ -403,4 +403,29 @@ public class TaskFragmentTest extends WindowTestsBase {
assertFalse(activity0.hasOverlayOverUntrustedModeEmbedded());
assertFalse(activity1.hasOverlayOverUntrustedModeEmbedded());
}
@Test
public void testIsAllowedToBeEmbeddedInTrustedMode() {
final TaskFragment taskFragment = new TaskFragmentBuilder(mAtm)
.setCreateParentTask()
.createActivityCount(2)
.build();
final ActivityRecord activity0 = taskFragment.getBottomMostActivity();
final ActivityRecord activity1 = taskFragment.getTopMostActivity();
// Allowed if all children activities are allowed.
doReturn(true).when(taskFragment).isAllowedToEmbedActivityInTrustedMode(activity0);
doReturn(true).when(taskFragment).isAllowedToEmbedActivityInTrustedMode(activity1);
assertTrue(taskFragment.isAllowedToBeEmbeddedInTrustedMode());
// Disallowed if any child activity is not allowed.
doReturn(false).when(taskFragment).isAllowedToEmbedActivityInTrustedMode(activity0);
assertFalse(taskFragment.isAllowedToBeEmbeddedInTrustedMode());
doReturn(false).when(taskFragment).isAllowedToEmbedActivityInTrustedMode(activity1);
assertFalse(taskFragment.isAllowedToBeEmbeddedInTrustedMode());
}
}