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