Make Task have type ActivityRecord children (55/n)

ActivityRecord now extends AppWindowToken and changing Task to have
type ActivityRecord children will make the Task level merging easier.

Bug: 80414790
Test: Existing tests pass
Change-Id: I331ffe054d942cc5dd58bff369fa890b130a45f4
This commit is contained in:
Wale Ogunwale
2019-10-10 14:45:03 +02:00
parent 1a06f15356
commit 3198da4283
14 changed files with 49 additions and 73 deletions

View File

@@ -1253,7 +1253,7 @@ final class ActivityRecord extends AppWindowToken {
boolean setOccludesParent(boolean occludesParent) {
final boolean changed = super.setOccludesParent(occludesParent);
if (changed) {
if (changed && task != null) {
if (!occludesParent) {
getActivityStack().convertActivityToTranslucent(this);
}
@@ -3542,7 +3542,7 @@ final class ActivityRecord extends AppWindowToken {
super.resolveOverrideConfiguration(newParentConfiguration);
// If the activity has override bounds, the relative configuration (e.g. screen size,
// layout) needs to be resolved according to the bounds.
if (!matchParentBounds()) {
if (task != null && !matchParentBounds()) {
task.computeConfigResourceOverrides(getResolvedOverrideConfiguration(),
newParentConfiguration);
}

View File

@@ -1420,7 +1420,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
mReparenting = true;
getParent().removeChild(this);
task.addChild(this, position);
task.addChild((ActivityRecord) this, position);
mReparenting = false;

View File

@@ -58,7 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
import java.io.PrintWriter;
import java.util.function.Consumer;
class Task extends WindowContainer<AppWindowToken> implements ConfigurationContainerListener{
class Task extends WindowContainer<ActivityRecord> implements ConfigurationContainerListener{
static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
// TODO: Track parent marks like this in WindowContainer.
@@ -170,14 +170,14 @@ class Task extends WindowContainer<AppWindowToken> implements ConfigurationConta
}
@Override
void addChild(AppWindowToken wtoken, int position) {
void addChild(ActivityRecord child, int position) {
position = getAdjustedAddPosition(position);
super.addChild(wtoken, position);
super.addChild(child, position);
mDeferRemoval = false;
}
@Override
void positionChildAt(int position, AppWindowToken child, boolean includingParents) {
void positionChildAt(int position, ActivityRecord child, boolean includingParents) {
position = getAdjustedAddPosition(position);
super.positionChildAt(position, child, includingParents);
mDeferRemoval = false;
@@ -279,13 +279,13 @@ class Task extends WindowContainer<AppWindowToken> implements ConfigurationConta
}
@Override
void removeChild(AppWindowToken token) {
if (!mChildren.contains(token)) {
void removeChild(ActivityRecord child) {
if (!mChildren.contains(child)) {
Slog.e(TAG, "removeChild: token=" + this + " not found.");
return;
}
super.removeChild(token);
super.removeChild(child);
if (mChildren.isEmpty()) {
EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
@@ -674,18 +674,18 @@ class Task extends WindowContainer<AppWindowToken> implements ConfigurationConta
return null;
}
void positionChildAtTop(AppWindowToken aToken) {
positionChildAt(aToken, POSITION_TOP);
void positionChildAtTop(ActivityRecord child) {
positionChildAt(child, POSITION_TOP);
}
void positionChildAt(AppWindowToken aToken, int position) {
if (aToken == null) {
void positionChildAt(ActivityRecord child, int position) {
if (child == null) {
Slog.w(TAG_WM,
"Attempted to position of non-existing app");
return;
}
positionChildAt(position, aToken, false /* includeParents */);
positionChildAt(position, child, false /* includeParents */);
}
void forceWindowsScaleable(boolean force) {

View File

@@ -215,23 +215,6 @@ class ActivityTestsBase extends SystemServiceTestsBase {
return this;
}
static Pair<Intent, ActivityInfo> createIntentAndActivityInfo() {
// TODO: Look into consolidating with dup. code in build() method below.
final int id = sCurrentActivityId++;
final ComponentName component = ComponentName.createRelative(
DEFAULT_COMPONENT_PACKAGE_NAME, DEFAULT_COMPONENT_CLASS_NAME + id);
final Intent intent = new Intent();
intent.setComponent(component);
final ActivityInfo aInfo = new ActivityInfo();
aInfo.applicationInfo = new ApplicationInfo();
aInfo.applicationInfo.packageName = component.getPackageName();
aInfo.applicationInfo.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
aInfo.packageName = component.getPackageName();
return new Pair<>(intent, aInfo);
}
ActivityRecord build() {
if (mComponent == null) {
final int id = sCurrentActivityId++;
@@ -249,6 +232,7 @@ class ActivityTestsBase extends SystemServiceTestsBase {
intent.setComponent(mComponent);
final ActivityInfo aInfo = new ActivityInfo();
aInfo.applicationInfo = new ApplicationInfo();
aInfo.applicationInfo.targetSdkVersion = Build.VERSION_CODES.CUR_DEVELOPMENT;
aInfo.applicationInfo.packageName = mComponent.getPackageName();
aInfo.applicationInfo.uid = mUid;
aInfo.packageName = mComponent.getPackageName();

View File

@@ -57,7 +57,7 @@ public class AppChangeTransitionTests extends WindowTestsBase {
private TaskStack mStack;
private Task mTask;
private AppWindowToken mToken;
private ActivityRecord mToken;
public void setUpOnDisplay(DisplayContent dc) {
mStack = createTaskStackOnDisplay(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, dc);

View File

@@ -101,10 +101,10 @@ public class AppTransitionControllerTest extends WindowTestsBase {
@Test
@FlakyTest(bugId = 131005232)
public void testTransitWithinTask() {
final AppWindowToken opening = createAppWindowToken(mDisplayContent,
final ActivityRecord opening = createAppWindowToken(mDisplayContent,
WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
opening.setOccludesParent(false);
final AppWindowToken closing = createAppWindowToken(mDisplayContent,
final ActivityRecord closing = createAppWindowToken(mDisplayContent,
WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
closing.setOccludesParent(false);
final Task task = opening.getTask();

View File

@@ -159,7 +159,7 @@ public class AppTransitionTests extends WindowTestsBase {
final TaskStack stack1 = createTaskStackOnDisplay(dc1);
final Task task1 = createTaskInStack(stack1, 0 /* userId */);
final AppWindowToken token1 =
final ActivityRecord token1 =
WindowTestUtils.createTestAppWindowToken(dc1);
task1.addChild(token1, 0);

View File

@@ -77,7 +77,7 @@ public class AppWindowTokenTests extends WindowTestsBase {
TaskStack mStack;
Task mTask;
AppWindowToken mToken;
ActivityRecord mToken;
private final String mPackageName = getInstrumentation().getTargetContext().getPackageName();
@@ -410,7 +410,7 @@ public class AppWindowTokenTests extends WindowTestsBase {
}
private AppWindowToken createTestAppWindowTokenForGivenTask(Task task) {
final AppWindowToken appToken =
final ActivityRecord appToken =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task.addChild(appToken, 0);
waitUntilHandlersIdle();

View File

@@ -241,7 +241,7 @@ public class DisplayContentTests extends WindowTestsBase {
assertEquals(dc, stack.getDisplayContent());
final Task task = createTaskInStack(stack, 0 /* userId */);
final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(dc);
final ActivityRecord token = WindowTestUtils.createTestAppWindowToken(dc);
task.addChild(token, 0);
assertEquals(dc, task.getDisplayContent());
assertEquals(dc, token.getDisplayContent());
@@ -313,7 +313,7 @@ public class DisplayContentTests extends WindowTestsBase {
// Add stack with activity.
final TaskStack stack0 = createTaskStackOnDisplay(dc0);
final Task task0 = createTaskInStack(stack0, 0 /* userId */);
final AppWindowToken token =
final ActivityRecord token =
WindowTestUtils.createTestAppWindowToken(dc0);
task0.addChild(token, 0);
dc0.configureDisplayPolicy();
@@ -321,7 +321,7 @@ public class DisplayContentTests extends WindowTestsBase {
final TaskStack stack1 = createTaskStackOnDisplay(dc1);
final Task task1 = createTaskInStack(stack1, 0 /* userId */);
final AppWindowToken token1 =
final ActivityRecord token1 =
WindowTestUtils.createTestAppWindowToken(dc0);
task1.addChild(token1, 0);
dc1.configureDisplayPolicy();
@@ -682,16 +682,15 @@ public class DisplayContentTests extends WindowTestsBase {
// is appWin & null on the other display.
mDisplayContent.setInputMethodWindowLocked(mImeWindow);
newDisplay.setInputMethodWindowLocked(null);
assertTrue("appWin should be IME target window",
appWin.equals(mDisplayContent.mInputMethodTarget));
assertEquals("appWin should be IME target window",
appWin, mDisplayContent.mInputMethodTarget);
assertNull("newDisplay Ime target: ", newDisplay.mInputMethodTarget);
// Switch input method window on new display & make sure the input method target also
// switched as expected.
newDisplay.setInputMethodWindowLocked(mImeWindow);
mDisplayContent.setInputMethodWindowLocked(null);
assertTrue("appWin1 should be IME target window",
appWin1.equals(newDisplay.mInputMethodTarget));
assertEquals("appWin1 should be IME target window", appWin1, newDisplay.mInputMethodTarget);
assertNull("default display Ime target: ", mDisplayContent.mInputMethodTarget);
}

View File

@@ -96,7 +96,7 @@ public class DragDropControllerTests extends WindowTestsBase {
* Creates a window state which can be used as a drop target.
*/
private WindowState createDropTargetWindow(String name, int ownerId) {
final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(
final ActivityRecord token = WindowTestUtils.createTestAppWindowToken(
mDisplayContent);
final TaskStack stack = createTaskStackOnDisplay(
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, mDisplayContent);

View File

@@ -54,7 +54,7 @@ public class TaskStackContainersTests extends WindowTestsBase {
// Stack should contain visible app window to be considered visible.
final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
assertFalse(mPinnedStack.isVisible());
final AppWindowToken pinnedApp =
final ActivityRecord pinnedApp =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
pinnedTask.addChild(pinnedApp, 0 /* addPos */);
assertTrue(mPinnedStack.isVisible());

View File

@@ -68,13 +68,13 @@ public class TaskStackTests extends WindowTestsBase {
public void testClosingAppDifferentStackOrientation() {
final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
final Task task1 = createTaskInStack(stack, 0 /* userId */);
AppWindowToken appWindowToken1 =
ActivityRecord appWindowToken1 =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task1.addChild(appWindowToken1, 0);
appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
final Task task2 = createTaskInStack(stack, 1 /* userId */);
AppWindowToken appWindowToken2 =
ActivityRecord appWindowToken2 =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task2.addChild(appWindowToken2, 0);
appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
@@ -88,13 +88,13 @@ public class TaskStackTests extends WindowTestsBase {
public void testMoveTaskToBackDifferentStackOrientation() {
final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
final Task task1 = createTaskInStack(stack, 0 /* userId */);
AppWindowToken appWindowToken1 =
ActivityRecord appWindowToken1 =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task1.addChild(appWindowToken1, 0);
appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
final Task task2 = createTaskInStack(stack, 1 /* userId */);
AppWindowToken appWindowToken2 =
ActivityRecord appWindowToken2 =
WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task2.addChild(appWindowToken2, 0);
appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);

View File

@@ -19,17 +19,11 @@ package com.android.server.wm;
import static android.app.AppOpsManager.OP_NONE;
import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.wm.ActivityTestsBase.ActivityBuilder.createIntentAndActivityInfo;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import android.app.ActivityManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.IBinder;
import android.util.Pair;
import android.view.IWindow;
import android.view.WindowManager;
@@ -51,23 +45,22 @@ class WindowTestUtils {
}
/** Creates an {@link AppWindowToken} and adds it to the specified {@link Task}. */
static AppWindowToken createAppWindowTokenInTask(DisplayContent dc, Task task) {
final AppWindowToken newToken = createTestAppWindowToken(dc);
static ActivityRecord createAppWindowTokenInTask(DisplayContent dc, Task task) {
final ActivityRecord newToken = createTestAppWindowToken(dc);
task.addChild(newToken, POSITION_TOP);
return newToken;
}
static AppWindowToken createTestAppWindowToken(DisplayContent dc) {
static ActivityRecord createTestAppWindowToken(DisplayContent dc) {
synchronized (dc.mWmService.mGlobalLock) {
Pair<Intent, ActivityInfo> pair = createIntentAndActivityInfo();
final AppWindowToken token = new AppWindowToken(dc.mWmService,
dc.mWmService.mAtmService, new ActivityRecord.Token(pair.first), pair.second,
null, pair.first, dc);
token.setOccludesParent(true);
token.setHidden(false);
token.hiddenRequested = false;
spyOn(token);
return token;
final ActivityRecord r =
new ActivityTestsBase.ActivityBuilder(dc.mWmService.mAtmService)
.build();
r.onDisplayChanged(dc);
r.setOccludesParent(true);
r.setHidden(false);
r.hiddenRequested = false;
return r;
}
}

View File

@@ -204,15 +204,15 @@ class WindowTestsBase extends SystemServiceTestsBase {
}
}
AppWindowToken createAppWindowToken(DisplayContent dc, int windowingMode, int activityType) {
ActivityRecord createAppWindowToken(DisplayContent dc, int windowingMode, int activityType) {
return createTestAppWindowToken(dc, windowingMode, activityType);
}
AppWindowToken createTestAppWindowToken(DisplayContent dc, int
ActivityRecord createTestAppWindowToken(DisplayContent dc, int
windowingMode, int activityType) {
final TaskStack stack = createTaskStackOnDisplay(windowingMode, activityType, dc);
final Task task = createTaskInStack(stack, 0 /* userId */);
final AppWindowToken appWindowToken =
final ActivityRecord appWindowToken =
WindowTestUtils.createTestAppWindowToken(dc);
task.addChild(appWindowToken, 0);
return appWindowToken;
@@ -244,7 +244,7 @@ class WindowTestsBase extends SystemServiceTestsBase {
WindowState createAppWindow(Task task, int type, String name) {
synchronized (mWm.mGlobalLock) {
final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent);
final ActivityRecord token = WindowTestUtils.createTestAppWindowToken(mDisplayContent);
task.addChild(token, 0);
return createWindow(null, type, token, name);
}