blob: e6fd0abf21727fb3260ec2ab5c50399097a30855 [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
Wale Ogunwale943002b2017-02-15 19:34:01 -080019import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
20import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Wale Ogunwaled993a572017-02-05 13:52:09 -080021import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Wale Ogunwale943002b2017-02-15 19:34:01 -080022import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080023import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
24import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
25import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
26import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
27import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028
29import android.content.ClipData;
30import android.content.Context;
31import android.content.res.Configuration;
32import android.graphics.Rect;
33import android.graphics.Region;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.IBinder;
37import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070038import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.os.RemoteException;
40import android.os.ServiceManager;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070041import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.util.Slog;
Craig Mautner6881a102012-07-27 13:04:51 -070043import android.view.Display;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080044import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080047import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048import android.view.InputChannel;
49import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080050import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051import android.view.SurfaceSession;
52import android.view.WindowManager;
53
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080054import com.android.internal.view.IInputContext;
55import com.android.internal.view.IInputMethodClient;
56import com.android.internal.view.IInputMethodManager;
57import com.android.server.wm.WindowManagerService.H;
58
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059import java.io.PrintWriter;
Wale Ogunwale943002b2017-02-15 19:34:01 -080060import java.util.HashSet;
61import java.util.Set;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062
63/**
64 * This class represents an active client session. There is generally one
65 * Session object per process that is interacting with the window manager.
66 */
Wale Ogunwalecfca2582016-10-19 09:53:25 -070067// Needs to be public and not final so we can mock during tests...sucks I know :(
68public class Session extends IWindowSession.Stub
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069 implements IBinder.DeathRecipient {
70 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070071 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 final IInputMethodClient mClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 final int mUid;
74 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070075 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070077 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080078 // Set of visible application overlay window surfaces connected to this session.
79 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
80 // Set of visible alert window surfaces connected to this session.
81 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
82 final boolean mCanAddInternalSystemWindow;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070083 private boolean mClientDead = false;
84 private float mLastReportedAnimatorScale;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080085
Dianne Hackborneb94fa72014-06-03 17:48:12 -070086 public Session(WindowManagerService service, IWindowSessionCallback callback,
87 IInputMethodClient client, IInputContext inputContext) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070089 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090 mClient = client;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 mUid = Binder.getCallingUid();
92 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070093 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale943002b2017-02-15 19:34:01 -080094 mCanAddInternalSystemWindow = service.mContext.checkCallingPermission(
95 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 StringBuilder sb = new StringBuilder();
97 sb.append("Session{");
98 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070099 sb.append(" ");
100 sb.append(mPid);
101 if (mUid < Process.FIRST_APPLICATION_UID) {
102 sb.append(":");
103 sb.append(mUid);
104 } else {
105 sb.append(":u");
106 sb.append(UserHandle.getUserId(mUid));
107 sb.append('a');
108 sb.append(UserHandle.getAppId(mUid));
109 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 sb.append("}");
111 mStringName = sb.toString();
112
113 synchronized (mService.mWindowMap) {
114 if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
115 IBinder b = ServiceManager.getService(
116 Context.INPUT_METHOD_SERVICE);
117 mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
118 }
119 }
120 long ident = Binder.clearCallingIdentity();
121 try {
122 // Note: it is safe to call in to the input method manager
123 // here because we are not holding our lock.
124 if (mService.mInputMethodManager != null) {
125 mService.mInputMethodManager.addClient(client, inputContext,
126 mUid, mPid);
127 } else {
128 client.setUsingInputMethod(false);
129 }
130 client.asBinder().linkToDeath(this, 0);
131 } catch (RemoteException e) {
132 // The caller has died, so we can just forget about this.
133 try {
134 if (mService.mInputMethodManager != null) {
135 mService.mInputMethodManager.removeClient(client);
136 }
137 } catch (RemoteException ee) {
138 }
139 } finally {
140 Binder.restoreCallingIdentity(ident);
141 }
142 }
143
144 @Override
145 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
146 throws RemoteException {
147 try {
148 return super.onTransact(code, data, reply, flags);
149 } catch (RuntimeException e) {
150 // Log all 'real' exceptions thrown to the caller
151 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800152 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 }
154 throw e;
155 }
156 }
157
158 public void binderDied() {
159 // Note: it is safe to call in to the input method manager
160 // here because we are not holding our lock.
161 try {
162 if (mService.mInputMethodManager != null) {
163 mService.mInputMethodManager.removeClient(mClient);
164 }
165 } catch (RemoteException e) {
166 }
167 synchronized(mService.mWindowMap) {
168 mClient.asBinder().unlinkToDeath(this, 0);
169 mClientDead = true;
170 killSessionLocked();
171 }
172 }
173
Craig Mautner6881a102012-07-27 13:04:51 -0700174 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700175 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100176 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
177 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700178 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700179 outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 }
Craig Mautner6881a102012-07-27 13:04:51 -0700181
182 @Override
183 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100184 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700185 Rect outOutsets, InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700186 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700187 outContentInsets, outStableInsets, outOutsets, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700188 }
189
190 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700191 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100192 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700193 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100194 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700195 }
196
197 @Override
198 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100199 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700200 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700201 outContentInsets, outStableInsets, null /* outOutsets */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 }
203
204 public void remove(IWindow window) {
205 mService.removeWindow(this, window);
206 }
207
Rob Carr64e516f2015-10-29 00:20:45 +0000208 @Override
Robert Carr64aadd02015-11-06 13:54:20 -0800209 public void repositionChild(IWindow window, int left, int top, int right, int bottom,
Chong Zhang61362732016-03-21 16:13:10 -0700210 long deferTransactionUntilFrame, Rect outFrame) {
Robert Carr64aadd02015-11-06 13:54:20 -0800211 mService.repositionChild(this, window, left, top, right, bottom,
212 deferTransactionUntilFrame, outFrame);
Rob Carr64e516f2015-10-29 00:20:45 +0000213 }
214
Robert Carr23fa16b2016-01-13 13:19:58 -0800215 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700216 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700217 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800218 }
219
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700220 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800222 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800223 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
224 Configuration outConfig, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800225 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700226 + Binder.getCallingPid());
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700227 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800228 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800229 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800230 outStableInsets, outsets, outBackdropFrame, outConfig, outSurface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800231 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700232 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 return res;
234 }
235
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800236 public void performDeferredDestroy(IWindow window) {
237 mService.performDeferredDestroyWindow(this, window);
238 }
239
Dianne Hackborn64825172011-03-02 21:32:58 -0800240 public boolean outOfMemory(IWindow window) {
241 return mService.outOfMemoryWindow(this, window);
242 }
243
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 public void setTransparentRegion(IWindow window, Region region) {
245 mService.setTransparentRegionWindow(this, window, region);
246 }
247
248 public void setInsets(IWindow window, int touchableInsets,
249 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
250 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
251 visibleInsets, touchableArea);
252 }
253
254 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
255 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
256 }
257
258 public void finishDrawing(IWindow window) {
259 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800260 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 mService.finishDrawingWindow(this, window);
262 }
263
264 public void setInTouchMode(boolean mode) {
265 synchronized(mService.mWindowMap) {
266 mService.mInTouchMode = mode;
267 }
268 }
269
270 public boolean getInTouchMode() {
271 synchronized(mService.mWindowMap) {
272 return mService.mInTouchMode;
273 }
274 }
275
276 public boolean performHapticFeedback(IWindow window, int effectId,
277 boolean always) {
278 synchronized(mService.mWindowMap) {
279 long ident = Binder.clearCallingIdentity();
280 try {
281 return mService.mPolicy.performHapticFeedbackLw(
282 mService.windowForClientLocked(this, window, true),
283 effectId, always);
284 } finally {
285 Binder.restoreCallingIdentity(ident);
286 }
287 }
288 }
289
290 /* Drag/drop */
291 public IBinder prepareDrag(IWindow window, int flags,
292 int width, int height, Surface outSurface) {
293 return mService.prepareDragSurface(window, mSurfaceSession, flags,
294 width, height, outSurface);
295 }
296
297 public boolean performDrag(IWindow window, IBinder dragToken,
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800298 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 ClipData data) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800300 if (DEBUG_DRAG) {
301 Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 }
303
304 synchronized (mService.mWindowMap) {
305 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800306 Slog.w(TAG_WM, "No drag prepared");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 throw new IllegalStateException("performDrag() without prepareDrag()");
308 }
309
310 if (dragToken != mService.mDragState.mToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800311 Slog.w(TAG_WM, "Performing mismatched drag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 throw new IllegalStateException("performDrag() does not match prepareDrag()");
313 }
314
315 WindowState callingWin = mService.windowForClientLocked(null, window, false);
316 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800317 Slog.w(TAG_WM, "Bad requesting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 return false; // !!! TODO: throw here?
319 }
320
321 // !!! TODO: if input is not still focused on the initiating window, fail
322 // the drag initiation (e.g. an alarm window popped up just as the application
323 // called performDrag()
324
325 mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
326
327 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
328 // will let us eliminate the (touchX,touchY) parameters from the API.
329
330 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
331 // the actual drag event dispatch stuff in the dragstate
332
Craig Mautnerdf88d732014-01-27 09:21:32 -0800333 final DisplayContent displayContent = callingWin.getDisplayContent();
334 if (displayContent == null) {
335 return false;
336 }
337 Display display = displayContent.getDisplay();
Jeff Brown14a9f2b2012-09-24 14:36:44 -0700338 mService.mDragState.register(display);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700340 mService.mDragState.getInputChannel())) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800341 Slog.e(TAG_WM, "Unable to transfer touch focus");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 mService.mDragState.unregister();
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700343 mService.mDragState.reset();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 mService.mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 return false;
346 }
347
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700348 mService.mDragState.mDisplayContent = displayContent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 mService.mDragState.mData = data;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 mService.mDragState.broadcastDragStartedLw(touchX, touchY);
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800351 mService.mDragState.overridePointerIconLw(touchSource);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352
353 // remember the thumb offsets for later
354 mService.mDragState.mThumbOffsetX = thumbCenterX;
355 mService.mDragState.mThumbOffsetY = thumbCenterY;
356
357 // Make the surface visible at the proper location
Mathias Agopian29479eb2013-02-14 14:36:04 -0800358 final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800359 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
360 TAG_WM, ">>> OPEN TRANSACTION performDrag");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700361 mService.openSurfaceTransaction();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800363 surfaceControl.setPosition(touchX - thumbCenterX,
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700364 touchY - thumbCenterY);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800365 surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
366 surfaceControl.setLayerStack(display.getLayerStack());
367 surfaceControl.show();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700369 mService.closeSurfaceTransaction();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800370 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
371 TAG_WM, "<<< CLOSE TRANSACTION performDrag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 }
Vladislav Kaznacheevd0ed8932016-01-15 15:37:05 -0800373
374 mService.mDragState.notifyLocationLw(touchX, touchY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 }
376
377 return true; // success!
378 }
379
Chong Zhang8e89b312015-09-09 15:09:30 -0700380 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800381 if (DEBUG_TASK_POSITIONING) Slog.d(
382 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700383
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800384 long ident = Binder.clearCallingIdentity();
385 try {
386 return mService.startMovingTask(window, startX, startY);
387 } finally {
388 Binder.restoreCallingIdentity(ident);
389 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700390 }
391
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 public void reportDropResult(IWindow window, boolean consumed) {
393 IBinder token = window.asBinder();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800394 if (DEBUG_DRAG) {
395 Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 }
397
398 synchronized (mService.mWindowMap) {
399 long ident = Binder.clearCallingIdentity();
400 try {
Christopher Tate05e9c652011-10-20 12:34:36 -0700401 if (mService.mDragState == null) {
402 // Most likely the drop recipient ANRed and we ended the drag
403 // out from under it. Log the issue and move on.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800404 Slog.w(TAG_WM, "Drop result given but no drag in progress");
Christopher Tate05e9c652011-10-20 12:34:36 -0700405 return;
406 }
407
408 if (mService.mDragState.mToken != token) {
409 // We're in a drag, but the wrong window has responded.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800410 Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 throw new IllegalStateException("reportDropResult() by non-recipient");
412 }
413
414 // The right window has responded, even if it's no longer around,
415 // so be sure to halt the timeout even if the later WindowState
416 // lookup fails.
417 mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
418 WindowState callingWin = mService.windowForClientLocked(null, window, false);
419 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800420 Slog.w(TAG_WM, "Bad result-reporting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800421 return; // !!! TODO: throw here?
422 }
423
424 mService.mDragState.mDragResult = consumed;
425 mService.mDragState.endDragLw();
426 } finally {
427 Binder.restoreCallingIdentity(ident);
428 }
429 }
430 }
431
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800432 public void cancelDragAndDrop(IBinder dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800433 if (DEBUG_DRAG) {
434 Slog.d(TAG_WM, "cancelDragAndDrop");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800435 }
436
437 synchronized (mService.mWindowMap) {
438 long ident = Binder.clearCallingIdentity();
439 try {
440 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800441 Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800442 throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()");
443 }
444
445 if (mService.mDragState.mToken != dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800446 Slog.w(TAG_WM,
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800447 "cancelDragAndDrop() does not match prepareDrag()");
448 throw new IllegalStateException(
449 "cancelDragAndDrop() does not match prepareDrag()");
450 }
451
452 mService.mDragState.mDragResult = false;
Vladislav Kaznacheevce2aef92015-11-20 18:49:59 -0800453 mService.mDragState.cancelDragLw();
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800454 } finally {
455 Binder.restoreCallingIdentity(ident);
456 }
457 }
458 }
459
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 public void dragRecipientEntered(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800461 if (DEBUG_DRAG) {
462 Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 }
464 }
465
466 public void dragRecipientExited(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800467 if (DEBUG_DRAG) {
468 Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 }
470 }
471
472 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
473 synchronized(mService.mWindowMap) {
474 long ident = Binder.clearCallingIdentity();
475 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700476 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 mService.windowForClientLocked(this, window, true),
478 x, y, xStep, yStep);
479 } finally {
480 Binder.restoreCallingIdentity(ident);
481 }
482 }
483 }
484
485 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700486 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700487 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 }
490
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700491 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
492 synchronized(mService.mWindowMap) {
493 long ident = Binder.clearCallingIdentity();
494 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700495 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700496 mService.windowForClientLocked(this, window, true), x, y);
497 } finally {
498 Binder.restoreCallingIdentity(ident);
499 }
500 }
501 }
502
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
504 int z, Bundle extras, boolean sync) {
505 synchronized(mService.mWindowMap) {
506 long ident = Binder.clearCallingIdentity();
507 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700508 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 mService.windowForClientLocked(this, window, true),
510 action, x, y, z, extras, sync);
511 } finally {
512 Binder.restoreCallingIdentity(ident);
513 }
514 }
515 }
516
517 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700518 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700519 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700520 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521 }
522
Svetoslavf7174e82014-06-12 11:29:35 -0700523 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700524 synchronized(mService.mWindowMap) {
525 final long identity = Binder.clearCallingIdentity();
526 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700527 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700528 } finally {
529 Binder.restoreCallingIdentity(identity);
530 }
531 }
532 }
533
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800534 public IWindowId getWindowId(IBinder window) {
535 return mService.getWindowId(window);
536 }
537
Jeff Brownc2932a12014-11-20 18:04:05 -0800538 @Override
539 public void pokeDrawLock(IBinder window) {
540 final long identity = Binder.clearCallingIdentity();
541 try {
542 mService.pokeDrawLock(this, window);
543 } finally {
544 Binder.restoreCallingIdentity(identity);
545 }
546 }
547
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800548 @Override
549 public void updatePointerIcon(IWindow window) {
550 final long identity = Binder.clearCallingIdentity();
551 try {
552 mService.updatePointerIcon(window);
553 } finally {
554 Binder.restoreCallingIdentity(identity);
555 }
556 }
557
Wale Ogunwale943002b2017-02-15 19:34:01 -0800558 void windowAddedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 if (mSurfaceSession == null) {
560 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800561 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800563 if (SHOW_TRANSACTIONS) Slog.i(
564 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800565 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700566 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
567 mService.dispatchNewAnimatorScaleLocked(this);
568 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569 }
570 mNumWindow++;
571 }
572
Wale Ogunwale943002b2017-02-15 19:34:01 -0800573 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800575 killSessionLocked();
576 }
577
578
579 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
580 boolean visible, int type) {
581
582 if (!isSystemAlertWindowType(type)) {
583 return;
584 }
585
586 boolean changed;
587
588 if (!mCanAddInternalSystemWindow) {
589 // We want to track non-system signature apps adding alert windows so we can post an
590 // on-going notification for the user to control their visibility.
591 if (visible) {
592 changed = mAlertWindowSurfaces.add(surfaceController);
593 } else {
594 changed = mAlertWindowSurfaces.remove(surfaceController);
595 }
596
597 if (changed) {
598 // TODO: Update notification.
Wale Ogunwaled993a572017-02-05 13:52:09 -0800599 }
600 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800601
602 if (type != TYPE_APPLICATION_OVERLAY) {
603 return;
604 }
605
606 if (visible) {
607 changed = mAppOverlaySurfaces.add(surfaceController);
608 } else {
609 changed = mAppOverlaySurfaces.remove(surfaceController);
610 }
611
612 if (changed) {
613 // Notify activity manager of changes to app overlay windows so it can adjust the
614 // importance score for the process.
615 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
616 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 }
618
Wale Ogunwaled993a572017-02-05 13:52:09 -0800619 private void killSessionLocked() {
620 if (mNumWindow > 0 || !mClientDead) {
621 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800623
624 mService.mSessions.remove(this);
625 if (mSurfaceSession == null) {
626 return;
627 }
628
629 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
630 + ", destroying " + mSurfaceSession);
631 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
632 try {
633 mSurfaceSession.kill();
634 } catch (Exception e) {
635 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
636 + " in session " + this + ": " + e.toString());
637 }
638 mSurfaceSession = null;
639 setHasOverlayUi(false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800640 // TODO: Update notification
Wale Ogunwaled993a572017-02-05 13:52:09 -0800641 }
642
643 private void setHasOverlayUi(boolean hasOverlayUi) {
644 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 }
646
647 void dump(PrintWriter pw, String prefix) {
648 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800649 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
650 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 pw.print(" mClientDead="); pw.print(mClientDead);
652 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
653 }
654
655 @Override
656 public String toString() {
657 return mStringName;
658 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700659}