blob: ead70e184e5c87eada639e948a1056f14ed9a7ef [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 */
Wale Ogunwalecfca2582016-10-19 09:53:25 -070061// Needs to be public and not final so we can mock during tests...sucks I know :(
62public class Session extends IWindowSession.Stub
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 implements IBinder.DeathRecipient {
64 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070065 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066 final IInputMethodClient mClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067 final int mUid;
68 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070069 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070071 private int mNumWindow = 0;
72 private boolean mClientDead = false;
73 private 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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080 mUid = Binder.getCallingUid();
81 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070082 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083 StringBuilder sb = new StringBuilder();
84 sb.append("Session{");
85 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070086 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 Hackborn6e1eb762011-02-17 16:07:28 -080097 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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800139 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 }
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 Mautner6881a102012-07-27 13:04:51 -0700161 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700162 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100163 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
164 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700165 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700166 outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 }
Craig Mautner6881a102012-07-27 13:04:51 -0700168
169 @Override
170 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100171 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700172 Rect outOutsets, InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700173 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700174 outContentInsets, outStableInsets, outOutsets, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700175 }
176
177 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700178 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100179 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700180 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100181 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700182 }
183
184 @Override
185 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100186 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700187 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700188 outContentInsets, outStableInsets, null /* outOutsets */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 }
190
191 public void remove(IWindow window) {
192 mService.removeWindow(this, window);
193 }
194
Rob Carr64e516f2015-10-29 00:20:45 +0000195 @Override
Robert Carr64aadd02015-11-06 13:54:20 -0800196 public void repositionChild(IWindow window, int left, int top, int right, int bottom,
Chong Zhang61362732016-03-21 16:13:10 -0700197 long deferTransactionUntilFrame, Rect outFrame) {
Robert Carr64aadd02015-11-06 13:54:20 -0800198 mService.repositionChild(this, window, left, top, right, bottom,
199 deferTransactionUntilFrame, outFrame);
Rob Carr64e516f2015-10-29 00:20:45 +0000200 }
201
Robert Carr23fa16b2016-01-13 13:19:58 -0800202 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700203 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700204 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800205 }
206
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700207 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800209 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800210 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
211 Configuration outConfig, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800212 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700213 + Binder.getCallingPid());
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700214 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800215 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800216 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800217 outStableInsets, outsets, outBackdropFrame, outConfig, outSurface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800218 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700219 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 return res;
221 }
222
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800223 public void performDeferredDestroy(IWindow window) {
224 mService.performDeferredDestroyWindow(this, window);
225 }
226
Dianne Hackborn64825172011-03-02 21:32:58 -0800227 public boolean outOfMemory(IWindow window) {
228 return mService.outOfMemoryWindow(this, window);
229 }
230
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800247 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 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 Kaznacheevba761122016-01-22 12:09:45 -0800285 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 ClipData data) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800287 if (DEBUG_DRAG) {
288 Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 }
290
291 synchronized (mService.mWindowMap) {
292 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800293 Slog.w(TAG_WM, "No drag prepared");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 throw new IllegalStateException("performDrag() without prepareDrag()");
295 }
296
297 if (dragToken != mService.mDragState.mToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800298 Slog.w(TAG_WM, "Performing mismatched drag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 throw new IllegalStateException("performDrag() does not match prepareDrag()");
300 }
301
302 WindowState callingWin = mService.windowForClientLocked(null, window, false);
303 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800304 Slog.w(TAG_WM, "Bad requesting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 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 Mautnerdf88d732014-01-27 09:21:32 -0800320 final DisplayContent displayContent = callingWin.getDisplayContent();
321 if (displayContent == null) {
322 return false;
323 }
324 Display display = displayContent.getDisplay();
Jeff Brown14a9f2b2012-09-24 14:36:44 -0700325 mService.mDragState.register(display);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700327 mService.mDragState.getInputChannel())) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800328 Slog.e(TAG_WM, "Unable to transfer touch focus");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 mService.mDragState.unregister();
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700330 mService.mDragState.reset();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 mService.mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 return false;
333 }
334
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700335 mService.mDragState.mDisplayContent = displayContent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 mService.mDragState.mData = data;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 mService.mDragState.broadcastDragStartedLw(touchX, touchY);
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800338 mService.mDragState.overridePointerIconLw(touchSource);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339
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 Agopian29479eb2013-02-14 14:36:04 -0800345 final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800346 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
347 TAG_WM, ">>> OPEN TRANSACTION performDrag");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700348 mService.openSurfaceTransaction();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800350 surfaceControl.setPosition(touchX - thumbCenterX,
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700351 touchY - thumbCenterY);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800352 surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
353 surfaceControl.setLayerStack(display.getLayerStack());
354 surfaceControl.show();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700356 mService.closeSurfaceTransaction();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800357 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
358 TAG_WM, "<<< CLOSE TRANSACTION performDrag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 }
Vladislav Kaznacheevd0ed8932016-01-15 15:37:05 -0800360
361 mService.mDragState.notifyLocationLw(touchX, touchY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 }
363
364 return true; // success!
365 }
366
Chong Zhang8e89b312015-09-09 15:09:30 -0700367 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800368 if (DEBUG_TASK_POSITIONING) Slog.d(
369 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700370
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800371 long ident = Binder.clearCallingIdentity();
372 try {
373 return mService.startMovingTask(window, startX, startY);
374 } finally {
375 Binder.restoreCallingIdentity(ident);
376 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700377 }
378
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800379 public void reportDropResult(IWindow window, boolean consumed) {
380 IBinder token = window.asBinder();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800381 if (DEBUG_DRAG) {
382 Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 }
384
385 synchronized (mService.mWindowMap) {
386 long ident = Binder.clearCallingIdentity();
387 try {
Christopher Tate05e9c652011-10-20 12:34:36 -0700388 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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800391 Slog.w(TAG_WM, "Drop result given but no drag in progress");
Christopher Tate05e9c652011-10-20 12:34:36 -0700392 return;
393 }
394
395 if (mService.mDragState.mToken != token) {
396 // We're in a drag, but the wrong window has responded.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800397 Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800407 Slog.w(TAG_WM, "Bad result-reporting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 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 Kaznacheev82063912015-11-20 14:20:13 -0800419 public void cancelDragAndDrop(IBinder dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800420 if (DEBUG_DRAG) {
421 Slog.d(TAG_WM, "cancelDragAndDrop");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800422 }
423
424 synchronized (mService.mWindowMap) {
425 long ident = Binder.clearCallingIdentity();
426 try {
427 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800428 Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800429 throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()");
430 }
431
432 if (mService.mDragState.mToken != dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800433 Slog.w(TAG_WM,
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800434 "cancelDragAndDrop() does not match prepareDrag()");
435 throw new IllegalStateException(
436 "cancelDragAndDrop() does not match prepareDrag()");
437 }
438
439 mService.mDragState.mDragResult = false;
Vladislav Kaznacheevce2aef92015-11-20 18:49:59 -0800440 mService.mDragState.cancelDragLw();
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800441 } finally {
442 Binder.restoreCallingIdentity(ident);
443 }
444 }
445 }
446
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 public void dragRecipientEntered(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800448 if (DEBUG_DRAG) {
449 Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450 }
451 }
452
453 public void dragRecipientExited(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800454 if (DEBUG_DRAG) {
455 Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 }
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 Ogunwale0303c572016-10-20 10:16:29 -0700463 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 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 Ogunwalee8069dc2015-08-18 09:52:01 -0700473 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700474 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700475 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 }
477
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700478 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
479 synchronized(mService.mWindowMap) {
480 long ident = Binder.clearCallingIdentity();
481 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700482 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700483 mService.windowForClientLocked(this, window, true), x, y);
484 } finally {
485 Binder.restoreCallingIdentity(ident);
486 }
487 }
488 }
489
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490 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 Ogunwale0303c572016-10-20 10:16:29 -0700495 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 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 Ogunwalee8069dc2015-08-18 09:52:01 -0700505 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700506 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700507 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 }
509
Svetoslavf7174e82014-06-12 11:29:35 -0700510 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700511 synchronized(mService.mWindowMap) {
512 final long identity = Binder.clearCallingIdentity();
513 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700514 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700515 } finally {
516 Binder.restoreCallingIdentity(identity);
517 }
518 }
519 }
520
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800521 public IWindowId getWindowId(IBinder window) {
522 return mService.getWindowId(window);
523 }
524
Jeff Brownc2932a12014-11-20 18:04:05 -0800525 @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 Kaznacheev989b58a2016-02-10 12:19:33 -0800535 @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 Hackborn6e1eb762011-02-17 16:07:28 -0800545 void windowAddedLocked() {
546 if (mSurfaceSession == null) {
547 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800548 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800549 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800550 if (SHOW_TRANSACTIONS) Slog.i(
551 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800552 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700553 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
554 mService.dispatchNewAnimatorScaleLocked(this);
555 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 }
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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800570 TAG_WM, "Last window removed from " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800571 + ", destroying " + mSurfaceSession);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800572 if (SHOW_TRANSACTIONS) Slog.i(
573 TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 try {
575 mSurfaceSession.kill();
576 } catch (Exception e) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800577 Slog.w(TAG_WM, "Exception thrown when killing surface session "
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800578 + 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 Gruszczynski2217f612015-05-26 11:32:08 -0700596}