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 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 19 | import com.android.server.input.InputManagerService; |
| 20 | import com.android.server.input.InputApplicationHandle; |
| 21 | import com.android.server.input.InputWindowHandle; |
| 22 | |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 24 | import android.graphics.Rect; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 25 | import android.os.RemoteException; |
| 26 | import android.util.Log; |
| 27 | import android.util.Slog; |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 28 | import android.view.Display; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 29 | import android.view.InputChannel; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 30 | import android.view.KeyEvent; |
| 31 | import android.view.WindowManager; |
| 32 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 33 | import java.util.Arrays; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 34 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 35 | final class InputMonitor implements InputManagerService.WindowManagerCallbacks { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 36 | private final WindowManagerService mService; |
| 37 | |
| 38 | // Current window with input focus for keys and other non-touch events. May be null. |
| 39 | private WindowState mInputFocus; |
| 40 | |
| 41 | // When true, prevents input dispatch from proceeding until set to false again. |
| 42 | private boolean mInputDispatchFrozen; |
| 43 | |
| 44 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 45 | // Initially false, so that input does not get dispatched until boot is finished at |
| 46 | // which point the ActivityManager will enable dispatching. |
| 47 | private boolean mInputDispatchEnabled; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 48 | |
| 49 | // When true, need to call updateInputWindowsLw(). |
| 50 | private boolean mUpdateInputWindowsNeeded = true; |
| 51 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 52 | // Array of window handles to provide to the input dispatcher. |
| 53 | private InputWindowHandle[] mInputWindowHandles; |
| 54 | private int mInputWindowHandleCount; |
| 55 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 56 | // Set to true when the first input device configuration change notification |
| 57 | // is received to indicate that the input devices are ready. |
| 58 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 59 | private boolean mInputDevicesReady; |
| 60 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 61 | Rect mTmpRect = new Rect(); |
| 62 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 63 | public InputMonitor(WindowManagerService service) { |
| 64 | mService = service; |
| 65 | } |
| 66 | |
| 67 | /* Notifies the window manager about a broken input channel. |
| 68 | * |
| 69 | * Called by the InputManager. |
| 70 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 71 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 72 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 73 | if (inputWindowHandle == null) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | synchronized (mService.mWindowMap) { |
| 78 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 79 | if (windowState != null) { |
| 80 | Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState); |
| 81 | mService.removeWindowLocked(windowState.mSession, windowState); |
| 82 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /* Notifies the window manager about an application that is not responding. |
| 87 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
| 88 | * |
| 89 | * Called by the InputManager. |
| 90 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 91 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 92 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 93 | InputWindowHandle inputWindowHandle, String reason) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 94 | AppWindowToken appWindowToken = null; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 95 | WindowState windowState = null; |
| 96 | boolean aboveSystem = false; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 97 | synchronized (mService.mWindowMap) { |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 98 | if (inputWindowHandle != null) { |
| 99 | windowState = (WindowState) inputWindowHandle.windowState; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 100 | if (windowState != null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 101 | appWindowToken = windowState.mAppToken; |
| 102 | } |
| 103 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 104 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 105 | appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 106 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 107 | |
| 108 | if (windowState != null) { |
| 109 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 110 | + "sending to " + windowState.mAttrs.getTitle() |
| 111 | + ". Reason: " + reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 112 | // Figure out whether this window is layered above system windows. |
| 113 | // We need to do this here to help the activity manager know how to |
| 114 | // layer its ANR dialog. |
| 115 | int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw( |
| 116 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 117 | aboveSystem = windowState.mBaseLayer > systemAlertLayer; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 118 | } else if (appWindowToken != null) { |
| 119 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 120 | + "sending to application " + appWindowToken.stringName |
| 121 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 122 | } else { |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 123 | Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " |
| 124 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 127 | mService.saveANRStateLocked(appWindowToken, windowState, reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| 131 | try { |
| 132 | // Notify the activity manager about the timeout and let it decide whether |
| 133 | // to abort dispatching or keep waiting. |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 134 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 135 | if (! abort) { |
| 136 | // The activity manager declined to abort dispatching. |
| 137 | // Wait a bit longer and timeout again later. |
| 138 | return appWindowToken.inputDispatchingTimeoutNanos; |
| 139 | } |
| 140 | } catch (RemoteException ex) { |
| 141 | } |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 142 | } else if (windowState != null) { |
| 143 | try { |
| 144 | // Notify the activity manager about the timeout and let it decide whether |
| 145 | // to abort dispatching or keep waiting. |
| 146 | long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut( |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 147 | windowState.mSession.mPid, aboveSystem, reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 148 | if (timeout >= 0) { |
| 149 | // The activity manager declined to abort dispatching. |
| 150 | // Wait a bit longer and timeout again later. |
| 151 | return timeout; |
| 152 | } |
| 153 | } catch (RemoteException ex) { |
| 154 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 155 | } |
| 156 | return 0; // abort dispatching |
| 157 | } |
| 158 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 159 | private void addInputWindowHandleLw(final InputWindowHandle windowHandle) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 160 | if (mInputWindowHandles == null) { |
| 161 | mInputWindowHandles = new InputWindowHandle[16]; |
| 162 | } |
| 163 | if (mInputWindowHandleCount >= mInputWindowHandles.length) { |
| 164 | mInputWindowHandles = Arrays.copyOf(mInputWindowHandles, |
| 165 | mInputWindowHandleCount * 2); |
| 166 | } |
| 167 | mInputWindowHandles[mInputWindowHandleCount++] = windowHandle; |
| 168 | } |
| 169 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 170 | private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 171 | final WindowState child, int flags, int privateFlags, final int type, |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 172 | final boolean isVisible, final boolean hasFocus, final boolean hasWallpaper) { |
| 173 | // Add a window to our list of input windows. |
| 174 | inputWindowHandle.name = child.toString(); |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 175 | final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 176 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0; |
| 177 | if (modal && child.mAppToken != null) { |
| 178 | // Limit the outer touch to the activity stack region. |
| 179 | flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 180 | child.getStackBounds(mTmpRect); |
| 181 | inputWindowHandle.touchableRegion.set(mTmpRect); |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 182 | } else { |
| 183 | // Not modal or full screen modal |
| 184 | child.getTouchableRegion(inputWindowHandle.touchableRegion); |
| 185 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 186 | inputWindowHandle.layoutParamsFlags = flags; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 187 | inputWindowHandle.layoutParamsPrivateFlags = privateFlags; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 188 | inputWindowHandle.layoutParamsType = type; |
| 189 | inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 190 | inputWindowHandle.visible = isVisible; |
| 191 | inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); |
| 192 | inputWindowHandle.hasFocus = hasFocus; |
| 193 | inputWindowHandle.hasWallpaper = hasWallpaper; |
| 194 | inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 195 | inputWindowHandle.layer = child.mLayer; |
| 196 | inputWindowHandle.ownerPid = child.mSession.mPid; |
| 197 | inputWindowHandle.ownerUid = child.mSession.mUid; |
| 198 | inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; |
| 199 | |
| 200 | final Rect frame = child.mFrame; |
| 201 | inputWindowHandle.frameLeft = frame.left; |
| 202 | inputWindowHandle.frameTop = frame.top; |
| 203 | inputWindowHandle.frameRight = frame.right; |
| 204 | inputWindowHandle.frameBottom = frame.bottom; |
| 205 | |
| 206 | if (child.mGlobalScale != 1) { |
| 207 | // If we are scaling the window, input coordinates need |
| 208 | // to be inversely scaled to map from what is on screen |
| 209 | // to what is actually being touched in the UI. |
| 210 | inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; |
| 211 | } else { |
| 212 | inputWindowHandle.scaleFactor = 1; |
| 213 | } |
| 214 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 215 | |
| 216 | addInputWindowHandleLw(inputWindowHandle); |
| 217 | } |
| 218 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 219 | private void clearInputWindowHandlesLw() { |
| 220 | while (mInputWindowHandleCount != 0) { |
| 221 | mInputWindowHandles[--mInputWindowHandleCount] = null; |
| 222 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | public void setUpdateInputWindowsNeededLw() { |
| 226 | mUpdateInputWindowsNeeded = true; |
| 227 | } |
| 228 | |
| 229 | /* Updates the cached window information provided to the input dispatcher. */ |
| 230 | public void updateInputWindowsLw(boolean force) { |
| 231 | if (!force && !mUpdateInputWindowsNeeded) { |
| 232 | return; |
| 233 | } |
| 234 | mUpdateInputWindowsNeeded = false; |
| 235 | |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 236 | if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 238 | // Populate the input window list with information about all of the windows that |
| 239 | // could potentially receive input. |
| 240 | // As an optimization, we could try to prune the list of windows but this turns |
| 241 | // out to be difficult because only the native code knows for sure which window |
| 242 | // currently has touch focus. |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 243 | final WindowStateAnimator universeBackground = mService.mAnimator.mUniverseBackground; |
| 244 | final int aboveUniverseLayer = mService.mAnimator.mAboveUniverseLayer; |
| 245 | boolean addedUniverse = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 246 | |
| 247 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 248 | final boolean inDrag = (mService.mDragState != null); |
| 249 | if (inDrag) { |
| 250 | if (WindowManagerService.DEBUG_DRAG) { |
| 251 | Log.d(WindowManagerService.TAG, "Inserting drag window"); |
| 252 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 253 | final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle; |
| 254 | if (dragWindowHandle != null) { |
| 255 | addInputWindowHandleLw(dragWindowHandle); |
| 256 | } else { |
| 257 | Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no " |
| 258 | + "drag window handle."); |
| 259 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 262 | final int NFW = mService.mFakeWindows.size(); |
| 263 | for (int i = 0; i < NFW; i++) { |
| 264 | addInputWindowHandleLw(mService.mFakeWindows.get(i).mWindowHandle); |
| 265 | } |
| 266 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 267 | // Add all windows on the default display. |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 268 | final int numDisplays = mService.mDisplayContents.size(); |
| 269 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 270 | WindowList windows = mService.mDisplayContents.valueAt(displayNdx).getWindowList(); |
| 271 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 272 | final WindowState child = windows.get(winNdx); |
| 273 | final InputChannel inputChannel = child.mInputChannel; |
| 274 | final InputWindowHandle inputWindowHandle = child.mInputWindowHandle; |
| 275 | if (inputChannel == null || inputWindowHandle == null || child.mRemoved) { |
| 276 | // Skip this window because it cannot possibly receive input. |
| 277 | continue; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 278 | } |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 279 | |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 280 | final int flags = child.mAttrs.flags; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 281 | final int privateFlags = child.mAttrs.privateFlags; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 282 | final int type = child.mAttrs.type; |
| 283 | |
| 284 | final boolean hasFocus = (child == mInputFocus); |
| 285 | final boolean isVisible = child.isVisibleLw(); |
| 286 | final boolean hasWallpaper = (child == mService.mWallpaperTarget) |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame^] | 287 | && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0; |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 288 | final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY); |
| 289 | |
| 290 | // If there's a drag in progress and 'child' is a potential drop target, |
| 291 | // make sure it's been told about the drag |
| 292 | if (inDrag && isVisible && onDefaultDisplay) { |
| 293 | mService.mDragState.sendDragStartedIfNeededLw(child); |
| 294 | } |
| 295 | |
| 296 | if (universeBackground != null && !addedUniverse |
| 297 | && child.mBaseLayer < aboveUniverseLayer && onDefaultDisplay) { |
| 298 | final WindowState u = universeBackground.mWin; |
| 299 | if (u.mInputChannel != null && u.mInputWindowHandle != null) { |
| 300 | addInputWindowHandleLw(u.mInputWindowHandle, u, u.mAttrs.flags, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 301 | u.mAttrs.privateFlags, u.mAttrs.type, |
| 302 | true, u == mInputFocus, false); |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 303 | } |
| 304 | addedUniverse = true; |
| 305 | } |
| 306 | |
| 307 | if (child.mWinAnimator != universeBackground) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 308 | addInputWindowHandleLw(inputWindowHandle, child, flags, privateFlags, type, |
Craig Mautner | f892415 | 2013-07-16 09:10:55 -0700 | [diff] [blame] | 309 | isVisible, hasFocus, hasWallpaper); |
| 310 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 311 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Send windows to native code. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 315 | mService.mInputManager.setInputWindows(mInputWindowHandles); |
| 316 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 317 | // Clear the list in preparation for the next round. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 318 | clearInputWindowHandlesLw(); |
| 319 | |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 320 | if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* Notifies that the input device configuration has changed. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 324 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 325 | public void notifyConfigurationChanged() { |
| 326 | mService.sendNewConfiguration(); |
| 327 | |
| 328 | synchronized (mInputDevicesReadyMonitor) { |
| 329 | if (!mInputDevicesReady) { |
| 330 | mInputDevicesReady = true; |
| 331 | mInputDevicesReadyMonitor.notifyAll(); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /* Waits until the built-in input devices have been configured. */ |
| 337 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 338 | synchronized (mInputDevicesReadyMonitor) { |
| 339 | if (!mInputDevicesReady) { |
| 340 | try { |
| 341 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 342 | } catch (InterruptedException ex) { |
| 343 | } |
| 344 | } |
| 345 | return mInputDevicesReady; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* Notifies that the lid switch changed state. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 350 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 351 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 352 | mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 353 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 354 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 355 | /* Provides an opportunity for the window manager policy to intercept early key |
| 356 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 357 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 358 | public int interceptKeyBeforeQueueing( |
| 359 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 360 | return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
| 361 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 362 | |
| 363 | /* Provides an opportunity for the window manager policy to intercept early |
| 364 | * motion event processing when the screen is off since these events are normally |
| 365 | * dropped. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 366 | @Override |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 367 | public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) { |
| 368 | return mService.mPolicy.interceptMotionBeforeQueueingWhenScreenOff(whenNanos, policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 371 | /* Provides an opportunity for the window manager policy to process a key before |
| 372 | * ordinary dispatch. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 373 | @Override |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 374 | public long interceptKeyBeforeDispatching( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 375 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 376 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 377 | return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| 378 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 379 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 380 | /* Provides an opportunity for the window manager policy to process a key that |
| 381 | * the application did not handle. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 382 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 383 | public KeyEvent dispatchUnhandledKey( |
| 384 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 385 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 386 | return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| 387 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 388 | |
| 389 | /* Callback to get pointer layer. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 390 | @Override |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 391 | public int getPointerLayer() { |
| 392 | return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER) |
| 393 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 394 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 395 | } |
| 396 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 397 | /* Called when the current input focus changes. |
| 398 | * Layer assignment is assumed to be complete by the time this is called. |
| 399 | */ |
| 400 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 401 | if (WindowManagerService.DEBUG_FOCUS_LIGHT || WindowManagerService.DEBUG_INPUT) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 402 | Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow); |
| 403 | } |
| 404 | |
| 405 | if (newWindow != mInputFocus) { |
| 406 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 407 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 408 | // This is to protect against bugs if someone pauses dispatching but |
| 409 | // forgets to resume. |
| 410 | newWindow.mToken.paused = false; |
| 411 | } |
| 412 | |
| 413 | mInputFocus = newWindow; |
| 414 | setUpdateInputWindowsNeededLw(); |
| 415 | |
| 416 | if (updateInputWindows) { |
| 417 | updateInputWindowsLw(false /*force*/); |
| 418 | } |
| 419 | } |
| 420 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 421 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 422 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 423 | // Focused app has changed. |
| 424 | if (newApp == null) { |
| 425 | mService.mInputManager.setFocusedApplication(null); |
| 426 | } else { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 427 | final InputApplicationHandle handle = newApp.mInputApplicationHandle; |
| 428 | handle.name = newApp.toString(); |
| 429 | handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 430 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 431 | mService.mInputManager.setFocusedApplication(handle); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 432 | } |
| 433 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 434 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 435 | public void pauseDispatchingLw(WindowToken window) { |
| 436 | if (! window.paused) { |
| 437 | if (WindowManagerService.DEBUG_INPUT) { |
| 438 | Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window); |
| 439 | } |
| 440 | |
| 441 | window.paused = true; |
| 442 | updateInputWindowsLw(true /*force*/); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | public void resumeDispatchingLw(WindowToken window) { |
| 447 | if (window.paused) { |
| 448 | if (WindowManagerService.DEBUG_INPUT) { |
| 449 | Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window); |
| 450 | } |
| 451 | |
| 452 | window.paused = false; |
| 453 | updateInputWindowsLw(true /*force*/); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | public void freezeInputDispatchingLw() { |
| 458 | if (! mInputDispatchFrozen) { |
| 459 | if (WindowManagerService.DEBUG_INPUT) { |
| 460 | Slog.v(WindowManagerService.TAG, "Freezing input dispatching"); |
| 461 | } |
| 462 | |
| 463 | mInputDispatchFrozen = true; |
| 464 | updateInputDispatchModeLw(); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | public void thawInputDispatchingLw() { |
| 469 | if (mInputDispatchFrozen) { |
| 470 | if (WindowManagerService.DEBUG_INPUT) { |
| 471 | Slog.v(WindowManagerService.TAG, "Thawing input dispatching"); |
| 472 | } |
| 473 | |
| 474 | mInputDispatchFrozen = false; |
| 475 | updateInputDispatchModeLw(); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | public void setEventDispatchingLw(boolean enabled) { |
| 480 | if (mInputDispatchEnabled != enabled) { |
| 481 | if (WindowManagerService.DEBUG_INPUT) { |
| 482 | Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled); |
| 483 | } |
| 484 | |
| 485 | mInputDispatchEnabled = enabled; |
| 486 | updateInputDispatchModeLw(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | private void updateInputDispatchModeLw() { |
| 491 | mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 492 | } |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 493 | } |