blob: 56147f216e73e754eb84de497787c2ae050cd35f [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;
Valerie Hau30360552020-01-14 16:12:01 -080034import android.graphics.Point;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080035import android.graphics.Rect;
36import android.graphics.Region;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.IBinder;
40import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070041import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.os.RemoteException;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070043import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070044import android.os.UserHandle;
Riddle Hsuccf09402019-08-13 00:33:06 +080045import android.util.ArraySet;
Andrii Kulian44607962017-03-16 11:06:24 -070046import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047import android.util.Slog;
Adrian Roos5c6b6222017-11-07 17:36:10 +010048import android.view.DisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080050import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080051import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080052import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053import android.view.InputChannel;
Tiger Huang0426a332020-03-29 01:17:08 +080054import android.view.InsetsSourceControl;
Tiger Huangdda14a72019-01-10 17:20:27 +080055import android.view.InsetsState;
Daichi Hironoa1fb9be2017-12-18 17:02:54 +090056import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057import android.view.SurfaceSession;
58import android.view.WindowManager;
59
Chenjie Yue8904192017-12-08 19:12:57 -080060import com.android.internal.os.logging.MetricsLoggerWrapper;
Adrian Roosb125e0b2019-10-02 14:55:14 +020061import com.android.server.protolog.common.ProtoLog;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080062import com.android.server.wm.WindowManagerService.H;
63
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064import java.io.PrintWriter;
Adrian Roos4ffc8972019-02-07 20:45:11 +010065import java.util.List;
wilsonshihc32538e2018-11-07 17:27:34 +080066import java.util.function.BiConsumer;
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 int mUid;
76 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070077 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070079 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080080 // Set of visible application overlay window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080081 private final ArraySet<WindowSurfaceController> mAppOverlaySurfaces = new ArraySet<>();
Wale Ogunwale943002b2017-02-15 19:34:01 -080082 // Set of visible alert window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080083 private final ArraySet<WindowSurfaceController> mAlertWindowSurfaces = new ArraySet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090084 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080085 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070086 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020087 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080088 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070089 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070090 private boolean mClientDead = false;
91 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080092 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070093 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094
Yohei Yukawaa71bb252018-09-19 19:21:24 -070095 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070097 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080098 mUid = Binder.getCallingUid();
99 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700100 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800101 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800102 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700103 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
104 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200105 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
106 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700107 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900108 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 StringBuilder sb = new StringBuilder();
110 sb.append("Session{");
111 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700112 sb.append(" ");
113 sb.append(mPid);
114 if (mUid < Process.FIRST_APPLICATION_UID) {
115 sb.append(":");
116 sb.append(mUid);
117 } else {
118 sb.append(":u");
119 sb.append(UserHandle.getUserId(mUid));
120 sb.append('a');
121 sb.append(UserHandle.getAppId(mUid));
122 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 sb.append("}");
124 mStringName = sb.toString();
125
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700127 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 } catch (RemoteException e) {
129 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700130 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 }
132 }
133
134 @Override
135 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
136 throws RemoteException {
137 try {
138 return super.onTransact(code, data, reply, flags);
139 } catch (RuntimeException e) {
140 // Log all 'real' exceptions thrown to the caller
141 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800142 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 }
144 throw e;
145 }
146 }
147
Andrew Scull26f830d2017-05-19 12:16:10 +0100148 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700150 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700151 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 mClientDead = true;
153 killSessionLocked();
154 }
155 }
156
Craig Mautner6881a102012-07-27 13:04:51 -0700157 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700158 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100159 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
Jorim Jaggif081f062019-10-24 16:24:54 +0200160 Rect outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200161 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
Tiger Huang0426a332020-03-29 01:17:08 +0800162 InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100163 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif081f062019-10-24 16:24:54 +0200164 outContentInsets, outStableInsets, outDisplayCutout, outInputChannel,
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800165 outInsetsState, outActiveControls, UserHandle.getUserId(mUid));
166 }
167
168
169 @Override
170 public int addToDisplayAsUser(IWindow window, int seq, WindowManager.LayoutParams attrs,
171 int viewVisibility, int displayId, int userId, Rect outFrame,
172 Rect outContentInsets, Rect outStableInsets,
173 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
174 InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) {
175 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
176 outContentInsets, outStableInsets, outDisplayCutout, outInputChannel,
177 outInsetsState, outActiveControls, userId);
Craig Mautner6881a102012-07-27 13:04:51 -0700178 }
179
180 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700181 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200182 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
183 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700184 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Jorim Jaggif081f062019-10-24 16:24:54 +0200185 new Rect() /* outFrame */, outContentInsets, outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200186 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800187 outInsetsState, null, UserHandle.getUserId(mUid));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 }
189
Andrew Scull26f830d2017-05-19 12:16:10 +0100190 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 public void remove(IWindow window) {
192 mService.removeWindow(this, window);
193 }
194
Rob Carr64e516f2015-10-29 00:20:45 +0000195 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700196 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700197 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800198 }
199
Andrew Scull26f830d2017-05-19 12:16:10 +0100200 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700201 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700202 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200203 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
204 Rect outStableInsets, Rect outBackdropFrame,
chaviwbe43ac82018-04-04 15:14:49 -0700205 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Valerie Hau30360552020-01-14 16:12:01 -0800206 SurfaceControl outSurfaceControl, InsetsState outInsetsState,
Tiger Huang0426a332020-03-29 01:17:08 +0800207 InsetsSourceControl[] outActiveControls, Point outSurfaceSize,
208 SurfaceControl outBLASTSurfaceControl) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800209 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700210 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700211 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700212 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700213 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200214 outFrame, outContentInsets, outVisibleInsets,
215 outStableInsets, outBackdropFrame, cutout,
Tiger Huang0426a332020-03-29 01:17:08 +0800216 mergedConfiguration, outSurfaceControl, outInsetsState, outActiveControls,
217 outSurfaceSize, outBLASTSurfaceControl);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700218 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800219 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700220 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 return res;
222 }
223
Andrew Scull26f830d2017-05-19 12:16:10 +0100224 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800225 public boolean outOfMemory(IWindow window) {
226 return mService.outOfMemoryWindow(this, window);
227 }
228
Andrew Scull26f830d2017-05-19 12:16:10 +0100229 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 public void setTransparentRegion(IWindow window, Region region) {
231 mService.setTransparentRegionWindow(this, window, region);
232 }
233
Andrew Scull26f830d2017-05-19 12:16:10 +0100234 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 public void setInsets(IWindow window, int touchableInsets,
236 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
237 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
238 visibleInsets, touchableArea);
239 }
240
Andrew Scull26f830d2017-05-19 12:16:10 +0100241 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
243 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
244 }
245
Andrew Scull26f830d2017-05-19 12:16:10 +0100246 @Override
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700247 public void finishDrawing(IWindow window,
248 @Nullable SurfaceControl.Transaction postDrawTransaction) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200249 if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window);
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700250 mService.finishDrawingWindow(this, window, postDrawTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 }
252
Andrew Scull26f830d2017-05-19 12:16:10 +0100253 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 public void setInTouchMode(boolean mode) {
Arthur Hung6d1b7c52020-01-21 18:35:14 +0800255 mService.setInTouchMode(mode);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 }
257
Andrew Scull26f830d2017-05-19 12:16:10 +0100258 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 public boolean getInTouchMode() {
Arthur Hung6d1b7c52020-01-21 18:35:14 +0800260 return mService.getInTouchMode();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
262
Andrew Scull26f830d2017-05-19 12:16:10 +0100263 @Override
Arthur Hunga4c52062019-02-19 11:31:44 +0800264 public boolean performHapticFeedback(int effectId, boolean always) {
265 long ident = Binder.clearCallingIdentity();
266 try {
267 return mService.mPolicy.performHapticFeedback(mUid, mPackageName,
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100268 effectId, always, null);
Arthur Hunga4c52062019-02-19 11:31:44 +0800269 } finally {
270 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 }
272 }
273
274 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900275
Andrew Scull26f830d2017-05-19 12:16:10 +0100276 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900277 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
278 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900279 final long ident = Binder.clearCallingIdentity();
280 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800281 return mDragDropController.performDrag(mSurfaceSession, mPid, mUid, window,
Daichi Hironofabca092017-12-19 15:02:50 +0900282 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900283 } finally {
284 Binder.restoreCallingIdentity(ident);
285 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 }
287
Andrew Scull26f830d2017-05-19 12:16:10 +0100288 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900289 public void reportDropResult(IWindow window, boolean consumed) {
290 final long ident = Binder.clearCallingIdentity();
291 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900292 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900293 } finally {
294 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900296 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297
Daichi Hironodf5cf622017-09-11 14:59:26 +0900298 @Override
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900299 public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900300 final long ident = Binder.clearCallingIdentity();
301 try {
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900302 mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900303 } finally {
304 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900306 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307
Daichi Hironodf5cf622017-09-11 14:59:26 +0900308 @Override
309 public void dragRecipientEntered(IWindow window) {
310 mDragDropController.dragRecipientEntered(window);
311 }
312
313 @Override
314 public void dragRecipientExited(IWindow window) {
315 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 }
317
Andrew Scull26f830d2017-05-19 12:16:10 +0100318 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700319 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800320 if (DEBUG_TASK_POSITIONING) Slog.d(
321 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700322
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800323 long ident = Binder.clearCallingIdentity();
324 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900325 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800326 } finally {
327 Binder.restoreCallingIdentity(ident);
328 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700329 }
330
Adrian Roos4ffc8972019-02-07 20:45:11 +0100331 @Override
yj81.kwon19585ff2019-04-23 18:53:57 -0700332 public void finishMovingTask(IWindow window) {
333 if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask");
334
335 long ident = Binder.clearCallingIdentity();
336 try {
337 mService.mTaskPositioningController.finishTaskPositioning(window);
338 } finally {
339 Binder.restoreCallingIdentity(ident);
340 }
341 }
342
343 @Override
Adrian Roos4ffc8972019-02-07 20:45:11 +0100344 public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) {
345 long ident = Binder.clearCallingIdentity();
346 try {
347 mService.reportSystemGestureExclusionChanged(this, window, exclusionRects);
348 } finally {
349 Binder.restoreCallingIdentity(ident);
350 }
351 }
352
wilsonshihc32538e2018-11-07 17:27:34 +0800353 private void actionOnWallpaper(IBinder window,
354 BiConsumer<WallpaperController, WindowState> action) {
355 final WindowState windowState = mService.windowForClientLocked(this, window, true);
356 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
357 }
358
Andrew Scull26f830d2017-05-19 12:16:10 +0100359 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700361 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 long ident = Binder.clearCallingIdentity();
363 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800364 actionOnWallpaper(window, (wpController, windowState) ->
365 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 } finally {
367 Binder.restoreCallingIdentity(ident);
368 }
369 }
370 }
371
Andrew Scull26f830d2017-05-19 12:16:10 +0100372 @Override
Lucas Dupin13f4b8a2020-02-19 13:41:52 -0800373 public void setWallpaperZoomOut(IBinder window, float zoom) {
374 if (Float.compare(0f, zoom) > 0 || Float.compare(1f, zoom) < 0 || Float.isNaN(zoom)) {
375 throw new IllegalArgumentException("Zoom must be a valid float between 0 and 1: "
376 + zoom);
377 }
378 synchronized (mService.mGlobalLock) {
379 long ident = Binder.clearCallingIdentity();
380 try {
381 actionOnWallpaper(window, (wpController, windowState) ->
382 wpController.setWallpaperZoomOut(windowState, zoom));
383 } finally {
384 Binder.restoreCallingIdentity(ident);
385 }
386 }
387 }
388
389 @Override
390 public void setShouldZoomOutWallpaper(IBinder window, boolean shouldZoom) {
391 synchronized (mService.mGlobalLock) {
392 actionOnWallpaper(window, (wpController, windowState) ->
393 wpController.setShouldZoomOutWallpaper(windowState, shouldZoom));
394 }
395 }
396
397 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700399 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800400 actionOnWallpaper(window, (wpController, windowState) ->
401 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700402 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 }
404
Andrew Scull26f830d2017-05-19 12:16:10 +0100405 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700406 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700407 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700408 long ident = Binder.clearCallingIdentity();
409 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800410 actionOnWallpaper(window, (wpController, windowState) ->
411 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700412 } finally {
413 Binder.restoreCallingIdentity(ident);
414 }
415 }
416 }
417
Andrew Scull26f830d2017-05-19 12:16:10 +0100418 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
420 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700421 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422 long ident = Binder.clearCallingIdentity();
423 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800424 final WindowState windowState = mService.windowForClientLocked(this, window, true);
425 return windowState.getDisplayContent().mWallpaperController
426 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427 } finally {
428 Binder.restoreCallingIdentity(ident);
429 }
430 }
431 }
432
Andrew Scull26f830d2017-05-19 12:16:10 +0100433 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800434 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700435 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800436 actionOnWallpaper(window, (wpController, windowState) ->
437 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700438 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 }
440
Andrew Scull26f830d2017-05-19 12:16:10 +0100441 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700442 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700443 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700444 final long identity = Binder.clearCallingIdentity();
445 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700446 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700447 } finally {
448 Binder.restoreCallingIdentity(identity);
449 }
450 }
451 }
452
Andrew Scull26f830d2017-05-19 12:16:10 +0100453 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800454 public IWindowId getWindowId(IBinder window) {
455 return mService.getWindowId(window);
456 }
457
Jeff Brownc2932a12014-11-20 18:04:05 -0800458 @Override
459 public void pokeDrawLock(IBinder window) {
460 final long identity = Binder.clearCallingIdentity();
461 try {
462 mService.pokeDrawLock(this, window);
463 } finally {
464 Binder.restoreCallingIdentity(identity);
465 }
466 }
467
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800468 @Override
469 public void updatePointerIcon(IWindow window) {
470 final long identity = Binder.clearCallingIdentity();
471 try {
472 mService.updatePointerIcon(window);
473 } finally {
474 Binder.restoreCallingIdentity(identity);
475 }
476 }
477
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800478 @Override
Tiger Huangd8ec9382019-04-18 14:35:09 -0700479 public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) {
480 mService.reparentDisplayContent(window, sc, displayId);
481 }
482
483 @Override
484 public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) {
485 mService.updateDisplayContentLocation(window, x, y, displayId);
486 }
487
488 @Override
chaviwaa0d74e2019-12-26 14:13:40 -0800489 public void updateTapExcludeRegion(IWindow window, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800490 final long identity = Binder.clearCallingIdentity();
491 try {
chaviwaa0d74e2019-12-26 14:13:40 -0800492 mService.updateTapExcludeRegion(window, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800493 } finally {
494 Binder.restoreCallingIdentity(identity);
495 }
496 }
497
Jorim Jaggie35c0592018-11-06 16:21:08 +0100498 @Override
499 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800500 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100501 final WindowState windowState = mService.windowForClientLocked(this, window,
502 false /* throwOnError */);
503 if (windowState != null) {
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100504 windowState.updateRequestedInsetsState(state);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100505 windowState.getDisplayContent().getInsetsPolicy().onInsetsModified(
Jorim Jaggie35c0592018-11-06 16:21:08 +0100506 windowState, state);
507 }
508 }
509 }
510
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800511 void windowAddedLocked(String packageName) {
512 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700513 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 if (mSurfaceSession == null) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200515 if (DEBUG) {
516 Slog.v(TAG_WM, "First window added to " + this + ", creating SurfaceSession");
517 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518 mSurfaceSession = new SurfaceSession();
Adrian Roosb125e0b2019-10-02 14:55:14 +0200519 ProtoLog.i(WM_SHOW_TRANSACTIONS, " NEW SURFACE SESSION %s", mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800520 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700521 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
522 mService.dispatchNewAnimatorScaleLocked(this);
523 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 }
525 mNumWindow++;
526 }
527
Wale Ogunwale943002b2017-02-15 19:34:01 -0800528 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800529 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800530 killSessionLocked();
531 }
532
533
534 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
535 boolean visible, int type) {
536
537 if (!isSystemAlertWindowType(type)) {
538 return;
539 }
540
541 boolean changed;
542
543 if (!mCanAddInternalSystemWindow) {
544 // We want to track non-system signature apps adding alert windows so we can post an
545 // on-going notification for the user to control their visibility.
546 if (visible) {
547 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800548 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800549 } else {
550 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800551 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800552 }
553
554 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800555 if (mAlertWindowSurfaces.isEmpty()) {
556 cancelAlertWindowNotification();
557 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800558 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700559 if (mShowingAlertWindowNotificationAllowed) {
560 mAlertWindowNotification.post();
561 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800562 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800563 }
564 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800565
566 if (type != TYPE_APPLICATION_OVERLAY) {
567 return;
568 }
569
570 if (visible) {
571 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800572 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800573 } else {
574 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800575 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800576 }
577
578 if (changed) {
579 // Notify activity manager of changes to app overlay windows so it can adjust the
580 // importance score for the process.
581 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
582 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 }
584
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700585 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
586 mShowingAlertWindowNotificationAllowed = allowed;
587 if (mAlertWindowNotification != null) {
588 if (allowed) {
589 mAlertWindowNotification.post();
590 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800591 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700592 }
593 }
594 }
595
Wale Ogunwaled993a572017-02-05 13:52:09 -0800596 private void killSessionLocked() {
597 if (mNumWindow > 0 || !mClientDead) {
598 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800600
601 mService.mSessions.remove(this);
602 if (mSurfaceSession == null) {
603 return;
604 }
605
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200606 if (DEBUG) {
607 Slog.v(TAG_WM, "Last window removed from " + this
608 + ", destroying " + mSurfaceSession);
609 }
Adrian Roosb125e0b2019-10-02 14:55:14 +0200610 ProtoLog.i(WM_SHOW_TRANSACTIONS, " KILL SURFACE SESSION %s", mSurfaceSession);
Wale Ogunwaled993a572017-02-05 13:52:09 -0800611 try {
612 mSurfaceSession.kill();
613 } catch (Exception e) {
614 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
615 + " in session " + this + ": " + e.toString());
616 }
617 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800618 mAlertWindowSurfaces.clear();
619 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800620 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800621 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800622 }
623
624 private void setHasOverlayUi(boolean hasOverlayUi) {
625 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800626 }
627
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800628 private void cancelAlertWindowNotification() {
629 if (mAlertWindowNotification == null) {
630 return;
631 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800632 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800633 mAlertWindowNotification = null;
634 }
635
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 void dump(PrintWriter pw, String prefix) {
637 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800638 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800639 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
640 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 pw.print(" mClientDead="); pw.print(mClientDead);
642 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700643 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644 }
645
646 @Override
647 public String toString() {
648 return mStringName;
649 }
Robert Carr0e007272017-10-02 13:00:55 -0700650
Riddle Hsuccf09402019-08-13 00:33:06 +0800651 /** @return {@code true} if there is an alert window surface on the given display. */
652 boolean hasAlertWindowSurfaces(DisplayContent displayContent) {
653 for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) {
654 final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i);
655 if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) {
656 return true;
657 }
658 }
659 return false;
Robert Carr0e007272017-10-02 13:00:55 -0700660 }
Robert Carr9d431e12018-12-17 13:11:48 -0800661
Vishnu Nairddbd2512019-11-12 14:39:43 -0800662 @Override
Vishnu Nair5cf253192019-11-07 15:33:20 -0800663 public void grantInputChannel(int displayId, SurfaceControl surface,
Evan Rosky680377e2020-01-10 19:12:10 -0800664 IWindow window, IBinder hostInputToken, int flags, InputChannel outInputChannel) {
Vishnu Nairddbd2512019-11-12 14:39:43 -0800665 if (hostInputToken == null && !mCanAddInternalSystemWindow) {
666 // Callers without INTERNAL_SYSTEM_WINDOW permission cannot grant input channel to
667 // embedded windows without providing a host window input token
668 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
669 }
670
Robert Carr9d431e12018-12-17 13:11:48 -0800671 final long identity = Binder.clearCallingIdentity();
672 try {
Evan Rosky680377e2020-01-10 19:12:10 -0800673 mService.grantInputChannel(mUid, mPid, displayId, surface, window, hostInputToken,
674 flags, outInputChannel);
675 } finally {
676 Binder.restoreCallingIdentity(identity);
677 }
678 }
679
680 @Override
681 public void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
682 int flags) {
683 final long identity = Binder.clearCallingIdentity();
684 try {
685 mService.updateInputChannel(channelToken, displayId, surface, flags);
Robert Carr9d431e12018-12-17 13:11:48 -0800686 } finally {
687 Binder.restoreCallingIdentity(identity);
688 }
689 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700690}