blob: 192d6c84e190937b0f9bba452a150accff54307a [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
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020019import static android.Manifest.permission.DEVICE_POWER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070020import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Wale Ogunwale943002b2017-02-15 19:34:01 -080021import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
22import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070023import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwaled993a572017-02-05 13:52:09 -080024import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Wale Ogunwale943002b2017-02-15 19:34:01 -080025import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Adrian Roos5c6b6222017-11-07 17:36:10 +010026
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030
31import android.content.ClipData;
32import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.graphics.Rect;
34import android.graphics.Region;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.IBinder;
38import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070039import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040import android.os.RemoteException;
41import android.os.ServiceManager;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070042import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070043import android.os.UserHandle;
Andrii Kulian44607962017-03-16 11:06:24 -070044import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.util.Slog;
Craig Mautner6881a102012-07-27 13:04:51 -070046import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +010047import android.view.DisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080049import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080051import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052import android.view.InputChannel;
53import android.view.Surface;
54import android.view.SurfaceSession;
55import android.view.WindowManager;
56
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080057import com.android.internal.view.IInputContext;
58import com.android.internal.view.IInputMethodClient;
59import com.android.internal.view.IInputMethodManager;
60import com.android.server.wm.WindowManagerService.H;
61
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import java.io.PrintWriter;
Wale Ogunwale943002b2017-02-15 19:34:01 -080063import java.util.HashSet;
64import java.util.Set;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
66/**
67 * This class represents an active client session. There is generally one
68 * Session object per process that is interacting with the window manager.
69 */
Bryce Leea5592862017-10-23 12:57:37 -070070class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070072 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 final IInputMethodClient mClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 final int mUid;
75 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070076 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070078 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080079 // Set of visible application overlay window surfaces connected to this session.
80 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
81 // Set of visible alert window surfaces connected to this session.
82 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090083 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080084 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070085 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020086 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080087 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070088 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070089 private boolean mClientDead = false;
90 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080091 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070092 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093
Dianne Hackborneb94fa72014-06-03 17:48:12 -070094 public Session(WindowManagerService service, IWindowSessionCallback callback,
95 IInputMethodClient client, IInputContext inputContext) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070097 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 mClient = client;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 mUid = Binder.getCallingUid();
100 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700101 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800102 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800103 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700104 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
105 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200106 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
107 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700108 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900109 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 StringBuilder sb = new StringBuilder();
111 sb.append("Session{");
112 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700113 sb.append(" ");
114 sb.append(mPid);
115 if (mUid < Process.FIRST_APPLICATION_UID) {
116 sb.append(":");
117 sb.append(mUid);
118 } else {
119 sb.append(":u");
120 sb.append(UserHandle.getUserId(mUid));
121 sb.append('a');
122 sb.append(UserHandle.getAppId(mUid));
123 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 sb.append("}");
125 mStringName = sb.toString();
126
127 synchronized (mService.mWindowMap) {
128 if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
129 IBinder b = ServiceManager.getService(
130 Context.INPUT_METHOD_SERVICE);
131 mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
132 }
133 }
134 long ident = Binder.clearCallingIdentity();
135 try {
136 // Note: it is safe to call in to the input method manager
137 // here because we are not holding our lock.
138 if (mService.mInputMethodManager != null) {
139 mService.mInputMethodManager.addClient(client, inputContext,
140 mUid, mPid);
141 } else {
142 client.setUsingInputMethod(false);
143 }
144 client.asBinder().linkToDeath(this, 0);
145 } catch (RemoteException e) {
146 // The caller has died, so we can just forget about this.
147 try {
148 if (mService.mInputMethodManager != null) {
149 mService.mInputMethodManager.removeClient(client);
150 }
151 } catch (RemoteException ee) {
152 }
153 } finally {
154 Binder.restoreCallingIdentity(ident);
155 }
156 }
157
158 @Override
159 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
160 throws RemoteException {
161 try {
162 return super.onTransact(code, data, reply, flags);
163 } catch (RuntimeException e) {
164 // Log all 'real' exceptions thrown to the caller
165 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800166 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 }
168 throw e;
169 }
170 }
171
Andrew Scull26f830d2017-05-19 12:16:10 +0100172 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 public void binderDied() {
174 // Note: it is safe to call in to the input method manager
175 // here because we are not holding our lock.
176 try {
177 if (mService.mInputMethodManager != null) {
178 mService.mInputMethodManager.removeClient(mClient);
179 }
180 } catch (RemoteException e) {
181 }
182 synchronized(mService.mWindowMap) {
183 mClient.asBinder().unlinkToDeath(this, 0);
184 mClientDead = true;
185 killSessionLocked();
186 }
187 }
188
Craig Mautner6881a102012-07-27 13:04:51 -0700189 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700190 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100191 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
192 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700193 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100194 outContentInsets, outStableInsets, null /* outOutsets */, null /* cutout */,
195 outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196 }
Craig Mautner6881a102012-07-27 13:04:51 -0700197
198 @Override
199 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100200 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100201 Rect outOutsets, DisplayCutout.ParcelableWrapper outDisplayCutout,
202 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700203 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100204 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700205 }
206
207 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700208 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100209 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700210 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100211 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700212 }
213
214 @Override
215 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100216 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700217 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100218 outContentInsets, outStableInsets, null /* outOutsets */, null /* cutout */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800219 }
220
Andrew Scull26f830d2017-05-19 12:16:10 +0100221 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 public void remove(IWindow window) {
223 mService.removeWindow(this, window);
224 }
225
Rob Carr64e516f2015-10-29 00:20:45 +0000226 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700227 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700228 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800229 }
230
Andrew Scull26f830d2017-05-19 12:16:10 +0100231 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700232 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800234 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800235 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100236 DisplayCutout.ParcelableWrapper cutout,
Andrii Kulian44607962017-03-16 11:06:24 -0700237 MergedConfiguration mergedConfiguration, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800238 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700239 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700240 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700241 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800242 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800243 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100244 outStableInsets, outsets, outBackdropFrame, cutout,
245 mergedConfiguration, outSurface);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700246 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800247 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700248 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 return res;
250 }
251
Andrew Scull26f830d2017-05-19 12:16:10 +0100252 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800253 public boolean outOfMemory(IWindow window) {
254 return mService.outOfMemoryWindow(this, window);
255 }
256
Andrew Scull26f830d2017-05-19 12:16:10 +0100257 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 public void setTransparentRegion(IWindow window, Region region) {
259 mService.setTransparentRegionWindow(this, window, region);
260 }
261
Andrew Scull26f830d2017-05-19 12:16:10 +0100262 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 public void setInsets(IWindow window, int touchableInsets,
264 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
265 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
266 visibleInsets, touchableArea);
267 }
268
Andrew Scull26f830d2017-05-19 12:16:10 +0100269 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
271 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
272 }
273
Andrew Scull26f830d2017-05-19 12:16:10 +0100274 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 public void finishDrawing(IWindow window) {
276 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800277 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 mService.finishDrawingWindow(this, window);
279 }
280
Andrew Scull26f830d2017-05-19 12:16:10 +0100281 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 public void setInTouchMode(boolean mode) {
283 synchronized(mService.mWindowMap) {
284 mService.mInTouchMode = mode;
285 }
286 }
287
Andrew Scull26f830d2017-05-19 12:16:10 +0100288 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 public boolean getInTouchMode() {
290 synchronized(mService.mWindowMap) {
291 return mService.mInTouchMode;
292 }
293 }
294
Andrew Scull26f830d2017-05-19 12:16:10 +0100295 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 public boolean performHapticFeedback(IWindow window, int effectId,
297 boolean always) {
298 synchronized(mService.mWindowMap) {
299 long ident = Binder.clearCallingIdentity();
300 try {
301 return mService.mPolicy.performHapticFeedbackLw(
302 mService.windowForClientLocked(this, window, true),
303 effectId, always);
304 } finally {
305 Binder.restoreCallingIdentity(ident);
306 }
307 }
308 }
309
310 /* Drag/drop */
Andrew Scull26f830d2017-05-19 12:16:10 +0100311 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900312 public IBinder prepareDrag(IWindow window, int flags, int width, int height,
313 Surface outSurface) {
314 final int callerPid = Binder.getCallingPid();
315 final int callerUid = Binder.getCallingUid();
316 final long ident = Binder.clearCallingIdentity();
317 try {
318 return mDragDropController.prepareDrag(
Daichi Hirono58e25e12017-10-25 15:48:08 +0900319 mSurfaceSession, callerPid, callerUid, window, flags, width, height,
Daichi Hironodf5cf622017-09-11 14:59:26 +0900320 outSurface);
321 } finally {
322 Binder.restoreCallingIdentity(ident);
323 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 }
325
Andrew Scull26f830d2017-05-19 12:16:10 +0100326 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 public boolean performDrag(IWindow window, IBinder dragToken,
Vladislav Kaznacheevba761122016-01-22 12:09:45 -0800328 int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 ClipData data) {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900330 return mDragDropController.performDrag(window, dragToken, touchSource,
Daichi Hironodf5cf622017-09-11 14:59:26 +0900331 touchX, touchY, thumbCenterX, thumbCenterY, data);
332 }
333
334 @Override
335 public void reportDropResult(IWindow window, boolean consumed) {
336 final long ident = Binder.clearCallingIdentity();
337 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900338 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900339 } finally {
340 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900342 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343
Daichi Hironodf5cf622017-09-11 14:59:26 +0900344 @Override
345 public void cancelDragAndDrop(IBinder dragToken) {
346 final long ident = Binder.clearCallingIdentity();
347 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900348 mDragDropController.cancelDragAndDrop(dragToken);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900349 } finally {
350 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900352 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353
Daichi Hironodf5cf622017-09-11 14:59:26 +0900354 @Override
355 public void dragRecipientEntered(IWindow window) {
356 mDragDropController.dragRecipientEntered(window);
357 }
358
359 @Override
360 public void dragRecipientExited(IWindow window) {
361 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 }
363
Andrew Scull26f830d2017-05-19 12:16:10 +0100364 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700365 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800366 if (DEBUG_TASK_POSITIONING) Slog.d(
367 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700368
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800369 long ident = Binder.clearCallingIdentity();
370 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900371 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800372 } finally {
373 Binder.restoreCallingIdentity(ident);
374 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700375 }
376
Andrew Scull26f830d2017-05-19 12:16:10 +0100377 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
379 synchronized(mService.mWindowMap) {
380 long ident = Binder.clearCallingIdentity();
381 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700382 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 mService.windowForClientLocked(this, window, true),
384 x, y, xStep, yStep);
385 } finally {
386 Binder.restoreCallingIdentity(ident);
387 }
388 }
389 }
390
Andrew Scull26f830d2017-05-19 12:16:10 +0100391 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700393 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700394 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700395 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 }
397
Andrew Scull26f830d2017-05-19 12:16:10 +0100398 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700399 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
400 synchronized(mService.mWindowMap) {
401 long ident = Binder.clearCallingIdentity();
402 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700403 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700404 mService.windowForClientLocked(this, window, true), x, y);
405 } finally {
406 Binder.restoreCallingIdentity(ident);
407 }
408 }
409 }
410
Andrew Scull26f830d2017-05-19 12:16:10 +0100411 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
413 int z, Bundle extras, boolean sync) {
414 synchronized(mService.mWindowMap) {
415 long ident = Binder.clearCallingIdentity();
416 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700417 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 mService.windowForClientLocked(this, window, true),
419 action, x, y, z, extras, sync);
420 } finally {
421 Binder.restoreCallingIdentity(ident);
422 }
423 }
424 }
425
Andrew Scull26f830d2017-05-19 12:16:10 +0100426 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700428 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700429 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700430 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 }
432
Andrew Scull26f830d2017-05-19 12:16:10 +0100433 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700434 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700435 synchronized(mService.mWindowMap) {
436 final long identity = Binder.clearCallingIdentity();
437 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700438 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700439 } finally {
440 Binder.restoreCallingIdentity(identity);
441 }
442 }
443 }
444
Andrew Scull26f830d2017-05-19 12:16:10 +0100445 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800446 public IWindowId getWindowId(IBinder window) {
447 return mService.getWindowId(window);
448 }
449
Jeff Brownc2932a12014-11-20 18:04:05 -0800450 @Override
451 public void pokeDrawLock(IBinder window) {
452 final long identity = Binder.clearCallingIdentity();
453 try {
454 mService.pokeDrawLock(this, window);
455 } finally {
456 Binder.restoreCallingIdentity(identity);
457 }
458 }
459
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800460 @Override
461 public void updatePointerIcon(IWindow window) {
462 final long identity = Binder.clearCallingIdentity();
463 try {
464 mService.updatePointerIcon(window);
465 } finally {
466 Binder.restoreCallingIdentity(identity);
467 }
468 }
469
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800470 void windowAddedLocked(String packageName) {
471 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700472 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 if (mSurfaceSession == null) {
474 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800475 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800477 if (SHOW_TRANSACTIONS) Slog.i(
478 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700480 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
481 mService.dispatchNewAnimatorScaleLocked(this);
482 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 }
484 mNumWindow++;
485 }
486
Wale Ogunwale943002b2017-02-15 19:34:01 -0800487 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800489 killSessionLocked();
490 }
491
492
493 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
494 boolean visible, int type) {
495
496 if (!isSystemAlertWindowType(type)) {
497 return;
498 }
499
500 boolean changed;
501
502 if (!mCanAddInternalSystemWindow) {
503 // We want to track non-system signature apps adding alert windows so we can post an
504 // on-going notification for the user to control their visibility.
505 if (visible) {
506 changed = mAlertWindowSurfaces.add(surfaceController);
507 } else {
508 changed = mAlertWindowSurfaces.remove(surfaceController);
509 }
510
511 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800512 if (mAlertWindowSurfaces.isEmpty()) {
513 cancelAlertWindowNotification();
514 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800515 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700516 if (mShowingAlertWindowNotificationAllowed) {
517 mAlertWindowNotification.post();
518 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800519 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800520 }
521 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800522
523 if (type != TYPE_APPLICATION_OVERLAY) {
524 return;
525 }
526
527 if (visible) {
528 changed = mAppOverlaySurfaces.add(surfaceController);
529 } else {
530 changed = mAppOverlaySurfaces.remove(surfaceController);
531 }
532
533 if (changed) {
534 // Notify activity manager of changes to app overlay windows so it can adjust the
535 // importance score for the process.
536 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
537 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800538 }
539
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700540 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
541 mShowingAlertWindowNotificationAllowed = allowed;
542 if (mAlertWindowNotification != null) {
543 if (allowed) {
544 mAlertWindowNotification.post();
545 } else {
546 mAlertWindowNotification.cancel();
547 }
548 }
549 }
550
Wale Ogunwaled993a572017-02-05 13:52:09 -0800551 private void killSessionLocked() {
552 if (mNumWindow > 0 || !mClientDead) {
553 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800555
556 mService.mSessions.remove(this);
557 if (mSurfaceSession == null) {
558 return;
559 }
560
561 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
562 + ", destroying " + mSurfaceSession);
563 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
564 try {
565 mSurfaceSession.kill();
566 } catch (Exception e) {
567 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
568 + " in session " + this + ": " + e.toString());
569 }
570 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800571 mAlertWindowSurfaces.clear();
572 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800573 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800574 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800575 }
576
577 private void setHasOverlayUi(boolean hasOverlayUi) {
578 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 }
580
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800581 private void cancelAlertWindowNotification() {
582 if (mAlertWindowNotification == null) {
583 return;
584 }
585 mAlertWindowNotification.cancel();
586 mAlertWindowNotification = null;
587 }
588
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 void dump(PrintWriter pw, String prefix) {
590 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800591 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800592 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
593 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800594 pw.print(" mClientDead="); pw.print(mClientDead);
595 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700596 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800597 }
598
599 @Override
600 public String toString() {
601 return mStringName;
602 }
Robert Carr0e007272017-10-02 13:00:55 -0700603
604 boolean hasAlertWindowSurfaces() {
605 return !mAlertWindowSurfaces.isEmpty();
606 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700607}