Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 19 | import static android.app.AppOpsManager.OP_NONE; |
| 20 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 21 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 23 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 24 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
| 25 | import static com.android.server.wm.ActivityTestsBase.ActivityBuilder.createIntentAndActivityInfo; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 26 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 27 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 29 | import android.content.Intent; |
| 30 | import android.content.pm.ActivityInfo; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 31 | import android.os.IBinder; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 32 | import android.util.Pair; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 33 | import android.view.IWindow; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 34 | import android.view.WindowManager; |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 35 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 36 | /** |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 37 | * A collection of static functions that provide access to WindowManager related test functionality. |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 38 | */ |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 39 | class WindowTestUtils { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 40 | private static int sNextTaskId = 0; |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 41 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 42 | /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 43 | static Task createTaskInStack(WindowManagerService service, TaskStack stack, |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 44 | int userId) { |
| 45 | synchronized (service.mGlobalLock) { |
| 46 | final Task newTask = new Task(sNextTaskId++, stack, userId, service, 0, false, |
| 47 | new ActivityManager.TaskDescription(), null); |
| 48 | stack.addTask(newTask, POSITION_TOP); |
| 49 | return newTask; |
| 50 | } |
| 51 | } |
| 52 | |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 53 | /** Creates an {@link AppWindowToken} and adds it to the specified {@link Task}. */ |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 54 | static AppWindowToken createAppWindowTokenInTask(DisplayContent dc, Task task) { |
| 55 | final AppWindowToken newToken = createTestAppWindowToken(dc); |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 56 | task.addChild(newToken, POSITION_TOP); |
| 57 | return newToken; |
| 58 | } |
| 59 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 60 | static AppWindowToken createTestAppWindowToken(DisplayContent dc) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 61 | synchronized (dc.mWmService.mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame^] | 62 | Pair<Intent, ActivityInfo> pair = createIntentAndActivityInfo(); |
| 63 | final AppWindowToken token = new AppWindowToken(dc.mWmService, |
| 64 | dc.mWmService.mAtmService, new ActivityRecord.Token(pair.first), pair.second, |
| 65 | null, pair.first, dc); |
| 66 | token.setOccludesParent(true); |
| 67 | token.setHidden(false); |
| 68 | token.hiddenRequested = false; |
| 69 | spyOn(token); |
| 70 | return token; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 74 | static TestWindowToken createTestWindowToken(int type, DisplayContent dc) { |
| 75 | return createTestWindowToken(type, dc, false /* persistOnEmpty */); |
| 76 | } |
| 77 | |
| 78 | static TestWindowToken createTestWindowToken(int type, DisplayContent dc, |
| 79 | boolean persistOnEmpty) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 80 | synchronized (dc.mWmService.mGlobalLock) { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 81 | return new TestWindowToken(type, dc, persistOnEmpty); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /* Used so we can gain access to some protected members of the {@link WindowToken} class */ |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 86 | static class TestWindowToken extends WindowToken { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 87 | |
| 88 | private TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 89 | super(dc.mWmService, mock(IBinder.class), type, persistOnEmpty, dc, |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 90 | false /* ownerCanManageAppTokens */); |
| 91 | } |
| 92 | |
| 93 | int getWindowsCount() { |
| 94 | return mChildren.size(); |
| 95 | } |
| 96 | |
| 97 | boolean hasWindow(WindowState w) { |
| 98 | return mChildren.contains(w); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* Used so we can gain access to some protected members of the {@link Task} class */ |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 103 | static class TestTask extends Task { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 104 | boolean mShouldDeferRemoval = false; |
| 105 | boolean mOnDisplayChangedCalled = false; |
| 106 | private boolean mIsAnimating = false; |
| 107 | |
| 108 | TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, |
| 109 | int resizeMode, boolean supportsPictureInPicture, |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 110 | TaskRecord taskRecord) { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 111 | super(taskId, stack, userId, service, resizeMode, supportsPictureInPicture, |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 112 | new ActivityManager.TaskDescription(), taskRecord); |
| 113 | stack.addTask(this, POSITION_TOP); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | boolean shouldDeferRemoval() { |
| 117 | return mShouldDeferRemoval; |
| 118 | } |
| 119 | |
| 120 | int positionInParent() { |
| 121 | return getParent().mChildren.indexOf(this); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | void onDisplayChanged(DisplayContent dc) { |
| 126 | super.onDisplayChanged(dc); |
| 127 | mOnDisplayChangedCalled = true; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | boolean isSelfAnimating() { |
| 132 | return mIsAnimating; |
| 133 | } |
| 134 | |
| 135 | void setLocalIsAnimating(boolean isAnimating) { |
| 136 | mIsAnimating = isAnimating; |
| 137 | } |
| 138 | } |
| 139 | |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 140 | static TestTask createTestTask(TaskStack stack) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 141 | return new TestTask(sNextTaskId++, stack, 0, stack.mWmService, RESIZE_MODE_UNRESIZEABLE, |
| 142 | false, mock(TaskRecord.class)); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 143 | } |
| 144 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 145 | /** Used to track resize reports. */ |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 146 | static class TestWindowState extends WindowState { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 147 | boolean mResizeReported; |
| 148 | |
| 149 | TestWindowState(WindowManagerService service, Session session, IWindow window, |
| 150 | WindowManager.LayoutParams attrs, WindowToken token) { |
| 151 | super(service, session, window, token, null, OP_NONE, 0, attrs, 0, 0, |
| 152 | false /* ownerCanAddInternalSystemWindow */); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | void reportResized() { |
| 157 | super.reportResized(); |
| 158 | mResizeReported = true; |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public boolean isGoneForLayoutLw() { |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | void updateResizingWindowIfNeeded() { |
| 168 | // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive |
| 169 | // the system that it can actually update the window. |
| 170 | boolean hadSurface = mHasSurface; |
| 171 | mHasSurface = true; |
| 172 | |
| 173 | super.updateResizingWindowIfNeeded(); |
| 174 | |
| 175 | mHasSurface = hadSurface; |
| 176 | } |
| 177 | } |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 178 | } |