blob: 1b6957d9e5541cc524d7e066fd04ac407842a5b3 [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,
198 long deferTransactionUntilFrame, Rect outFrame) {
199 mService.repositionChild(this, window, left, top, right, bottom,
200 deferTransactionUntilFrame, outFrame);
Rob Carr64e516f2015-10-29 00:20:45 +0000201 }
202
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700203 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800205 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700206 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Configuration
207 outConfig,
Adrian Roosfa104232014-06-20 16:10:14 -0700208 Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800209 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700210 + Binder.getCallingPid());
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700211 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800212 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800213 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700214 outStableInsets, outsets, outConfig, outSurface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800215 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700216 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 return res;
218 }
219
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800220 public void performDeferredDestroy(IWindow window) {
221 mService.performDeferredDestroyWindow(this, window);
222 }
223
Dianne Hackborn64825172011-03-02 21:32:58 -0800224 public boolean outOfMemory(IWindow window) {
225 return mService.outOfMemoryWindow(this, window);
226 }
227
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 public void setTransparentRegion(IWindow window, Region region) {
229 mService.setTransparentRegionWindow(this, window, region);
230 }
231
232 public void setInsets(IWindow window, int touchableInsets,
233 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
234 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
235 visibleInsets, touchableArea);
236 }
237
238 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
239 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
240 }
241
242 public void finishDrawing(IWindow window) {
243 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800244 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 mService.finishDrawingWindow(this, window);
246 }
247
248 public void setInTouchMode(boolean mode) {
249 synchronized(mService.mWindowMap) {
250 mService.mInTouchMode = mode;
251 }
252 }
253
254 public boolean getInTouchMode() {
255 synchronized(mService.mWindowMap) {
256 return mService.mInTouchMode;
257 }
258 }
259
260 public boolean performHapticFeedback(IWindow window, int effectId,
261 boolean always) {
262 synchronized(mService.mWindowMap) {
263 long ident = Binder.clearCallingIdentity();
264 try {
265 return mService.mPolicy.performHapticFeedbackLw(
266 mService.windowForClientLocked(this, window, true),
267 effectId, always);
268 } finally {
269 Binder.restoreCallingIdentity(ident);
270 }
271 }
272 }
273
274 /* Drag/drop */
275 public IBinder prepareDrag(IWindow window, int flags,
276 int width, int height, Surface outSurface) {
277 return mService.prepareDragSurface(window, mSurfaceSession, flags,
278 width, height, outSurface);
279 }
280
281 public boolean performDrag(IWindow window, IBinder dragToken,
282 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
283 ClipData data) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800284 if (DEBUG_DRAG) {
285 Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 }
287
288 synchronized (mService.mWindowMap) {
289 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800290 Slog.w(TAG_WM, "No drag prepared");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 throw new IllegalStateException("performDrag() without prepareDrag()");
292 }
293
294 if (dragToken != mService.mDragState.mToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800295 Slog.w(TAG_WM, "Performing mismatched drag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 throw new IllegalStateException("performDrag() does not match prepareDrag()");
297 }
298
299 WindowState callingWin = mService.windowForClientLocked(null, window, false);
300 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800301 Slog.w(TAG_WM, "Bad requesting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 return false; // !!! TODO: throw here?
303 }
304
305 // !!! TODO: if input is not still focused on the initiating window, fail
306 // the drag initiation (e.g. an alarm window popped up just as the application
307 // called performDrag()
308
309 mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
310
311 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
312 // will let us eliminate the (touchX,touchY) parameters from the API.
313
314 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
315 // the actual drag event dispatch stuff in the dragstate
316
Craig Mautnerdf88d732014-01-27 09:21:32 -0800317 final DisplayContent displayContent = callingWin.getDisplayContent();
318 if (displayContent == null) {
319 return false;
320 }
321 Display display = displayContent.getDisplay();
Jeff Brown14a9f2b2012-09-24 14:36:44 -0700322 mService.mDragState.register(display);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
324 if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
325 mService.mDragState.mServerChannel)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800326 Slog.e(TAG_WM, "Unable to transfer touch focus");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 mService.mDragState.unregister();
328 mService.mDragState = null;
329 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
330 return false;
331 }
332
333 mService.mDragState.mData = data;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 mService.mDragState.broadcastDragStartedLw(touchX, touchY);
335
336 // remember the thumb offsets for later
337 mService.mDragState.mThumbOffsetX = thumbCenterX;
338 mService.mDragState.mThumbOffsetY = thumbCenterY;
339
340 // Make the surface visible at the proper location
Mathias Agopian29479eb2013-02-14 14:36:04 -0800341 final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800342 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
343 TAG_WM, ">>> OPEN TRANSACTION performDrag");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800344 SurfaceControl.openTransaction();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800346 surfaceControl.setPosition(touchX - thumbCenterX,
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700347 touchY - thumbCenterY);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800348 surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
349 surfaceControl.setLayerStack(display.getLayerStack());
350 surfaceControl.show();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800352 SurfaceControl.closeTransaction();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800353 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
354 TAG_WM, "<<< CLOSE TRANSACTION performDrag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 }
356 }
357
358 return true; // success!
359 }
360
Chong Zhang8e89b312015-09-09 15:09:30 -0700361 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800362 if (DEBUG_TASK_POSITIONING) Slog.d(
363 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700364
365 return mService.startMovingTask(window, startX, startY);
366 }
367
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 public void reportDropResult(IWindow window, boolean consumed) {
369 IBinder token = window.asBinder();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800370 if (DEBUG_DRAG) {
371 Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 }
373
374 synchronized (mService.mWindowMap) {
375 long ident = Binder.clearCallingIdentity();
376 try {
Christopher Tate05e9c652011-10-20 12:34:36 -0700377 if (mService.mDragState == null) {
378 // Most likely the drop recipient ANRed and we ended the drag
379 // out from under it. Log the issue and move on.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800380 Slog.w(TAG_WM, "Drop result given but no drag in progress");
Christopher Tate05e9c652011-10-20 12:34:36 -0700381 return;
382 }
383
384 if (mService.mDragState.mToken != token) {
385 // We're in a drag, but the wrong window has responded.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800386 Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 throw new IllegalStateException("reportDropResult() by non-recipient");
388 }
389
390 // The right window has responded, even if it's no longer around,
391 // so be sure to halt the timeout even if the later WindowState
392 // lookup fails.
393 mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
394 WindowState callingWin = mService.windowForClientLocked(null, window, false);
395 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800396 Slog.w(TAG_WM, "Bad result-reporting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 return; // !!! TODO: throw here?
398 }
399
400 mService.mDragState.mDragResult = consumed;
401 mService.mDragState.endDragLw();
402 } finally {
403 Binder.restoreCallingIdentity(ident);
404 }
405 }
406 }
407
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800408 public void cancelDragAndDrop(IBinder dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800409 if (DEBUG_DRAG) {
410 Slog.d(TAG_WM, "cancelDragAndDrop");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800411 }
412
413 synchronized (mService.mWindowMap) {
414 long ident = Binder.clearCallingIdentity();
415 try {
416 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800417 Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800418 throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()");
419 }
420
421 if (mService.mDragState.mToken != dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800422 Slog.w(TAG_WM,
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800423 "cancelDragAndDrop() does not match prepareDrag()");
424 throw new IllegalStateException(
425 "cancelDragAndDrop() does not match prepareDrag()");
426 }
427
428 mService.mDragState.mDragResult = false;
Vladislav Kaznacheevce2aef92015-11-20 18:49:59 -0800429 mService.mDragState.cancelDragLw();
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800430 } finally {
431 Binder.restoreCallingIdentity(ident);
432 }
433 }
434 }
435
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 public void dragRecipientEntered(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800437 if (DEBUG_DRAG) {
438 Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 }
440 }
441
442 public void dragRecipientExited(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800443 if (DEBUG_DRAG) {
444 Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445 }
446 }
447
448 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
449 synchronized(mService.mWindowMap) {
450 long ident = Binder.clearCallingIdentity();
451 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700452 mService.mWallpaperControllerLocked.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 mService.windowForClientLocked(this, window, true),
454 x, y, xStep, yStep);
455 } finally {
456 Binder.restoreCallingIdentity(ident);
457 }
458 }
459 }
460
461 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700462 synchronized (mService.mWindowMap) {
463 mService.mWallpaperControllerLocked.wallpaperOffsetsComplete(window);
464 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 }
466
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700467 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
468 synchronized(mService.mWindowMap) {
469 long ident = Binder.clearCallingIdentity();
470 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700471 mService.mWallpaperControllerLocked.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700472 mService.windowForClientLocked(this, window, true), x, y);
473 } finally {
474 Binder.restoreCallingIdentity(ident);
475 }
476 }
477 }
478
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
480 int z, Bundle extras, boolean sync) {
481 synchronized(mService.mWindowMap) {
482 long ident = Binder.clearCallingIdentity();
483 try {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700484 return mService.mWallpaperControllerLocked.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 mService.windowForClientLocked(this, window, true),
486 action, x, y, z, extras, sync);
487 } finally {
488 Binder.restoreCallingIdentity(ident);
489 }
490 }
491 }
492
493 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700494 synchronized (mService.mWindowMap) {
495 mService.mWallpaperControllerLocked.wallpaperCommandComplete(window);
496 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 }
498
Svetoslavf7174e82014-06-12 11:29:35 -0700499 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700500 synchronized(mService.mWindowMap) {
501 final long identity = Binder.clearCallingIdentity();
502 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700503 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700504 } finally {
505 Binder.restoreCallingIdentity(identity);
506 }
507 }
508 }
509
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800510 public IWindowId getWindowId(IBinder window) {
511 return mService.getWindowId(window);
512 }
513
Jeff Brownc2932a12014-11-20 18:04:05 -0800514 @Override
515 public void pokeDrawLock(IBinder window) {
516 final long identity = Binder.clearCallingIdentity();
517 try {
518 mService.pokeDrawLock(this, window);
519 } finally {
520 Binder.restoreCallingIdentity(identity);
521 }
522 }
523
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 void windowAddedLocked() {
525 if (mSurfaceSession == null) {
526 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800527 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800529 if (SHOW_TRANSACTIONS) Slog.i(
530 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800531 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700532 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
533 mService.dispatchNewAnimatorScaleLocked(this);
534 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800535 }
536 mNumWindow++;
537 }
538
539 void windowRemovedLocked() {
540 mNumWindow--;
541 killSessionLocked();
542 }
543
544 void killSessionLocked() {
545 if (mNumWindow <= 0 && mClientDead) {
546 mService.mSessions.remove(this);
547 if (mSurfaceSession != null) {
548 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800549 TAG_WM, "Last window removed from " + this
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550 + ", destroying " + mSurfaceSession);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800551 if (SHOW_TRANSACTIONS) Slog.i(
552 TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553 try {
554 mSurfaceSession.kill();
555 } catch (Exception e) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800556 Slog.w(TAG_WM, "Exception thrown when killing surface session "
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 + mSurfaceSession + " in session " + this
558 + ": " + e.toString());
559 }
560 mSurfaceSession = null;
561 }
562 }
563 }
564
565 void dump(PrintWriter pw, String prefix) {
566 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
567 pw.print(" mClientDead="); pw.print(mClientDead);
568 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
569 }
570
571 @Override
572 public String toString() {
573 return mStringName;
574 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700575}