blob: 72bb355146d18b1eaeecd9146dd1566e6c494f6a [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
Adam Pardyl8c2d19c2019-09-16 17:15:38 +020027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
30import 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;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080059import com.android.server.wm.WindowManagerService.H;
60
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061import java.io.PrintWriter;
Adrian Roos4ffc8972019-02-07 20:45:11 +010062import java.util.List;
wilsonshihc32538e2018-11-07 17:27:34 +080063import java.util.function.BiConsumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064
65/**
66 * This class represents an active client session. There is generally one
67 * Session object per process that is interacting with the window manager.
68 */
Bryce Leea5592862017-10-23 12:57:37 -070069class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070071 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 final int mUid;
73 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070074 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070076 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080077 // Set of visible application overlay window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080078 private final ArraySet<WindowSurfaceController> mAppOverlaySurfaces = new ArraySet<>();
Wale Ogunwale943002b2017-02-15 19:34:01 -080079 // Set of visible alert window surfaces connected to this session.
Riddle Hsuccf09402019-08-13 00:33:06 +080080 private final ArraySet<WindowSurfaceController> mAlertWindowSurfaces = new ArraySet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090081 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080082 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070083 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020084 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080085 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070086 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070087 private boolean mClientDead = false;
88 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080089 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070090 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091
Yohei Yukawaa71bb252018-09-19 19:21:24 -070092 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070094 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095 mUid = Binder.getCallingUid();
96 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070097 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -080098 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -080099 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700100 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
101 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200102 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
103 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700104 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900105 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 StringBuilder sb = new StringBuilder();
107 sb.append("Session{");
108 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700109 sb.append(" ");
110 sb.append(mPid);
111 if (mUid < Process.FIRST_APPLICATION_UID) {
112 sb.append(":");
113 sb.append(mUid);
114 } else {
115 sb.append(":u");
116 sb.append(UserHandle.getUserId(mUid));
117 sb.append('a');
118 sb.append(UserHandle.getAppId(mUid));
119 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 sb.append("}");
121 mStringName = sb.toString();
122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700124 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 } catch (RemoteException e) {
126 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700127 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 }
129 }
130
131 @Override
132 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
133 throws RemoteException {
134 try {
135 return super.onTransact(code, data, reply, flags);
136 } catch (RuntimeException e) {
137 // Log all 'real' exceptions thrown to the caller
138 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800139 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 }
141 throw e;
142 }
143 }
144
Andrew Scull26f830d2017-05-19 12:16:10 +0100145 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700147 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700148 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 mClientDead = true;
150 killSessionLocked();
151 }
152 }
153
Craig Mautner6881a102012-07-27 13:04:51 -0700154 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700155 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100156 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
157 Rect outStableInsets, Rect outOutsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200158 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
159 InsetsState outInsetsState) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100160 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200161 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel,
162 outInsetsState);
Craig Mautner6881a102012-07-27 13:04:51 -0700163 }
164
165 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700166 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200167 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
168 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700169 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos9e370f22018-03-06 18:19:45 +0100170 new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200171 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
172 outInsetsState);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 }
174
Andrew Scull26f830d2017-05-19 12:16:10 +0100175 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 public void remove(IWindow window) {
177 mService.removeWindow(this, window);
178 }
179
Rob Carr64e516f2015-10-29 00:20:45 +0000180 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700181 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700182 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800183 }
184
Andrew Scull26f830d2017-05-19 12:16:10 +0100185 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700186 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700187 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
188 Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
189 Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
190 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Robert Carr5fea55b2018-12-10 13:05:52 -0800191 SurfaceControl outSurfaceControl, InsetsState outInsetsState) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800192 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700193 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700194 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700195 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700196 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800197 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100198 outStableInsets, outsets, outBackdropFrame, cutout,
Robert Carr5fea55b2018-12-10 13:05:52 -0800199 mergedConfiguration, outSurfaceControl, outInsetsState);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700200 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800201 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700202 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 return res;
204 }
205
Andrew Scull26f830d2017-05-19 12:16:10 +0100206 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800207 public boolean outOfMemory(IWindow window) {
208 return mService.outOfMemoryWindow(this, window);
209 }
210
Andrew Scull26f830d2017-05-19 12:16:10 +0100211 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 public void setTransparentRegion(IWindow window, Region region) {
213 mService.setTransparentRegionWindow(this, window, region);
214 }
215
Andrew Scull26f830d2017-05-19 12:16:10 +0100216 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 public void setInsets(IWindow window, int touchableInsets,
218 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
219 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
220 visibleInsets, touchableArea);
221 }
222
Andrew Scull26f830d2017-05-19 12:16:10 +0100223 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
225 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
226 }
227
Andrew Scull26f830d2017-05-19 12:16:10 +0100228 @Override
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700229 public void finishDrawing(IWindow window,
230 @Nullable SurfaceControl.Transaction postDrawTransaction) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200231 if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window);
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700232 mService.finishDrawingWindow(this, window, postDrawTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 }
234
Andrew Scull26f830d2017-05-19 12:16:10 +0100235 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 public void setInTouchMode(boolean mode) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700237 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 mService.mInTouchMode = mode;
239 }
240 }
241
Andrew Scull26f830d2017-05-19 12:16:10 +0100242 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 public boolean getInTouchMode() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700244 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 return mService.mInTouchMode;
246 }
247 }
248
Andrew Scull26f830d2017-05-19 12:16:10 +0100249 @Override
Arthur Hunga4c52062019-02-19 11:31:44 +0800250 public boolean performHapticFeedback(int effectId, boolean always) {
251 long ident = Binder.clearCallingIdentity();
252 try {
253 return mService.mPolicy.performHapticFeedback(mUid, mPackageName,
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100254 effectId, always, null);
Arthur Hunga4c52062019-02-19 11:31:44 +0800255 } finally {
256 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 }
258 }
259
260 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900261
Andrew Scull26f830d2017-05-19 12:16:10 +0100262 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900263 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
264 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900265 final int callerPid = Binder.getCallingPid();
266 final int callerUid = Binder.getCallingUid();
267 final long ident = Binder.clearCallingIdentity();
268 try {
Daichi Hironofabca092017-12-19 15:02:50 +0900269 return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window,
270 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900271 } finally {
272 Binder.restoreCallingIdentity(ident);
273 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 }
275
Andrew Scull26f830d2017-05-19 12:16:10 +0100276 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900277 public void reportDropResult(IWindow window, boolean consumed) {
278 final long ident = Binder.clearCallingIdentity();
279 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900280 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900281 } finally {
282 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900284 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285
Daichi Hironodf5cf622017-09-11 14:59:26 +0900286 @Override
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900287 public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900288 final long ident = Binder.clearCallingIdentity();
289 try {
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900290 mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900291 } finally {
292 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900294 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295
Daichi Hironodf5cf622017-09-11 14:59:26 +0900296 @Override
297 public void dragRecipientEntered(IWindow window) {
298 mDragDropController.dragRecipientEntered(window);
299 }
300
301 @Override
302 public void dragRecipientExited(IWindow window) {
303 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 }
305
Andrew Scull26f830d2017-05-19 12:16:10 +0100306 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700307 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800308 if (DEBUG_TASK_POSITIONING) Slog.d(
309 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700310
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800311 long ident = Binder.clearCallingIdentity();
312 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900313 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800314 } finally {
315 Binder.restoreCallingIdentity(ident);
316 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700317 }
318
Adrian Roos4ffc8972019-02-07 20:45:11 +0100319 @Override
yj81.kwon19585ff2019-04-23 18:53:57 -0700320 public void finishMovingTask(IWindow window) {
321 if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask");
322
323 long ident = Binder.clearCallingIdentity();
324 try {
325 mService.mTaskPositioningController.finishTaskPositioning(window);
326 } finally {
327 Binder.restoreCallingIdentity(ident);
328 }
329 }
330
331 @Override
Adrian Roos4ffc8972019-02-07 20:45:11 +0100332 public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) {
333 long ident = Binder.clearCallingIdentity();
334 try {
335 mService.reportSystemGestureExclusionChanged(this, window, exclusionRects);
336 } finally {
337 Binder.restoreCallingIdentity(ident);
338 }
339 }
340
wilsonshihc32538e2018-11-07 17:27:34 +0800341 private void actionOnWallpaper(IBinder window,
342 BiConsumer<WallpaperController, WindowState> action) {
343 final WindowState windowState = mService.windowForClientLocked(this, window, true);
344 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
345 }
346
Andrew Scull26f830d2017-05-19 12:16:10 +0100347 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700349 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 long ident = Binder.clearCallingIdentity();
351 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800352 actionOnWallpaper(window, (wpController, windowState) ->
353 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 } finally {
355 Binder.restoreCallingIdentity(ident);
356 }
357 }
358 }
359
Andrew Scull26f830d2017-05-19 12:16:10 +0100360 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700362 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800363 actionOnWallpaper(window, (wpController, windowState) ->
364 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700365 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 }
367
Andrew Scull26f830d2017-05-19 12:16:10 +0100368 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700369 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700370 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700371 long ident = Binder.clearCallingIdentity();
372 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800373 actionOnWallpaper(window, (wpController, windowState) ->
374 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700375 } finally {
376 Binder.restoreCallingIdentity(ident);
377 }
378 }
379 }
380
Andrew Scull26f830d2017-05-19 12:16:10 +0100381 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
383 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700384 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 long ident = Binder.clearCallingIdentity();
386 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800387 final WindowState windowState = mService.windowForClientLocked(this, window, true);
388 return windowState.getDisplayContent().mWallpaperController
389 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 } finally {
391 Binder.restoreCallingIdentity(ident);
392 }
393 }
394 }
395
Andrew Scull26f830d2017-05-19 12:16:10 +0100396 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700398 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800399 actionOnWallpaper(window, (wpController, windowState) ->
400 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700401 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 }
403
Andrew Scull26f830d2017-05-19 12:16:10 +0100404 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700405 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700406 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700407 final long identity = Binder.clearCallingIdentity();
408 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700409 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700410 } finally {
411 Binder.restoreCallingIdentity(identity);
412 }
413 }
414 }
415
Andrew Scull26f830d2017-05-19 12:16:10 +0100416 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800417 public IWindowId getWindowId(IBinder window) {
418 return mService.getWindowId(window);
419 }
420
Jeff Brownc2932a12014-11-20 18:04:05 -0800421 @Override
422 public void pokeDrawLock(IBinder window) {
423 final long identity = Binder.clearCallingIdentity();
424 try {
425 mService.pokeDrawLock(this, window);
426 } finally {
427 Binder.restoreCallingIdentity(identity);
428 }
429 }
430
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800431 @Override
432 public void updatePointerIcon(IWindow window) {
433 final long identity = Binder.clearCallingIdentity();
434 try {
435 mService.updatePointerIcon(window);
436 } finally {
437 Binder.restoreCallingIdentity(identity);
438 }
439 }
440
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800441 @Override
Tiger Huangd8ec9382019-04-18 14:35:09 -0700442 public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) {
443 mService.reparentDisplayContent(window, sc, displayId);
444 }
445
446 @Override
447 public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) {
448 mService.updateDisplayContentLocation(window, x, y, displayId);
449 }
450
451 @Override
Tiger Huang2b210c22019-03-18 21:21:26 +0800452 public void updateTapExcludeRegion(IWindow window, int regionId, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800453 final long identity = Binder.clearCallingIdentity();
454 try {
Tiger Huang2b210c22019-03-18 21:21:26 +0800455 mService.updateTapExcludeRegion(window, regionId, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800456 } finally {
457 Binder.restoreCallingIdentity(identity);
458 }
459 }
460
Jorim Jaggie35c0592018-11-06 16:21:08 +0100461 @Override
462 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800463 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100464 final WindowState windowState = mService.windowForClientLocked(this, window,
465 false /* throwOnError */);
466 if (windowState != null) {
467 windowState.getDisplayContent().getInsetsStateController().onInsetsModified(
468 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();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800481 if (SHOW_TRANSACTIONS) Slog.i(
482 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700484 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
485 mService.dispatchNewAnimatorScaleLocked(this);
486 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 }
488 mNumWindow++;
489 }
490
Wale Ogunwale943002b2017-02-15 19:34:01 -0800491 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800493 killSessionLocked();
494 }
495
496
497 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
498 boolean visible, int type) {
499
500 if (!isSystemAlertWindowType(type)) {
501 return;
502 }
503
504 boolean changed;
505
506 if (!mCanAddInternalSystemWindow) {
507 // We want to track non-system signature apps adding alert windows so we can post an
508 // on-going notification for the user to control their visibility.
509 if (visible) {
510 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800511 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800512 } else {
513 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800514 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800515 }
516
517 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800518 if (mAlertWindowSurfaces.isEmpty()) {
519 cancelAlertWindowNotification();
520 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800521 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700522 if (mShowingAlertWindowNotificationAllowed) {
523 mAlertWindowNotification.post();
524 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800525 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800526 }
527 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800528
529 if (type != TYPE_APPLICATION_OVERLAY) {
530 return;
531 }
532
533 if (visible) {
534 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800535 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800536 } else {
537 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800538 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800539 }
540
541 if (changed) {
542 // Notify activity manager of changes to app overlay windows so it can adjust the
543 // importance score for the process.
544 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
545 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 }
547
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700548 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
549 mShowingAlertWindowNotificationAllowed = allowed;
550 if (mAlertWindowNotification != null) {
551 if (allowed) {
552 mAlertWindowNotification.post();
553 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800554 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700555 }
556 }
557 }
558
Wale Ogunwaled993a572017-02-05 13:52:09 -0800559 private void killSessionLocked() {
560 if (mNumWindow > 0 || !mClientDead) {
561 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800563
564 mService.mSessions.remove(this);
565 if (mSurfaceSession == null) {
566 return;
567 }
568
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200569 if (DEBUG) {
570 Slog.v(TAG_WM, "Last window removed from " + this
571 + ", destroying " + mSurfaceSession);
572 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800573 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
574 try {
575 mSurfaceSession.kill();
576 } catch (Exception e) {
577 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
578 + " in session " + this + ": " + e.toString());
579 }
580 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800581 mAlertWindowSurfaces.clear();
582 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800583 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800584 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800585 }
586
587 private void setHasOverlayUi(boolean hasOverlayUi) {
588 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 }
590
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800591 private void cancelAlertWindowNotification() {
592 if (mAlertWindowNotification == null) {
593 return;
594 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800595 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800596 mAlertWindowNotification = null;
597 }
598
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 void dump(PrintWriter pw, String prefix) {
600 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800601 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800602 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
603 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800604 pw.print(" mClientDead="); pw.print(mClientDead);
605 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700606 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800607 }
608
609 @Override
610 public String toString() {
611 return mStringName;
612 }
Robert Carr0e007272017-10-02 13:00:55 -0700613
Riddle Hsuccf09402019-08-13 00:33:06 +0800614 /** @return {@code true} if there is an alert window surface on the given display. */
615 boolean hasAlertWindowSurfaces(DisplayContent displayContent) {
616 for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) {
617 final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i);
618 if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) {
619 return true;
620 }
621 }
622 return false;
Robert Carr0e007272017-10-02 13:00:55 -0700623 }
Robert Carr9d431e12018-12-17 13:11:48 -0800624
625 public void blessInputSurface(int displayId, SurfaceControl surface,
626 InputChannel outInputChannel) {
627 final int callerUid = Binder.getCallingUid();
628 final int callerPid = Binder.getCallingPid();
629 final long identity = Binder.clearCallingIdentity();
630 try {
631 mService.blessInputSurface(callerUid, callerPid, displayId, surface, outInputChannel);
632 } finally {
633 Binder.restoreCallingIdentity(identity);
634 }
635 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700636}