blob: e2258093dcbe978293428000dcdb2a098f20e08a [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;
Tiger Huang57ea97e2020-05-08 19:39:18 +080094 private final InsetsSourceControl[] mDummyControls = new InsetsSourceControl[0];
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080095
Yohei Yukawaa71bb252018-09-19 19:21:24 -070096 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080097 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070098 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099 mUid = Binder.getCallingUid();
100 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700101 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800102 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800103 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700104 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
105 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200106 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
107 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700108 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900109 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 StringBuilder sb = new StringBuilder();
111 sb.append("Session{");
112 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700113 sb.append(" ");
114 sb.append(mPid);
115 if (mUid < Process.FIRST_APPLICATION_UID) {
116 sb.append(":");
117 sb.append(mUid);
118 } else {
119 sb.append(":u");
120 sb.append(UserHandle.getUserId(mUid));
121 sb.append('a');
122 sb.append(UserHandle.getAppId(mUid));
123 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124 sb.append("}");
125 mStringName = sb.toString();
126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700128 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 } catch (RemoteException e) {
130 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700131 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 }
133 }
134
135 @Override
136 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
137 throws RemoteException {
138 try {
139 return super.onTransact(code, data, reply, flags);
140 } catch (RuntimeException e) {
141 // Log all 'real' exceptions thrown to the caller
142 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800143 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 }
145 throw e;
146 }
147 }
148
Andrew Scull26f830d2017-05-19 12:16:10 +0100149 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700151 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700152 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 mClientDead = true;
154 killSessionLocked();
155 }
156 }
157
Craig Mautner6881a102012-07-27 13:04:51 -0700158 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700159 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100160 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
Jorim Jaggif081f062019-10-24 16:24:54 +0200161 Rect outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200162 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
Tiger Huang0426a332020-03-29 01:17:08 +0800163 InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100164 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif081f062019-10-24 16:24:54 +0200165 outContentInsets, outStableInsets, outDisplayCutout, outInputChannel,
wilsonshihd0fc2ca2020-03-18 22:41:55 +0800166 outInsetsState, outActiveControls, UserHandle.getUserId(mUid));
167 }
168
169
170 @Override
171 public int addToDisplayAsUser(IWindow window, int seq, WindowManager.LayoutParams attrs,
172 int viewVisibility, int displayId, int userId, Rect outFrame,
173 Rect outContentInsets, Rect outStableInsets,
174 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
175 InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) {
176 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
177 outContentInsets, outStableInsets, outDisplayCutout, outInputChannel,
178 outInsetsState, outActiveControls, userId);
Craig Mautner6881a102012-07-27 13:04:51 -0700179 }
180
181 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700182 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200183 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
184 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700185 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Jorim Jaggif081f062019-10-24 16:24:54 +0200186 new Rect() /* outFrame */, outContentInsets, outStableInsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200187 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
Tiger Huang57ea97e2020-05-08 19:39:18 +0800188 outInsetsState, mDummyControls, UserHandle.getUserId(mUid));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 }
190
Andrew Scull26f830d2017-05-19 12:16:10 +0100191 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 public void remove(IWindow window) {
193 mService.removeWindow(this, window);
194 }
195
Rob Carr64e516f2015-10-29 00:20:45 +0000196 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700197 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700198 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800199 }
200
Andrew Scull26f830d2017-05-19 12:16:10 +0100201 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700202 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700203 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200204 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
205 Rect outStableInsets, Rect outBackdropFrame,
chaviwbe43ac82018-04-04 15:14:49 -0700206 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Valerie Hau30360552020-01-14 16:12:01 -0800207 SurfaceControl outSurfaceControl, InsetsState outInsetsState,
Tiger Huang0426a332020-03-29 01:17:08 +0800208 InsetsSourceControl[] outActiveControls, Point outSurfaceSize,
209 SurfaceControl outBLASTSurfaceControl) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800210 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700211 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700212 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700213 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700214 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Jorim Jaggif081f062019-10-24 16:24:54 +0200215 outFrame, outContentInsets, outVisibleInsets,
216 outStableInsets, outBackdropFrame, cutout,
Tiger Huang0426a332020-03-29 01:17:08 +0800217 mergedConfiguration, outSurfaceControl, outInsetsState, outActiveControls,
218 outSurfaceSize, outBLASTSurfaceControl);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700219 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800220 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700221 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 return res;
223 }
224
Andrew Scull26f830d2017-05-19 12:16:10 +0100225 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800226 public boolean outOfMemory(IWindow window) {
227 return mService.outOfMemoryWindow(this, window);
228 }
229
Andrew Scull26f830d2017-05-19 12:16:10 +0100230 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 public void setTransparentRegion(IWindow window, Region region) {
232 mService.setTransparentRegionWindow(this, window, region);
233 }
234
Andrew Scull26f830d2017-05-19 12:16:10 +0100235 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 public void setInsets(IWindow window, int touchableInsets,
237 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
238 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
239 visibleInsets, touchableArea);
240 }
241
Andrew Scull26f830d2017-05-19 12:16:10 +0100242 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
244 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
245 }
246
Andrew Scull26f830d2017-05-19 12:16:10 +0100247 @Override
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700248 public void finishDrawing(IWindow window,
249 @Nullable SurfaceControl.Transaction postDrawTransaction) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200250 if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window);
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700251 mService.finishDrawingWindow(this, window, postDrawTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 }
253
Andrew Scull26f830d2017-05-19 12:16:10 +0100254 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 public void setInTouchMode(boolean mode) {
Arthur Hung6d1b7c52020-01-21 18:35:14 +0800256 mService.setInTouchMode(mode);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 }
258
Andrew Scull26f830d2017-05-19 12:16:10 +0100259 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 public boolean getInTouchMode() {
Arthur Hung6d1b7c52020-01-21 18:35:14 +0800261 return mService.getInTouchMode();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 }
263
Andrew Scull26f830d2017-05-19 12:16:10 +0100264 @Override
Arthur Hunga4c52062019-02-19 11:31:44 +0800265 public boolean performHapticFeedback(int effectId, boolean always) {
266 long ident = Binder.clearCallingIdentity();
267 try {
268 return mService.mPolicy.performHapticFeedback(mUid, mPackageName,
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100269 effectId, always, null);
Arthur Hunga4c52062019-02-19 11:31:44 +0800270 } finally {
271 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 }
273 }
274
275 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900276
Andrew Scull26f830d2017-05-19 12:16:10 +0100277 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900278 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
279 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900280 final long ident = Binder.clearCallingIdentity();
281 try {
Vishnu Nair0e7536c2019-11-07 14:18:47 -0800282 return mDragDropController.performDrag(mSurfaceSession, mPid, mUid, window,
Daichi Hironofabca092017-12-19 15:02:50 +0900283 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900284 } finally {
285 Binder.restoreCallingIdentity(ident);
286 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 }
288
Andrew Scull26f830d2017-05-19 12:16:10 +0100289 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900290 public void reportDropResult(IWindow window, boolean consumed) {
291 final long ident = Binder.clearCallingIdentity();
292 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900293 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900294 } finally {
295 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900297 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
Daichi Hironodf5cf622017-09-11 14:59:26 +0900299 @Override
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900300 public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900301 final long ident = Binder.clearCallingIdentity();
302 try {
Daichi Hirono3e9d5102019-04-15 15:58:11 +0900303 mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900304 } finally {
305 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900307 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308
Daichi Hironodf5cf622017-09-11 14:59:26 +0900309 @Override
310 public void dragRecipientEntered(IWindow window) {
311 mDragDropController.dragRecipientEntered(window);
312 }
313
314 @Override
315 public void dragRecipientExited(IWindow window) {
316 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 }
318
Andrew Scull26f830d2017-05-19 12:16:10 +0100319 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700320 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800321 if (DEBUG_TASK_POSITIONING) Slog.d(
322 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700323
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800324 long ident = Binder.clearCallingIdentity();
325 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900326 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800327 } finally {
328 Binder.restoreCallingIdentity(ident);
329 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700330 }
331
Adrian Roos4ffc8972019-02-07 20:45:11 +0100332 @Override
yj81.kwon19585ff2019-04-23 18:53:57 -0700333 public void finishMovingTask(IWindow window) {
334 if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask");
335
336 long ident = Binder.clearCallingIdentity();
337 try {
338 mService.mTaskPositioningController.finishTaskPositioning(window);
339 } finally {
340 Binder.restoreCallingIdentity(ident);
341 }
342 }
343
344 @Override
Adrian Roos4ffc8972019-02-07 20:45:11 +0100345 public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) {
346 long ident = Binder.clearCallingIdentity();
347 try {
348 mService.reportSystemGestureExclusionChanged(this, window, exclusionRects);
349 } finally {
350 Binder.restoreCallingIdentity(ident);
351 }
352 }
353
wilsonshihc32538e2018-11-07 17:27:34 +0800354 private void actionOnWallpaper(IBinder window,
355 BiConsumer<WallpaperController, WindowState> action) {
356 final WindowState windowState = mService.windowForClientLocked(this, window, true);
357 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
358 }
359
Andrew Scull26f830d2017-05-19 12:16:10 +0100360 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700362 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 long ident = Binder.clearCallingIdentity();
364 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800365 actionOnWallpaper(window, (wpController, windowState) ->
366 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 } finally {
368 Binder.restoreCallingIdentity(ident);
369 }
370 }
371 }
372
Andrew Scull26f830d2017-05-19 12:16:10 +0100373 @Override
Lucas Dupin13f4b8a2020-02-19 13:41:52 -0800374 public void setWallpaperZoomOut(IBinder window, float zoom) {
375 if (Float.compare(0f, zoom) > 0 || Float.compare(1f, zoom) < 0 || Float.isNaN(zoom)) {
376 throw new IllegalArgumentException("Zoom must be a valid float between 0 and 1: "
377 + zoom);
378 }
379 synchronized (mService.mGlobalLock) {
380 long ident = Binder.clearCallingIdentity();
381 try {
382 actionOnWallpaper(window, (wpController, windowState) ->
383 wpController.setWallpaperZoomOut(windowState, zoom));
384 } finally {
385 Binder.restoreCallingIdentity(ident);
386 }
387 }
388 }
389
390 @Override
391 public void setShouldZoomOutWallpaper(IBinder window, boolean shouldZoom) {
392 synchronized (mService.mGlobalLock) {
393 actionOnWallpaper(window, (wpController, windowState) ->
394 wpController.setShouldZoomOutWallpaper(windowState, shouldZoom));
395 }
396 }
397
398 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700400 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800401 actionOnWallpaper(window, (wpController, windowState) ->
402 wpController.wallpaperOffsetsComplete(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
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700407 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700408 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700409 long ident = Binder.clearCallingIdentity();
410 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800411 actionOnWallpaper(window, (wpController, windowState) ->
412 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700413 } finally {
414 Binder.restoreCallingIdentity(ident);
415 }
416 }
417 }
418
Andrew Scull26f830d2017-05-19 12:16:10 +0100419 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
421 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700422 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423 long ident = Binder.clearCallingIdentity();
424 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800425 final WindowState windowState = mService.windowForClientLocked(this, window, true);
426 return windowState.getDisplayContent().mWallpaperController
427 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428 } finally {
429 Binder.restoreCallingIdentity(ident);
430 }
431 }
432 }
433
Andrew Scull26f830d2017-05-19 12:16:10 +0100434 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800435 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700436 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800437 actionOnWallpaper(window, (wpController, windowState) ->
438 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700439 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440 }
441
Andrew Scull26f830d2017-05-19 12:16:10 +0100442 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700443 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700444 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700445 final long identity = Binder.clearCallingIdentity();
446 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700447 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700448 } finally {
449 Binder.restoreCallingIdentity(identity);
450 }
451 }
452 }
453
Andrew Scull26f830d2017-05-19 12:16:10 +0100454 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800455 public IWindowId getWindowId(IBinder window) {
456 return mService.getWindowId(window);
457 }
458
Jeff Brownc2932a12014-11-20 18:04:05 -0800459 @Override
460 public void pokeDrawLock(IBinder window) {
461 final long identity = Binder.clearCallingIdentity();
462 try {
463 mService.pokeDrawLock(this, window);
464 } finally {
465 Binder.restoreCallingIdentity(identity);
466 }
467 }
468
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800469 @Override
470 public void updatePointerIcon(IWindow window) {
471 final long identity = Binder.clearCallingIdentity();
472 try {
473 mService.updatePointerIcon(window);
474 } finally {
475 Binder.restoreCallingIdentity(identity);
476 }
477 }
478
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800479 @Override
Tiger Huangd8ec9382019-04-18 14:35:09 -0700480 public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) {
481 mService.reparentDisplayContent(window, sc, displayId);
482 }
483
484 @Override
485 public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) {
486 mService.updateDisplayContentLocation(window, x, y, displayId);
487 }
488
489 @Override
chaviwaa0d74e2019-12-26 14:13:40 -0800490 public void updateTapExcludeRegion(IWindow window, Region region) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800491 final long identity = Binder.clearCallingIdentity();
492 try {
chaviwaa0d74e2019-12-26 14:13:40 -0800493 mService.updateTapExcludeRegion(window, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800494 } finally {
495 Binder.restoreCallingIdentity(identity);
496 }
497 }
498
Jorim Jaggie35c0592018-11-06 16:21:08 +0100499 @Override
500 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800501 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100502 final WindowState windowState = mService.windowForClientLocked(this, window,
503 false /* throwOnError */);
504 if (windowState != null) {
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100505 windowState.updateRequestedInsetsState(state);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100506 windowState.getDisplayContent().getInsetsPolicy().onInsetsModified(
Jorim Jaggie35c0592018-11-06 16:21:08 +0100507 windowState, state);
508 }
509 }
510 }
511
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800512 void windowAddedLocked(String packageName) {
513 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700514 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515 if (mSurfaceSession == null) {
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200516 if (DEBUG) {
517 Slog.v(TAG_WM, "First window added to " + this + ", creating SurfaceSession");
518 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 mSurfaceSession = new SurfaceSession();
Adrian Roosb125e0b2019-10-02 14:55:14 +0200520 ProtoLog.i(WM_SHOW_TRANSACTIONS, " NEW SURFACE SESSION %s", mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700522 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
523 mService.dispatchNewAnimatorScaleLocked(this);
524 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800525 }
526 mNumWindow++;
527 }
528
Wale Ogunwale943002b2017-02-15 19:34:01 -0800529 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800530 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800531 killSessionLocked();
532 }
533
534
535 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
536 boolean visible, int type) {
537
538 if (!isSystemAlertWindowType(type)) {
539 return;
540 }
541
542 boolean changed;
543
544 if (!mCanAddInternalSystemWindow) {
545 // We want to track non-system signature apps adding alert windows so we can post an
546 // on-going notification for the user to control their visibility.
547 if (visible) {
548 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800549 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800550 } else {
551 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800552 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800553 }
554
555 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800556 if (mAlertWindowSurfaces.isEmpty()) {
557 cancelAlertWindowNotification();
558 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800559 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700560 if (mShowingAlertWindowNotificationAllowed) {
561 mAlertWindowNotification.post();
562 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800563 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800564 }
565 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800566
567 if (type != TYPE_APPLICATION_OVERLAY) {
568 return;
569 }
570
571 if (visible) {
572 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800573 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800574 } else {
575 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800576 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800577 }
578
579 if (changed) {
580 // Notify activity manager of changes to app overlay windows so it can adjust the
581 // importance score for the process.
582 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
583 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 }
585
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700586 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
587 mShowingAlertWindowNotificationAllowed = allowed;
588 if (mAlertWindowNotification != null) {
589 if (allowed) {
590 mAlertWindowNotification.post();
591 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800592 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700593 }
594 }
595 }
596
Wale Ogunwaled993a572017-02-05 13:52:09 -0800597 private void killSessionLocked() {
598 if (mNumWindow > 0 || !mClientDead) {
599 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800600 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800601
602 mService.mSessions.remove(this);
603 if (mSurfaceSession == null) {
604 return;
605 }
606
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200607 if (DEBUG) {
608 Slog.v(TAG_WM, "Last window removed from " + this
609 + ", destroying " + mSurfaceSession);
610 }
Adrian Roosb125e0b2019-10-02 14:55:14 +0200611 ProtoLog.i(WM_SHOW_TRANSACTIONS, " KILL SURFACE SESSION %s", mSurfaceSession);
Wale Ogunwaled993a572017-02-05 13:52:09 -0800612 try {
613 mSurfaceSession.kill();
614 } catch (Exception e) {
615 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
616 + " in session " + this + ": " + e.toString());
617 }
618 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800619 mAlertWindowSurfaces.clear();
620 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800621 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800622 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800623 }
624
625 private void setHasOverlayUi(boolean hasOverlayUi) {
626 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800627 }
628
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800629 private void cancelAlertWindowNotification() {
630 if (mAlertWindowNotification == null) {
631 return;
632 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800633 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800634 mAlertWindowNotification = null;
635 }
636
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800637 void dump(PrintWriter pw, String prefix) {
638 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800639 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800640 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
641 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 pw.print(" mClientDead="); pw.print(mClientDead);
643 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700644 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 }
646
647 @Override
648 public String toString() {
649 return mStringName;
650 }
Robert Carr0e007272017-10-02 13:00:55 -0700651
Riddle Hsuccf09402019-08-13 00:33:06 +0800652 /** @return {@code true} if there is an alert window surface on the given display. */
653 boolean hasAlertWindowSurfaces(DisplayContent displayContent) {
654 for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) {
655 final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i);
656 if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) {
657 return true;
658 }
659 }
660 return false;
Robert Carr0e007272017-10-02 13:00:55 -0700661 }
Robert Carr9d431e12018-12-17 13:11:48 -0800662
Vishnu Nairddbd2512019-11-12 14:39:43 -0800663 @Override
Vishnu Nair5cf253192019-11-07 15:33:20 -0800664 public void grantInputChannel(int displayId, SurfaceControl surface,
arthurhungd3f17d72020-05-08 17:20:38 +0800665 IWindow window, IBinder hostInputToken, int flags, int type,
666 InputChannel outInputChannel) {
Vishnu Nairddbd2512019-11-12 14:39:43 -0800667 if (hostInputToken == null && !mCanAddInternalSystemWindow) {
668 // Callers without INTERNAL_SYSTEM_WINDOW permission cannot grant input channel to
669 // embedded windows without providing a host window input token
670 throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
671 }
672
arthurhungd3f17d72020-05-08 17:20:38 +0800673 if (!mCanAddInternalSystemWindow && type != 0) {
674 Slog.w(TAG_WM, "Requires INTERNAL_SYSTEM_WINDOW permission if assign type to"
675 + " input");
676 }
677
Robert Carr9d431e12018-12-17 13:11:48 -0800678 final long identity = Binder.clearCallingIdentity();
679 try {
Evan Rosky680377e2020-01-10 19:12:10 -0800680 mService.grantInputChannel(mUid, mPid, displayId, surface, window, hostInputToken,
arthurhungd3f17d72020-05-08 17:20:38 +0800681 flags, mCanAddInternalSystemWindow ? type : 0, outInputChannel);
Evan Rosky680377e2020-01-10 19:12:10 -0800682 } finally {
683 Binder.restoreCallingIdentity(identity);
684 }
685 }
686
687 @Override
688 public void updateInputChannel(IBinder channelToken, int displayId, SurfaceControl surface,
Evan Rosky12837282020-04-27 19:12:25 -0700689 int flags, Region region) {
Evan Rosky680377e2020-01-10 19:12:10 -0800690 final long identity = Binder.clearCallingIdentity();
691 try {
Evan Rosky12837282020-04-27 19:12:25 -0700692 mService.updateInputChannel(channelToken, displayId, surface, flags, region);
Robert Carr9d431e12018-12-17 13:11:48 -0800693 } finally {
694 Binder.restoreCallingIdentity(identity);
695 }
696 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700697}