Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 24 | |
| 25 | import android.content.ClipData; |
| 26 | import android.content.Context; |
| 27 | import android.content.res.Configuration; |
| 28 | import android.graphics.Rect; |
| 29 | import android.graphics.Region; |
| 30 | import android.os.Binder; |
| 31 | import android.os.Bundle; |
| 32 | import android.os.IBinder; |
| 33 | import android.os.Parcel; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 34 | import android.os.Process; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 35 | import android.os.RemoteException; |
| 36 | import android.os.ServiceManager; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 38 | import android.util.Slog; |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 39 | import android.view.Display; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 40 | import android.view.IWindow; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 41 | import android.view.IWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 42 | import android.view.IWindowSession; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 43 | import android.view.IWindowSessionCallback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 44 | import android.view.InputChannel; |
| 45 | import android.view.Surface; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 46 | import android.view.SurfaceControl; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 47 | import android.view.SurfaceSession; |
| 48 | import android.view.WindowManager; |
| 49 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 50 | import com.android.internal.view.IInputContext; |
| 51 | import com.android.internal.view.IInputMethodClient; |
| 52 | import com.android.internal.view.IInputMethodManager; |
| 53 | import com.android.server.wm.WindowManagerService.H; |
| 54 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 55 | import java.io.PrintWriter; |
| 56 | |
| 57 | /** |
| 58 | * This class represents an active client session. There is generally one |
| 59 | * Session object per process that is interacting with the window manager. |
| 60 | */ |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 61 | // Needs to be public and not final so we can mock during tests...sucks I know :( |
| 62 | public class Session extends IWindowSession.Stub |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 63 | implements IBinder.DeathRecipient { |
| 64 | final WindowManagerService mService; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 65 | final IWindowSessionCallback mCallback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 66 | final IInputMethodClient mClient; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 67 | final int mUid; |
| 68 | final int mPid; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 69 | private final String mStringName; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 70 | SurfaceSession mSurfaceSession; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 71 | private int mNumWindow = 0; |
| 72 | private boolean mClientDead = false; |
| 73 | private float mLastReportedAnimatorScale; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 74 | |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 75 | public Session(WindowManagerService service, IWindowSessionCallback callback, |
| 76 | IInputMethodClient client, IInputContext inputContext) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 77 | mService = service; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 78 | mCallback = callback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 79 | mClient = client; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 80 | mUid = Binder.getCallingUid(); |
| 81 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 82 | mLastReportedAnimatorScale = service.getCurrentAnimatorScale(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 83 | StringBuilder sb = new StringBuilder(); |
| 84 | sb.append("Session{"); |
| 85 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 86 | sb.append(" "); |
| 87 | sb.append(mPid); |
| 88 | if (mUid < Process.FIRST_APPLICATION_UID) { |
| 89 | sb.append(":"); |
| 90 | sb.append(mUid); |
| 91 | } else { |
| 92 | sb.append(":u"); |
| 93 | sb.append(UserHandle.getUserId(mUid)); |
| 94 | sb.append('a'); |
| 95 | sb.append(UserHandle.getAppId(mUid)); |
| 96 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 97 | sb.append("}"); |
| 98 | mStringName = sb.toString(); |
| 99 | |
| 100 | synchronized (mService.mWindowMap) { |
| 101 | if (mService.mInputMethodManager == null && mService.mHaveInputMethods) { |
| 102 | IBinder b = ServiceManager.getService( |
| 103 | Context.INPUT_METHOD_SERVICE); |
| 104 | mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 105 | } |
| 106 | } |
| 107 | long ident = Binder.clearCallingIdentity(); |
| 108 | try { |
| 109 | // Note: it is safe to call in to the input method manager |
| 110 | // here because we are not holding our lock. |
| 111 | if (mService.mInputMethodManager != null) { |
| 112 | mService.mInputMethodManager.addClient(client, inputContext, |
| 113 | mUid, mPid); |
| 114 | } else { |
| 115 | client.setUsingInputMethod(false); |
| 116 | } |
| 117 | client.asBinder().linkToDeath(this, 0); |
| 118 | } catch (RemoteException e) { |
| 119 | // The caller has died, so we can just forget about this. |
| 120 | try { |
| 121 | if (mService.mInputMethodManager != null) { |
| 122 | mService.mInputMethodManager.removeClient(client); |
| 123 | } |
| 124 | } catch (RemoteException ee) { |
| 125 | } |
| 126 | } finally { |
| 127 | Binder.restoreCallingIdentity(ident); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 133 | throws RemoteException { |
| 134 | try { |
| 135 | return super.onTransact(code, data, reply, flags); |
| 136 | } catch (RuntimeException e) { |
| 137 | // Log all 'real' exceptions thrown to the caller |
| 138 | if (!(e instanceof SecurityException)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 139 | Slog.wtf(TAG_WM, "Window Session Crash", e); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 140 | } |
| 141 | throw e; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | public void binderDied() { |
| 146 | // Note: it is safe to call in to the input method manager |
| 147 | // here because we are not holding our lock. |
| 148 | try { |
| 149 | if (mService.mInputMethodManager != null) { |
| 150 | mService.mInputMethodManager.removeClient(mClient); |
| 151 | } |
| 152 | } catch (RemoteException e) { |
| 153 | } |
| 154 | synchronized(mService.mWindowMap) { |
| 155 | mClient.asBinder().unlinkToDeath(this, 0); |
| 156 | mClientDead = true; |
| 157 | killSessionLocked(); |
| 158 | } |
| 159 | } |
| 160 | |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 161 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 162 | public int add(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 163 | int viewVisibility, Rect outContentInsets, Rect outStableInsets, |
| 164 | InputChannel outInputChannel) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 165 | return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 166 | outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 167 | } |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 168 | |
| 169 | @Override |
| 170 | public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 171 | int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 172 | Rect outOutsets, InputChannel outInputChannel) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 173 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 174 | outContentInsets, outStableInsets, outOutsets, outInputChannel); |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 178 | public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 179 | int viewVisibility, Rect outContentInsets, Rect outStableInsets) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 180 | return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 181 | Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets); |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 186 | int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 187 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 188 | outContentInsets, outStableInsets, null /* outOutsets */, null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public void remove(IWindow window) { |
| 192 | mService.removeWindow(this, window); |
| 193 | } |
| 194 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 195 | @Override |
Robert Carr | 64aadd0 | 2015-11-06 13:54:20 -0800 | [diff] [blame] | 196 | public void repositionChild(IWindow window, int left, int top, int right, int bottom, |
Chong Zhang | 6136273 | 2016-03-21 16:13:10 -0700 | [diff] [blame] | 197 | long deferTransactionUntilFrame, Rect outFrame) { |
Robert Carr | 64aadd0 | 2015-11-06 13:54:20 -0800 | [diff] [blame] | 198 | mService.repositionChild(this, window, left, top, right, bottom, |
| 199 | deferTransactionUntilFrame, outFrame); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 202 | @Override |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 203 | public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 204 | mService.setWillReplaceWindows(appToken, childrenOnly); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 207 | public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 208 | int requestedWidth, int requestedHeight, int viewFlags, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 209 | int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 210 | Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame, |
| 211 | Configuration outConfig, Surface outSurface) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 212 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 213 | + Binder.getCallingPid()); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 214 | int res = mService.relayoutWindow(this, window, seq, attrs, |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 215 | requestedWidth, requestedHeight, viewFlags, flags, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 216 | outFrame, outOverscanInsets, outContentInsets, outVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 217 | outStableInsets, outsets, outBackdropFrame, outConfig, outSurface); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 218 | if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 219 | + Binder.getCallingPid()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 220 | return res; |
| 221 | } |
| 222 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 223 | public void performDeferredDestroy(IWindow window) { |
| 224 | mService.performDeferredDestroyWindow(this, window); |
| 225 | } |
| 226 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 227 | public boolean outOfMemory(IWindow window) { |
| 228 | return mService.outOfMemoryWindow(this, window); |
| 229 | } |
| 230 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 231 | public void setTransparentRegion(IWindow window, Region region) { |
| 232 | mService.setTransparentRegionWindow(this, window, region); |
| 233 | } |
| 234 | |
| 235 | public void setInsets(IWindow window, int touchableInsets, |
| 236 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
| 237 | mService.setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 238 | visibleInsets, touchableArea); |
| 239 | } |
| 240 | |
| 241 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 242 | mService.getWindowDisplayFrame(this, window, outDisplayFrame); |
| 243 | } |
| 244 | |
| 245 | public void finishDrawing(IWindow window) { |
| 246 | if (WindowManagerService.localLOGV) Slog.v( |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 247 | TAG_WM, "IWindow finishDrawing called for " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 248 | mService.finishDrawingWindow(this, window); |
| 249 | } |
| 250 | |
| 251 | public void setInTouchMode(boolean mode) { |
| 252 | synchronized(mService.mWindowMap) { |
| 253 | mService.mInTouchMode = mode; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | public boolean getInTouchMode() { |
| 258 | synchronized(mService.mWindowMap) { |
| 259 | return mService.mInTouchMode; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 264 | boolean always) { |
| 265 | synchronized(mService.mWindowMap) { |
| 266 | long ident = Binder.clearCallingIdentity(); |
| 267 | try { |
| 268 | return mService.mPolicy.performHapticFeedbackLw( |
| 269 | mService.windowForClientLocked(this, window, true), |
| 270 | effectId, always); |
| 271 | } finally { |
| 272 | Binder.restoreCallingIdentity(ident); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /* Drag/drop */ |
| 278 | public IBinder prepareDrag(IWindow window, int flags, |
| 279 | int width, int height, Surface outSurface) { |
| 280 | return mService.prepareDragSurface(window, mSurfaceSession, flags, |
| 281 | width, height, outSurface); |
| 282 | } |
| 283 | |
| 284 | public boolean performDrag(IWindow window, IBinder dragToken, |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 285 | int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 286 | ClipData data) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 287 | if (DEBUG_DRAG) { |
| 288 | Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | synchronized (mService.mWindowMap) { |
| 292 | if (mService.mDragState == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 293 | Slog.w(TAG_WM, "No drag prepared"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 294 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 295 | } |
| 296 | |
| 297 | if (dragToken != mService.mDragState.mToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 298 | Slog.w(TAG_WM, "Performing mismatched drag"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 299 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 300 | } |
| 301 | |
| 302 | WindowState callingWin = mService.windowForClientLocked(null, window, false); |
| 303 | if (callingWin == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 304 | Slog.w(TAG_WM, "Bad requesting window " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 305 | return false; // !!! TODO: throw here? |
| 306 | } |
| 307 | |
| 308 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 309 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 310 | // called performDrag() |
| 311 | |
| 312 | mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 313 | |
| 314 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 315 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| 316 | |
| 317 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 318 | // the actual drag event dispatch stuff in the dragstate |
| 319 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 320 | final DisplayContent displayContent = callingWin.getDisplayContent(); |
| 321 | if (displayContent == null) { |
| 322 | return false; |
| 323 | } |
| 324 | Display display = displayContent.getDisplay(); |
Jeff Brown | 14a9f2b | 2012-09-24 14:36:44 -0700 | [diff] [blame] | 325 | mService.mDragState.register(display); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 326 | if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 327 | mService.mDragState.getInputChannel())) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 328 | Slog.e(TAG_WM, "Unable to transfer touch focus"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 329 | mService.mDragState.unregister(); |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 330 | mService.mDragState.reset(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 331 | mService.mDragState = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 332 | return false; |
| 333 | } |
| 334 | |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 335 | mService.mDragState.mDisplayContent = displayContent; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 336 | mService.mDragState.mData = data; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 337 | mService.mDragState.broadcastDragStartedLw(touchX, touchY); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 338 | mService.mDragState.overridePointerIconLw(touchSource); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 339 | |
| 340 | // remember the thumb offsets for later |
| 341 | mService.mDragState.mThumbOffsetX = thumbCenterX; |
| 342 | mService.mDragState.mThumbOffsetY = thumbCenterY; |
| 343 | |
| 344 | // Make the surface visible at the proper location |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 345 | final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 346 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 347 | TAG_WM, ">>> OPEN TRANSACTION performDrag"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 348 | mService.openSurfaceTransaction(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 349 | try { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 350 | surfaceControl.setPosition(touchX - thumbCenterX, |
Dianne Hackborn | d040edb | 2011-08-31 12:47:58 -0700 | [diff] [blame] | 351 | touchY - thumbCenterY); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 352 | surfaceControl.setLayer(mService.mDragState.getDragLayerLw()); |
| 353 | surfaceControl.setLayerStack(display.getLayerStack()); |
| 354 | surfaceControl.show(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 355 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 356 | mService.closeSurfaceTransaction(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 357 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 358 | TAG_WM, "<<< CLOSE TRANSACTION performDrag"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 359 | } |
Vladislav Kaznacheev | d0ed893 | 2016-01-15 15:37:05 -0800 | [diff] [blame] | 360 | |
| 361 | mService.mDragState.notifyLocationLw(touchX, touchY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return true; // success! |
| 365 | } |
| 366 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 367 | public boolean startMovingTask(IWindow window, float startX, float startY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 368 | if (DEBUG_TASK_POSITIONING) Slog.d( |
| 369 | TAG_WM, "startMovingTask: {" + startX + "," + startY + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 370 | |
Wale Ogunwale | 09e1b8d | 2016-02-23 10:38:35 -0800 | [diff] [blame] | 371 | long ident = Binder.clearCallingIdentity(); |
| 372 | try { |
| 373 | return mService.startMovingTask(window, startX, startY); |
| 374 | } finally { |
| 375 | Binder.restoreCallingIdentity(ident); |
| 376 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 379 | public void reportDropResult(IWindow window, boolean consumed) { |
| 380 | IBinder token = window.asBinder(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 381 | if (DEBUG_DRAG) { |
| 382 | Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | synchronized (mService.mWindowMap) { |
| 386 | long ident = Binder.clearCallingIdentity(); |
| 387 | try { |
Christopher Tate | 05e9c65 | 2011-10-20 12:34:36 -0700 | [diff] [blame] | 388 | if (mService.mDragState == null) { |
| 389 | // Most likely the drop recipient ANRed and we ended the drag |
| 390 | // out from under it. Log the issue and move on. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 391 | Slog.w(TAG_WM, "Drop result given but no drag in progress"); |
Christopher Tate | 05e9c65 | 2011-10-20 12:34:36 -0700 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | |
| 395 | if (mService.mDragState.mToken != token) { |
| 396 | // We're in a drag, but the wrong window has responded. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 397 | Slog.w(TAG_WM, "Invalid drop-result claim by " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 398 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 399 | } |
| 400 | |
| 401 | // The right window has responded, even if it's no longer around, |
| 402 | // so be sure to halt the timeout even if the later WindowState |
| 403 | // lookup fails. |
| 404 | mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 405 | WindowState callingWin = mService.windowForClientLocked(null, window, false); |
| 406 | if (callingWin == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 407 | Slog.w(TAG_WM, "Bad result-reporting window " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 408 | return; // !!! TODO: throw here? |
| 409 | } |
| 410 | |
| 411 | mService.mDragState.mDragResult = consumed; |
| 412 | mService.mDragState.endDragLw(); |
| 413 | } finally { |
| 414 | Binder.restoreCallingIdentity(ident); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 419 | public void cancelDragAndDrop(IBinder dragToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 420 | if (DEBUG_DRAG) { |
| 421 | Slog.d(TAG_WM, "cancelDragAndDrop"); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | synchronized (mService.mWindowMap) { |
| 425 | long ident = Binder.clearCallingIdentity(); |
| 426 | try { |
| 427 | if (mService.mDragState == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 428 | Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()"); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 429 | throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()"); |
| 430 | } |
| 431 | |
| 432 | if (mService.mDragState.mToken != dragToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 433 | Slog.w(TAG_WM, |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 434 | "cancelDragAndDrop() does not match prepareDrag()"); |
| 435 | throw new IllegalStateException( |
| 436 | "cancelDragAndDrop() does not match prepareDrag()"); |
| 437 | } |
| 438 | |
| 439 | mService.mDragState.mDragResult = false; |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 440 | mService.mDragState.cancelDragLw(); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 441 | } finally { |
| 442 | Binder.restoreCallingIdentity(ident); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 447 | public void dragRecipientEntered(IWindow window) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 448 | if (DEBUG_DRAG) { |
| 449 | Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | public void dragRecipientExited(IWindow window) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 454 | if (DEBUG_DRAG) { |
| 455 | Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
| 459 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
| 460 | synchronized(mService.mWindowMap) { |
| 461 | long ident = Binder.clearCallingIdentity(); |
| 462 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame^] | 463 | mService.mRoot.mWallpaperController.setWindowWallpaperPosition( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 464 | mService.windowForClientLocked(this, window, true), |
| 465 | x, y, xStep, yStep); |
| 466 | } finally { |
| 467 | Binder.restoreCallingIdentity(ident); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | public void wallpaperOffsetsComplete(IBinder window) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 473 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame^] | 474 | mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 475 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 478 | public void setWallpaperDisplayOffset(IBinder window, int x, int y) { |
| 479 | synchronized(mService.mWindowMap) { |
| 480 | long ident = Binder.clearCallingIdentity(); |
| 481 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame^] | 482 | mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset( |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 483 | mService.windowForClientLocked(this, window, true), x, y); |
| 484 | } finally { |
| 485 | Binder.restoreCallingIdentity(ident); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 490 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 491 | int z, Bundle extras, boolean sync) { |
| 492 | synchronized(mService.mWindowMap) { |
| 493 | long ident = Binder.clearCallingIdentity(); |
| 494 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame^] | 495 | return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 496 | mService.windowForClientLocked(this, window, true), |
| 497 | action, x, y, z, extras, sync); |
| 498 | } finally { |
| 499 | Binder.restoreCallingIdentity(ident); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 505 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame^] | 506 | mService.mRoot.mWallpaperController.wallpaperCommandComplete(window); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 507 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 510 | public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) { |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 511 | synchronized(mService.mWindowMap) { |
| 512 | final long identity = Binder.clearCallingIdentity(); |
| 513 | try { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 514 | mService.onRectangleOnScreenRequested(token, rectangle); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 515 | } finally { |
| 516 | Binder.restoreCallingIdentity(identity); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 521 | public IWindowId getWindowId(IBinder window) { |
| 522 | return mService.getWindowId(window); |
| 523 | } |
| 524 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 525 | @Override |
| 526 | public void pokeDrawLock(IBinder window) { |
| 527 | final long identity = Binder.clearCallingIdentity(); |
| 528 | try { |
| 529 | mService.pokeDrawLock(this, window); |
| 530 | } finally { |
| 531 | Binder.restoreCallingIdentity(identity); |
| 532 | } |
| 533 | } |
| 534 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 535 | @Override |
| 536 | public void updatePointerIcon(IWindow window) { |
| 537 | final long identity = Binder.clearCallingIdentity(); |
| 538 | try { |
| 539 | mService.updatePointerIcon(window); |
| 540 | } finally { |
| 541 | Binder.restoreCallingIdentity(identity); |
| 542 | } |
| 543 | } |
| 544 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 545 | void windowAddedLocked() { |
| 546 | if (mSurfaceSession == null) { |
| 547 | if (WindowManagerService.localLOGV) Slog.v( |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 548 | TAG_WM, "First window added to " + this + ", creating SurfaceSession"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 549 | mSurfaceSession = new SurfaceSession(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 550 | if (SHOW_TRANSACTIONS) Slog.i( |
| 551 | TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 552 | mService.mSessions.add(this); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 553 | if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) { |
| 554 | mService.dispatchNewAnimatorScaleLocked(this); |
| 555 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 556 | } |
| 557 | mNumWindow++; |
| 558 | } |
| 559 | |
| 560 | void windowRemovedLocked() { |
| 561 | mNumWindow--; |
| 562 | killSessionLocked(); |
| 563 | } |
| 564 | |
| 565 | void killSessionLocked() { |
| 566 | if (mNumWindow <= 0 && mClientDead) { |
| 567 | mService.mSessions.remove(this); |
| 568 | if (mSurfaceSession != null) { |
| 569 | if (WindowManagerService.localLOGV) Slog.v( |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 570 | TAG_WM, "Last window removed from " + this |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 571 | + ", destroying " + mSurfaceSession); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 572 | if (SHOW_TRANSACTIONS) Slog.i( |
| 573 | TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 574 | try { |
| 575 | mSurfaceSession.kill(); |
| 576 | } catch (Exception e) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 577 | Slog.w(TAG_WM, "Exception thrown when killing surface session " |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 578 | + mSurfaceSession + " in session " + this |
| 579 | + ": " + e.toString()); |
| 580 | } |
| 581 | mSurfaceSession = null; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | void dump(PrintWriter pw, String prefix) { |
| 587 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 588 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 589 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 590 | } |
| 591 | |
| 592 | @Override |
| 593 | public String toString() { |
| 594 | return mStringName; |
| 595 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 596 | } |