blob: 58cf73a9a2bd8ea82dcd4fa61c6244b887be8f26 [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
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030
31import android.content.ClipData;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080032import android.graphics.Rect;
33import android.graphics.Region;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.IBinder;
37import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070038import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080039import android.os.RemoteException;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070040import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070041import android.os.UserHandle;
Andrii Kulian44607962017-03-16 11:06:24 -070042import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080043import android.util.Slog;
Adrian Roos5c6b6222017-11-07 17:36:10 +010044import android.view.DisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.view.IWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080046import android.view.IWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080047import android.view.IWindowSession;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080048import android.view.IWindowSessionCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080049import android.view.InputChannel;
Tiger Huangdda14a72019-01-10 17:20:27 +080050import android.view.InsetsState;
Daichi Hironoa1fb9be2017-12-18 17:02:54 +090051import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052import android.view.SurfaceSession;
53import android.view.WindowManager;
54
Chenjie Yue8904192017-12-08 19:12:57 -080055import com.android.internal.os.logging.MetricsLoggerWrapper;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080056import com.android.server.wm.WindowManagerService.H;
57
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058import java.io.PrintWriter;
Wale Ogunwale943002b2017-02-15 19:34:01 -080059import java.util.HashSet;
60import java.util.Set;
wilsonshihc32538e2018-11-07 17:27:34 +080061import java.util.function.BiConsumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062
63/**
64 * This class represents an active client session. There is generally one
65 * Session object per process that is interacting with the window manager.
66 */
Bryce Leea5592862017-10-23 12:57:37 -070067class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080068 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070069 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080070 final int mUid;
71 final int mPid;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070072 private final String mStringName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080073 SurfaceSession mSurfaceSession;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070074 private int mNumWindow = 0;
Wale Ogunwale943002b2017-02-15 19:34:01 -080075 // Set of visible application overlay window surfaces connected to this session.
76 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
77 // Set of visible alert window surfaces connected to this session.
78 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090079 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080080 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070081 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020082 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080083 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070084 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070085 private boolean mClientDead = false;
86 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080087 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070088 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089
Yohei Yukawaa71bb252018-09-19 19:21:24 -070090 public Session(WindowManagerService service, IWindowSessionCallback callback) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 mService = service;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070092 mCallback = callback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093 mUid = Binder.getCallingUid();
94 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -070095 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -080096 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -080097 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070098 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
99 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200100 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
101 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700102 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900103 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104 StringBuilder sb = new StringBuilder();
105 sb.append("Session{");
106 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700107 sb.append(" ");
108 sb.append(mPid);
109 if (mUid < Process.FIRST_APPLICATION_UID) {
110 sb.append(":");
111 sb.append(mUid);
112 } else {
113 sb.append(":u");
114 sb.append(UserHandle.getUserId(mUid));
115 sb.append('a');
116 sb.append(UserHandle.getAppId(mUid));
117 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118 sb.append("}");
119 mStringName = sb.toString();
120
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 try {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700122 mCallback.asBinder().linkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 } catch (RemoteException e) {
124 // The caller has died, so we can just forget about this.
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700125 // Hmmm, should we call killSessionLocked()??
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 }
127 }
128
129 @Override
130 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
131 throws RemoteException {
132 try {
133 return super.onTransact(code, data, reply, flags);
134 } catch (RuntimeException e) {
135 // Log all 'real' exceptions thrown to the caller
136 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800137 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 }
139 throw e;
140 }
141 }
142
Andrew Scull26f830d2017-05-19 12:16:10 +0100143 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 public void binderDied() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700145 synchronized (mService.mGlobalLock) {
Yohei Yukawaa71bb252018-09-19 19:21:24 -0700146 mCallback.asBinder().unlinkToDeath(this, 0);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 mClientDead = true;
148 killSessionLocked();
149 }
150 }
151
Craig Mautner6881a102012-07-27 13:04:51 -0700152 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700153 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos9e370f22018-03-06 18:19:45 +0100154 int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets,
155 Rect outStableInsets, Rect outOutsets,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200156 DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
157 InsetsState outInsetsState) {
Adrian Roos9e370f22018-03-06 18:19:45 +0100158 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200159 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel,
160 outInsetsState);
Craig Mautner6881a102012-07-27 13:04:51 -0700161 }
162
163 @Override
Craig Mautner6881a102012-07-27 13:04:51 -0700164 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200165 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
166 InsetsState outInsetsState) {
Craig Mautner6881a102012-07-27 13:04:51 -0700167 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos9e370f22018-03-06 18:19:45 +0100168 new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */,
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200169 new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */,
170 outInsetsState);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 }
172
Andrew Scull26f830d2017-05-19 12:16:10 +0100173 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 public void remove(IWindow window) {
175 mService.removeWindow(this, window);
176 }
177
Rob Carr64e516f2015-10-29 00:20:45 +0000178 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700179 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700180 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800181 }
182
Andrew Scull26f830d2017-05-19 12:16:10 +0100183 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700184 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700185 int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
186 Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
187 Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
188 DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
Robert Carr5fea55b2018-12-10 13:05:52 -0800189 SurfaceControl outSurfaceControl, InsetsState outInsetsState) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800190 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700191 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700192 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700193 int res = mService.relayoutWindow(this, window, seq, attrs,
chaviwbe43ac82018-04-04 15:14:49 -0700194 requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800195 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100196 outStableInsets, outsets, outBackdropFrame, cutout,
Robert Carr5fea55b2018-12-10 13:05:52 -0800197 mergedConfiguration, outSurfaceControl, outInsetsState);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700198 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800199 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700200 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 return res;
202 }
203
Andrew Scull26f830d2017-05-19 12:16:10 +0100204 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800205 public boolean outOfMemory(IWindow window) {
206 return mService.outOfMemoryWindow(this, window);
207 }
208
Andrew Scull26f830d2017-05-19 12:16:10 +0100209 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 public void setTransparentRegion(IWindow window, Region region) {
211 mService.setTransparentRegionWindow(this, window, region);
212 }
213
Andrew Scull26f830d2017-05-19 12:16:10 +0100214 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 public void setInsets(IWindow window, int touchableInsets,
216 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
217 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
218 visibleInsets, touchableArea);
219 }
220
Andrew Scull26f830d2017-05-19 12:16:10 +0100221 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
223 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
224 }
225
Andrew Scull26f830d2017-05-19 12:16:10 +0100226 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 public void finishDrawing(IWindow window) {
228 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800229 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 mService.finishDrawingWindow(this, window);
231 }
232
Andrew Scull26f830d2017-05-19 12:16:10 +0100233 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 public void setInTouchMode(boolean mode) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700235 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 mService.mInTouchMode = mode;
237 }
238 }
239
Andrew Scull26f830d2017-05-19 12:16:10 +0100240 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 public boolean getInTouchMode() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700242 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 return mService.mInTouchMode;
244 }
245 }
246
Andrew Scull26f830d2017-05-19 12:16:10 +0100247 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 public boolean performHapticFeedback(IWindow window, int effectId,
249 boolean always) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700250 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 long ident = Binder.clearCallingIdentity();
252 try {
253 return mService.mPolicy.performHapticFeedbackLw(
254 mService.windowForClientLocked(this, window, true),
Alexey Kuzmine1f06b82018-06-20 17:48:43 +0100255 effectId, always, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 } finally {
257 Binder.restoreCallingIdentity(ident);
258 }
259 }
260 }
261
262 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900263
Andrew Scull26f830d2017-05-19 12:16:10 +0100264 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900265 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
266 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900267 final int callerPid = Binder.getCallingPid();
268 final int callerUid = Binder.getCallingUid();
269 final long ident = Binder.clearCallingIdentity();
270 try {
Daichi Hironofabca092017-12-19 15:02:50 +0900271 return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window,
272 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
289 public void cancelDragAndDrop(IBinder dragToken) {
290 final long ident = Binder.clearCallingIdentity();
291 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900292 mDragDropController.cancelDragAndDrop(dragToken);
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
wilsonshihc32538e2018-11-07 17:27:34 +0800321 private void actionOnWallpaper(IBinder window,
322 BiConsumer<WallpaperController, WindowState> action) {
323 final WindowState windowState = mService.windowForClientLocked(this, window, true);
324 action.accept(windowState.getDisplayContent().mWallpaperController, windowState);
325 }
326
Andrew Scull26f830d2017-05-19 12:16:10 +0100327 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700329 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 long ident = Binder.clearCallingIdentity();
331 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800332 actionOnWallpaper(window, (wpController, windowState) ->
333 wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 } finally {
335 Binder.restoreCallingIdentity(ident);
336 }
337 }
338 }
339
Andrew Scull26f830d2017-05-19 12:16:10 +0100340 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700342 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800343 actionOnWallpaper(window, (wpController, windowState) ->
344 wpController.wallpaperOffsetsComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700345 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346 }
347
Andrew Scull26f830d2017-05-19 12:16:10 +0100348 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700349 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700350 synchronized (mService.mGlobalLock) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700351 long ident = Binder.clearCallingIdentity();
352 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800353 actionOnWallpaper(window, (wpController, windowState) ->
354 wpController.setWindowWallpaperDisplayOffset(windowState, x, y));
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700355 } finally {
356 Binder.restoreCallingIdentity(ident);
357 }
358 }
359 }
360
Andrew Scull26f830d2017-05-19 12:16:10 +0100361 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
363 int z, Bundle extras, boolean sync) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700364 synchronized (mService.mGlobalLock) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 long ident = Binder.clearCallingIdentity();
366 try {
wilsonshihc32538e2018-11-07 17:27:34 +0800367 final WindowState windowState = mService.windowForClientLocked(this, window, true);
368 return windowState.getDisplayContent().mWallpaperController
369 .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 } finally {
371 Binder.restoreCallingIdentity(ident);
372 }
373 }
374 }
375
Andrew Scull26f830d2017-05-19 12:16:10 +0100376 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 public void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700378 synchronized (mService.mGlobalLock) {
wilsonshihc32538e2018-11-07 17:27:34 +0800379 actionOnWallpaper(window, (wpController, windowState) ->
380 wpController.wallpaperCommandComplete(window));
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700381 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 }
383
Andrew Scull26f830d2017-05-19 12:16:10 +0100384 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700385 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700386 synchronized (mService.mGlobalLock) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700387 final long identity = Binder.clearCallingIdentity();
388 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700389 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700390 } finally {
391 Binder.restoreCallingIdentity(identity);
392 }
393 }
394 }
395
Andrew Scull26f830d2017-05-19 12:16:10 +0100396 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800397 public IWindowId getWindowId(IBinder window) {
398 return mService.getWindowId(window);
399 }
400
Jeff Brownc2932a12014-11-20 18:04:05 -0800401 @Override
402 public void pokeDrawLock(IBinder window) {
403 final long identity = Binder.clearCallingIdentity();
404 try {
405 mService.pokeDrawLock(this, window);
406 } finally {
407 Binder.restoreCallingIdentity(identity);
408 }
409 }
410
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800411 @Override
412 public void updatePointerIcon(IWindow window) {
413 final long identity = Binder.clearCallingIdentity();
414 try {
415 mService.updatePointerIcon(window);
416 } finally {
417 Binder.restoreCallingIdentity(identity);
418 }
419 }
420
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800421 @Override
422 public void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
423 int height) {
424 final long identity = Binder.clearCallingIdentity();
425 try {
426 mService.updateTapExcludeRegion(window, regionId, left, top, width, height);
427 } finally {
428 Binder.restoreCallingIdentity(identity);
429 }
430 }
431
Jorim Jaggie35c0592018-11-06 16:21:08 +0100432 @Override
433 public void insetsModified(IWindow window, InsetsState state) {
Tiger Huangdda14a72019-01-10 17:20:27 +0800434 synchronized (mService.mGlobalLock) {
Jorim Jaggie35c0592018-11-06 16:21:08 +0100435 final WindowState windowState = mService.windowForClientLocked(this, window,
436 false /* throwOnError */);
437 if (windowState != null) {
438 windowState.getDisplayContent().getInsetsStateController().onInsetsModified(
439 windowState, state);
440 }
441 }
442 }
443
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800444 void windowAddedLocked(String packageName) {
445 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700446 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 if (mSurfaceSession == null) {
448 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800449 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450 mSurfaceSession = new SurfaceSession();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800451 if (SHOW_TRANSACTIONS) Slog.i(
452 TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 mService.mSessions.add(this);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700454 if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) {
455 mService.dispatchNewAnimatorScaleLocked(this);
456 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 }
458 mNumWindow++;
459 }
460
Wale Ogunwale943002b2017-02-15 19:34:01 -0800461 void windowRemovedLocked() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 mNumWindow--;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800463 killSessionLocked();
464 }
465
466
467 void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController,
468 boolean visible, int type) {
469
470 if (!isSystemAlertWindowType(type)) {
471 return;
472 }
473
474 boolean changed;
475
476 if (!mCanAddInternalSystemWindow) {
477 // We want to track non-system signature apps adding alert windows so we can post an
478 // on-going notification for the user to control their visibility.
479 if (visible) {
480 changed = mAlertWindowSurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800481 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800482 } else {
483 changed = mAlertWindowSurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800484 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800485 }
486
487 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800488 if (mAlertWindowSurfaces.isEmpty()) {
489 cancelAlertWindowNotification();
490 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800491 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700492 if (mShowingAlertWindowNotificationAllowed) {
493 mAlertWindowNotification.post();
494 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800495 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800496 }
497 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800498
499 if (type != TYPE_APPLICATION_OVERLAY) {
500 return;
501 }
502
503 if (visible) {
504 changed = mAppOverlaySurfaces.add(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800505 MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800506 } else {
507 changed = mAppOverlaySurfaces.remove(surfaceController);
Chenjie Yu08d6d722018-02-28 10:19:54 -0800508 MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800509 }
510
511 if (changed) {
512 // Notify activity manager of changes to app overlay windows so it can adjust the
513 // importance score for the process.
514 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
515 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 }
517
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700518 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
519 mShowingAlertWindowNotificationAllowed = allowed;
520 if (mAlertWindowNotification != null) {
521 if (allowed) {
522 mAlertWindowNotification.post();
523 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800524 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700525 }
526 }
527 }
528
Wale Ogunwaled993a572017-02-05 13:52:09 -0800529 private void killSessionLocked() {
530 if (mNumWindow > 0 || !mClientDead) {
531 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800533
534 mService.mSessions.remove(this);
535 if (mSurfaceSession == null) {
536 return;
537 }
538
539 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
540 + ", destroying " + mSurfaceSession);
541 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
542 try {
543 mSurfaceSession.kill();
544 } catch (Exception e) {
545 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
546 + " in session " + this + ": " + e.toString());
547 }
548 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800549 mAlertWindowSurfaces.clear();
550 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800551 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800552 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800553 }
554
555 private void setHasOverlayUi(boolean hasOverlayUi) {
556 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 }
558
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800559 private void cancelAlertWindowNotification() {
560 if (mAlertWindowNotification == null) {
561 return;
562 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800563 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800564 mAlertWindowNotification = null;
565 }
566
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 void dump(PrintWriter pw, String prefix) {
568 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800569 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800570 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
571 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800572 pw.print(" mClientDead="); pw.print(mClientDead);
573 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700574 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800575 }
576
577 @Override
578 public String toString() {
579 return mStringName;
580 }
Robert Carr0e007272017-10-02 13:00:55 -0700581
582 boolean hasAlertWindowSurfaces() {
583 return !mAlertWindowSurfaces.isEmpty();
584 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700585}