Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 15 | */ |
Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [diff] [blame] | 16 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 21 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.INPUT_CONSUMER_PIP; |
| 23 | import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS; |
| 26 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 33 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 34 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 36 | import android.graphics.Rect; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 37 | import android.os.Debug; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 38 | import android.os.Looper; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 39 | import android.os.RemoteException; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 40 | import android.util.ArrayMap; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 41 | import android.util.Log; |
| 42 | import android.util.Slog; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 43 | import android.view.InputChannel; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 44 | import android.view.InputEventReceiver; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 45 | import android.view.KeyEvent; |
| 46 | import android.view.WindowManager; |
| 47 | |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 48 | import android.view.WindowManagerPolicy; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 49 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 50 | import com.android.server.input.InputApplicationHandle; |
| 51 | import com.android.server.input.InputManagerService; |
| 52 | import com.android.server.input.InputWindowHandle; |
| 53 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 54 | import java.io.PrintWriter; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 55 | import java.util.Arrays; |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 56 | import java.util.Set; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 57 | import java.util.function.Consumer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 58 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 59 | final class InputMonitor implements InputManagerService.WindowManagerCallbacks { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 60 | private final WindowManagerService mService; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 61 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 62 | // Current window with input focus for keys and other non-touch events. May be null. |
| 63 | private WindowState mInputFocus; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 64 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 65 | // When true, prevents input dispatch from proceeding until set to false again. |
| 66 | private boolean mInputDispatchFrozen; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 67 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 68 | // The reason the input is currently frozen or null if the input isn't frozen. |
| 69 | private String mInputFreezeReason = null; |
| 70 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 71 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 72 | // Initially false, so that input does not get dispatched until boot is finished at |
| 73 | // which point the ActivityManager will enable dispatching. |
| 74 | private boolean mInputDispatchEnabled; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 75 | |
| 76 | // When true, need to call updateInputWindowsLw(). |
| 77 | private boolean mUpdateInputWindowsNeeded = true; |
| 78 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 79 | // Array of window handles to provide to the input dispatcher. |
| 80 | private InputWindowHandle[] mInputWindowHandles; |
| 81 | private int mInputWindowHandleCount; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 82 | private InputWindowHandle mFocusedInputWindowHandle; |
| 83 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 84 | private boolean mAddInputConsumerHandle; |
| 85 | private boolean mAddPipInputConsumerHandle; |
| 86 | private boolean mAddWallpaperInputConsumerHandle; |
| 87 | private boolean mDisableWallpaperTouchEvents; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 88 | private final Rect mTmpRect = new Rect(); |
| 89 | private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer = |
| 90 | new UpdateInputForAllWindowsConsumer(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 91 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 92 | // Set to true when the first input device configuration change notification |
| 93 | // is received to indicate that the input devices are ready. |
| 94 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 95 | private boolean mInputDevicesReady; |
| 96 | |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 97 | /** |
| 98 | * The set of input consumer added to the window manager by name, which consumes input events |
| 99 | * for the windows below it. |
| 100 | */ |
| 101 | private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap(); |
| 102 | |
| 103 | private static final class EventReceiverInputConsumer extends InputConsumerImpl |
| 104 | implements WindowManagerPolicy.InputConsumer { |
| 105 | private InputMonitor mInputMonitor; |
| 106 | private final InputEventReceiver mInputEventReceiver; |
| 107 | |
| 108 | EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor, |
| 109 | Looper looper, String name, |
| 110 | InputEventReceiver.Factory inputEventReceiverFactory) { |
| 111 | super(service, name, null); |
| 112 | mInputMonitor = monitor; |
| 113 | mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( |
| 114 | mClientChannel, looper); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void dismiss() { |
| 119 | synchronized (mService.mWindowMap) { |
| 120 | if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) { |
| 121 | mInputEventReceiver.dispose(); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 127 | public InputMonitor(WindowManagerService service) { |
| 128 | mService = service; |
| 129 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 130 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 131 | private void addInputConsumer(String name, InputConsumerImpl consumer) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 132 | mInputConsumers.put(name, consumer); |
| 133 | updateInputWindowsLw(true /* force */); |
| 134 | } |
| 135 | |
| 136 | boolean destroyInputConsumer(String name) { |
| 137 | if (disposeInputConsumer(mInputConsumers.remove(name))) { |
| 138 | updateInputWindowsLw(true /* force */); |
| 139 | return true; |
| 140 | } |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | private boolean disposeInputConsumer(InputConsumerImpl consumer) { |
| 145 | if (consumer != null) { |
| 146 | consumer.disposeChannelsLw(); |
| 147 | return true; |
| 148 | } |
| 149 | return false; |
| 150 | } |
| 151 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 152 | InputConsumerImpl getInputConsumer(String name, int displayId) { |
| 153 | // TODO(multi-display): Allow input consumers on non-default displays? |
| 154 | return (displayId == DEFAULT_DISPLAY) ? mInputConsumers.get(name) : null; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void layoutInputConsumers(int dw, int dh) { |
| 158 | for (int i = mInputConsumers.size() - 1; i >= 0; i--) { |
| 159 | mInputConsumers.valueAt(i).layout(dw, dh); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name, |
| 164 | InputEventReceiver.Factory inputEventReceiverFactory) { |
| 165 | if (mInputConsumers.containsKey(name)) { |
| 166 | throw new IllegalStateException("Existing input consumer found with name: " + name); |
| 167 | } |
| 168 | |
| 169 | final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService, |
| 170 | this, looper, name, inputEventReceiverFactory); |
| 171 | addInputConsumer(name, consumer); |
| 172 | return consumer; |
| 173 | } |
| 174 | |
| 175 | void createInputConsumer(String name, InputChannel inputChannel) { |
| 176 | if (mInputConsumers.containsKey(name)) { |
| 177 | throw new IllegalStateException("Existing input consumer found with name: " + name); |
| 178 | } |
| 179 | |
| 180 | final InputConsumerImpl consumer = new InputConsumerImpl(mService, name, inputChannel); |
| 181 | switch (name) { |
| 182 | case INPUT_CONSUMER_WALLPAPER: |
| 183 | consumer.mWindowHandle.hasWallpaper = true; |
| 184 | break; |
| 185 | case INPUT_CONSUMER_PIP: |
| 186 | // The touchable region of the Pip input window is cropped to the bounds of the |
| 187 | // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 188 | consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 189 | break; |
| 190 | } |
| 191 | addInputConsumer(name, consumer); |
| 192 | } |
| 193 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 194 | /* Notifies the window manager about a broken input channel. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 195 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 196 | * Called by the InputManager. |
| 197 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 198 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 199 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 200 | if (inputWindowHandle == null) { |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | synchronized (mService.mWindowMap) { |
| 205 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 206 | if (windowState != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 207 | Slog.i(TAG_WM, "WINDOW DIED " + windowState); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 208 | windowState.removeIfPossible(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 209 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 212 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 213 | /* Notifies the window manager about an application that is not responding. |
| 214 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 215 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 216 | * Called by the InputManager. |
| 217 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 218 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 219 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 220 | InputWindowHandle inputWindowHandle, String reason) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 221 | AppWindowToken appWindowToken = null; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 222 | WindowState windowState = null; |
| 223 | boolean aboveSystem = false; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 224 | synchronized (mService.mWindowMap) { |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 225 | if (inputWindowHandle != null) { |
| 226 | windowState = (WindowState) inputWindowHandle.windowState; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 227 | if (windowState != null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 228 | appWindowToken = windowState.mAppToken; |
| 229 | } |
| 230 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 231 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 232 | appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 233 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 234 | |
| 235 | if (windowState != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 236 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 237 | + "sending to " + windowState.mAttrs.getTitle() |
| 238 | + ". Reason: " + reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 239 | // Figure out whether this window is layered above system windows. |
| 240 | // We need to do this here to help the activity manager know how to |
| 241 | // layer its ANR dialog. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 242 | int systemAlertLayer = mService.mPolicy.getWindowLayerFromTypeLw( |
| 243 | TYPE_APPLICATION_OVERLAY, windowState.mOwnerCanAddInternalSystemWindow); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 244 | aboveSystem = windowState.mBaseLayer > systemAlertLayer; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 245 | } else if (appWindowToken != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 246 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 247 | + "sending to application " + appWindowToken.stringName |
| 248 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 249 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 250 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 251 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 254 | mService.saveANRStateLocked(appWindowToken, windowState, reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 258 | // Notify the activity manager about the timeout and let it decide whether |
| 259 | // to abort dispatching or keep waiting. |
| 260 | final AppWindowContainerController controller = appWindowToken.getController(); |
| 261 | final boolean abort = controller != null && controller.keyDispatchingTimedOut(reason); |
| 262 | if (!abort) { |
| 263 | // The activity manager declined to abort dispatching. |
| 264 | // Wait a bit longer and timeout again later. |
| 265 | return appWindowToken.mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 266 | } |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 267 | } else if (windowState != null) { |
| 268 | try { |
| 269 | // Notify the activity manager about the timeout and let it decide whether |
| 270 | // to abort dispatching or keep waiting. |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 271 | long timeout = ActivityManager.getService().inputDispatchingTimedOut( |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 272 | windowState.mSession.mPid, aboveSystem, reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 273 | if (timeout >= 0) { |
| 274 | // The activity manager declined to abort dispatching. |
| 275 | // Wait a bit longer and timeout again later. |
baik.han | def340d | 2015-04-15 10:21:05 +0900 | [diff] [blame] | 276 | return timeout * 1000000L; // nanoseconds |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 277 | } |
| 278 | } catch (RemoteException ex) { |
| 279 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 280 | } |
| 281 | return 0; // abort dispatching |
| 282 | } |
| 283 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 284 | void addInputWindowHandle(final InputWindowHandle windowHandle) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 285 | if (mInputWindowHandles == null) { |
| 286 | mInputWindowHandles = new InputWindowHandle[16]; |
| 287 | } |
| 288 | if (mInputWindowHandleCount >= mInputWindowHandles.length) { |
| 289 | mInputWindowHandles = Arrays.copyOf(mInputWindowHandles, |
| 290 | mInputWindowHandleCount * 2); |
| 291 | } |
| 292 | mInputWindowHandles[mInputWindowHandleCount++] = windowHandle; |
| 293 | } |
| 294 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 295 | void addInputWindowHandle(final InputWindowHandle inputWindowHandle, |
Craig Mautner | c08eab8 | 2014-11-11 09:03:59 -0800 | [diff] [blame] | 296 | final WindowState child, int flags, final int type, final boolean isVisible, |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 297 | final boolean hasFocus, final boolean hasWallpaper) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 298 | // Add a window to our list of input windows. |
| 299 | inputWindowHandle.name = child.toString(); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 300 | flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 301 | inputWindowHandle.layoutParamsFlags = flags; |
| 302 | inputWindowHandle.layoutParamsType = type; |
| 303 | inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 304 | inputWindowHandle.visible = isVisible; |
| 305 | inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); |
| 306 | inputWindowHandle.hasFocus = hasFocus; |
| 307 | inputWindowHandle.hasWallpaper = hasWallpaper; |
| 308 | inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 309 | inputWindowHandle.layer = child.mLayer; |
| 310 | inputWindowHandle.ownerPid = child.mSession.mPid; |
| 311 | inputWindowHandle.ownerUid = child.mSession.mUid; |
| 312 | inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; |
| 313 | |
| 314 | final Rect frame = child.mFrame; |
| 315 | inputWindowHandle.frameLeft = frame.left; |
| 316 | inputWindowHandle.frameTop = frame.top; |
| 317 | inputWindowHandle.frameRight = frame.right; |
| 318 | inputWindowHandle.frameBottom = frame.bottom; |
| 319 | |
| 320 | if (child.mGlobalScale != 1) { |
| 321 | // If we are scaling the window, input coordinates need |
| 322 | // to be inversely scaled to map from what is on screen |
| 323 | // to what is actually being touched in the UI. |
| 324 | inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; |
| 325 | } else { |
| 326 | inputWindowHandle.scaleFactor = 1; |
| 327 | } |
| 328 | |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 329 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 330 | Slog.d(TAG_WM, "addInputWindowHandle: " |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 331 | + child + ", " + inputWindowHandle); |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 332 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 333 | addInputWindowHandle(inputWindowHandle); |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 334 | if (hasFocus) { |
| 335 | mFocusedInputWindowHandle = inputWindowHandle; |
| 336 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 339 | private void clearInputWindowHandlesLw() { |
| 340 | while (mInputWindowHandleCount != 0) { |
| 341 | mInputWindowHandles[--mInputWindowHandleCount] = null; |
| 342 | } |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 343 | mFocusedInputWindowHandle = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 346 | void setUpdateInputWindowsNeededLw() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 347 | mUpdateInputWindowsNeeded = true; |
| 348 | } |
| 349 | |
| 350 | /* Updates the cached window information provided to the input dispatcher. */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 351 | void updateInputWindowsLw(boolean force) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 352 | if (!force && !mUpdateInputWindowsNeeded) { |
| 353 | return; |
| 354 | } |
| 355 | mUpdateInputWindowsNeeded = false; |
| 356 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 357 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 358 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 359 | // Populate the input window list with information about all of the windows that |
| 360 | // could potentially receive input. |
| 361 | // As an optimization, we could try to prune the list of windows but this turns |
| 362 | // out to be difficult because only the native code knows for sure which window |
| 363 | // currently has touch focus. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 364 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 365 | // If there's a drag in flight, provide a pseudo-window to catch drag input |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 366 | final boolean inDrag = (mService.mDragState != null); |
| 367 | if (inDrag) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 368 | if (DEBUG_DRAG) { |
| 369 | Log.d(TAG_WM, "Inserting drag window"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 370 | } |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 371 | final InputWindowHandle dragWindowHandle = mService.mDragState.getInputWindowHandle(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 372 | if (dragWindowHandle != null) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 373 | addInputWindowHandle(dragWindowHandle); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 374 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 375 | Slog.w(TAG_WM, "Drag is in progress but there is no " |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 376 | + "drag window handle."); |
| 377 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 380 | final boolean inPositioning = (mService.mTaskPositioner != null); |
| 381 | if (inPositioning) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 382 | if (DEBUG_TASK_POSITIONING) { |
| 383 | Log.d(TAG_WM, "Inserting window handle for repositioning"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 384 | } |
| 385 | final InputWindowHandle dragWindowHandle = mService.mTaskPositioner.mDragWindowHandle; |
| 386 | if (dragWindowHandle != null) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 387 | addInputWindowHandle(dragWindowHandle); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 388 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 389 | Slog.e(TAG_WM, |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 390 | "Repositioning is in progress but there is no drag window handle."); |
| 391 | } |
| 392 | } |
| 393 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 394 | // Add all windows on the default display. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 395 | mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 396 | |
| 397 | if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw"); |
| 398 | } |
| 399 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 400 | /* Notifies that the input device configuration has changed. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 401 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 402 | public void notifyConfigurationChanged() { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 403 | // TODO(multi-display): Notify proper displays that are associated with this input device. |
| 404 | mService.sendNewConfiguration(DEFAULT_DISPLAY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 405 | |
| 406 | synchronized (mInputDevicesReadyMonitor) { |
| 407 | if (!mInputDevicesReady) { |
| 408 | mInputDevicesReady = true; |
| 409 | mInputDevicesReadyMonitor.notifyAll(); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /* Waits until the built-in input devices have been configured. */ |
| 415 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 416 | synchronized (mInputDevicesReadyMonitor) { |
| 417 | if (!mInputDevicesReady) { |
| 418 | try { |
| 419 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 420 | } catch (InterruptedException ex) { |
| 421 | } |
| 422 | } |
| 423 | return mInputDevicesReady; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* Notifies that the lid switch changed state. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 428 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 429 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 430 | mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 431 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 432 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 433 | /* Notifies that the camera lens cover state has changed. */ |
| 434 | @Override |
| 435 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 436 | mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); |
| 437 | } |
| 438 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 439 | /* Provides an opportunity for the window manager policy to intercept early key |
| 440 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 441 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 442 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
| 443 | return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 444 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 445 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 446 | /* Provides an opportunity for the window manager policy to intercept early motion event |
| 447 | * processing when the device is in a non-interactive state since these events are normally |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 448 | * dropped. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 449 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 450 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 451 | return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive( |
| 452 | whenNanos, policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 455 | /* Provides an opportunity for the window manager policy to process a key before |
| 456 | * ordinary dispatch. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 457 | @Override |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 458 | public long interceptKeyBeforeDispatching( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 459 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 460 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 461 | return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| 462 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 463 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 464 | /* Provides an opportunity for the window manager policy to process a key that |
| 465 | * the application did not handle. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 466 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 467 | public KeyEvent dispatchUnhandledKey( |
| 468 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 469 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 470 | return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| 471 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 472 | |
| 473 | /* Callback to get pointer layer. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 474 | @Override |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 475 | public int getPointerLayer() { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 476 | return mService.mPolicy.getWindowLayerFromTypeLw(WindowManager.LayoutParams.TYPE_POINTER) |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 477 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 478 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 479 | } |
| 480 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 481 | /* Called when the current input focus changes. |
| 482 | * Layer assignment is assumed to be complete by the time this is called. |
| 483 | */ |
| 484 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 485 | if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 486 | Slog.d(TAG_WM, "Input focus has changed to " + newWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (newWindow != mInputFocus) { |
| 490 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 491 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 492 | // This is to protect against bugs if someone pauses dispatching but |
| 493 | // forgets to resume. |
| 494 | newWindow.mToken.paused = false; |
| 495 | } |
| 496 | |
| 497 | mInputFocus = newWindow; |
| 498 | setUpdateInputWindowsNeededLw(); |
| 499 | |
| 500 | if (updateInputWindows) { |
| 501 | updateInputWindowsLw(false /*force*/); |
| 502 | } |
| 503 | } |
| 504 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 505 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 506 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 507 | // Focused app has changed. |
| 508 | if (newApp == null) { |
| 509 | mService.mInputManager.setFocusedApplication(null); |
| 510 | } else { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 511 | final InputApplicationHandle handle = newApp.mInputApplicationHandle; |
| 512 | handle.name = newApp.toString(); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 513 | handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 514 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 515 | mService.mInputManager.setFocusedApplication(handle); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 518 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 519 | public void pauseDispatchingLw(WindowToken window) { |
| 520 | if (! window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 521 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 522 | Slog.v(TAG_WM, "Pausing WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 523 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 524 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 525 | window.paused = true; |
| 526 | updateInputWindowsLw(true /*force*/); |
| 527 | } |
| 528 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 529 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 530 | public void resumeDispatchingLw(WindowToken window) { |
| 531 | if (window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 532 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 533 | Slog.v(TAG_WM, "Resuming WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 534 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 535 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 536 | window.paused = false; |
| 537 | updateInputWindowsLw(true /*force*/); |
| 538 | } |
| 539 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 540 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 541 | public void freezeInputDispatchingLw() { |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 542 | if (!mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 543 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 544 | Slog.v(TAG_WM, "Freezing input dispatching"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 545 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 546 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 547 | mInputDispatchFrozen = true; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 548 | |
| 549 | if (DEBUG_INPUT || true) { |
| 550 | mInputFreezeReason = Debug.getCallers(6); |
| 551 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 552 | updateInputDispatchModeLw(); |
| 553 | } |
| 554 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 555 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 556 | public void thawInputDispatchingLw() { |
| 557 | if (mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 558 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 559 | Slog.v(TAG_WM, "Thawing input dispatching"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 560 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 561 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | mInputDispatchFrozen = false; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 563 | mInputFreezeReason = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 564 | updateInputDispatchModeLw(); |
| 565 | } |
| 566 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 567 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 568 | public void setEventDispatchingLw(boolean enabled) { |
| 569 | if (mInputDispatchEnabled != enabled) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 570 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 571 | Slog.v(TAG_WM, "Setting event dispatching to " + enabled); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 572 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 573 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 574 | mInputDispatchEnabled = enabled; |
| 575 | updateInputDispatchModeLw(); |
| 576 | } |
| 577 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 578 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 579 | private void updateInputDispatchModeLw() { |
| 580 | mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 581 | } |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 582 | |
| 583 | void dump(PrintWriter pw, String prefix) { |
| 584 | if (mInputFreezeReason != null) { |
| 585 | pw.println(prefix + "mInputFreezeReason=" + mInputFreezeReason); |
| 586 | } |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 587 | final Set<String> inputConsumerKeys = mInputConsumers.keySet(); |
| 588 | if (!inputConsumerKeys.isEmpty()) { |
| 589 | pw.println(prefix + "InputConsumers:"); |
| 590 | for (String key : inputConsumerKeys) { |
| 591 | pw.println(prefix + " name=" + key); |
| 592 | } |
| 593 | } |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 594 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 595 | |
| 596 | private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> { |
| 597 | |
| 598 | InputConsumerImpl navInputConsumer; |
| 599 | InputConsumerImpl pipInputConsumer; |
| 600 | InputConsumerImpl wallpaperInputConsumer; |
| 601 | Rect pipTouchableBounds; |
| 602 | boolean inDrag; |
| 603 | WallpaperController wallpaperController; |
| 604 | |
| 605 | private void updateInputWindows(boolean inDrag) { |
| 606 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 607 | // TODO: multi-display |
| 608 | navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION, DEFAULT_DISPLAY); |
| 609 | pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP, DEFAULT_DISPLAY); |
| 610 | wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER, DEFAULT_DISPLAY); |
| 611 | mAddInputConsumerHandle = navInputConsumer != null; |
| 612 | mAddPipInputConsumerHandle = pipInputConsumer != null; |
| 613 | mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null; |
| 614 | mTmpRect.setEmpty(); |
| 615 | pipTouchableBounds = mAddPipInputConsumerHandle ? mTmpRect : null; |
| 616 | mDisableWallpaperTouchEvents = false; |
| 617 | this.inDrag = inDrag; |
| 618 | wallpaperController = mService.mRoot.mWallpaperController; |
| 619 | |
| 620 | mService.mRoot.forAllWindows(this, true /* traverseTopToBottom */); |
| 621 | if (mAddWallpaperInputConsumerHandle) { |
| 622 | // No visible wallpaper found, add the wallpaper input consumer at the end. |
| 623 | addInputWindowHandle(wallpaperInputConsumer.mWindowHandle); |
| 624 | } |
| 625 | |
| 626 | // Send windows to native code. |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 627 | mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle); |
Vladislav Kaznacheev | 2e96c63 | 2016-12-13 14:31:24 -0800 | [diff] [blame] | 628 | |
| 629 | clearInputWindowHandlesLw(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | @Override |
| 633 | public void accept(WindowState w) { |
| 634 | final InputChannel inputChannel = w.mInputChannel; |
| 635 | final InputWindowHandle inputWindowHandle = w.mInputWindowHandle; |
| 636 | if (inputChannel == null || inputWindowHandle == null || w.mRemoved |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 637 | || w.canReceiveTouchInput()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 638 | // Skip this window because it cannot possibly receive input. |
| 639 | return; |
| 640 | } |
| 641 | |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 642 | final int flags = w.mAttrs.flags; |
| 643 | final int privateFlags = w.mAttrs.privateFlags; |
| 644 | final int type = w.mAttrs.type; |
| 645 | final boolean hasFocus = w == mInputFocus; |
| 646 | final boolean isVisible = w.isVisibleLw(); |
| 647 | |
| 648 | if (w.getStackId() == PINNED_STACK_ID) { |
| 649 | if (mAddPipInputConsumerHandle |
| 650 | && (inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer)) { |
| 651 | // Update the bounds of the Pip input consumer to match the Pinned stack |
| 652 | w.getStack().getBounds(pipTouchableBounds); |
| 653 | pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds); |
| 654 | addInputWindowHandle(pipInputConsumer.mWindowHandle); |
| 655 | mAddPipInputConsumerHandle = false; |
| 656 | } |
| 657 | // TODO: Fix w.canReceiveTouchInput() to handle this case |
| 658 | if (!hasFocus) { |
| 659 | // Skip this pinned stack window if it does not have focus |
| 660 | return; |
| 661 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | if (mAddInputConsumerHandle |
| 665 | && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) { |
| 666 | addInputWindowHandle(navInputConsumer.mWindowHandle); |
| 667 | mAddInputConsumerHandle = false; |
| 668 | } |
| 669 | |
| 670 | if (mAddWallpaperInputConsumerHandle) { |
| 671 | if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) { |
| 672 | // Add the wallpaper input consumer above the first visible wallpaper. |
| 673 | addInputWindowHandle(wallpaperInputConsumer.mWindowHandle); |
| 674 | mAddWallpaperInputConsumerHandle = false; |
| 675 | } |
| 676 | } |
| 677 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 678 | if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) { |
| 679 | mDisableWallpaperTouchEvents = true; |
| 680 | } |
| 681 | final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w) |
| 682 | && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0 |
| 683 | && !mDisableWallpaperTouchEvents; |
| 684 | |
| 685 | // If there's a drag in progress and 'child' is a potential drop target, |
| 686 | // make sure it's been told about the drag |
| 687 | if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) { |
| 688 | mService.mDragState.sendDragStartedIfNeededLw(w); |
| 689 | } |
| 690 | |
| 691 | addInputWindowHandle( |
| 692 | inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper); |
| 693 | } |
| 694 | } |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 695 | } |