blob: 37b5a7c3021879fe616a1dc6923e10df933ac798 [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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import android.graphics.Rect;
33import android.graphics.Region;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.IBinder;
37import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070038import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.os.RemoteException;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070040import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070041import android.os.UserHandle;
Andrii Kulian44607962017-03-16 11:06:24 -070042import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080043import android.util.Slog;
Adrian Roos5c6b6222017-11-07 17:36:10 +010044import android.view.DisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080046import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080048import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.view.InputChannel;
50import android.view.Surface;
Daichi Hironoa1fb9be2017-12-18 17:02:54 +090051import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052import android.view.SurfaceSession;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020053import android.view.InsetsState;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054import android.view.WindowManager;
55
Chenjie Yue8904192017-12-08 19:12:57 -080056import com.android.internal.os.logging.MetricsLoggerWrapper;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080057import 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;
wilsonshihc32538e2018-11-07 17:27:34 +080062import java.util.function.BiConsumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063
64/**
65 * This class represents an active client session. There is generally one
66 * Session object per process that is interacting with the window manager.
67 */
Bryce Leea5592862017-10-23 12:57:37 -070068class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070070 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071 final int mUid;
72 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070073 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070075 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080076 // Set of visible application overlay window surfaces connected to this session.
77 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
78 // Set of visible alert window surfaces connected to this session.
79 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090080 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080081 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070082 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020083 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080084 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070085 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070086 private boolean mClientDead = false;
87 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080088 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070089 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080090
Yohei Yukawaa71bb252018-09-19 19:21:24 -070091 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070093 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 mUid = Binder.getCallingUid();
95 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070096 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -080097 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -080098 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070099 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
100 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200101 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
102 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700103 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900104 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105 StringBuilder sb = new StringBuilder();
106 sb.append("Session{");
107 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700108 sb.append(" ");
109 sb.append(mPid);
110 if (mUid < Process.FIRST_APPLICATION_UID) {
111 sb.append(":");
112 sb.append(mUid);
113 } else {
114 sb.append(":u");
115 sb.append(UserHandle.getUserId(mUid));
116 sb.append('a');
117 sb.append(UserHandle.getAppId(mUid));
118 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 sb.append("}");
120 mStringName = sb.toString();
121
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700123 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 } catch (RemoteException e) {
125 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700126 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 }
128 }
129
130 @Override
131 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
132 throws RemoteException {
133 try {
134 return super.onTransact(code, data, reply, flags);
135 } catch (RuntimeException e) {
136 // Log all 'real' exceptions thrown to the caller
137 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800138 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 }
140 throw e;
141 }
142 }
143
Andrew Scull26f830d2017-05-19 12:16:10 +0100144 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700146 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700147 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 mClientDead = true;
149 killSessionLocked();
150 }
151 }
152
Craig Mautner6881a102012-07-27 13:04:51 -0700153 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700154 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100155 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
156 Rect outStableInsets, Rect outOutsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200157 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
158 InsetsState outInsetsState) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100159 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200160 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel,
161 outInsetsState);
Craig Mautner6881a102012-07-27 13:04:51 -0700162 }
163
164 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700165 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200166 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
167 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700168 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos9e370f22018-03-06 18:19:45 +0100169 new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200170 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
171 outInsetsState);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 }
173
Andrew Scull26f830d2017-05-19 12:16:10 +0100174 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 public void remove(IWindow window) {
176 mService.removeWindow(this, window);
177 }
178
Rob Carr64e516f2015-10-29 00:20:45 +0000179 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700180 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700181 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800182 }
183
Andrew Scull26f830d2017-05-19 12:16:10 +0100184 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700185 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700186 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
187 Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
188 Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
189 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200190 Surface outSurface, InsetsState outInsetsState) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800191 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700192 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700193 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700194 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700195 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800196 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100197 outStableInsets, outsets, outBackdropFrame, cutout,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200198 mergedConfiguration, outSurface, outInsetsState);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700199 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800200 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700201 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 return res;
203 }
204
Andrew Scull26f830d2017-05-19 12:16:10 +0100205 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800206 public boolean outOfMemory(IWindow window) {
207 return mService.outOfMemoryWindow(this, window);
208 }
209
Andrew Scull26f830d2017-05-19 12:16:10 +0100210 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 public void setTransparentRegion(IWindow window, Region region) {
212 mService.setTransparentRegionWindow(this, window, region);
213 }
214
Andrew Scull26f830d2017-05-19 12:16:10 +0100215 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 public void setInsets(IWindow window, int touchableInsets,
217 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
218 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
219 visibleInsets, touchableArea);
220 }
221
Andrew Scull26f830d2017-05-19 12:16:10 +0100222 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
224 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
225 }
226
Andrew Scull26f830d2017-05-19 12:16:10 +0100227 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 public void finishDrawing(IWindow window) {
229 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800230 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 mService.finishDrawingWindow(this, window);
232 }
233
Andrew Scull26f830d2017-05-19 12:16:10 +0100234 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 public void setInTouchMode(boolean mode) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700236 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 mService.mInTouchMode = mode;
238 }
239 }
240
Andrew Scull26f830d2017-05-19 12:16:10 +0100241 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 public boolean getInTouchMode() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700243 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 return mService.mInTouchMode;
245 }
246 }
247
Andrew Scull26f830d2017-05-19 12:16:10 +0100248 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 public boolean performHapticFeedback(IWindow window, int effectId,
250 boolean always) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700251 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 long ident = Binder.clearCallingIdentity();
253 try {
254 return mService.mPolicy.performHapticFeedbackLw(
255 mService.windowForClientLocked(this, window, true),
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100256 effectId, always, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 } finally {
258 Binder.restoreCallingIdentity(ident);
259 }
260 }
261 }
262
263 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900264
Andrew Scull26f830d2017-05-19 12:16:10 +0100265 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900266 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
267 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900268 final int callerPid = Binder.getCallingPid();
269 final int callerUid = Binder.getCallingUid();
270 final long ident = Binder.clearCallingIdentity();
271 try {
Daichi Hironofabca092017-12-19 15:02:50 +0900272 return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window,
273 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900274 } finally {
275 Binder.restoreCallingIdentity(ident);
276 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 }
278
Andrew Scull26f830d2017-05-19 12:16:10 +0100279 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900280 public void reportDropResult(IWindow window, boolean consumed) {
281 final long ident = Binder.clearCallingIdentity();
282 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900283 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900284 } finally {
285 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900287 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288
Daichi Hironodf5cf622017-09-11 14:59:26 +0900289 @Override
290 public void cancelDragAndDrop(IBinder dragToken) {
291 final long ident = Binder.clearCallingIdentity();
292 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900293 mDragDropController.cancelDragAndDrop(dragToken);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900294 } finally {
295 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900297 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
Daichi Hironodf5cf622017-09-11 14:59:26 +0900299 @Override
300 public void dragRecipientEntered(IWindow window) {
301 mDragDropController.dragRecipientEntered(window);
302 }
303
304 @Override
305 public void dragRecipientExited(IWindow window) {
306 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 }
308
Andrew Scull26f830d2017-05-19 12:16:10 +0100309 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700310 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800311 if (DEBUG_TASK_POSITIONING) Slog.d(
312 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700313
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800314 long ident = Binder.clearCallingIdentity();
315 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900316 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800317 } finally {
318 Binder.restoreCallingIdentity(ident);
319 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700320 }
321
wilsonshihc32538e2018-11-07 17:27:34 +0800322 private void actionOnWallpaper(IBinder window,
323 BiConsumer<WallpaperController, WindowState> action) {
324 final WindowState windowState = mService.windowForClientLocked(this, window, true);
325 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
326 }
327
Andrew Scull26f830d2017-05-19 12:16:10 +0100328 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700330 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 long ident = Binder.clearCallingIdentity();
332 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800333 actionOnWallpaper(window, (wpController, windowState) ->
334 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 } finally {
336 Binder.restoreCallingIdentity(ident);
337 }
338 }
339 }
340
Andrew Scull26f830d2017-05-19 12:16:10 +0100341 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700343 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800344 actionOnWallpaper(window, (wpController, windowState) ->
345 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700346 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 }
348
Andrew Scull26f830d2017-05-19 12:16:10 +0100349 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700350 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700351 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700352 long ident = Binder.clearCallingIdentity();
353 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800354 actionOnWallpaper(window, (wpController, windowState) ->
355 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700356 } finally {
357 Binder.restoreCallingIdentity(ident);
358 }
359 }
360 }
361
Andrew Scull26f830d2017-05-19 12:16:10 +0100362 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
364 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700365 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 long ident = Binder.clearCallingIdentity();
367 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800368 final WindowState windowState = mService.windowForClientLocked(this, window, true);
369 return windowState.getDisplayContent().mWallpaperController
370 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 } finally {
372 Binder.restoreCallingIdentity(ident);
373 }
374 }
375 }
376
Andrew Scull26f830d2017-05-19 12:16:10 +0100377 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700379 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800380 actionOnWallpaper(window, (wpController, windowState) ->
381 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700382 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 }
384
Andrew Scull26f830d2017-05-19 12:16:10 +0100385 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700386 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700387 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700388 final long identity = Binder.clearCallingIdentity();
389 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700390 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700391 } finally {
392 Binder.restoreCallingIdentity(identity);
393 }
394 }
395 }
396
Andrew Scull26f830d2017-05-19 12:16:10 +0100397 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800398 public IWindowId getWindowId(IBinder window) {
399 return mService.getWindowId(window);
400 }
401
Jeff Brownc2932a12014-11-20 18:04:05 -0800402 @Override
403 public void pokeDrawLock(IBinder window) {
404 final long identity = Binder.clearCallingIdentity();
405 try {
406 mService.pokeDrawLock(this, window);
407 } finally {
408 Binder.restoreCallingIdentity(identity);
409 }
410 }
411
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800412 @Override
413 public void updatePointerIcon(IWindow window) {
414 final long identity = Binder.clearCallingIdentity();
415 try {
416 mService.updatePointerIcon(window);
417 } finally {
418 Binder.restoreCallingIdentity(identity);
419 }
420 }
421
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800422 @Override
423 public void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
424 int height) {
425 final long identity = Binder.clearCallingIdentity();
426 try {
427 mService.updateTapExcludeRegion(window, regionId, left, top, width, height);
428 } finally {
429 Binder.restoreCallingIdentity(identity);
430 }
431 }
432
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800433 void windowAddedLocked(String packageName) {
434 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700435 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 if (mSurfaceSession == null) {
437 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800438 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800440 if (SHOW_TRANSACTIONS) Slog.i(
441 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700443 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
444 mService.dispatchNewAnimatorScaleLocked(this);
445 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 }
447 mNumWindow++;
448 }
449
Wale Ogunwale943002b2017-02-15 19:34:01 -0800450 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800452 killSessionLocked();
453 }
454
455
456 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
457 boolean visible, int type) {
458
459 if (!isSystemAlertWindowType(type)) {
460 return;
461 }
462
463 boolean changed;
464
465 if (!mCanAddInternalSystemWindow) {
466 // We want to track non-system signature apps adding alert windows so we can post an
467 // on-going notification for the user to control their visibility.
468 if (visible) {
469 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800470 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800471 } else {
472 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800473 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800474 }
475
476 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800477 if (mAlertWindowSurfaces.isEmpty()) {
478 cancelAlertWindowNotification();
479 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800480 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700481 if (mShowingAlertWindowNotificationAllowed) {
482 mAlertWindowNotification.post();
483 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800484 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800485 }
486 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800487
488 if (type != TYPE_APPLICATION_OVERLAY) {
489 return;
490 }
491
492 if (visible) {
493 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800494 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800495 } else {
496 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800497 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800498 }
499
500 if (changed) {
501 // Notify activity manager of changes to app overlay windows so it can adjust the
502 // importance score for the process.
503 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
504 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 }
506
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700507 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
508 mShowingAlertWindowNotificationAllowed = allowed;
509 if (mAlertWindowNotification != null) {
510 if (allowed) {
511 mAlertWindowNotification.post();
512 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800513 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700514 }
515 }
516 }
517
Wale Ogunwaled993a572017-02-05 13:52:09 -0800518 private void killSessionLocked() {
519 if (mNumWindow > 0 || !mClientDead) {
520 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800522
523 mService.mSessions.remove(this);
524 if (mSurfaceSession == null) {
525 return;
526 }
527
528 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
529 + ", destroying " + mSurfaceSession);
530 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
531 try {
532 mSurfaceSession.kill();
533 } catch (Exception e) {
534 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
535 + " in session " + this + ": " + e.toString());
536 }
537 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800538 mAlertWindowSurfaces.clear();
539 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800540 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800541 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800542 }
543
544 private void setHasOverlayUi(boolean hasOverlayUi) {
545 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 }
547
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800548 private void cancelAlertWindowNotification() {
549 if (mAlertWindowNotification == null) {
550 return;
551 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800552 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800553 mAlertWindowNotification = null;
554 }
555
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 void dump(PrintWriter pw, String prefix) {
557 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800558 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800559 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
560 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800561 pw.print(" mClientDead="); pw.print(mClientDead);
562 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700563 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 }
565
566 @Override
567 public String toString() {
568 return mStringName;
569 }
Robert Carr0e007272017-10-02 13:00:55 -0700570
571 boolean hasAlertWindowSurfaces() {
572 return !mAlertWindowSurfaces.isEmpty();
573 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700574}