blob: 7135b21d507ded988e41677e9adf7d047b467428 [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
Adrian Roosb125e0b2019-10-02 14:55:14 +020027import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
Adam Pardyl8c2d19c2019-09-16 17:15:38 +020028import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031
Vishnu Nairf7645aa2019-06-18 11:14:01 -070032import android.annotation.Nullable;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.content.ClipData;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034import android.graphics.Rect;
35import android.graphics.Region;
36import android.os.Binder;
37import android.os.Bundle;
38import android.os.IBinder;
39import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070040import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080041import android.os.RemoteException;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070042import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070043import android.os.UserHandle;
Riddle Hsuccf09402019-08-13 00:33:06 +080044import android.util.ArraySet;
Andrii Kulian44607962017-03-16 11:06:24 -070045import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080046import android.util.Slog;
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;
Tiger Huangdda14a72019-01-10 17:20:27 +080053import android.view.InsetsState;
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;
Adrian Roosb125e0b2019-10-02 14:55:14 +020059import com.android.server.protolog.common.ProtoLog;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080060import com.android.server.wm.WindowManagerService.H;
61
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import java.io.PrintWriter;
Adrian Roos4ffc8972019-02-07 20:45:11 +010063import java.util.List;
wilsonshihc32538e2018-11-07 17:27:34 +080064import java.util.function.BiConsumer;
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 int mUid;
74 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070075 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070077 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080078 // Set of visible application overlay window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080079 private final ArraySet<WindowSurfaceController> mAppOverlaySurfaces = new ArraySet<>();
Wale Ogunwale943002b2017-02-15 19:34:01 -080080 // Set of visible alert window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080081 private final ArraySet<WindowSurfaceController> mAlertWindowSurfaces = new ArraySet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090082 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080083 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070084 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020085 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080086 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070087 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070088 private boolean mClientDead = false;
89 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080090 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070091 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092
Yohei Yukawaa71bb252018-09-19 19:21:24 -070093 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070095 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 mUid = Binder.getCallingUid();
97 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070098 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -080099 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800100 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700101 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
102 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200103 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
104 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700105 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900106 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107 StringBuilder sb = new StringBuilder();
108 sb.append("Session{");
109 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700110 sb.append(" ");
111 sb.append(mPid);
112 if (mUid < Process.FIRST_APPLICATION_UID) {
113 sb.append(":");
114 sb.append(mUid);
115 } else {
116 sb.append(":u");
117 sb.append(UserHandle.getUserId(mUid));
118 sb.append('a');
119 sb.append(UserHandle.getAppId(mUid));
120 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 sb.append("}");
122 mStringName = sb.toString();
123
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700125 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 } catch (RemoteException e) {
127 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700128 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 }
130 }
131
132 @Override
133 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
134 throws RemoteException {
135 try {
136 return super.onTransact(code, data, reply, flags);
137 } catch (RuntimeException e) {
138 // Log all 'real' exceptions thrown to the caller
139 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800140 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 }
142 throw e;
143 }
144 }
145
Andrew Scull26f830d2017-05-19 12:16:10 +0100146 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700148 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700149 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 mClientDead = true;
151 killSessionLocked();
152 }
153 }
154
Craig Mautner6881a102012-07-27 13:04:51 -0700155 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700156 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100157 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
158 Rect outStableInsets, Rect outOutsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200159 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
160 InsetsState outInsetsState) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100161 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200162 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel,
163 outInsetsState);
Craig Mautner6881a102012-07-27 13:04:51 -0700164 }
165
166 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700167 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200168 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
169 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700170 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos9e370f22018-03-06 18:19:45 +0100171 new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200172 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
173 outInsetsState);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 }
175
Andrew Scull26f830d2017-05-19 12:16:10 +0100176 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177 public void remove(IWindow window) {
178 mService.removeWindow(this, window);
179 }
180
Rob Carr64e516f2015-10-29 00:20:45 +0000181 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700182 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700183 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800184 }
185
Andrew Scull26f830d2017-05-19 12:16:10 +0100186 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700187 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700188 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
189 Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
190 Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
191 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Robert Carr5fea55b2018-12-10 13:05:52 -0800192 SurfaceControl outSurfaceControl, InsetsState outInsetsState) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800193 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700194 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700195 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700196 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700197 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800198 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100199 outStableInsets, outsets, outBackdropFrame, cutout,
Robert Carr5fea55b2018-12-10 13:05:52 -0800200 mergedConfiguration, outSurfaceControl, outInsetsState);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700201 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800202 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700203 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 return res;
205 }
206
Andrew Scull26f830d2017-05-19 12:16:10 +0100207 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800208 public boolean outOfMemory(IWindow window) {
209 return mService.outOfMemoryWindow(this, window);
210 }
211
Andrew Scull26f830d2017-05-19 12:16:10 +0100212 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 public void setTransparentRegion(IWindow window, Region region) {
214 mService.setTransparentRegionWindow(this, window, region);
215 }
216
Andrew Scull26f830d2017-05-19 12:16:10 +0100217 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 public void setInsets(IWindow window, int touchableInsets,
219 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
220 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
221 visibleInsets, touchableArea);
222 }
223
Andrew Scull26f830d2017-05-19 12:16:10 +0100224 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
226 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
227 }
228
Andrew Scull26f830d2017-05-19 12:16:10 +0100229 @Override
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700230 public void finishDrawing(IWindow window,
231 @Nullable SurfaceControl.Transaction postDrawTransaction) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200232 if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window);
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700233 mService.finishDrawingWindow(this, window, postDrawTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 }
235
Andrew Scull26f830d2017-05-19 12:16:10 +0100236 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 public void setInTouchMode(boolean mode) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700238 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800239 mService.mInTouchMode = mode;
240 }
241 }
242
Andrew Scull26f830d2017-05-19 12:16:10 +0100243 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 public boolean getInTouchMode() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700245 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 return mService.mInTouchMode;
247 }
248 }
249
Andrew Scull26f830d2017-05-19 12:16:10 +0100250 @Override
Arthur Hunga4c52062019-02-19 11:31:44 +0800251 public boolean performHapticFeedback(int effectId, boolean always) {
252 long ident = Binder.clearCallingIdentity();
253 try {
254 return mService.mPolicy.performHapticFeedback(mUid, mPackageName,
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100255 effectId, always, null);
Arthur Hunga4c52062019-02-19 11:31:44 +0800256 } finally {
257 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 }
259 }
260
261 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900262
Andrew Scull26f830d2017-05-19 12:16:10 +0100263 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900264 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
265 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900266 final long ident = Binder.clearCallingIdentity();
267 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800268 return mDragDropController.performDrag(mSurfaceSession, mPid, mUid, window,
Daichi Hironofabca092017-12-19 15:02:50 +0900269 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900270 } finally {
271 Binder.restoreCallingIdentity(ident);
272 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 }
274
Andrew Scull26f830d2017-05-19 12:16:10 +0100275 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900276 public void reportDropResult(IWindow window, boolean consumed) {
277 final long ident = Binder.clearCallingIdentity();
278 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900279 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900280 } finally {
281 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900283 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284
Daichi Hironodf5cf622017-09-11 14:59:26 +0900285 @Override
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900286 public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900287 final long ident = Binder.clearCallingIdentity();
288 try {
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900289 mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900290 } finally {
291 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900293 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294
Daichi Hironodf5cf622017-09-11 14:59:26 +0900295 @Override
296 public void dragRecipientEntered(IWindow window) {
297 mDragDropController.dragRecipientEntered(window);
298 }
299
300 @Override
301 public void dragRecipientExited(IWindow window) {
302 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303 }
304
Andrew Scull26f830d2017-05-19 12:16:10 +0100305 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700306 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800307 if (DEBUG_TASK_POSITIONING) Slog.d(
308 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700309
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800310 long ident = Binder.clearCallingIdentity();
311 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900312 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800313 } finally {
314 Binder.restoreCallingIdentity(ident);
315 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700316 }
317
Adrian Roos4ffc8972019-02-07 20:45:11 +0100318 @Override
yj81.kwon19585ff2019-04-23 18:53:57 -0700319 public void finishMovingTask(IWindow window) {
320 if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask");
321
322 long ident = Binder.clearCallingIdentity();
323 try {
324 mService.mTaskPositioningController.finishTaskPositioning(window);
325 } finally {
326 Binder.restoreCallingIdentity(ident);
327 }
328 }
329
330 @Override
Adrian Roos4ffc8972019-02-07 20:45:11 +0100331 public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) {
332 long ident = Binder.clearCallingIdentity();
333 try {
334 mService.reportSystemGestureExclusionChanged(this, window, exclusionRects);
335 } finally {
336 Binder.restoreCallingIdentity(ident);
337 }
338 }
339
wilsonshihc32538e2018-11-07 17:27:34 +0800340 private void actionOnWallpaper(IBinder window,
341 BiConsumer<WallpaperController, WindowState> action) {
342 final WindowState windowState = mService.windowForClientLocked(this, window, true);
343 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
344 }
345
Andrew Scull26f830d2017-05-19 12:16:10 +0100346 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700348 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 long ident = Binder.clearCallingIdentity();
350 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800351 actionOnWallpaper(window, (wpController, windowState) ->
352 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 } finally {
354 Binder.restoreCallingIdentity(ident);
355 }
356 }
357 }
358
Andrew Scull26f830d2017-05-19 12:16:10 +0100359 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700361 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800362 actionOnWallpaper(window, (wpController, windowState) ->
363 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700364 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 }
366
Andrew Scull26f830d2017-05-19 12:16:10 +0100367 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700368 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700369 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700370 long ident = Binder.clearCallingIdentity();
371 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800372 actionOnWallpaper(window, (wpController, windowState) ->
373 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700374 } finally {
375 Binder.restoreCallingIdentity(ident);
376 }
377 }
378 }
379
Andrew Scull26f830d2017-05-19 12:16:10 +0100380 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800381 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
382 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700383 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 long ident = Binder.clearCallingIdentity();
385 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800386 final WindowState windowState = mService.windowForClientLocked(this, window, true);
387 return windowState.getDisplayContent().mWallpaperController
388 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 } finally {
390 Binder.restoreCallingIdentity(ident);
391 }
392 }
393 }
394
Andrew Scull26f830d2017-05-19 12:16:10 +0100395 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700397 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800398 actionOnWallpaper(window, (wpController, windowState) ->
399 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700400 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 }
402
Andrew Scull26f830d2017-05-19 12:16:10 +0100403 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700404 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700405 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700406 final long identity = Binder.clearCallingIdentity();
407 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700408 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700409 } finally {
410 Binder.restoreCallingIdentity(identity);
411 }
412 }
413 }
414
Andrew Scull26f830d2017-05-19 12:16:10 +0100415 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800416 public IWindowId getWindowId(IBinder window) {
417 return mService.getWindowId(window);
418 }
419
Jeff Brownc2932a12014-11-20 18:04:05 -0800420 @Override
421 public void pokeDrawLock(IBinder window) {
422 final long identity = Binder.clearCallingIdentity();
423 try {
424 mService.pokeDrawLock(this, window);
425 } finally {
426 Binder.restoreCallingIdentity(identity);
427 }
428 }
429
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800430 @Override
431 public void updatePointerIcon(IWindow window) {
432 final long identity = Binder.clearCallingIdentity();
433 try {
434 mService.updatePointerIcon(window);
435 } finally {
436 Binder.restoreCallingIdentity(identity);
437 }
438 }
439
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800440 @Override
Tiger Huangd8ec9382019-04-18 14:35:09 -0700441 public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) {
442 mService.reparentDisplayContent(window, sc, displayId);
443 }
444
445 @Override
446 public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) {
447 mService.updateDisplayContentLocation(window, x, y, displayId);
448 }
449
450 @Override
Tiger Huang2b210c22019-03-18 21:21:26 +0800451 public void updateTapExcludeRegion(IWindow window, int regionId, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800452 final long identity = Binder.clearCallingIdentity();
453 try {
Tiger Huang2b210c22019-03-18 21:21:26 +0800454 mService.updateTapExcludeRegion(window, regionId, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800455 } finally {
456 Binder.restoreCallingIdentity(identity);
457 }
458 }
459
Jorim Jaggie35c0592018-11-06 16:21:08 +0100460 @Override
461 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800462 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100463 final WindowState windowState = mService.windowForClientLocked(this, window,
464 false /* throwOnError */);
465 if (windowState != null) {
Jorim Jaggi956ca412019-01-07 14:49:14 +0100466 windowState.setClientInsetsState(state);
467 windowState.getDisplayContent().getInsetsPolicy().onInsetsModified(
Jorim Jaggie35c0592018-11-06 16:21:08 +0100468 windowState, state);
469 }
470 }
471 }
472
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800473 void windowAddedLocked(String packageName) {
474 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700475 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 if (mSurfaceSession == null) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200477 if (DEBUG) {
478 Slog.v(TAG_WM, "First window added to " + this + ", creating SurfaceSession");
479 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 mSurfaceSession = new SurfaceSession();
Adrian Roosb125e0b2019-10-02 14:55:14 +0200481 ProtoLog.i(WM_SHOW_TRANSACTIONS, " NEW SURFACE SESSION %s", mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700483 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
484 mService.dispatchNewAnimatorScaleLocked(this);
485 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 }
487 mNumWindow++;
488 }
489
Wale Ogunwale943002b2017-02-15 19:34:01 -0800490 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800492 killSessionLocked();
493 }
494
495
496 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
497 boolean visible, int type) {
498
499 if (!isSystemAlertWindowType(type)) {
500 return;
501 }
502
503 boolean changed;
504
505 if (!mCanAddInternalSystemWindow) {
506 // We want to track non-system signature apps adding alert windows so we can post an
507 // on-going notification for the user to control their visibility.
508 if (visible) {
509 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800510 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800511 } else {
512 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800513 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800514 }
515
516 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800517 if (mAlertWindowSurfaces.isEmpty()) {
518 cancelAlertWindowNotification();
519 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800520 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700521 if (mShowingAlertWindowNotificationAllowed) {
522 mAlertWindowNotification.post();
523 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800524 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800525 }
526 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800527
528 if (type != TYPE_APPLICATION_OVERLAY) {
529 return;
530 }
531
532 if (visible) {
533 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800534 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800535 } else {
536 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800537 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800538 }
539
540 if (changed) {
541 // Notify activity manager of changes to app overlay windows so it can adjust the
542 // importance score for the process.
543 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
544 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800545 }
546
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700547 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
548 mShowingAlertWindowNotificationAllowed = allowed;
549 if (mAlertWindowNotification != null) {
550 if (allowed) {
551 mAlertWindowNotification.post();
552 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800553 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700554 }
555 }
556 }
557
Wale Ogunwaled993a572017-02-05 13:52:09 -0800558 private void killSessionLocked() {
559 if (mNumWindow > 0 || !mClientDead) {
560 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800561 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800562
563 mService.mSessions.remove(this);
564 if (mSurfaceSession == null) {
565 return;
566 }
567
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200568 if (DEBUG) {
569 Slog.v(TAG_WM, "Last window removed from " + this
570 + ", destroying " + mSurfaceSession);
571 }
Adrian Roosb125e0b2019-10-02 14:55:14 +0200572 ProtoLog.i(WM_SHOW_TRANSACTIONS, " KILL SURFACE SESSION %s", mSurfaceSession);
Wale Ogunwaled993a572017-02-05 13:52:09 -0800573 try {
574 mSurfaceSession.kill();
575 } catch (Exception e) {
576 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
577 + " in session " + this + ": " + e.toString());
578 }
579 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800580 mAlertWindowSurfaces.clear();
581 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800582 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800583 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800584 }
585
586 private void setHasOverlayUi(boolean hasOverlayUi) {
587 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800588 }
589
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800590 private void cancelAlertWindowNotification() {
591 if (mAlertWindowNotification == null) {
592 return;
593 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800594 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800595 mAlertWindowNotification = null;
596 }
597
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800598 void dump(PrintWriter pw, String prefix) {
599 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800600 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800601 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
602 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 pw.print(" mClientDead="); pw.print(mClientDead);
604 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700605 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 }
607
608 @Override
609 public String toString() {
610 return mStringName;
611 }
Robert Carr0e007272017-10-02 13:00:55 -0700612
Riddle Hsuccf09402019-08-13 00:33:06 +0800613 /** @return {@code true} if there is an alert window surface on the given display. */
614 boolean hasAlertWindowSurfaces(DisplayContent displayContent) {
615 for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) {
616 final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i);
617 if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) {
618 return true;
619 }
620 }
621 return false;
Robert Carr0e007272017-10-02 13:00:55 -0700622 }
Robert Carr9d431e12018-12-17 13:11:48 -0800623
Vishnu Nair5cf253192019-11-07 15:33:20 -0800624 public void grantInputChannel(int displayId, SurfaceControl surface,
625 IWindow window, IBinder hostInputToken, InputChannel outInputChannel) {
Robert Carr9d431e12018-12-17 13:11:48 -0800626 final long identity = Binder.clearCallingIdentity();
627 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800628 mService.grantInputChannel(mUid, mPid, displayId, surface, window,
Vishnu Nair5cf253192019-11-07 15:33:20 -0800629 hostInputToken, outInputChannel);
Robert Carr9d431e12018-12-17 13:11:48 -0800630 } finally {
631 Binder.restoreCallingIdentity(identity);
632 }
633 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700634}