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