Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.RESIZE_MODE_USER; |
| 20 | import static android.app.ActivityTaskManager.RESIZE_MODE_USER_FORCED; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 21 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Garfield Tan | 07544cd | 2018-09-12 16:16:54 -0700 | [diff] [blame] | 22 | |
| 23 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 26 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 29 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_HEIGHT_IN_DP; |
| 30 | import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_WIDTH_IN_DP; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 31 | |
| 32 | import android.annotation.IntDef; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 33 | import android.app.IActivityTaskManager; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 34 | import android.graphics.Point; |
| 35 | import android.graphics.Rect; |
Robert Carr | 0bcbe64 | 2018-10-11 19:07:43 -0700 | [diff] [blame] | 36 | import android.os.Binder; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 37 | import android.os.Looper; |
| 38 | import android.os.Process; |
| 39 | import android.os.RemoteException; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 40 | import android.os.Trace; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 41 | import android.util.DisplayMetrics; |
| 42 | import android.util.Slog; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 43 | import android.view.BatchedInputEventReceiver; |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 44 | import android.view.Choreographer; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 45 | import android.view.Display; |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 46 | import android.view.InputApplicationHandle; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 47 | import android.view.InputChannel; |
| 48 | import android.view.InputDevice; |
| 49 | import android.view.InputEvent; |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 50 | import android.view.InputWindowHandle; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 51 | import android.view.MotionEvent; |
| 52 | import android.view.WindowManager; |
| 53 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 54 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 55 | |
| 56 | import java.lang.annotation.Retention; |
| 57 | import java.lang.annotation.RetentionPolicy; |
| 58 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 59 | class TaskPositioner { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 60 | private static final boolean DEBUG_ORIENTATION_VIOLATIONS = false; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 61 | private static final String TAG_LOCAL = "TaskPositioner"; |
| 62 | private static final String TAG = TAG_WITH_CLASS_NAME ? TAG_LOCAL : TAG_WM; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 63 | |
Garfield Tan | 6caf1d8c | 2018-01-18 12:37:50 -0800 | [diff] [blame] | 64 | private static Factory sFactory; |
| 65 | |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 66 | // The margin the pointer position has to be within the side of the screen to be |
| 67 | // considered at the side of the screen. |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 68 | static final int SIDE_MARGIN_DIP = 100; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 69 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 70 | @IntDef(flag = true, |
| 71 | value = { |
| 72 | CTRL_NONE, |
| 73 | CTRL_LEFT, |
| 74 | CTRL_RIGHT, |
| 75 | CTRL_TOP, |
| 76 | CTRL_BOTTOM |
| 77 | }) |
| 78 | @Retention(RetentionPolicy.SOURCE) |
| 79 | @interface CtrlType {} |
| 80 | |
| 81 | private static final int CTRL_NONE = 0x0; |
| 82 | private static final int CTRL_LEFT = 0x1; |
| 83 | private static final int CTRL_RIGHT = 0x2; |
| 84 | private static final int CTRL_TOP = 0x4; |
| 85 | private static final int CTRL_BOTTOM = 0x8; |
| 86 | |
Filip Gruszczynski | 64b6b44 | 2016-01-18 13:20:58 -0800 | [diff] [blame] | 87 | public static final float RESIZING_HINT_ALPHA = 0.5f; |
| 88 | |
| 89 | public static final int RESIZING_HINT_DURATION_MS = 0; |
| 90 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 91 | // The minimal aspect ratio which needs to be met to count as landscape (or 1/.. for portrait). |
| 92 | // Note: We do not use the 1.33 from the CDD here since the user is allowed to use what ever |
| 93 | // aspect he desires. |
| 94 | @VisibleForTesting |
| 95 | static final float MIN_ASPECT = 1.2f; |
| 96 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 97 | private final WindowManagerService mService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 98 | private final IActivityTaskManager mActivityManager; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 99 | private WindowPositionerEventReceiver mInputEventReceiver; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 100 | private DisplayContent mDisplayContent; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 101 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 102 | private Rect mTmpRect = new Rect(); |
| 103 | private int mSideMargin; |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 104 | private int mMinVisibleWidth; |
| 105 | private int mMinVisibleHeight; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 106 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 107 | private Task mTask; |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 108 | private boolean mResizing; |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 109 | private boolean mPreserveOrientation; |
| 110 | private boolean mStartOrientationWasLandscape; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 111 | private final Rect mWindowOriginalBounds = new Rect(); |
| 112 | private final Rect mWindowDragBounds = new Rect(); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 113 | private final Point mMaxVisibleSize = new Point(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 114 | private float mStartDragX; |
| 115 | private float mStartDragY; |
| 116 | @CtrlType |
| 117 | private int mCtrlType = CTRL_NONE; |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 118 | private boolean mDragEnded = false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 119 | |
| 120 | InputChannel mServerChannel; |
| 121 | InputChannel mClientChannel; |
| 122 | InputApplicationHandle mDragApplicationHandle; |
| 123 | InputWindowHandle mDragWindowHandle; |
| 124 | |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 125 | private final class WindowPositionerEventReceiver extends BatchedInputEventReceiver { |
| 126 | public WindowPositionerEventReceiver( |
| 127 | InputChannel inputChannel, Looper looper, Choreographer choreographer) { |
| 128 | super(inputChannel, looper, choreographer); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | @Override |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 132 | public void onInputEvent(InputEvent event) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 133 | if (!(event instanceof MotionEvent) |
| 134 | || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 135 | return; |
| 136 | } |
| 137 | final MotionEvent motionEvent = (MotionEvent) event; |
| 138 | boolean handled = false; |
| 139 | |
| 140 | try { |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 141 | if (mDragEnded) { |
| 142 | // The drag has ended but the clean-up message has not been processed by |
| 143 | // window manager. Drop events that occur after this until window manager |
| 144 | // has a chance to clean-up the input handle. |
| 145 | handled = true; |
| 146 | return; |
| 147 | } |
| 148 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 149 | final float newX = motionEvent.getRawX(); |
| 150 | final float newY = motionEvent.getRawY(); |
| 151 | |
| 152 | switch (motionEvent.getAction()) { |
| 153 | case MotionEvent.ACTION_DOWN: { |
| 154 | if (DEBUG_TASK_POSITIONING) { |
| 155 | Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}"); |
| 156 | } |
| 157 | } break; |
| 158 | |
| 159 | case MotionEvent.ACTION_MOVE: { |
| 160 | if (DEBUG_TASK_POSITIONING){ |
| 161 | Slog.w(TAG, "ACTION_MOVE @ {" + newX + ", " + newY + "}"); |
| 162 | } |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 163 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 164 | mDragEnded = notifyMoveLocked(newX, newY); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 165 | mTask.getDimBounds(mTmpRect); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 166 | } |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 167 | if (!mTmpRect.equals(mWindowDragBounds)) { |
| 168 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, |
| 169 | "wm.TaskPositioner.resizeTask"); |
| 170 | try { |
Daichi Hirono | 67f2f4b | 2018-05-25 16:07:30 +0900 | [diff] [blame] | 171 | mActivityManager.resizeTask( |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 172 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER); |
| 173 | } catch (RemoteException e) { |
| 174 | } |
| 175 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 176 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 177 | } break; |
| 178 | |
| 179 | case MotionEvent.ACTION_UP: { |
| 180 | if (DEBUG_TASK_POSITIONING) { |
| 181 | Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}"); |
| 182 | } |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 183 | mDragEnded = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 184 | } break; |
| 185 | |
| 186 | case MotionEvent.ACTION_CANCEL: { |
| 187 | if (DEBUG_TASK_POSITIONING) { |
| 188 | Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}"); |
| 189 | } |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 190 | mDragEnded = true; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 191 | } break; |
| 192 | } |
| 193 | |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 194 | if (mDragEnded) { |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 195 | final boolean wasResizing = mResizing; |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 196 | synchronized (mService.mGlobalLock) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 197 | endDragLocked(); |
Vladislav Kaznacheev | 824bc5d | 2016-04-22 17:48:35 -0700 | [diff] [blame] | 198 | mTask.getDimBounds(mTmpRect); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 199 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 200 | try { |
Vladislav Kaznacheev | 824bc5d | 2016-04-22 17:48:35 -0700 | [diff] [blame] | 201 | if (wasResizing && !mTmpRect.equals(mWindowDragBounds)) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 202 | // We were using fullscreen surface during resizing. Request |
| 203 | // resizeTask() one last time to restore surface to window size. |
Daichi Hirono | 67f2f4b | 2018-05-25 16:07:30 +0900 | [diff] [blame] | 204 | mActivityManager.resizeTask( |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 205 | mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER_FORCED); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 206 | } |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 207 | } catch(RemoteException e) {} |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 208 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 209 | // Post back to WM to handle clean-ups. We still need the input |
| 210 | // event handler for the last finishInputEvent()! |
Daichi Hirono | ce2f97a | 2017-11-30 16:44:15 +0900 | [diff] [blame] | 211 | mService.mTaskPositioningController.finishTaskPositioning(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 212 | } |
| 213 | handled = true; |
| 214 | } catch (Exception e) { |
| 215 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 216 | } finally { |
| 217 | finishInputEvent(event, handled); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
Daichi Hirono | 67f2f4b | 2018-05-25 16:07:30 +0900 | [diff] [blame] | 222 | @VisibleForTesting |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 223 | TaskPositioner(WindowManagerService service, IActivityTaskManager activityManager) { |
Daichi Hirono | 67f2f4b | 2018-05-25 16:07:30 +0900 | [diff] [blame] | 224 | mService = service; |
| 225 | mActivityManager = activityManager; |
| 226 | } |
| 227 | |
Garfield Tan | 6caf1d8c | 2018-01-18 12:37:50 -0800 | [diff] [blame] | 228 | /** Use {@link #create(WindowManagerService)} instead **/ |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 229 | TaskPositioner(WindowManagerService service) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 230 | this(service, service.mActivityTaskManager); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 231 | } |
| 232 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 233 | @VisibleForTesting |
| 234 | Rect getWindowDragBounds() { |
| 235 | return mWindowDragBounds; |
| 236 | } |
| 237 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 238 | /** |
Garfield Tan | 07544cd | 2018-09-12 16:16:54 -0700 | [diff] [blame] | 239 | * @param displayContent The Display that the window being dragged is on. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 240 | */ |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 241 | void register(DisplayContent displayContent) { |
| 242 | final Display display = displayContent.getDisplay(); |
| 243 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 244 | if (DEBUG_TASK_POSITIONING) { |
| 245 | Slog.d(TAG, "Registering task positioner"); |
| 246 | } |
| 247 | |
| 248 | if (mClientChannel != null) { |
| 249 | Slog.e(TAG, "Task positioner already registered"); |
| 250 | return; |
| 251 | } |
| 252 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 253 | mDisplayContent = displayContent; |
| 254 | display.getMetrics(mDisplayMetrics); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 255 | final InputChannel[] channels = InputChannel.openInputChannelPair(TAG); |
| 256 | mServerChannel = channels[0]; |
| 257 | mClientChannel = channels[1]; |
| 258 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
| 259 | |
Wale Ogunwale | 4f52bc6 | 2015-09-24 13:47:31 -0700 | [diff] [blame] | 260 | mInputEventReceiver = new WindowPositionerEventReceiver( |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 261 | mClientChannel, mService.mAnimationHandler.getLooper(), |
| 262 | mService.mAnimator.getChoreographer()); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 263 | |
Robert Carr | 0bcbe64 | 2018-10-11 19:07:43 -0700 | [diff] [blame] | 264 | mDragApplicationHandle = new InputApplicationHandle(new Binder()); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 265 | mDragApplicationHandle.name = TAG; |
| 266 | mDragApplicationHandle.dispatchingTimeoutNanos = |
| 267 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 268 | |
Robert Carr | e0a353c | 2018-08-02 16:38:04 -0700 | [diff] [blame] | 269 | mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 270 | display.getDisplayId()); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 271 | mDragWindowHandle.name = TAG; |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 272 | mDragWindowHandle.token = mServerChannel.getToken(); |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 273 | mDragWindowHandle.layer = mService.getDragLayerLocked(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 274 | mDragWindowHandle.layoutParamsFlags = 0; |
| 275 | mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 276 | mDragWindowHandle.dispatchingTimeoutNanos = |
| 277 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 278 | mDragWindowHandle.visible = true; |
| 279 | mDragWindowHandle.canReceiveKeys = false; |
| 280 | mDragWindowHandle.hasFocus = true; |
| 281 | mDragWindowHandle.hasWallpaper = false; |
| 282 | mDragWindowHandle.paused = false; |
| 283 | mDragWindowHandle.ownerPid = Process.myPid(); |
| 284 | mDragWindowHandle.ownerUid = Process.myUid(); |
| 285 | mDragWindowHandle.inputFeatures = 0; |
| 286 | mDragWindowHandle.scaleFactor = 1.0f; |
| 287 | |
| 288 | // The drag window cannot receive new touches. |
| 289 | mDragWindowHandle.touchableRegion.setEmpty(); |
| 290 | |
| 291 | // The drag window covers the entire display |
| 292 | mDragWindowHandle.frameLeft = 0; |
| 293 | mDragWindowHandle.frameTop = 0; |
| 294 | final Point p = new Point(); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 295 | display.getRealSize(p); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 296 | mDragWindowHandle.frameRight = p.x; |
| 297 | mDragWindowHandle.frameBottom = p.y; |
| 298 | |
| 299 | // Pause rotations before a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 300 | if (DEBUG_ORIENTATION) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 301 | Slog.d(TAG, "Pausing rotation during re-position"); |
| 302 | } |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 303 | mDisplayContent.pauseRotationLocked(); |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 304 | |
Garfield Tan | 07544cd | 2018-09-12 16:16:54 -0700 | [diff] [blame] | 305 | // Notify InputMonitor to take mDragWindowHandle. |
| 306 | mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/); |
| 307 | |
Filip Gruszczynski | 57b6cce | 2015-10-06 09:50:51 -0700 | [diff] [blame] | 308 | mSideMargin = dipToPixel(SIDE_MARGIN_DIP, mDisplayMetrics); |
| 309 | mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, mDisplayMetrics); |
| 310 | mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, mDisplayMetrics); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 311 | display.getRealSize(mMaxVisibleSize); |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 312 | |
| 313 | mDragEnded = false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void unregister() { |
| 317 | if (DEBUG_TASK_POSITIONING) { |
| 318 | Slog.d(TAG, "Unregistering task positioner"); |
| 319 | } |
| 320 | |
| 321 | if (mClientChannel == null) { |
| 322 | Slog.e(TAG, "Task positioner not registered"); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
| 327 | |
| 328 | mInputEventReceiver.dispose(); |
| 329 | mInputEventReceiver = null; |
| 330 | mClientChannel.dispose(); |
| 331 | mServerChannel.dispose(); |
| 332 | mClientChannel = null; |
| 333 | mServerChannel = null; |
| 334 | |
| 335 | mDragWindowHandle = null; |
| 336 | mDragApplicationHandle = null; |
Wale Ogunwale | 6a804b8 | 2015-09-23 21:04:21 -0700 | [diff] [blame] | 337 | mDragEnded = true; |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 338 | |
Garfield Tan | 07544cd | 2018-09-12 16:16:54 -0700 | [diff] [blame] | 339 | // Notify InputMonitor to remove mDragWindowHandle. |
| 340 | mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/); |
| 341 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 342 | // Resume rotations after a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 343 | if (DEBUG_ORIENTATION) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 344 | Slog.d(TAG, "Resuming rotation after re-position"); |
| 345 | } |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 346 | mDisplayContent.resumeRotationLocked(); |
| 347 | mDisplayContent = null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 348 | } |
| 349 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 350 | void startDrag(WindowState win, boolean resize, boolean preserveOrientation, float startX, |
| 351 | float startY) { |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 352 | if (DEBUG_TASK_POSITIONING) { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 353 | Slog.d(TAG, "startDrag: win=" + win + ", resize=" + resize |
| 354 | + ", preserveOrientation=" + preserveOrientation + ", {" + startX + ", " |
| 355 | + startY + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 356 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 357 | mTask = win.getTask(); |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 358 | // Use the bounds of the task which accounts for |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 359 | // multiple app windows. Don't use any bounds from win itself as it |
| 360 | // may not be the same size as the task. |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 361 | mTask.getBounds(mTmpRect); |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 362 | startDrag(resize, preserveOrientation, startX, startY, mTmpRect); |
| 363 | } |
| 364 | |
Daichi Hirono | 43094a1 | 2018-05-31 12:32:23 +0900 | [diff] [blame] | 365 | protected void startDrag(boolean resize, boolean preserveOrientation, |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 366 | float startX, float startY, Rect startBounds) { |
| 367 | mCtrlType = CTRL_NONE; |
| 368 | mStartDragX = startX; |
| 369 | mStartDragY = startY; |
| 370 | mPreserveOrientation = preserveOrientation; |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 371 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 372 | if (resize) { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 373 | if (startX < startBounds.left) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 374 | mCtrlType |= CTRL_LEFT; |
| 375 | } |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 376 | if (startX > startBounds.right) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 377 | mCtrlType |= CTRL_RIGHT; |
| 378 | } |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 379 | if (startY < startBounds.top) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 380 | mCtrlType |= CTRL_TOP; |
| 381 | } |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 382 | if (startY > startBounds.bottom) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 383 | mCtrlType |= CTRL_BOTTOM; |
| 384 | } |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 385 | mResizing = mCtrlType != CTRL_NONE; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 386 | } |
| 387 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 388 | // In case of !isDockedInEffect we are using the union of all task bounds. These might be |
| 389 | // made up out of multiple windows which are only partially overlapping. When that happens, |
| 390 | // the orientation from the window of interest to the entire stack might diverge. However |
| 391 | // for now we treat them as the same. |
| 392 | mStartOrientationWasLandscape = startBounds.width() >= startBounds.height(); |
| 393 | mWindowOriginalBounds.set(startBounds); |
Vladislav Kaznacheev | 824bc5d | 2016-04-22 17:48:35 -0700 | [diff] [blame] | 394 | |
Tomasz Mikolajewski | 79e8d17 | 2017-11-21 11:21:42 +0900 | [diff] [blame] | 395 | // Notify the app that resizing has started, even though we haven't received any new |
| 396 | // bounds yet. This will guarantee that the app starts the backdrop renderer before |
| 397 | // configuration changes which could cause an activity restart. |
| 398 | if (mResizing) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 399 | synchronized (mService.mGlobalLock) { |
Tomasz Mikolajewski | 79e8d17 | 2017-11-21 11:21:42 +0900 | [diff] [blame] | 400 | notifyMoveLocked(startX, startY); |
| 401 | } |
| 402 | |
| 403 | // Perform the resize on the WMS handler thread when we don't have the WMS lock held |
| 404 | // to ensure that we don't deadlock WMS and AMS. Note that WindowPositionerEventReceiver |
| 405 | // callbacks are delivered on the same handler so this initial resize is always |
| 406 | // guaranteed to happen before subsequent drag resizes. |
| 407 | mService.mH.post(() -> { |
| 408 | try { |
Daichi Hirono | 67f2f4b | 2018-05-25 16:07:30 +0900 | [diff] [blame] | 409 | mActivityManager.resizeTask( |
Tomasz Mikolajewski | 79e8d17 | 2017-11-21 11:21:42 +0900 | [diff] [blame] | 410 | mTask.mTaskId, startBounds, RESIZE_MODE_USER_FORCED); |
| 411 | } catch (RemoteException e) { |
| 412 | } |
| 413 | }); |
| 414 | } |
| 415 | |
Vladislav Kaznacheev | 824bc5d | 2016-04-22 17:48:35 -0700 | [diff] [blame] | 416 | // Make sure we always have valid drag bounds even if the drag ends before any move events |
| 417 | // have been handled. |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 418 | mWindowDragBounds.set(startBounds); |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | private void endDragLocked() { |
| 422 | mResizing = false; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 423 | mTask.setDragResizing(false, DRAG_RESIZE_MODE_FREEFORM); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 426 | /** Returns true if the move operation should be ended. */ |
| 427 | private boolean notifyMoveLocked(float x, float y) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 428 | if (DEBUG_TASK_POSITIONING) { |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 429 | Slog.d(TAG, "notifyMoveLocked: {" + x + "," + y + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | if (mCtrlType != CTRL_NONE) { |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 433 | resizeDrag(x, y); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 434 | mTask.setDragResizing(true, DRAG_RESIZE_MODE_FREEFORM); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 435 | return false; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 436 | } |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 437 | |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 438 | // This is a moving or scrolling operation. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 439 | mTask.mStack.getDimBounds(mTmpRect); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 440 | |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 441 | int nX = (int) x; |
| 442 | int nY = (int) y; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 443 | if (!mTmpRect.contains(nX, nY)) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 444 | // For a moving operation we allow the pointer to go out of the stack bounds, but |
| 445 | // use the clamped pointer position for the drag bounds computation. |
| 446 | nX = Math.min(Math.max(nX, mTmpRect.left), mTmpRect.right); |
| 447 | nY = Math.min(Math.max(nY, mTmpRect.top), mTmpRect.bottom); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 450 | updateWindowDragBounds(nX, nY, mTmpRect); |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 451 | return false; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 452 | } |
| 453 | |
skuhne@google.com | 322347b | 2016-12-02 12:54:03 -0800 | [diff] [blame] | 454 | /** |
| 455 | * The user is drag - resizing the window. |
| 456 | * |
| 457 | * @param x The x coordinate of the current drag coordinate. |
| 458 | * @param y the y coordinate of the current drag coordinate. |
| 459 | */ |
| 460 | @VisibleForTesting |
| 461 | void resizeDrag(float x, float y) { |
| 462 | // This is a resizing operation. |
| 463 | // We need to keep various constraints: |
| 464 | // 1. mMinVisible[Width/Height] <= [width/height] <= mMaxVisibleSize.[x/y] |
| 465 | // 2. The orientation is kept - if required. |
| 466 | final int deltaX = Math.round(x - mStartDragX); |
| 467 | final int deltaY = Math.round(y - mStartDragY); |
| 468 | int left = mWindowOriginalBounds.left; |
| 469 | int top = mWindowOriginalBounds.top; |
| 470 | int right = mWindowOriginalBounds.right; |
| 471 | int bottom = mWindowOriginalBounds.bottom; |
| 472 | |
| 473 | // The aspect which we have to respect. Note that if the orientation does not need to be |
| 474 | // preserved the aspect will be calculated as 1.0 which neutralizes the following |
| 475 | // computations. |
| 476 | final float minAspect = !mPreserveOrientation |
| 477 | ? 1.0f |
| 478 | : (mStartOrientationWasLandscape ? MIN_ASPECT : (1.0f / MIN_ASPECT)); |
| 479 | // Calculate the resulting width and height of the drag operation. |
| 480 | int width = right - left; |
| 481 | int height = bottom - top; |
| 482 | if ((mCtrlType & CTRL_LEFT) != 0) { |
| 483 | width = Math.max(mMinVisibleWidth, width - deltaX); |
| 484 | } else if ((mCtrlType & CTRL_RIGHT) != 0) { |
| 485 | width = Math.max(mMinVisibleWidth, width + deltaX); |
| 486 | } |
| 487 | if ((mCtrlType & CTRL_TOP) != 0) { |
| 488 | height = Math.max(mMinVisibleHeight, height - deltaY); |
| 489 | } else if ((mCtrlType & CTRL_BOTTOM) != 0) { |
| 490 | height = Math.max(mMinVisibleHeight, height + deltaY); |
| 491 | } |
| 492 | |
| 493 | // If we have to preserve the orientation - check that we are doing so. |
| 494 | final float aspect = (float) width / (float) height; |
| 495 | if (mPreserveOrientation && ((mStartOrientationWasLandscape && aspect < MIN_ASPECT) |
| 496 | || (!mStartOrientationWasLandscape && aspect > (1.0 / MIN_ASPECT)))) { |
| 497 | // Calculate 2 rectangles fulfilling all requirements for either X or Y being the major |
| 498 | // drag axis. What ever is producing the bigger rectangle will be chosen. |
| 499 | int width1; |
| 500 | int width2; |
| 501 | int height1; |
| 502 | int height2; |
| 503 | if (mStartOrientationWasLandscape) { |
| 504 | // Assuming that the width is our target we calculate the height. |
| 505 | width1 = Math.max(mMinVisibleWidth, Math.min(mMaxVisibleSize.x, width)); |
| 506 | height1 = Math.min(height, Math.round((float)width1 / MIN_ASPECT)); |
| 507 | if (height1 < mMinVisibleHeight) { |
| 508 | // If the resulting height is too small we adjust to the minimal size. |
| 509 | height1 = mMinVisibleHeight; |
| 510 | width1 = Math.max(mMinVisibleWidth, |
| 511 | Math.min(mMaxVisibleSize.x, Math.round((float)height1 * MIN_ASPECT))); |
| 512 | } |
| 513 | // Assuming that the height is our target we calculate the width. |
| 514 | height2 = Math.max(mMinVisibleHeight, Math.min(mMaxVisibleSize.y, height)); |
| 515 | width2 = Math.max(width, Math.round((float)height2 * MIN_ASPECT)); |
| 516 | if (width2 < mMinVisibleWidth) { |
| 517 | // If the resulting width is too small we adjust to the minimal size. |
| 518 | width2 = mMinVisibleWidth; |
| 519 | height2 = Math.max(mMinVisibleHeight, |
| 520 | Math.min(mMaxVisibleSize.y, Math.round((float)width2 / MIN_ASPECT))); |
| 521 | } |
| 522 | } else { |
| 523 | // Assuming that the width is our target we calculate the height. |
| 524 | width1 = Math.max(mMinVisibleWidth, Math.min(mMaxVisibleSize.x, width)); |
| 525 | height1 = Math.max(height, Math.round((float)width1 * MIN_ASPECT)); |
| 526 | if (height1 < mMinVisibleHeight) { |
| 527 | // If the resulting height is too small we adjust to the minimal size. |
| 528 | height1 = mMinVisibleHeight; |
| 529 | width1 = Math.max(mMinVisibleWidth, |
| 530 | Math.min(mMaxVisibleSize.x, Math.round((float)height1 / MIN_ASPECT))); |
| 531 | } |
| 532 | // Assuming that the height is our target we calculate the width. |
| 533 | height2 = Math.max(mMinVisibleHeight, Math.min(mMaxVisibleSize.y, height)); |
| 534 | width2 = Math.min(width, Math.round((float)height2 / MIN_ASPECT)); |
| 535 | if (width2 < mMinVisibleWidth) { |
| 536 | // If the resulting width is too small we adjust to the minimal size. |
| 537 | width2 = mMinVisibleWidth; |
| 538 | height2 = Math.max(mMinVisibleHeight, |
| 539 | Math.min(mMaxVisibleSize.y, Math.round((float)width2 * MIN_ASPECT))); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | // Use the bigger of the two rectangles if the major change was positive, otherwise |
| 544 | // do the opposite. |
| 545 | final boolean grows = width > (right - left) || height > (bottom - top); |
| 546 | if (grows == (width1 * height1 > width2 * height2)) { |
| 547 | width = width1; |
| 548 | height = height1; |
| 549 | } else { |
| 550 | width = width2; |
| 551 | height = height2; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // Update mWindowDragBounds to the new drag size. |
| 556 | updateDraggedBounds(left, top, right, bottom, width, height); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Given the old coordinates and the new width and height, update the mWindowDragBounds. |
| 561 | * |
| 562 | * @param left The original left bound before the user started dragging. |
| 563 | * @param top The original top bound before the user started dragging. |
| 564 | * @param right The original right bound before the user started dragging. |
| 565 | * @param bottom The original bottom bound before the user started dragging. |
| 566 | * @param newWidth The new dragged width. |
| 567 | * @param newHeight The new dragged height. |
| 568 | */ |
| 569 | void updateDraggedBounds(int left, int top, int right, int bottom, int newWidth, |
| 570 | int newHeight) { |
| 571 | // Generate the final bounds by keeping the opposite drag edge constant. |
| 572 | if ((mCtrlType & CTRL_LEFT) != 0) { |
| 573 | left = right - newWidth; |
| 574 | } else { // Note: The right might have changed - if we pulled at the right or not. |
| 575 | right = left + newWidth; |
| 576 | } |
| 577 | if ((mCtrlType & CTRL_TOP) != 0) { |
| 578 | top = bottom - newHeight; |
| 579 | } else { // Note: The height might have changed - if we pulled at the bottom or not. |
| 580 | bottom = top + newHeight; |
| 581 | } |
| 582 | |
| 583 | mWindowDragBounds.set(left, top, right, bottom); |
| 584 | |
| 585 | checkBoundsForOrientationViolations(mWindowDragBounds); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Validate bounds against orientation violations (if DEBUG_ORIENTATION_VIOLATIONS is set). |
| 590 | * |
| 591 | * @param bounds The bounds to be checked. |
| 592 | */ |
| 593 | private void checkBoundsForOrientationViolations(Rect bounds) { |
| 594 | // When using debug check that we are not violating the given constraints. |
| 595 | if (DEBUG_ORIENTATION_VIOLATIONS) { |
| 596 | if (mStartOrientationWasLandscape != (bounds.width() >= bounds.height())) { |
| 597 | Slog.e(TAG, "Orientation violation detected! should be " |
| 598 | + (mStartOrientationWasLandscape ? "landscape" : "portrait") |
| 599 | + " but is the other"); |
| 600 | } else { |
| 601 | Slog.v(TAG, "new bounds size: " + bounds.width() + " x " + bounds.height()); |
| 602 | } |
| 603 | if (mMinVisibleWidth > bounds.width() || mMinVisibleHeight > bounds.height()) { |
| 604 | Slog.v(TAG, "Minimum requirement violated: Width(min, is)=(" + mMinVisibleWidth |
| 605 | + ", " + bounds.width() + ") Height(min,is)=(" |
| 606 | + mMinVisibleHeight + ", " + bounds.height() + ")"); |
| 607 | } |
| 608 | if (mMaxVisibleSize.x < bounds.width() || mMaxVisibleSize.y < bounds.height()) { |
| 609 | Slog.v(TAG, "Maximum requirement violated: Width(min, is)=(" + mMaxVisibleSize.x |
| 610 | + ", " + bounds.width() + ") Height(min,is)=(" |
| 611 | + mMaxVisibleSize.y + ", " + bounds.height() + ")"); |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 616 | private void updateWindowDragBounds(int x, int y, Rect stackBounds) { |
| 617 | final int offsetX = Math.round(x - mStartDragX); |
| 618 | final int offsetY = Math.round(y - mStartDragY); |
Wale Ogunwale | b8051b8 | 2015-09-17 15:41:52 -0700 | [diff] [blame] | 619 | mWindowDragBounds.set(mWindowOriginalBounds); |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 620 | // Horizontally, at least mMinVisibleWidth pixels of the window should remain visible. |
| 621 | final int maxLeft = stackBounds.right - mMinVisibleWidth; |
| 622 | final int minLeft = stackBounds.left + mMinVisibleWidth - mWindowOriginalBounds.width(); |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 623 | |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 624 | // Vertically, the top mMinVisibleHeight of the window should remain visible. |
| 625 | // (This assumes that the window caption bar is at the top of the window). |
| 626 | final int minTop = stackBounds.top; |
| 627 | final int maxTop = stackBounds.bottom - mMinVisibleHeight; |
Vladislav Kaznacheev | a90a3b8 | 2016-04-27 14:54:53 -0700 | [diff] [blame] | 628 | |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 629 | mWindowDragBounds.offsetTo( |
| 630 | Math.min(Math.max(mWindowOriginalBounds.left + offsetX, minLeft), maxLeft), |
| 631 | Math.min(Math.max(mWindowOriginalBounds.top + offsetY, minTop), maxTop)); |
| 632 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 633 | if (DEBUG_TASK_POSITIONING) Slog.d(TAG, |
| 634 | "updateWindowDragBounds: " + mWindowDragBounds); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 637 | public String toShortString() { |
| 638 | return TAG; |
| 639 | } |
Garfield Tan | 6caf1d8c | 2018-01-18 12:37:50 -0800 | [diff] [blame] | 640 | |
| 641 | static void setFactory(Factory factory) { |
| 642 | sFactory = factory; |
| 643 | } |
| 644 | |
| 645 | static TaskPositioner create(WindowManagerService service) { |
| 646 | if (sFactory == null) { |
| 647 | sFactory = new Factory() {}; |
| 648 | } |
| 649 | |
| 650 | return sFactory.create(service); |
| 651 | } |
| 652 | |
| 653 | interface Factory { |
| 654 | default TaskPositioner create(WindowManagerService service) { |
| 655 | return new TaskPositioner(service); |
| 656 | } |
| 657 | } |
Wale Ogunwale | 228d404 | 2015-09-13 10:17:34 -0700 | [diff] [blame] | 658 | } |