blob: 5cf5e0d74e2322909e0b7642150d9b7cc6d9e5e2 [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;
Daichi Hironoa1fb9be2017-12-18 17:02:54 +090054import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055import android.view.SurfaceSession;
56import android.view.WindowManager;
57
Chenjie Yue8904192017-12-08 19:12:57 -080058import com.android.internal.os.logging.MetricsLoggerWrapper;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080059import com.android.internal.view.IInputContext;
60import com.android.internal.view.IInputMethodClient;
61import com.android.internal.view.IInputMethodManager;
62import com.android.server.wm.WindowManagerService.H;
63
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064import java.io.PrintWriter;
Wale Ogunwale943002b2017-02-15 19:34:01 -080065import java.util.HashSet;
66import java.util.Set;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067
68/**
69 * This class represents an active client session. There is generally one
70 * Session object per process that is interacting with the window manager.
71 */
Bryce Leea5592862017-10-23 12:57:37 -070072class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070074 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075 final IInputMethodClient mClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 final int mUid;
77 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070078 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080079 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070080 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080081 // Set of visible application overlay window surfaces connected to this session.
82 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
83 // Set of visible alert window surfaces connected to this session.
84 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090085 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080086 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070087 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020088 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080089 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070090 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070091 private boolean mClientDead = false;
92 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080093 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070094 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095
Dianne Hackborneb94fa72014-06-03 17:48:12 -070096 public Session(WindowManagerService service, IWindowSessionCallback callback,
97 IInputMethodClient client, IInputContext inputContext) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070099 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 mClient = client;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800101 mUid = Binder.getCallingUid();
102 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700103 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800104 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800105 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700106 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
107 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200108 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
109 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700110 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900111 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 StringBuilder sb = new StringBuilder();
113 sb.append("Session{");
114 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700115 sb.append(" ");
116 sb.append(mPid);
117 if (mUid < Process.FIRST_APPLICATION_UID) {
118 sb.append(":");
119 sb.append(mUid);
120 } else {
121 sb.append(":u");
122 sb.append(UserHandle.getUserId(mUid));
123 sb.append('a');
124 sb.append(UserHandle.getAppId(mUid));
125 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 sb.append("}");
127 mStringName = sb.toString();
128
129 synchronized (mService.mWindowMap) {
130 if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
131 IBinder b = ServiceManager.getService(
132 Context.INPUT_METHOD_SERVICE);
133 mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
134 }
135 }
136 long ident = Binder.clearCallingIdentity();
137 try {
138 // Note: it is safe to call in to the input method manager
139 // here because we are not holding our lock.
140 if (mService.mInputMethodManager != null) {
141 mService.mInputMethodManager.addClient(client, inputContext,
142 mUid, mPid);
143 } else {
144 client.setUsingInputMethod(false);
145 }
146 client.asBinder().linkToDeath(this, 0);
147 } catch (RemoteException e) {
148 // The caller has died, so we can just forget about this.
149 try {
150 if (mService.mInputMethodManager != null) {
151 mService.mInputMethodManager.removeClient(client);
152 }
153 } catch (RemoteException ee) {
154 }
155 } finally {
156 Binder.restoreCallingIdentity(ident);
157 }
158 }
159
160 @Override
161 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
162 throws RemoteException {
163 try {
164 return super.onTransact(code, data, reply, flags);
165 } catch (RuntimeException e) {
166 // Log all 'real' exceptions thrown to the caller
167 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800168 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 }
170 throw e;
171 }
172 }
173
Andrew Scull26f830d2017-05-19 12:16:10 +0100174 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 public void binderDied() {
176 // Note: it is safe to call in to the input method manager
177 // here because we are not holding our lock.
178 try {
179 if (mService.mInputMethodManager != null) {
180 mService.mInputMethodManager.removeClient(mClient);
181 }
182 } catch (RemoteException e) {
183 }
184 synchronized(mService.mWindowMap) {
185 mClient.asBinder().unlinkToDeath(this, 0);
186 mClientDead = true;
187 killSessionLocked();
188 }
189 }
190
Craig Mautner6881a102012-07-27 13:04:51 -0700191 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700192 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100193 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
194 Rect outStableInsets, Rect outOutsets,
195 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel) {
196 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100197 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700198 }
199
200 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700201 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100202 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700203 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos9e370f22018-03-06 18:19:45 +0100204 new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */,
Daichi Hirono4ab9e822018-04-11 13:29:20 +0900205 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 }
207
Andrew Scull26f830d2017-05-19 12:16:10 +0100208 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 public void remove(IWindow window) {
210 mService.removeWindow(this, window);
211 }
212
Rob Carr64e516f2015-10-29 00:20:45 +0000213 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700214 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700215 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800216 }
217
Andrew Scull26f830d2017-05-19 12:16:10 +0100218 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700219 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700220 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
221 Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
222 Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
223 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
224 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());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700227 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700228 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700229 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800230 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100231 outStableInsets, outsets, outBackdropFrame, cutout,
232 mergedConfiguration, outSurface);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700233 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800234 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700235 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 return res;
237 }
238
Andrew Scull26f830d2017-05-19 12:16:10 +0100239 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800240 public boolean outOfMemory(IWindow window) {
241 return mService.outOfMemoryWindow(this, window);
242 }
243
Andrew Scull26f830d2017-05-19 12:16:10 +0100244 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 public void setTransparentRegion(IWindow window, Region region) {
246 mService.setTransparentRegionWindow(this, window, region);
247 }
248
Andrew Scull26f830d2017-05-19 12:16:10 +0100249 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 public void setInsets(IWindow window, int touchableInsets,
251 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
252 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
253 visibleInsets, touchableArea);
254 }
255
Andrew Scull26f830d2017-05-19 12:16:10 +0100256 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
258 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
259 }
260
Andrew Scull26f830d2017-05-19 12:16:10 +0100261 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 public void finishDrawing(IWindow window) {
263 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800264 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 mService.finishDrawingWindow(this, window);
266 }
267
Andrew Scull26f830d2017-05-19 12:16:10 +0100268 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 public void setInTouchMode(boolean mode) {
270 synchronized(mService.mWindowMap) {
271 mService.mInTouchMode = mode;
272 }
273 }
274
Andrew Scull26f830d2017-05-19 12:16:10 +0100275 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 public boolean getInTouchMode() {
277 synchronized(mService.mWindowMap) {
278 return mService.mInTouchMode;
279 }
280 }
281
Andrew Scull26f830d2017-05-19 12:16:10 +0100282 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 public boolean performHapticFeedback(IWindow window, int effectId,
284 boolean always) {
285 synchronized(mService.mWindowMap) {
286 long ident = Binder.clearCallingIdentity();
287 try {
288 return mService.mPolicy.performHapticFeedbackLw(
289 mService.windowForClientLocked(this, window, true),
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100290 effectId, always, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 } finally {
292 Binder.restoreCallingIdentity(ident);
293 }
294 }
295 }
296
297 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900298
Andrew Scull26f830d2017-05-19 12:16:10 +0100299 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900300 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
301 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900302 final int callerPid = Binder.getCallingPid();
303 final int callerUid = Binder.getCallingUid();
304 final long ident = Binder.clearCallingIdentity();
305 try {
Daichi Hironofabca092017-12-19 15:02:50 +0900306 return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window,
307 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900308 } finally {
309 Binder.restoreCallingIdentity(ident);
310 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 }
312
Andrew Scull26f830d2017-05-19 12:16:10 +0100313 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900314 public void reportDropResult(IWindow window, boolean consumed) {
315 final long ident = Binder.clearCallingIdentity();
316 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900317 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900318 } finally {
319 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900321 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322
Daichi Hironodf5cf622017-09-11 14:59:26 +0900323 @Override
324 public void cancelDragAndDrop(IBinder dragToken) {
325 final long ident = Binder.clearCallingIdentity();
326 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900327 mDragDropController.cancelDragAndDrop(dragToken);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900328 } finally {
329 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900331 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332
Daichi Hironodf5cf622017-09-11 14:59:26 +0900333 @Override
334 public void dragRecipientEntered(IWindow window) {
335 mDragDropController.dragRecipientEntered(window);
336 }
337
338 @Override
339 public void dragRecipientExited(IWindow window) {
340 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 }
342
Andrew Scull26f830d2017-05-19 12:16:10 +0100343 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700344 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800345 if (DEBUG_TASK_POSITIONING) Slog.d(
346 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700347
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800348 long ident = Binder.clearCallingIdentity();
349 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900350 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800351 } finally {
352 Binder.restoreCallingIdentity(ident);
353 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700354 }
355
Andrew Scull26f830d2017-05-19 12:16:10 +0100356 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
358 synchronized(mService.mWindowMap) {
359 long ident = Binder.clearCallingIdentity();
360 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700361 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 mService.windowForClientLocked(this, window, true),
363 x, y, xStep, yStep);
364 } finally {
365 Binder.restoreCallingIdentity(ident);
366 }
367 }
368 }
369
Andrew Scull26f830d2017-05-19 12:16:10 +0100370 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700372 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700373 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700374 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 }
376
Andrew Scull26f830d2017-05-19 12:16:10 +0100377 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700378 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
379 synchronized(mService.mWindowMap) {
380 long ident = Binder.clearCallingIdentity();
381 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700382 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700383 mService.windowForClientLocked(this, window, true), x, y);
384 } finally {
385 Binder.restoreCallingIdentity(ident);
386 }
387 }
388 }
389
Andrew Scull26f830d2017-05-19 12:16:10 +0100390 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
392 int z, Bundle extras, boolean sync) {
393 synchronized(mService.mWindowMap) {
394 long ident = Binder.clearCallingIdentity();
395 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700396 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 mService.windowForClientLocked(this, window, true),
398 action, x, y, z, extras, sync);
399 } finally {
400 Binder.restoreCallingIdentity(ident);
401 }
402 }
403 }
404
Andrew Scull26f830d2017-05-19 12:16:10 +0100405 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700407 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700408 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700409 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 }
411
Andrew Scull26f830d2017-05-19 12:16:10 +0100412 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700413 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700414 synchronized(mService.mWindowMap) {
415 final long identity = Binder.clearCallingIdentity();
416 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700417 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700418 } finally {
419 Binder.restoreCallingIdentity(identity);
420 }
421 }
422 }
423
Andrew Scull26f830d2017-05-19 12:16:10 +0100424 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800425 public IWindowId getWindowId(IBinder window) {
426 return mService.getWindowId(window);
427 }
428
Jeff Brownc2932a12014-11-20 18:04:05 -0800429 @Override
430 public void pokeDrawLock(IBinder window) {
431 final long identity = Binder.clearCallingIdentity();
432 try {
433 mService.pokeDrawLock(this, window);
434 } finally {
435 Binder.restoreCallingIdentity(identity);
436 }
437 }
438
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800439 @Override
440 public void updatePointerIcon(IWindow window) {
441 final long identity = Binder.clearCallingIdentity();
442 try {
443 mService.updatePointerIcon(window);
444 } finally {
445 Binder.restoreCallingIdentity(identity);
446 }
447 }
448
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800449 @Override
450 public void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
451 int height) {
452 final long identity = Binder.clearCallingIdentity();
453 try {
454 mService.updateTapExcludeRegion(window, regionId, left, top, width, height);
455 } finally {
456 Binder.restoreCallingIdentity(identity);
457 }
458 }
459
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800460 void windowAddedLocked(String packageName) {
461 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700462 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 if (mSurfaceSession == null) {
464 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800465 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800467 if (SHOW_TRANSACTIONS) Slog.i(
468 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700470 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
471 mService.dispatchNewAnimatorScaleLocked(this);
472 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 }
474 mNumWindow++;
475 }
476
Wale Ogunwale943002b2017-02-15 19:34:01 -0800477 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800479 killSessionLocked();
480 }
481
482
483 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
484 boolean visible, int type) {
485
486 if (!isSystemAlertWindowType(type)) {
487 return;
488 }
489
490 boolean changed;
491
492 if (!mCanAddInternalSystemWindow) {
493 // We want to track non-system signature apps adding alert windows so we can post an
494 // on-going notification for the user to control their visibility.
495 if (visible) {
496 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800497 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800498 } else {
499 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800500 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800501 }
502
503 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800504 if (mAlertWindowSurfaces.isEmpty()) {
505 cancelAlertWindowNotification();
506 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800507 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700508 if (mShowingAlertWindowNotificationAllowed) {
509 mAlertWindowNotification.post();
510 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800511 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800512 }
513 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800514
515 if (type != TYPE_APPLICATION_OVERLAY) {
516 return;
517 }
518
519 if (visible) {
520 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800521 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800522 } else {
523 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800524 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800525 }
526
527 if (changed) {
528 // Notify activity manager of changes to app overlay windows so it can adjust the
529 // importance score for the process.
530 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
531 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532 }
533
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700534 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
535 mShowingAlertWindowNotificationAllowed = allowed;
536 if (mAlertWindowNotification != null) {
537 if (allowed) {
538 mAlertWindowNotification.post();
539 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800540 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700541 }
542 }
543 }
544
Wale Ogunwaled993a572017-02-05 13:52:09 -0800545 private void killSessionLocked() {
546 if (mNumWindow > 0 || !mClientDead) {
547 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800549
550 mService.mSessions.remove(this);
551 if (mSurfaceSession == null) {
552 return;
553 }
554
555 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
556 + ", destroying " + mSurfaceSession);
557 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
558 try {
559 mSurfaceSession.kill();
560 } catch (Exception e) {
561 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
562 + " in session " + this + ": " + e.toString());
563 }
564 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800565 mAlertWindowSurfaces.clear();
566 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800567 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800568 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800569 }
570
571 private void setHasOverlayUi(boolean hasOverlayUi) {
572 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 }
574
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800575 private void cancelAlertWindowNotification() {
576 if (mAlertWindowNotification == null) {
577 return;
578 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800579 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800580 mAlertWindowNotification = null;
581 }
582
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 void dump(PrintWriter pw, String prefix) {
584 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800585 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800586 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
587 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800588 pw.print(" mClientDead="); pw.print(mClientDead);
589 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700590 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591 }
592
593 @Override
594 public String toString() {
595 return mStringName;
596 }
Robert Carr0e007272017-10-02 13:00:55 -0700597
598 boolean hasAlertWindowSurfaces() {
599 return !mAlertWindowSurfaces.isEmpty();
600 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700601}