blob: 08c0a4b013579a00e27b05a51386d3fc16b908d4 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
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
17package com.android.server.wm;
18
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080019import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
20import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
21import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
22import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080024
25import android.content.ClipData;
26import android.content.Context;
27import android.content.res.Configuration;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.os.Binder;
31import android.os.Bundle;
32import android.os.IBinder;
33import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070034import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035import android.os.RemoteException;
36import android.os.ServiceManager;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070037import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080038import android.util.Slog;
Craig Mautner6881a102012-07-27 13:04:51 -070039import android.view.Display;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080041import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044import android.view.InputChannel;
45import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047import android.view.SurfaceSession;
48import android.view.WindowManager;
49
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080050import com.android.internal.view.IInputContext;
51import com.android.internal.view.IInputMethodClient;
52import com.android.internal.view.IInputMethodManager;
53import com.android.server.wm.WindowManagerService.H;
54
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import 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 */
61final class Session extends IWindowSession.Stub
62 implements IBinder.DeathRecipient {
63 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070064 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065 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 Hackborneb94fa72014-06-03 17:48:12 -070073 float mLastReportedAnimatorScale;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
Dianne Hackborneb94fa72014-06-03 17:48:12 -070075 public Session(WindowManagerService service, IWindowSessionCallback callback,
76 IInputMethodClient client, IInputContext inputContext) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070078 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 mClient = client;
80 mInputContext = inputContext;
81 mUid = Binder.getCallingUid();
82 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070083 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080084 StringBuilder sb = new StringBuilder();
85 sb.append("Session{");
86 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070087 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 Hackborn6e1eb762011-02-17 16:07:28 -080098 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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800140 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 }
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 Mautner6881a102012-07-27 13:04:51 -0700162 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700163 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100164 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
165 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700166 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700167 outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 }
Craig Mautner6881a102012-07-27 13:04:51 -0700169
170 @Override
171 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100172 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700173 Rect outOutsets, InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700174 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700175 outContentInsets, outStableInsets, outOutsets, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700176 }
177
178 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700179 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100180 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700181 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100182 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700183 }
184
185 @Override
186 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100187 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700188 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700189 outContentInsets, outStableInsets, null /* outOutsets */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 }
191
192 public void remove(IWindow window) {
193 mService.removeWindow(this, window);
194 }
195
Rob Carr64e516f2015-10-29 00:20:45 +0000196 @Override
Robert Carr64aadd02015-11-06 13:54:20 -0800197 public void repositionChild(IWindow window, int left, int top, int right, int bottom,
Chong Zhang61362732016-03-21 16:13:10 -0700198 long deferTransactionUntilFrame, Rect outFrame) {
Robert Carr64aadd02015-11-06 13:54:20 -0800199 mService.repositionChild(this, window, left, top, right, bottom,
200 deferTransactionUntilFrame, outFrame);
Rob Carr64e516f2015-10-29 00:20:45 +0000201 }
202
Robert Carr23fa16b2016-01-13 13:19:58 -0800203 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700204 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
205 mService.setReplacingWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800206 }
207
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700208 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800210 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800211 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
212 Configuration outConfig, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800213 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700214 + Binder.getCallingPid());
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700215 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800216 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800217 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800218 outStableInsets, outsets, outBackdropFrame, outConfig, outSurface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800219 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700220 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 return res;
222 }
223
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800224 public void performDeferredDestroy(IWindow window) {
225 mService.performDeferredDestroyWindow(this, window);
226 }
227
Dianne Hackborn64825172011-03-02 21:32:58 -0800228 public boolean outOfMemory(IWindow window) {
229 return mService.outOfMemoryWindow(this, window);
230 }
231
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 public void setTransparentRegion(IWindow window, Region region) {
233 mService.setTransparentRegionWindow(this, window, region);
234 }
235
236 public void setInsets(IWindow window, int touchableInsets,
237 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
238 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
239 visibleInsets, touchableArea);
240 }
241
242 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
243 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
244 }
245
246 public void finishDrawing(IWindow window) {
247 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800248 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 mService.finishDrawingWindow(this, window);
250 }
251
252 public void setInTouchMode(boolean mode) {
253 synchronized(mService.mWindowMap) {
254 mService.mInTouchMode = mode;
255 }
256 }
257
258 public boolean getInTouchMode() {
259 synchronized(mService.mWindowMap) {
260 return mService.mInTouchMode;
261 }
262 }
263
264 public boolean performHapticFeedback(IWindow window, int effectId,
265 boolean always) {
266 synchronized(mService.mWindowMap) {
267 long ident = Binder.clearCallingIdentity();
268 try {
269 return mService.mPolicy.performHapticFeedbackLw(
270 mService.windowForClientLocked(this, window, true),
271 effectId, always);
272 } finally {
273 Binder.restoreCallingIdentity(ident);
274 }
275 }
276 }
277
278 /* Drag/drop */
279 public IBinder prepareDrag(IWindow window, int flags,
280 int width, int height, Surface outSurface) {
281 return mService.prepareDragSurface(window, mSurfaceSession, flags,
282 width, height, outSurface);
283 }
284
285 public boolean performDrag(IWindow window, IBinder dragToken,
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800286 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 ClipData data) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800288 if (DEBUG_DRAG) {
289 Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 }
291
292 synchronized (mService.mWindowMap) {
293 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800294 Slog.w(TAG_WM, "No drag prepared");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 throw new IllegalStateException("performDrag() without prepareDrag()");
296 }
297
298 if (dragToken != mService.mDragState.mToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800299 Slog.w(TAG_WM, "Performing mismatched drag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 throw new IllegalStateException("performDrag() does not match prepareDrag()");
301 }
302
303 WindowState callingWin = mService.windowForClientLocked(null, window, false);
304 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800305 Slog.w(TAG_WM, "Bad requesting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 return false; // !!! TODO: throw here?
307 }
308
309 // !!! TODO: if input is not still focused on the initiating window, fail
310 // the drag initiation (e.g. an alarm window popped up just as the application
311 // called performDrag()
312
313 mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
314
315 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
316 // will let us eliminate the (touchX,touchY) parameters from the API.
317
318 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
319 // the actual drag event dispatch stuff in the dragstate
320
Craig Mautnerdf88d732014-01-27 09:21:32 -0800321 final DisplayContent displayContent = callingWin.getDisplayContent();
322 if (displayContent == null) {
323 return false;
324 }
325 Display display = displayContent.getDisplay();
Jeff Brown14a9f2b2012-09-24 14:36:44 -0700326 mService.mDragState.register(display);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
328 if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
329 mService.mDragState.mServerChannel)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800330 Slog.e(TAG_WM, "Unable to transfer touch focus");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 mService.mDragState.unregister();
332 mService.mDragState = null;
333 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
334 return false;
335 }
336
337 mService.mDragState.mData = data;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 mService.mDragState.broadcastDragStartedLw(touchX, touchY);
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800339 mService.mDragState.overridePointerIconLw(touchSource);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340
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 Agopian29479eb2013-02-14 14:36:04 -0800346 final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800347 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
348 TAG_WM, ">>> OPEN TRANSACTION performDrag");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800349 SurfaceControl.openTransaction();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800351 surfaceControl.setPosition(touchX - thumbCenterX,
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700352 touchY - thumbCenterY);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800353 surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
354 surfaceControl.setLayerStack(display.getLayerStack());
355 surfaceControl.show();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357 SurfaceControl.closeTransaction();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800358 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
359 TAG_WM, "<<< CLOSE TRANSACTION performDrag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 }
Vladislav Kaznacheevd0ed8932016-01-15 15:37:05 -0800361
362 mService.mDragState.notifyLocationLw(touchX, touchY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 }
364
365 return true; // success!
366 }
367
Chong Zhang8e89b312015-09-09 15:09:30 -0700368 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800369 if (DEBUG_TASK_POSITIONING) Slog.d(
370 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700371
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800372 long ident = Binder.clearCallingIdentity();
373 try {
374 return mService.startMovingTask(window, startX, startY);
375 } finally {
376 Binder.restoreCallingIdentity(ident);
377 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700378 }
379
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800380 public void reportDropResult(IWindow window, boolean consumed) {
381 IBinder token = window.asBinder();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800382 if (DEBUG_DRAG) {
383 Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 }
385
386 synchronized (mService.mWindowMap) {
387 long ident = Binder.clearCallingIdentity();
388 try {
Christopher Tate05e9c652011-10-20 12:34:36 -0700389 if (mService.mDragState == null) {
390 // Most likely the drop recipient ANRed and we ended the drag
391 // out from under it. Log the issue and move on.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800392 Slog.w(TAG_WM, "Drop result given but no drag in progress");
Christopher Tate05e9c652011-10-20 12:34:36 -0700393 return;
394 }
395
396 if (mService.mDragState.mToken != token) {
397 // We're in a drag, but the wrong window has responded.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800398 Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 throw new IllegalStateException("reportDropResult() by non-recipient");
400 }
401
402 // The right window has responded, even if it's no longer around,
403 // so be sure to halt the timeout even if the later WindowState
404 // lookup fails.
405 mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
406 WindowState callingWin = mService.windowForClientLocked(null, window, false);
407 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800408 Slog.w(TAG_WM, "Bad result-reporting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409 return; // !!! TODO: throw here?
410 }
411
412 mService.mDragState.mDragResult = consumed;
413 mService.mDragState.endDragLw();
414 } finally {
415 Binder.restoreCallingIdentity(ident);
416 }
417 }
418 }
419
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800420 public void cancelDragAndDrop(IBinder dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800421 if (DEBUG_DRAG) {
422 Slog.d(TAG_WM, "cancelDragAndDrop");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800423 }
424
425 synchronized (mService.mWindowMap) {
426 long ident = Binder.clearCallingIdentity();
427 try {
428 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800429 Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800430 throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()");
431 }
432
433 if (mService.mDragState.mToken != dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800434 Slog.w(TAG_WM,
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800435 "cancelDragAndDrop() does not match prepareDrag()");
436 throw new IllegalStateException(
437 "cancelDragAndDrop() does not match prepareDrag()");
438 }
439
440 mService.mDragState.mDragResult = false;
Vladislav Kaznacheevce2aef92015-11-20 18:49:59 -0800441 mService.mDragState.cancelDragLw();
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800442 } finally {
443 Binder.restoreCallingIdentity(ident);
444 }
445 }
446 }
447
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 public void dragRecipientEntered(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800449 if (DEBUG_DRAG) {
450 Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 }
452 }
453
454 public void dragRecipientExited(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800455 if (DEBUG_DRAG) {
456 Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 }
458 }
459
460 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
461 synchronized(mService.mWindowMap) {
462 long ident = Binder.clearCallingIdentity();
463 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700464 mService.mWallpaperControllerLocked.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 mService.windowForClientLocked(this, window, true),
466 x, y, xStep, yStep);
467 } finally {
468 Binder.restoreCallingIdentity(ident);
469 }
470 }
471 }
472
473 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700474 synchronized (mService.mWindowMap) {
475 mService.mWallpaperControllerLocked.wallpaperOffsetsComplete(window);
476 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 }
478
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700479 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
480 synchronized(mService.mWindowMap) {
481 long ident = Binder.clearCallingIdentity();
482 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700483 mService.mWallpaperControllerLocked.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700484 mService.windowForClientLocked(this, window, true), x, y);
485 } finally {
486 Binder.restoreCallingIdentity(ident);
487 }
488 }
489 }
490
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
492 int z, Bundle extras, boolean sync) {
493 synchronized(mService.mWindowMap) {
494 long ident = Binder.clearCallingIdentity();
495 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700496 return mService.mWallpaperControllerLocked.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 mService.windowForClientLocked(this, window, true),
498 action, x, y, z, extras, sync);
499 } finally {
500 Binder.restoreCallingIdentity(ident);
501 }
502 }
503 }
504
505 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700506 synchronized (mService.mWindowMap) {
507 mService.mWallpaperControllerLocked.wallpaperCommandComplete(window);
508 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 }
510
Svetoslavf7174e82014-06-12 11:29:35 -0700511 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700512 synchronized(mService.mWindowMap) {
513 final long identity = Binder.clearCallingIdentity();
514 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700515 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700516 } finally {
517 Binder.restoreCallingIdentity(identity);
518 }
519 }
520 }
521
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800522 public IWindowId getWindowId(IBinder window) {
523 return mService.getWindowId(window);
524 }
525
Jeff Brownc2932a12014-11-20 18:04:05 -0800526 @Override
527 public void pokeDrawLock(IBinder window) {
528 final long identity = Binder.clearCallingIdentity();
529 try {
530 mService.pokeDrawLock(this, window);
531 } finally {
532 Binder.restoreCallingIdentity(identity);
533 }
534 }
535
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800536 @Override
537 public void updatePointerIcon(IWindow window) {
538 final long identity = Binder.clearCallingIdentity();
539 try {
540 mService.updatePointerIcon(window);
541 } finally {
542 Binder.restoreCallingIdentity(identity);
543 }
544 }
545
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 void windowAddedLocked() {
547 if (mSurfaceSession == null) {
548 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800549 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800551 if (SHOW_TRANSACTIONS) Slog.i(
552 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700554 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
555 mService.dispatchNewAnimatorScaleLocked(this);
556 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 }
558 mNumWindow++;
559 }
560
561 void windowRemovedLocked() {
562 mNumWindow--;
563 killSessionLocked();
564 }
565
566 void killSessionLocked() {
567 if (mNumWindow <= 0 && mClientDead) {
568 mService.mSessions.remove(this);
569 if (mSurfaceSession != null) {
570 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800571 TAG_WM, "Last window removed from " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800572 + ", destroying " + mSurfaceSession);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800573 if (SHOW_TRANSACTIONS) Slog.i(
574 TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800575 try {
576 mSurfaceSession.kill();
577 } catch (Exception e) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800578 Slog.w(TAG_WM, "Exception thrown when killing surface session "
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 + mSurfaceSession + " in session " + this
580 + ": " + e.toString());
581 }
582 mSurfaceSession = null;
583 }
584 }
585 }
586
587 void dump(PrintWriter pw, String prefix) {
588 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
589 pw.print(" mClientDead="); pw.print(mClientDead);
590 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
591 }
592
593 @Override
594 public String toString() {
595 return mStringName;
596 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700597}