blob: f09a294be75be1b20377caabb02b8806cbe63d3a [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;
32import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.graphics.Rect;
34import android.graphics.Region;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.IBinder;
38import android.os.Parcel;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070039import android.os.Process;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080040import android.os.RemoteException;
41import android.os.ServiceManager;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070042import android.os.Trace;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070043import android.os.UserHandle;
Andrii Kulian44607962017-03-16 11:06:24 -070044import android.util.MergedConfiguration;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080045import android.util.Slog;
Craig Mautner6881a102012-07-27 13:04:51 -070046import android.view.Display;
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;
53import android.view.Surface;
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
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080058import com.android.internal.view.IInputContext;
59import com.android.internal.view.IInputMethodClient;
60import com.android.internal.view.IInputMethodManager;
61import com.android.server.wm.WindowManagerService.H;
62
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import java.io.PrintWriter;
Wale Ogunwale943002b2017-02-15 19:34:01 -080064import java.util.HashSet;
65import java.util.Set;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
67/**
68 * This class represents an active client session. There is generally one
69 * Session object per process that is interacting with the window manager.
70 */
Bryce Leea5592862017-10-23 12:57:37 -070071class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080072 final WindowManagerService mService;
Dianne Hackborneb94fa72014-06-03 17:48:12 -070073 final IWindowSessionCallback mCallback;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074 final IInputMethodClient mClient;
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.
81 private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>();
82 // Set of visible alert window surfaces connected to this session.
83 private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
Daichi Hironodf5cf622017-09-11 14:59:26 +090084 private final DragDropController mDragDropController;
Wale Ogunwale943002b2017-02-15 19:34:01 -080085 final boolean mCanAddInternalSystemWindow;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070086 final boolean mCanHideNonSystemOverlayWindows;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +020087 final boolean mCanAcquireSleepToken;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080088 private AlertWindowNotification mAlertWindowNotification;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -070089 private boolean mShowingAlertWindowNotificationAllowed;
Wale Ogunwalecfca2582016-10-19 09:53:25 -070090 private boolean mClientDead = false;
91 private float mLastReportedAnimatorScale;
Wale Ogunwale387e4c62017-02-13 09:50:02 -080092 private String mPackageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070093 private String mRelayoutTag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080094
Dianne Hackborneb94fa72014-06-03 17:48:12 -070095 public Session(WindowManagerService service, IWindowSessionCallback callback,
96 IInputMethodClient client, IInputContext inputContext) {
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 mClient = client;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100 mUid = Binder.getCallingUid();
101 mPid = Binder.getCallingPid();
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700102 mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800103 mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
Wale Ogunwale943002b2017-02-15 19:34:01 -0800104 INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700105 mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
106 HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200107 mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
108 == PERMISSION_GRANTED;
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700109 mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
Daichi Hironodf5cf622017-09-11 14:59:26 +0900110 mDragDropController = mService.mDragDropController;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 StringBuilder sb = new StringBuilder();
112 sb.append("Session{");
113 sb.append(Integer.toHexString(System.identityHashCode(this)));
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -0700114 sb.append(" ");
115 sb.append(mPid);
116 if (mUid < Process.FIRST_APPLICATION_UID) {
117 sb.append(":");
118 sb.append(mUid);
119 } else {
120 sb.append(":u");
121 sb.append(UserHandle.getUserId(mUid));
122 sb.append('a');
123 sb.append(UserHandle.getAppId(mUid));
124 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 sb.append("}");
126 mStringName = sb.toString();
127
128 synchronized (mService.mWindowMap) {
129 if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
130 IBinder b = ServiceManager.getService(
131 Context.INPUT_METHOD_SERVICE);
132 mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
133 }
134 }
135 long ident = Binder.clearCallingIdentity();
136 try {
137 // Note: it is safe to call in to the input method manager
138 // here because we are not holding our lock.
139 if (mService.mInputMethodManager != null) {
140 mService.mInputMethodManager.addClient(client, inputContext,
141 mUid, mPid);
142 } else {
143 client.setUsingInputMethod(false);
144 }
145 client.asBinder().linkToDeath(this, 0);
146 } catch (RemoteException e) {
147 // The caller has died, so we can just forget about this.
148 try {
149 if (mService.mInputMethodManager != null) {
150 mService.mInputMethodManager.removeClient(client);
151 }
152 } catch (RemoteException ee) {
153 }
154 } finally {
155 Binder.restoreCallingIdentity(ident);
156 }
157 }
158
159 @Override
160 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
161 throws RemoteException {
162 try {
163 return super.onTransact(code, data, reply, flags);
164 } catch (RuntimeException e) {
165 // Log all 'real' exceptions thrown to the caller
166 if (!(e instanceof SecurityException)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800167 Slog.wtf(TAG_WM, "Window Session Crash", e);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 }
169 throw e;
170 }
171 }
172
Andrew Scull26f830d2017-05-19 12:16:10 +0100173 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 public void binderDied() {
175 // Note: it is safe to call in to the input method manager
176 // here because we are not holding our lock.
177 try {
178 if (mService.mInputMethodManager != null) {
179 mService.mInputMethodManager.removeClient(mClient);
180 }
181 } catch (RemoteException e) {
182 }
183 synchronized(mService.mWindowMap) {
184 mClient.asBinder().unlinkToDeath(this, 0);
185 mClientDead = true;
186 killSessionLocked();
187 }
188 }
189
Craig Mautner6881a102012-07-27 13:04:51 -0700190 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700191 public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100192 int viewVisibility, Rect outContentInsets, Rect outStableInsets,
193 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700194 return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100195 outContentInsets, outStableInsets, null /* outOutsets */, null /* cutout */,
196 outInputChannel);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 }
Craig Mautner6881a102012-07-27 13:04:51 -0700198
199 @Override
200 public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100201 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100202 Rect outOutsets, DisplayCutout.ParcelableWrapper outDisplayCutout,
203 InputChannel outInputChannel) {
Craig Mautner6881a102012-07-27 13:04:51 -0700204 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100205 outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel);
Craig Mautner6881a102012-07-27 13:04:51 -0700206 }
207
208 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700209 public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100210 int viewVisibility, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700211 return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
Adrian Roos37d7a682014-11-06 18:15:16 +0100212 Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets);
Craig Mautner6881a102012-07-27 13:04:51 -0700213 }
214
215 @Override
216 public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
Adrian Roos37d7a682014-11-06 18:15:16 +0100217 int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) {
Craig Mautner6881a102012-07-27 13:04:51 -0700218 return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100219 outContentInsets, outStableInsets, null /* outOutsets */, null /* cutout */, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 }
221
Andrew Scull26f830d2017-05-19 12:16:10 +0100222 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 public void remove(IWindow window) {
224 mService.removeWindow(this, window);
225 }
226
Rob Carr64e516f2015-10-29 00:20:45 +0000227 @Override
Robert Carr77bdfb52016-05-02 18:18:31 -0700228 public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700229 mService.setWillReplaceWindows(appToken, childrenOnly);
Robert Carr23fa16b2016-01-13 13:19:58 -0800230 }
231
Andrew Scull26f830d2017-05-19 12:16:10 +0100232 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700233 public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 int requestedWidth, int requestedHeight, int viewFlags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800235 int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800236 Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100237 DisplayCutout.ParcelableWrapper cutout,
Andrii Kulian44607962017-03-16 11:06:24 -0700238 MergedConfiguration mergedConfiguration, Surface outSurface) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800239 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700240 + Binder.getCallingPid());
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700241 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700242 int res = mService.relayoutWindow(this, window, seq, attrs,
Dianne Hackborn6d05fd32011-11-19 14:36:15 -0800243 requestedWidth, requestedHeight, viewFlags, flags,
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800244 outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100245 outStableInsets, outsets, outBackdropFrame, cutout,
246 mergedConfiguration, outSurface);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700247 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800248 if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
Dianne Hackbornb961cd22011-06-21 12:13:37 -0700249 + Binder.getCallingPid());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 return res;
251 }
252
Andrew Scull26f830d2017-05-19 12:16:10 +0100253 @Override
Dianne Hackborn64825172011-03-02 21:32:58 -0800254 public boolean outOfMemory(IWindow window) {
255 return mService.outOfMemoryWindow(this, window);
256 }
257
Andrew Scull26f830d2017-05-19 12:16:10 +0100258 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 public void setTransparentRegion(IWindow window, Region region) {
260 mService.setTransparentRegionWindow(this, window, region);
261 }
262
Andrew Scull26f830d2017-05-19 12:16:10 +0100263 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 public void setInsets(IWindow window, int touchableInsets,
265 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
266 mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
267 visibleInsets, touchableArea);
268 }
269
Andrew Scull26f830d2017-05-19 12:16:10 +0100270 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
272 mService.getWindowDisplayFrame(this, window, outDisplayFrame);
273 }
274
Andrew Scull26f830d2017-05-19 12:16:10 +0100275 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 public void finishDrawing(IWindow window) {
277 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800278 TAG_WM, "IWindow finishDrawing called for " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 mService.finishDrawingWindow(this, window);
280 }
281
Andrew Scull26f830d2017-05-19 12:16:10 +0100282 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 public void setInTouchMode(boolean mode) {
284 synchronized(mService.mWindowMap) {
285 mService.mInTouchMode = mode;
286 }
287 }
288
Andrew Scull26f830d2017-05-19 12:16:10 +0100289 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 public boolean getInTouchMode() {
291 synchronized(mService.mWindowMap) {
292 return mService.mInTouchMode;
293 }
294 }
295
Andrew Scull26f830d2017-05-19 12:16:10 +0100296 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 public boolean performHapticFeedback(IWindow window, int effectId,
298 boolean always) {
299 synchronized(mService.mWindowMap) {
300 long ident = Binder.clearCallingIdentity();
301 try {
302 return mService.mPolicy.performHapticFeedbackLw(
303 mService.windowForClientLocked(this, window, true),
304 effectId, always);
305 } finally {
306 Binder.restoreCallingIdentity(ident);
307 }
308 }
309 }
310
311 /* Drag/drop */
Daichi Hironofabca092017-12-19 15:02:50 +0900312
Andrew Scull26f830d2017-05-19 12:16:10 +0100313 @Override
Daichi Hironofabca092017-12-19 15:02:50 +0900314 public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource,
315 float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
Daichi Hironodf5cf622017-09-11 14:59:26 +0900316 final int callerPid = Binder.getCallingPid();
317 final int callerUid = Binder.getCallingUid();
318 final long ident = Binder.clearCallingIdentity();
319 try {
Daichi Hironofabca092017-12-19 15:02:50 +0900320 return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window,
321 flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900322 } finally {
323 Binder.restoreCallingIdentity(ident);
324 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325 }
326
Andrew Scull26f830d2017-05-19 12:16:10 +0100327 @Override
Daichi Hironodf5cf622017-09-11 14:59:26 +0900328 public void reportDropResult(IWindow window, boolean consumed) {
329 final long ident = Binder.clearCallingIdentity();
330 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900331 mDragDropController.reportDropResult(window, consumed);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900332 } finally {
333 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900335 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336
Daichi Hironodf5cf622017-09-11 14:59:26 +0900337 @Override
338 public void cancelDragAndDrop(IBinder dragToken) {
339 final long ident = Binder.clearCallingIdentity();
340 try {
Daichi Hirono58e25e12017-10-25 15:48:08 +0900341 mDragDropController.cancelDragAndDrop(dragToken);
Daichi Hironodf5cf622017-09-11 14:59:26 +0900342 } finally {
343 Binder.restoreCallingIdentity(ident);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 }
Daichi Hironodf5cf622017-09-11 14:59:26 +0900345 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800346
Daichi Hironodf5cf622017-09-11 14:59:26 +0900347 @Override
348 public void dragRecipientEntered(IWindow window) {
349 mDragDropController.dragRecipientEntered(window);
350 }
351
352 @Override
353 public void dragRecipientExited(IWindow window) {
354 mDragDropController.dragRecipientExited(window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 }
356
Andrew Scull26f830d2017-05-19 12:16:10 +0100357 @Override
Chong Zhang8e89b312015-09-09 15:09:30 -0700358 public boolean startMovingTask(IWindow window, float startX, float startY) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800359 if (DEBUG_TASK_POSITIONING) Slog.d(
360 TAG_WM, "startMovingTask: {" + startX + "," + startY + "}");
Chong Zhang8e89b312015-09-09 15:09:30 -0700361
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800362 long ident = Binder.clearCallingIdentity();
363 try {
Daichi Hirono34fb7312017-12-04 10:00:24 +0900364 return mService.mTaskPositioningController.startMovingTask(window, startX, startY);
Wale Ogunwale09e1b8d2016-02-23 10:38:35 -0800365 } finally {
366 Binder.restoreCallingIdentity(ident);
367 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700368 }
369
Andrew Scull26f830d2017-05-19 12:16:10 +0100370 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
372 synchronized(mService.mWindowMap) {
373 long ident = Binder.clearCallingIdentity();
374 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700375 mService.mRoot.mWallpaperController.setWindowWallpaperPosition(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 mService.windowForClientLocked(this, window, true),
377 x, y, xStep, yStep);
378 } finally {
379 Binder.restoreCallingIdentity(ident);
380 }
381 }
382 }
383
Andrew Scull26f830d2017-05-19 12:16:10 +0100384 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 public void wallpaperOffsetsComplete(IBinder window) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700386 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700387 mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700388 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 }
390
Andrew Scull26f830d2017-05-19 12:16:10 +0100391 @Override
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700392 public void setWallpaperDisplayOffset(IBinder window, int x, int y) {
393 synchronized(mService.mWindowMap) {
394 long ident = Binder.clearCallingIdentity();
395 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700396 mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset(
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700397 mService.windowForClientLocked(this, window, true), x, y);
398 } finally {
399 Binder.restoreCallingIdentity(ident);
400 }
401 }
402 }
403
Andrew Scull26f830d2017-05-19 12:16:10 +0100404 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
406 int z, Bundle extras, boolean sync) {
407 synchronized(mService.mWindowMap) {
408 long ident = Binder.clearCallingIdentity();
409 try {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700410 return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 mService.windowForClientLocked(this, window, true),
412 action, x, y, z, extras, sync);
413 } 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 void wallpaperCommandComplete(IBinder window, Bundle result) {
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700421 synchronized (mService.mWindowMap) {
Wale Ogunwale0303c572016-10-20 10:16:29 -0700422 mService.mRoot.mWallpaperController.wallpaperCommandComplete(window);
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700423 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800424 }
425
Andrew Scull26f830d2017-05-19 12:16:10 +0100426 @Override
Svetoslavf7174e82014-06-12 11:29:35 -0700427 public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700428 synchronized(mService.mWindowMap) {
429 final long identity = Binder.clearCallingIdentity();
430 try {
Svetoslavf7174e82014-06-12 11:29:35 -0700431 mService.onRectangleOnScreenRequested(token, rectangle);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700432 } finally {
433 Binder.restoreCallingIdentity(identity);
434 }
435 }
436 }
437
Andrew Scull26f830d2017-05-19 12:16:10 +0100438 @Override
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800439 public IWindowId getWindowId(IBinder window) {
440 return mService.getWindowId(window);
441 }
442
Jeff Brownc2932a12014-11-20 18:04:05 -0800443 @Override
444 public void pokeDrawLock(IBinder window) {
445 final long identity = Binder.clearCallingIdentity();
446 try {
447 mService.pokeDrawLock(this, window);
448 } finally {
449 Binder.restoreCallingIdentity(identity);
450 }
451 }
452
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -0800453 @Override
454 public void updatePointerIcon(IWindow window) {
455 final long identity = Binder.clearCallingIdentity();
456 try {
457 mService.updatePointerIcon(window);
458 } finally {
459 Binder.restoreCallingIdentity(identity);
460 }
461 }
462
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800463 @Override
464 public void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
465 int height) {
466 final long identity = Binder.clearCallingIdentity();
467 try {
468 mService.updateTapExcludeRegion(window, regionId, left, top, width, height);
469 } finally {
470 Binder.restoreCallingIdentity(identity);
471 }
472 }
473
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800474 void windowAddedLocked(String packageName) {
475 mPackageName = packageName;
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700476 mRelayoutTag = "relayoutWindow: " + mPackageName;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 if (mSurfaceSession == null) {
478 if (WindowManagerService.localLOGV) Slog.v(
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800479 TAG_WM, "First window added to " + this + ", creating SurfaceSession");
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);
511 } else {
512 changed = mAlertWindowSurfaces.remove(surfaceController);
513 }
514
515 if (changed) {
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800516 if (mAlertWindowSurfaces.isEmpty()) {
517 cancelAlertWindowNotification();
518 } else if (mAlertWindowNotification == null){
Wale Ogunwaled76881e2017-03-10 13:17:56 -0800519 mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700520 if (mShowingAlertWindowNotificationAllowed) {
521 mAlertWindowNotification.post();
522 }
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800523 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800524 }
525 }
Wale Ogunwale943002b2017-02-15 19:34:01 -0800526
527 if (type != TYPE_APPLICATION_OVERLAY) {
528 return;
529 }
530
531 if (visible) {
532 changed = mAppOverlaySurfaces.add(surfaceController);
533 } else {
534 changed = mAppOverlaySurfaces.remove(surfaceController);
535 }
536
537 if (changed) {
538 // Notify activity manager of changes to app overlay windows so it can adjust the
539 // importance score for the process.
540 setHasOverlayUi(!mAppOverlaySurfaces.isEmpty());
541 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800542 }
543
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700544 void setShowingAlertWindowNotificationAllowed(boolean allowed) {
545 mShowingAlertWindowNotificationAllowed = allowed;
546 if (mAlertWindowNotification != null) {
547 if (allowed) {
548 mAlertWindowNotification.post();
549 } else {
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800550 mAlertWindowNotification.cancel(false /* deleteChannel */);
Wale Ogunwalea10fc7e2017-04-06 07:09:51 -0700551 }
552 }
553 }
554
Wale Ogunwaled993a572017-02-05 13:52:09 -0800555 private void killSessionLocked() {
556 if (mNumWindow > 0 || !mClientDead) {
557 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558 }
Wale Ogunwaled993a572017-02-05 13:52:09 -0800559
560 mService.mSessions.remove(this);
561 if (mSurfaceSession == null) {
562 return;
563 }
564
565 if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this
566 + ", destroying " + mSurfaceSession);
567 if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession);
568 try {
569 mSurfaceSession.kill();
570 } catch (Exception e) {
571 Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession
572 + " in session " + this + ": " + e.toString());
573 }
574 mSurfaceSession = null;
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800575 mAlertWindowSurfaces.clear();
576 mAppOverlaySurfaces.clear();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800577 setHasOverlayUi(false);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800578 cancelAlertWindowNotification();
Wale Ogunwaled993a572017-02-05 13:52:09 -0800579 }
580
581 private void setHasOverlayUi(boolean hasOverlayUi) {
582 mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 }
584
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800585 private void cancelAlertWindowNotification() {
586 if (mAlertWindowNotification == null) {
587 return;
588 }
Wale Ogunwale6c8f2e42018-02-01 09:07:34 -0800589 mAlertWindowNotification.cancel(true /* deleteChannel */);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800590 mAlertWindowNotification = null;
591 }
592
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593 void dump(PrintWriter pw, String prefix) {
594 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
Wale Ogunwale5aa86832017-02-28 10:40:27 -0800595 pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800596 pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces);
597 pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800598 pw.print(" mClientDead="); pw.print(mClientDead);
599 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
Wale Ogunwale4958ad22017-06-22 09:08:14 -0700600 pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 }
602
603 @Override
604 public String toString() {
605 return mStringName;
606 }
Robert Carr0e007272017-10-02 13:00:55 -0700607
608 boolean hasAlertWindowSurfaces() {
609 return !mAlertWindowSurfaces.isEmpty();
610 }
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700611}