blob: 30e0dedd7c99b9bb3478e45046223b6a3530e9d6 [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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031import android.graphics.Rect;
32import android.graphics.Region;
33import android.os.Binder;
34import android.os.Bundle;
35import android.os.IBinder;
36import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070037import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080038import android.os.RemoteException;
39import android.os.ServiceManager;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070040import android.os.UserHandle;
Andrii Kulian44607962017-03-16 11:06:24 -070041import android.util.MergedConfiguration;
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 Ogunwale387e4c62017-02-13 09:50:02 -080083 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070084 private boolean mClientDead = false;
85 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080086 private String mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080087
Dianne Hackborneb94fa72014-06-03 17:48:12 -070088 public Session(WindowManagerService service, IWindowSessionCallback callback,
89 IInputMethodClient client, IInputContext inputContext) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070091 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 mClient = client;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 mUid = Binder.getCallingUid();
94 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070095 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -080096 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -080097 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 StringBuilder sb = new StringBuilder();
99 sb.append("Session{");
100 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700101 sb.append(" ");
102 sb.append(mPid);
103 if (mUid < Process.FIRST_APPLICATION_UID) {
104 sb.append(":");
105 sb.append(mUid);
106 } else {
107 sb.append(":u");
108 sb.append(UserHandle.getUserId(mUid));
109 sb.append('a');
110 sb.append(UserHandle.getAppId(mUid));
111 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 sb.append("}");
113 mStringName = sb.toString();
114
115 synchronized (mService.mWindowMap) {
116 if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
117 IBinder b = ServiceManager.getService(
118 Context.INPUT_METHOD_SERVICE);
119 mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
120 }
121 }
122 long ident = Binder.clearCallingIdentity();
123 try {
124 // Note: it is safe to call in to the input method manager
125 // here because we are not holding our lock.
126 if (mService.mInputMethodManager != null) {
127 mService.mInputMethodManager.addClient(client, inputContext,
128 mUid, mPid);
129 } else {
130 client.setUsingInputMethod(false);
131 }
132 client.asBinder().linkToDeath(this, 0);
133 } catch (RemoteException e) {
134 // The caller has died, so we can just forget about this.
135 try {
136 if (mService.mInputMethodManager != null) {
137 mService.mInputMethodManager.removeClient(client);
138 }
139 } catch (RemoteException ee) {
140 }
141 } finally {
142 Binder.restoreCallingIdentity(ident);
143 }
144 }
145
146 @Override
147 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
148 throws RemoteException {
149 try {
150 return super.onTransact(code, data, reply, flags);
151 } catch (RuntimeException e) {
152 // Log all 'real' exceptions thrown to the caller
153 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800154 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 }
156 throw e;
157 }
158 }
159
160 public void binderDied() {
161 // Note: it is safe to call in to the input method manager
162 // here because we are not holding our lock.
163 try {
164 if (mService.mInputMethodManager != null) {
165 mService.mInputMethodManager.removeClient(mClient);
166 }
167 } catch (RemoteException e) {
168 }
169 synchronized(mService.mWindowMap) {
170 mClient.asBinder().unlinkToDeath(this, 0);
171 mClientDead = true;
172 killSessionLocked();
173 }
174 }
175
Craig Mautner6881a102012-07-27 13:04:51 -0700176 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700177 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100178 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
179 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700180 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700181 outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800182 }
Craig Mautner6881a102012-07-27 13:04:51 -0700183
184 @Override
185 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100186 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700187 Rect outOutsets, InputChannel outInputChannel) {
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, outOutsets, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700190 }
191
192 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700193 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100194 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700195 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100196 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700197 }
198
199 @Override
200 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100201 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700202 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Filip Gruszczynski0ec13282015-06-25 11:26:01 -0700203 outContentInsets, outStableInsets, null /* outOutsets */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 }
205
206 public void remove(IWindow window) {
207 mService.removeWindow(this, window);
208 }
209
Rob Carr64e516f2015-10-29 00:20:45 +0000210 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700211 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700212 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800213 }
214
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700215 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800217 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800218 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
Andrii Kulian44607962017-03-16 11:06:24 -0700219 MergedConfiguration mergedConfiguration, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800220 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700221 + Binder.getCallingPid());
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700222 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800223 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800224 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -0700225 outStableInsets, outsets, outBackdropFrame, mergedConfiguration, outSurface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800226 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700227 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 return res;
229 }
230
Dianne Hackborn64825172011-03-02 21:32:58 -0800231 public boolean outOfMemory(IWindow window) {
232 return mService.outOfMemoryWindow(this, window);
233 }
234
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 public void setTransparentRegion(IWindow window, Region region) {
236 mService.setTransparentRegionWindow(this, window, region);
237 }
238
239 public void setInsets(IWindow window, int touchableInsets,
240 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
241 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
242 visibleInsets, touchableArea);
243 }
244
245 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
246 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
247 }
248
249 public void finishDrawing(IWindow window) {
250 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800251 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 mService.finishDrawingWindow(this, window);
253 }
254
255 public void setInTouchMode(boolean mode) {
256 synchronized(mService.mWindowMap) {
257 mService.mInTouchMode = mode;
258 }
259 }
260
261 public boolean getInTouchMode() {
262 synchronized(mService.mWindowMap) {
263 return mService.mInTouchMode;
264 }
265 }
266
267 public boolean performHapticFeedback(IWindow window, int effectId,
268 boolean always) {
269 synchronized(mService.mWindowMap) {
270 long ident = Binder.clearCallingIdentity();
271 try {
272 return mService.mPolicy.performHapticFeedbackLw(
273 mService.windowForClientLocked(this, window, true),
274 effectId, always);
275 } finally {
276 Binder.restoreCallingIdentity(ident);
277 }
278 }
279 }
280
281 /* Drag/drop */
282 public IBinder prepareDrag(IWindow window, int flags,
283 int width, int height, Surface outSurface) {
284 return mService.prepareDragSurface(window, mSurfaceSession, flags,
285 width, height, outSurface);
286 }
287
288 public boolean performDrag(IWindow window, IBinder dragToken,
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800289 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 ClipData data) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800291 if (DEBUG_DRAG) {
292 Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 }
294
295 synchronized (mService.mWindowMap) {
296 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800297 Slog.w(TAG_WM, "No drag prepared");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 throw new IllegalStateException("performDrag() without prepareDrag()");
299 }
300
301 if (dragToken != mService.mDragState.mToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800302 Slog.w(TAG_WM, "Performing mismatched drag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 throw new IllegalStateException("performDrag() does not match prepareDrag()");
304 }
305
306 WindowState callingWin = mService.windowForClientLocked(null, window, false);
307 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800308 Slog.w(TAG_WM, "Bad requesting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 return false; // !!! TODO: throw here?
310 }
311
312 // !!! TODO: if input is not still focused on the initiating window, fail
313 // the drag initiation (e.g. an alarm window popped up just as the application
314 // called performDrag()
315
316 mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
317
318 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
319 // will let us eliminate the (touchX,touchY) parameters from the API.
320
321 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
322 // the actual drag event dispatch stuff in the dragstate
323
Craig Mautnerdf88d732014-01-27 09:21:32 -0800324 final DisplayContent displayContent = callingWin.getDisplayContent();
325 if (displayContent == null) {
326 return false;
327 }
328 Display display = displayContent.getDisplay();
Jeff Brown14a9f2b2012-09-24 14:36:44 -0700329 mService.mDragState.register(display);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700331 mService.mDragState.getInputChannel())) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800332 Slog.e(TAG_WM, "Unable to transfer touch focus");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 mService.mDragState.unregister();
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700334 mService.mDragState.reset();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 mService.mDragState = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 return false;
337 }
338
Vladislav Kaznacheev64b103a2016-08-10 11:49:08 -0700339 mService.mDragState.mDisplayContent = displayContent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 mService.mDragState.mData = data;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 mService.mDragState.broadcastDragStartedLw(touchX, touchY);
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800342 mService.mDragState.overridePointerIconLw(touchSource);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343
344 // remember the thumb offsets for later
345 mService.mDragState.mThumbOffsetX = thumbCenterX;
346 mService.mDragState.mThumbOffsetY = thumbCenterY;
347
348 // Make the surface visible at the proper location
Mathias Agopian29479eb2013-02-14 14:36:04 -0800349 final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800350 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
351 TAG_WM, ">>> OPEN TRANSACTION performDrag");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700352 mService.openSurfaceTransaction();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800354 surfaceControl.setPosition(touchX - thumbCenterX,
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700355 touchY - thumbCenterY);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800356 surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
357 surfaceControl.setLayerStack(display.getLayerStack());
358 surfaceControl.show();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 } finally {
Robert Carr68e5c9e2016-09-14 10:50:09 -0700360 mService.closeSurfaceTransaction();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800361 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(
362 TAG_WM, "<<< CLOSE TRANSACTION performDrag");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 }
Vladislav Kaznacheevd0ed8932016-01-15 15:37:05 -0800364
365 mService.mDragState.notifyLocationLw(touchX, touchY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 }
367
368 return true; // success!
369 }
370
Chong Zhang8e89b312015-09-09 15:09:30 -0700371 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800372 if (DEBUG_TASK_POSITIONING) Slog.d(
373 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700374
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800375 long ident = Binder.clearCallingIdentity();
376 try {
377 return mService.startMovingTask(window, startX, startY);
378 } finally {
379 Binder.restoreCallingIdentity(ident);
380 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700381 }
382
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 public void reportDropResult(IWindow window, boolean consumed) {
384 IBinder token = window.asBinder();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800385 if (DEBUG_DRAG) {
386 Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 }
388
389 synchronized (mService.mWindowMap) {
390 long ident = Binder.clearCallingIdentity();
391 try {
Christopher Tate05e9c652011-10-20 12:34:36 -0700392 if (mService.mDragState == null) {
393 // Most likely the drop recipient ANRed and we ended the drag
394 // out from under it. Log the issue and move on.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800395 Slog.w(TAG_WM, "Drop result given but no drag in progress");
Christopher Tate05e9c652011-10-20 12:34:36 -0700396 return;
397 }
398
399 if (mService.mDragState.mToken != token) {
400 // We're in a drag, but the wrong window has responded.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800401 Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 throw new IllegalStateException("reportDropResult() by non-recipient");
403 }
404
405 // The right window has responded, even if it's no longer around,
406 // so be sure to halt the timeout even if the later WindowState
407 // lookup fails.
408 mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
409 WindowState callingWin = mService.windowForClientLocked(null, window, false);
410 if (callingWin == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800411 Slog.w(TAG_WM, "Bad result-reporting window " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 return; // !!! TODO: throw here?
413 }
414
415 mService.mDragState.mDragResult = consumed;
416 mService.mDragState.endDragLw();
417 } finally {
418 Binder.restoreCallingIdentity(ident);
419 }
420 }
421 }
422
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800423 public void cancelDragAndDrop(IBinder dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800424 if (DEBUG_DRAG) {
425 Slog.d(TAG_WM, "cancelDragAndDrop");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800426 }
427
428 synchronized (mService.mWindowMap) {
429 long ident = Binder.clearCallingIdentity();
430 try {
431 if (mService.mDragState == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800432 Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()");
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800433 throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()");
434 }
435
436 if (mService.mDragState.mToken != dragToken) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800437 Slog.w(TAG_WM,
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800438 "cancelDragAndDrop() does not match prepareDrag()");
439 throw new IllegalStateException(
440 "cancelDragAndDrop() does not match prepareDrag()");
441 }
442
443 mService.mDragState.mDragResult = false;
Vladislav Kaznacheevce2aef92015-11-20 18:49:59 -0800444 mService.mDragState.cancelDragLw();
Vladislav Kaznacheev82063912015-11-20 14:20:13 -0800445 } finally {
446 Binder.restoreCallingIdentity(ident);
447 }
448 }
449 }
450
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 public void dragRecipientEntered(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800452 if (DEBUG_DRAG) {
453 Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 }
455 }
456
457 public void dragRecipientExited(IWindow window) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800458 if (DEBUG_DRAG) {
459 Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 }
461 }
462
463 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
464 synchronized(mService.mWindowMap) {
465 long ident = Binder.clearCallingIdentity();
466 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700467 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 mService.windowForClientLocked(this, window, true),
469 x, y, xStep, yStep);
470 } finally {
471 Binder.restoreCallingIdentity(ident);
472 }
473 }
474 }
475
476 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700477 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700478 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700479 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 }
481
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700482 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
483 synchronized(mService.mWindowMap) {
484 long ident = Binder.clearCallingIdentity();
485 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700486 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700487 mService.windowForClientLocked(this, window, true), x, y);
488 } finally {
489 Binder.restoreCallingIdentity(ident);
490 }
491 }
492 }
493
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
495 int z, Bundle extras, boolean sync) {
496 synchronized(mService.mWindowMap) {
497 long ident = Binder.clearCallingIdentity();
498 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700499 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500 mService.windowForClientLocked(this, window, true),
501 action, x, y, z, extras, sync);
502 } finally {
503 Binder.restoreCallingIdentity(ident);
504 }
505 }
506 }
507
508 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700509 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700510 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700511 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 }
513
Svetoslavf7174e82014-06-12 11:29:35 -0700514 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700515 synchronized(mService.mWindowMap) {
516 final long identity = Binder.clearCallingIdentity();
517 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700518 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700519 } finally {
520 Binder.restoreCallingIdentity(identity);
521 }
522 }
523 }
524
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800525 public IWindowId getWindowId(IBinder window) {
526 return mService.getWindowId(window);
527 }
528
Jeff Brownc2932a12014-11-20 18:04:05 -0800529 @Override
530 public void pokeDrawLock(IBinder window) {
531 final long identity = Binder.clearCallingIdentity();
532 try {
533 mService.pokeDrawLock(this, window);
534 } finally {
535 Binder.restoreCallingIdentity(identity);
536 }
537 }
538
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800539 @Override
540 public void updatePointerIcon(IWindow window) {
541 final long identity = Binder.clearCallingIdentity();
542 try {
543 mService.updatePointerIcon(window);
544 } finally {
545 Binder.restoreCallingIdentity(identity);
546 }
547 }
548
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800549 void windowAddedLocked(String packageName) {
550 mPackageName = packageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 if (mSurfaceSession == null) {
552 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800553 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800555 if (SHOW_TRANSACTIONS) Slog.i(
556 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700558 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
559 mService.dispatchNewAnimatorScaleLocked(this);
560 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800561 }
562 mNumWindow++;
563 }
564
Wale Ogunwale943002b2017-02-15 19:34:01 -0800565 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800567 killSessionLocked();
568 }
569
570
571 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
572 boolean visible, int type) {
573
574 if (!isSystemAlertWindowType(type)) {
575 return;
576 }
577
578 boolean changed;
579
580 if (!mCanAddInternalSystemWindow) {
581 // We want to track non-system signature apps adding alert windows so we can post an
582 // on-going notification for the user to control their visibility.
583 if (visible) {
584 changed = mAlertWindowSurfaces.add(surfaceController);
585 } else {
586 changed = mAlertWindowSurfaces.remove(surfaceController);
587 }
588
589 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800590 if (mAlertWindowSurfaces.isEmpty()) {
591 cancelAlertWindowNotification();
592 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800593 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800594 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800595 }
596 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800597
598 if (type != TYPE_APPLICATION_OVERLAY) {
599 return;
600 }
601
602 if (visible) {
603 changed = mAppOverlaySurfaces.add(surfaceController);
604 } else {
605 changed = mAppOverlaySurfaces.remove(surfaceController);
606 }
607
608 if (changed) {
609 // Notify activity manager of changes to app overlay windows so it can adjust the
610 // importance score for the process.
611 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
612 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 }
614
Wale Ogunwaled993a572017-02-05 13:52:09 -0800615 private void killSessionLocked() {
616 if (mNumWindow > 0 || !mClientDead) {
617 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800619
620 mService.mSessions.remove(this);
621 if (mSurfaceSession == null) {
622 return;
623 }
624
625 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
626 + ", destroying " + mSurfaceSession);
627 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
628 try {
629 mSurfaceSession.kill();
630 } catch (Exception e) {
631 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
632 + " in session " + this + ": " + e.toString());
633 }
634 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800635 mAlertWindowSurfaces.clear();
636 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800637 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800638 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800639 }
640
641 private void setHasOverlayUi(boolean hasOverlayUi) {
642 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800643 }
644
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800645 private void cancelAlertWindowNotification() {
646 if (mAlertWindowNotification == null) {
647 return;
648 }
649 mAlertWindowNotification.cancel();
650 mAlertWindowNotification = null;
651 }
652
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 void dump(PrintWriter pw, String prefix) {
654 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800655 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800656 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
657 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 pw.print(" mClientDead="); pw.print(mClientDead);
659 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
660 }
661
662 @Override
663 public String toString() {
664 return mStringName;
665 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700666}