blob: de7f9e41cac08d0dae7a4ebe878fc113245de2ef [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 Huangdda14a72019-01-10 17:20:27 +080054import android.view.InsetsState;
Daichi Hironoa1fb9be2017-12-18 17:02:54 +090055import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056import android.view.SurfaceSession;
57import android.view.WindowManager;
58
Chenjie Yue8904192017-12-08 19:12:57 -080059import com.android.internal.os.logging.MetricsLoggerWrapper;
Adrian Roosb125e0b2019-10-02 14:55:14 +020060import com.android.server.protolog.common.ProtoLog;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080061import com.android.server.wm.WindowManagerService.H;
62
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import java.io.PrintWriter;
Adrian Roos4ffc8972019-02-07 20:45:11 +010064import java.util.List;
wilsonshihc32538e2018-11-07 17:27:34 +080065import java.util.function.BiConsumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67/**
68 * This class represents an active client session. There is generally one
69 * Session object per process that is interacting with the window manager.
70 */
Bryce Leea5592862017-10-23 12:57:37 -070071class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070073 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 final int mUid;
75 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070076 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070078 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080079 // Set of visible application overlay window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080080 private final ArraySet<WindowSurfaceController> mAppOverlaySurfaces = new ArraySet<>();
Wale Ogunwale943002b2017-02-15 19:34:01 -080081 // Set of visible alert window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080082 private final ArraySet<WindowSurfaceController> mAlertWindowSurfaces = new ArraySet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090083 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080084 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070085 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020086 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080087 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070088 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070089 private boolean mClientDead = false;
90 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080091 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070092 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093
Yohei Yukawaa71bb252018-09-19 19:21:24 -070094 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070096 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 mUid = Binder.getCallingUid();
98 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070099 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800100 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800101 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700102 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
103 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200104 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
105 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700106 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900107 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 StringBuilder sb = new StringBuilder();
109 sb.append("Session{");
110 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700111 sb.append(" ");
112 sb.append(mPid);
113 if (mUid < Process.FIRST_APPLICATION_UID) {
114 sb.append(":");
115 sb.append(mUid);
116 } else {
117 sb.append(":u");
118 sb.append(UserHandle.getUserId(mUid));
119 sb.append('a');
120 sb.append(UserHandle.getAppId(mUid));
121 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 sb.append("}");
123 mStringName = sb.toString();
124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700126 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 } catch (RemoteException e) {
128 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700129 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 }
131 }
132
133 @Override
134 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
135 throws RemoteException {
136 try {
137 return super.onTransact(code, data, reply, flags);
138 } catch (RuntimeException e) {
139 // Log all 'real' exceptions thrown to the caller
140 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800141 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 }
143 throw e;
144 }
145 }
146
Andrew Scull26f830d2017-05-19 12:16:10 +0100147 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700149 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700150 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 mClientDead = true;
152 killSessionLocked();
153 }
154 }
155
Craig Mautner6881a102012-07-27 13:04:51 -0700156 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700157 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100158 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
Jorim Jaggif081f062019-10-24 16:24:54 +0200159 Rect outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200160 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
161 InsetsState outInsetsState) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100162 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif081f062019-10-24 16:24:54 +0200163 outContentInsets, outStableInsets, outDisplayCutout, outInputChannel,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200164 outInsetsState);
Craig Mautner6881a102012-07-27 13:04:51 -0700165 }
166
167 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700168 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200169 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
170 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700171 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Jorim Jaggif081f062019-10-24 16:24:54 +0200172 new Rect() /* outFrame */, outContentInsets, outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200173 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
174 outInsetsState);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 }
176
Andrew Scull26f830d2017-05-19 12:16:10 +0100177 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 public void remove(IWindow window) {
179 mService.removeWindow(this, window);
180 }
181
Rob Carr64e516f2015-10-29 00:20:45 +0000182 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700183 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700184 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800185 }
186
Andrew Scull26f830d2017-05-19 12:16:10 +0100187 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700188 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700189 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200190 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
191 Rect outStableInsets, Rect outBackdropFrame,
chaviwbe43ac82018-04-04 15:14:49 -0700192 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Valerie Hau30360552020-01-14 16:12:01 -0800193 SurfaceControl outSurfaceControl, InsetsState outInsetsState,
Robert Carr2e20bcd2020-01-22 13:32:38 -0800194 Point outSurfaceSize, SurfaceControl outBLASTSurfaceControl) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800195 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700196 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700197 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700198 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700199 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200200 outFrame, outContentInsets, outVisibleInsets,
201 outStableInsets, outBackdropFrame, cutout,
Robert Carr2e20bcd2020-01-22 13:32:38 -0800202 mergedConfiguration, outSurfaceControl, outInsetsState, outSurfaceSize,
203 outBLASTSurfaceControl);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700204 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800205 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700206 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207 return res;
208 }
209
Andrew Scull26f830d2017-05-19 12:16:10 +0100210 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800211 public boolean outOfMemory(IWindow window) {
212 return mService.outOfMemoryWindow(this, window);
213 }
214
Andrew Scull26f830d2017-05-19 12:16:10 +0100215 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 public void setTransparentRegion(IWindow window, Region region) {
217 mService.setTransparentRegionWindow(this, window, region);
218 }
219
Andrew Scull26f830d2017-05-19 12:16:10 +0100220 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 public void setInsets(IWindow window, int touchableInsets,
222 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
223 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
224 visibleInsets, touchableArea);
225 }
226
Andrew Scull26f830d2017-05-19 12:16:10 +0100227 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
229 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
230 }
231
Andrew Scull26f830d2017-05-19 12:16:10 +0100232 @Override
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700233 public void finishDrawing(IWindow window,
234 @Nullable SurfaceControl.Transaction postDrawTransaction) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200235 if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window);
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700236 mService.finishDrawingWindow(this, window, postDrawTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 }
238
Andrew Scull26f830d2017-05-19 12:16:10 +0100239 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 public void setInTouchMode(boolean mode) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700241 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 mService.mInTouchMode = mode;
243 }
244 }
245
Andrew Scull26f830d2017-05-19 12:16:10 +0100246 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 public boolean getInTouchMode() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700248 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 return mService.mInTouchMode;
250 }
251 }
252
Andrew Scull26f830d2017-05-19 12:16:10 +0100253 @Override
Arthur Hunga4c52062019-02-19 11:31:44 +0800254 public boolean performHapticFeedback(int effectId, boolean always) {
255 long ident = Binder.clearCallingIdentity();
256 try {
257 return mService.mPolicy.performHapticFeedback(mUid, mPackageName,
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100258 effectId, always, null);
Arthur Hunga4c52062019-02-19 11:31:44 +0800259 } finally {
260 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 }
262 }
263
264 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900265
Andrew Scull26f830d2017-05-19 12:16:10 +0100266 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900267 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
268 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900269 final long ident = Binder.clearCallingIdentity();
270 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800271 return mDragDropController.performDrag(mSurfaceSession, mPid, mUid, window,
Daichi Hironofabca092017-12-19 15:02:50 +0900272 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900273 } finally {
274 Binder.restoreCallingIdentity(ident);
275 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 }
277
Andrew Scull26f830d2017-05-19 12:16:10 +0100278 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900279 public void reportDropResult(IWindow window, boolean consumed) {
280 final long ident = Binder.clearCallingIdentity();
281 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900282 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900283 } finally {
284 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900286 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287
Daichi Hironodf5cf622017-09-11 14:59:26 +0900288 @Override
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900289 public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900290 final long ident = Binder.clearCallingIdentity();
291 try {
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900292 mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
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
299 public void dragRecipientEntered(IWindow window) {
300 mDragDropController.dragRecipientEntered(window);
301 }
302
303 @Override
304 public void dragRecipientExited(IWindow window) {
305 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 }
307
Andrew Scull26f830d2017-05-19 12:16:10 +0100308 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700309 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800310 if (DEBUG_TASK_POSITIONING) Slog.d(
311 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700312
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800313 long ident = Binder.clearCallingIdentity();
314 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900315 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800316 } finally {
317 Binder.restoreCallingIdentity(ident);
318 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700319 }
320
Adrian Roos4ffc8972019-02-07 20:45:11 +0100321 @Override
yj81.kwon19585ff2019-04-23 18:53:57 -0700322 public void finishMovingTask(IWindow window) {
323 if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask");
324
325 long ident = Binder.clearCallingIdentity();
326 try {
327 mService.mTaskPositioningController.finishTaskPositioning(window);
328 } finally {
329 Binder.restoreCallingIdentity(ident);
330 }
331 }
332
333 @Override
Adrian Roos4ffc8972019-02-07 20:45:11 +0100334 public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) {
335 long ident = Binder.clearCallingIdentity();
336 try {
337 mService.reportSystemGestureExclusionChanged(this, window, exclusionRects);
338 } finally {
339 Binder.restoreCallingIdentity(ident);
340 }
341 }
342
wilsonshihc32538e2018-11-07 17:27:34 +0800343 private void actionOnWallpaper(IBinder window,
344 BiConsumer<WallpaperController, WindowState> action) {
345 final WindowState windowState = mService.windowForClientLocked(this, window, true);
346 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
347 }
348
Andrew Scull26f830d2017-05-19 12:16:10 +0100349 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700351 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 long ident = Binder.clearCallingIdentity();
353 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800354 actionOnWallpaper(window, (wpController, windowState) ->
355 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 } 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 void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700364 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800365 actionOnWallpaper(window, (wpController, windowState) ->
366 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700367 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 }
369
Andrew Scull26f830d2017-05-19 12:16:10 +0100370 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700371 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700372 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700373 long ident = Binder.clearCallingIdentity();
374 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800375 actionOnWallpaper(window, (wpController, windowState) ->
376 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700377 } finally {
378 Binder.restoreCallingIdentity(ident);
379 }
380 }
381 }
382
Andrew Scull26f830d2017-05-19 12:16:10 +0100383 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
385 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700386 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 long ident = Binder.clearCallingIdentity();
388 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800389 final WindowState windowState = mService.windowForClientLocked(this, window, true);
390 return windowState.getDisplayContent().mWallpaperController
391 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 } finally {
393 Binder.restoreCallingIdentity(ident);
394 }
395 }
396 }
397
Andrew Scull26f830d2017-05-19 12:16:10 +0100398 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700400 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800401 actionOnWallpaper(window, (wpController, windowState) ->
402 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700403 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 }
405
Andrew Scull26f830d2017-05-19 12:16:10 +0100406 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700407 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700408 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700409 final long identity = Binder.clearCallingIdentity();
410 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700411 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700412 } finally {
413 Binder.restoreCallingIdentity(identity);
414 }
415 }
416 }
417
Andrew Scull26f830d2017-05-19 12:16:10 +0100418 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800419 public IWindowId getWindowId(IBinder window) {
420 return mService.getWindowId(window);
421 }
422
Jeff Brownc2932a12014-11-20 18:04:05 -0800423 @Override
424 public void pokeDrawLock(IBinder window) {
425 final long identity = Binder.clearCallingIdentity();
426 try {
427 mService.pokeDrawLock(this, window);
428 } finally {
429 Binder.restoreCallingIdentity(identity);
430 }
431 }
432
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800433 @Override
434 public void updatePointerIcon(IWindow window) {
435 final long identity = Binder.clearCallingIdentity();
436 try {
437 mService.updatePointerIcon(window);
438 } finally {
439 Binder.restoreCallingIdentity(identity);
440 }
441 }
442
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800443 @Override
Tiger Huangd8ec9382019-04-18 14:35:09 -0700444 public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) {
445 mService.reparentDisplayContent(window, sc, displayId);
446 }
447
448 @Override
449 public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) {
450 mService.updateDisplayContentLocation(window, x, y, displayId);
451 }
452
453 @Override
chaviwaa0d74e2019-12-26 14:13:40 -0800454 public void updateTapExcludeRegion(IWindow window, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800455 final long identity = Binder.clearCallingIdentity();
456 try {
chaviwaa0d74e2019-12-26 14:13:40 -0800457 mService.updateTapExcludeRegion(window, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800458 } finally {
459 Binder.restoreCallingIdentity(identity);
460 }
461 }
462
Jorim Jaggie35c0592018-11-06 16:21:08 +0100463 @Override
464 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800465 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100466 final WindowState windowState = mService.windowForClientLocked(this, window,
467 false /* throwOnError */);
468 if (windowState != null) {
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100469 windowState.updateRequestedInsetsState(state);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100470 windowState.getDisplayContent().getInsetsPolicy().onInsetsModified(
Jorim Jaggie35c0592018-11-06 16:21:08 +0100471 windowState, state);
472 }
473 }
474 }
475
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800476 void windowAddedLocked(String packageName) {
477 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700478 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 if (mSurfaceSession == null) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200480 if (DEBUG) {
481 Slog.v(TAG_WM, "First window added to " + this + ", creating SurfaceSession");
482 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 mSurfaceSession = new SurfaceSession();
Adrian Roosb125e0b2019-10-02 14:55:14 +0200484 ProtoLog.i(WM_SHOW_TRANSACTIONS, " NEW SURFACE SESSION %s", mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700486 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
487 mService.dispatchNewAnimatorScaleLocked(this);
488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 }
490 mNumWindow++;
491 }
492
Wale Ogunwale943002b2017-02-15 19:34:01 -0800493 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800495 killSessionLocked();
496 }
497
498
499 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
500 boolean visible, int type) {
501
502 if (!isSystemAlertWindowType(type)) {
503 return;
504 }
505
506 boolean changed;
507
508 if (!mCanAddInternalSystemWindow) {
509 // We want to track non-system signature apps adding alert windows so we can post an
510 // on-going notification for the user to control their visibility.
511 if (visible) {
512 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800513 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800514 } else {
515 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800516 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800517 }
518
519 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800520 if (mAlertWindowSurfaces.isEmpty()) {
521 cancelAlertWindowNotification();
522 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800523 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700524 if (mShowingAlertWindowNotificationAllowed) {
525 mAlertWindowNotification.post();
526 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800527 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800528 }
529 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800530
531 if (type != TYPE_APPLICATION_OVERLAY) {
532 return;
533 }
534
535 if (visible) {
536 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800537 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800538 } else {
539 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800540 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800541 }
542
543 if (changed) {
544 // Notify activity manager of changes to app overlay windows so it can adjust the
545 // importance score for the process.
546 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
547 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 }
549
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700550 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
551 mShowingAlertWindowNotificationAllowed = allowed;
552 if (mAlertWindowNotification != null) {
553 if (allowed) {
554 mAlertWindowNotification.post();
555 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800556 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700557 }
558 }
559 }
560
Wale Ogunwaled993a572017-02-05 13:52:09 -0800561 private void killSessionLocked() {
562 if (mNumWindow > 0 || !mClientDead) {
563 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800565
566 mService.mSessions.remove(this);
567 if (mSurfaceSession == null) {
568 return;
569 }
570
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200571 if (DEBUG) {
572 Slog.v(TAG_WM, "Last window removed from " + this
573 + ", destroying " + mSurfaceSession);
574 }
Adrian Roosb125e0b2019-10-02 14:55:14 +0200575 ProtoLog.i(WM_SHOW_TRANSACTIONS, " KILL SURFACE SESSION %s", mSurfaceSession);
Wale Ogunwaled993a572017-02-05 13:52:09 -0800576 try {
577 mSurfaceSession.kill();
578 } catch (Exception e) {
579 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
580 + " in session " + this + ": " + e.toString());
581 }
582 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800583 mAlertWindowSurfaces.clear();
584 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800585 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800586 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800587 }
588
589 private void setHasOverlayUi(boolean hasOverlayUi) {
590 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591 }
592
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800593 private void cancelAlertWindowNotification() {
594 if (mAlertWindowNotification == null) {
595 return;
596 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800597 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800598 mAlertWindowNotification = null;
599 }
600
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 void dump(PrintWriter pw, String prefix) {
602 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800603 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800604 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
605 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 pw.print(" mClientDead="); pw.print(mClientDead);
607 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700608 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 }
610
611 @Override
612 public String toString() {
613 return mStringName;
614 }
Robert Carr0e007272017-10-02 13:00:55 -0700615
Riddle Hsuccf09402019-08-13 00:33:06 +0800616 /** @return {@code true} if there is an alert window surface on the given display. */
617 boolean hasAlertWindowSurfaces(DisplayContent displayContent) {
618 for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) {
619 final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i);
620 if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) {
621 return true;
622 }
623 }
624 return false;
Robert Carr0e007272017-10-02 13:00:55 -0700625 }
Robert Carr9d431e12018-12-17 13:11:48 -0800626
Vishnu Nairddbd2512019-11-12 14:39:43 -0800627 @Override
Vishnu Nair5cf253192019-11-07 15:33:20 -0800628 public void grantInputChannel(int displayId, SurfaceControl surface,
629 IWindow window, IBinder hostInputToken, InputChannel outInputChannel) {
Vishnu Nairddbd2512019-11-12 14:39:43 -0800630 if (hostInputToken == null && !mCanAddInternalSystemWindow) {
631 // Callers without INTERNAL_SYSTEM_WINDOW permission cannot grant input channel to
632 // embedded windows without providing a host window input token
633 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
634 }
635
Robert Carr9d431e12018-12-17 13:11:48 -0800636 final long identity = Binder.clearCallingIdentity();
637 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800638 mService.grantInputChannel(mUid, mPid, displayId, surface, window,
Vishnu Nair5cf253192019-11-07 15:33:20 -0800639 hostInputToken, outInputChannel);
Robert Carr9d431e12018-12-17 13:11:48 -0800640 } finally {
641 Binder.restoreCallingIdentity(identity);
642 }
643 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700644}