/** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
public static Task createTaskInStack(WindowManagerService service, TaskStack stack,
int userId) {
- final Task newTask = new Task(sNextTaskId++, stack, userId, service, 0, false,
- new ActivityManager.TaskDescription(), null);
- stack.addTask(newTask, POSITION_TOP);
- return newTask;
+ synchronized (service.mWindowMap) {
+ final Task newTask = new Task(sNextTaskId++, stack, userId, service, 0, false,
+ new ActivityManager.TaskDescription(), null);
+ stack.addTask(newTask, POSITION_TOP);
+ return newTask;
+ }
}
/**
}
}
+ static TestAppWindowToken createTestAppWindowToken(DisplayContent dc) {
+ synchronized (dc.mService.mWindowMap) {
+ return new TestAppWindowToken(dc);
+ }
+ }
+
/** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */
public static class TestAppWindowToken extends AppWindowToken {
boolean mOnTop = false;
- TestAppWindowToken(DisplayContent dc) {
+ private TestAppWindowToken(DisplayContent dc) {
super(dc.mService, new IApplicationToken.Stub() {
public String getName() {return null;}
}, false, dc, true /* fillsParent */);
}
}
- /* Used so we can gain access to some protected members of the {@link WindowToken} class */
- public static class TestWindowToken extends WindowToken {
+ static TestWindowToken createTestWindowToken(int type, DisplayContent dc) {
+ return createTestWindowToken(type, dc, false /* persistOnEmpty */);
+ }
- TestWindowToken(int type, DisplayContent dc) {
- this(type, dc, false /* persistOnEmpty */);
+ static TestWindowToken createTestWindowToken(int type, DisplayContent dc,
+ boolean persistOnEmpty) {
+ synchronized (dc.mService.mWindowMap) {
+ return new TestWindowToken(type, dc, persistOnEmpty);
}
+ }
+
+ /* Used so we can gain access to some protected members of the {@link WindowToken} class */
+ public static class TestWindowToken extends WindowToken {
- TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
+ private TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) {
super(dc.mService, mock(IBinder.class), type, persistOnEmpty, dc,
false /* ownerCanManageAppTokens */);
}
/**
* Common base class for window manager unit test classes.
+ *
+ * Make sure any requests to WM hold the WM lock if needed b/73966377
*/
class WindowTestsBase {
private static final String TAG = WindowTestsBase.class.getSimpleName();
// Set-up some common windows.
mCommonWindows = new HashSet();
- mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
- mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
- sWm.mInputMethodWindow = mImeWindow;
- mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG,
- "mImeDialogWindow");
- mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow");
- mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow");
- mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER,
- "mDockedDividerWindow");
- mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow");
- mChildAppWindowAbove = createCommonWindow(mAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG,
- "mChildAppWindowAbove");
- mChildAppWindowBelow = createCommonWindow(mAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY,
- "mChildAppWindowBelow");
-
+ synchronized (sWm.mWindowMap) {
+ mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow");
+ mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow");
+ sWm.mInputMethodWindow = mImeWindow;
+ mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG,
+ "mImeDialogWindow");
+ mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow");
+ mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow");
+ mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER,
+ "mDockedDividerWindow");
+ mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow");
+ mChildAppWindowAbove = createCommonWindow(mAppWindow,
+ TYPE_APPLICATION_ATTACHED_DIALOG,
+ "mChildAppWindowAbove");
+ mChildAppWindowBelow = createCommonWindow(mAppWindow,
+ TYPE_APPLICATION_MEDIA_OVERLAY,
+ "mChildAppWindowBelow");
+ }
// Adding a display will cause freezing the display. Make sure to wait until it's
// unfrozen to not run into race conditions with the tests.
waitUntilHandlersIdle();
}
private WindowState createCommonWindow(WindowState parent, int type, String name) {
- final WindowState win = createWindow(parent, type, name);
- mCommonWindows.add(win);
- // Prevent common windows from been IMe targets
- win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
- return win;
+ synchronized (sWm.mWindowMap) {
+ final WindowState win = createWindow(parent, type, name);
+ mCommonWindows.add(win);
+ // Prevent common windows from been IMe targets
+ win.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
+ return win;
+ }
}
/** Asserts that the first entry is greater than the second entry. */
private WindowToken createWindowToken(
DisplayContent dc, int windowingMode, int activityType, int type) {
- if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
- return new WindowTestUtils.TestWindowToken(type, dc);
- }
+ synchronized (sWm.mWindowMap) {
+ if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) {
+ return WindowTestUtils.createTestWindowToken(type, dc);
+ }
- return createAppWindowToken(dc, windowingMode, activityType);
+ return createAppWindowToken(dc, windowingMode, activityType);
+ }
}
AppWindowToken createAppWindowToken(DisplayContent dc, int windowingMode, int activityType) {
dc).mContainer;
final Task task = createTaskInStack(stack, 0 /* userId */);
final WindowTestUtils.TestAppWindowToken appWindowToken =
- new WindowTestUtils.TestAppWindowToken(mDisplayContent);
+ WindowTestUtils.createTestAppWindowToken(dc);
task.addChild(appWindowToken, 0);
return appWindowToken;
}
WindowState createWindow(WindowState parent, int type, String name) {
- return (parent == null)
- ? createWindow(parent, type, mDisplayContent, name)
- : createWindow(parent, type, parent.mToken, name);
+ synchronized (sWm.mWindowMap) {
+ return (parent == null)
+ ? createWindow(parent, type, mDisplayContent, name)
+ : createWindow(parent, type, parent.mToken, name);
+ }
}
WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType,
int type, DisplayContent dc, String name) {
- final WindowToken token = createWindowToken(dc, windowingMode, activityType, type);
- return createWindow(parent, type, token, name);
+ synchronized (sWm.mWindowMap) {
+ final WindowToken token = createWindowToken(dc, windowingMode, activityType, type);
+ return createWindow(parent, type, token, name);
+ }
}
WindowState createAppWindow(Task task, int type, String name) {
- final AppWindowToken token = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
- task.addChild(token, 0);
- return createWindow(null, type, token, name);
+ synchronized (sWm.mWindowMap) {
+ final AppWindowToken token = WindowTestUtils.createTestAppWindowToken(mDisplayContent);
+ task.addChild(token, 0);
+ return createWindow(null, type, token, name);
+ }
}
WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) {
- final WindowToken token = createWindowToken(
- dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
- return createWindow(parent, type, token, name);
+ synchronized (sWm.mWindowMap) {
+ final WindowToken token = createWindowToken(
+ dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
+ return createWindow(parent, type, token, name);
+ }
}
WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name,
boolean ownerCanAddInternalSystemWindow) {
- final WindowToken token = createWindowToken(
- dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
- return createWindow(parent, type, token, name, 0 /* ownerId */,
- ownerCanAddInternalSystemWindow);
+ synchronized (sWm.mWindowMap) {
+ final WindowToken token = createWindowToken(
+ dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type);
+ return createWindow(parent, type, token, name, 0 /* ownerId */,
+ ownerCanAddInternalSystemWindow);
+ }
}
static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) {
- return createWindow(parent, type, token, name, 0 /* ownerId */,
- false /* ownerCanAddInternalSystemWindow */);
+ synchronized (sWm.mWindowMap) {
+ return createWindow(parent, type, token, name, 0 /* ownerId */,
+ false /* ownerCanAddInternalSystemWindow */);
+ }
}
static WindowState createWindow(WindowState parent, int type, WindowToken token, String name,
int ownerId, boolean ownerCanAddInternalSystemWindow) {
- final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
- attrs.setTitle(name);
-
- final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE,
- 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow, mPowerManagerWrapper);
- // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
- // adding it to the token...
- token.addWindow(w);
- return w;
+ synchronized (sWm.mWindowMap) {
+ final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
+ attrs.setTitle(name);
+
+ final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent,
+ OP_NONE,
+ 0, attrs, VISIBLE, ownerId, ownerCanAddInternalSystemWindow,
+ mPowerManagerWrapper);
+ // TODO: Probably better to make this call in the WindowState ctor to avoid errors with
+ // adding it to the token...
+ token.addWindow(w);
+ return w;
+ }
}
/** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */
TaskStack createTaskStackOnDisplay(DisplayContent dc) {
- return createStackControllerOnDisplay(dc).mContainer;
+ synchronized (sWm.mWindowMap) {
+ return createStackControllerOnDisplay(dc).mContainer;
+ }
}
StackWindowController createStackControllerOnDisplay(DisplayContent dc) {
- return createStackControllerOnStackOnDisplay(
- WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc);
+ synchronized (sWm.mWindowMap) {
+ return createStackControllerOnStackOnDisplay(
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc);
+ }
}
StackWindowController createStackControllerOnStackOnDisplay(
int windowingMode, int activityType, DisplayContent dc) {
- final Configuration overrideConfig = new Configuration();
- overrideConfig.windowConfiguration.setWindowingMode(windowingMode);
- overrideConfig.windowConfiguration.setActivityType(activityType);
- final int stackId = ++sNextStackId;
- final StackWindowController controller = new StackWindowController(stackId, null,
- dc.getDisplayId(), true /* onTop */, new Rect(), sWm);
- controller.onOverrideConfigurationChanged(overrideConfig);
- return controller;
+ synchronized (sWm.mWindowMap) {
+ final Configuration overrideConfig = new Configuration();
+ overrideConfig.windowConfiguration.setWindowingMode(windowingMode);
+ overrideConfig.windowConfiguration.setActivityType(activityType);
+ final int stackId = ++sNextStackId;
+ final StackWindowController controller = new StackWindowController(stackId, null,
+ dc.getDisplayId(), true /* onTop */, new Rect(), sWm);
+ controller.onOverrideConfigurationChanged(overrideConfig);
+ return controller;
+ }
}
/** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */
final int displayId = sNextDisplayId++;
final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId,
mDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS);
- return new DisplayContent(display, sWm, mWallpaperController,
- mock(DisplayWindowController.class));
+ synchronized (sWm.mWindowMap) {
+ return new DisplayContent(display, sWm, mWallpaperController,
+ mock(DisplayWindowController.class));
+ }
}
/** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */
WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs,
WindowToken token) {
- return new WindowTestUtils.TestWindowState(sWm, sMockSession, sIWindow, attrs, token);
+ synchronized (sWm.mWindowMap) {
+ return new WindowTestUtils.TestWindowState(sWm, sMockSession, sIWindow, attrs, token);
+ }
}
}