Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 19 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 20 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 22 | import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 28 | |
| 29 | import android.content.ClipData; |
| 30 | import android.content.Context; |
| 31 | import android.content.res.Configuration; |
| 32 | import android.graphics.Rect; |
| 33 | import android.graphics.Region; |
| 34 | import android.os.Binder; |
| 35 | import android.os.Bundle; |
| 36 | import android.os.IBinder; |
| 37 | import android.os.Parcel; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 38 | import android.os.Process; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 39 | import android.os.RemoteException; |
| 40 | import android.os.ServiceManager; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 42 | import android.util.Slog; |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 43 | import android.view.Display; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 44 | import android.view.IWindow; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 45 | import android.view.IWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 46 | import android.view.IWindowSession; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 47 | import android.view.IWindowSessionCallback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 48 | import android.view.InputChannel; |
| 49 | import android.view.Surface; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 50 | import android.view.SurfaceControl; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 51 | import android.view.SurfaceSession; |
| 52 | import android.view.WindowManager; |
| 53 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 54 | import com.android.internal.view.IInputContext; |
| 55 | import com.android.internal.view.IInputMethodClient; |
| 56 | import com.android.internal.view.IInputMethodManager; |
| 57 | import com.android.server.wm.WindowManagerService.H; |
| 58 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 59 | import java.io.PrintWriter; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 60 | import java.util.HashSet; |
| 61 | import java.util.Set; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 62 | |
| 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 | */ |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 67 | // Needs to be public and not final so we can mock during tests...sucks I know :( |
| 68 | public class Session extends IWindowSession.Stub |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 69 | implements IBinder.DeathRecipient { |
| 70 | final WindowManagerService mService; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 71 | final IWindowSessionCallback mCallback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 72 | final IInputMethodClient mClient; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 73 | final int mUid; |
| 74 | final int mPid; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 75 | private final String mStringName; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 76 | SurfaceSession mSurfaceSession; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 77 | private int mNumWindow = 0; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 78 | // Set of visible application overlay window surfaces connected to this session. |
| 79 | private final Set<WindowSurfaceController> mAppOverlaySurfaces = new HashSet<>(); |
| 80 | // Set of visible alert window surfaces connected to this session. |
| 81 | private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>(); |
| 82 | final boolean mCanAddInternalSystemWindow; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 83 | private boolean mClientDead = false; |
| 84 | private float mLastReportedAnimatorScale; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 85 | |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 86 | public Session(WindowManagerService service, IWindowSessionCallback callback, |
| 87 | IInputMethodClient client, IInputContext inputContext) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 88 | mService = service; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 89 | mCallback = callback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 90 | mClient = client; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 91 | mUid = Binder.getCallingUid(); |
| 92 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 93 | mLastReportedAnimatorScale = service.getCurrentAnimatorScale(); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 94 | mCanAddInternalSystemWindow = service.mContext.checkCallingPermission( |
| 95 | INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 96 | StringBuilder sb = new StringBuilder(); |
| 97 | sb.append("Session{"); |
| 98 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 99 | sb.append(" "); |
| 100 | sb.append(mPid); |
| 101 | if (mUid < Process.FIRST_APPLICATION_UID) { |
| 102 | sb.append(":"); |
| 103 | sb.append(mUid); |
| 104 | } else { |
| 105 | sb.append(":u"); |
| 106 | sb.append(UserHandle.getUserId(mUid)); |
| 107 | sb.append('a'); |
| 108 | sb.append(UserHandle.getAppId(mUid)); |
| 109 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 110 | sb.append("}"); |
| 111 | mStringName = sb.toString(); |
| 112 | |
| 113 | synchronized (mService.mWindowMap) { |
| 114 | if (mService.mInputMethodManager == null && mService.mHaveInputMethods) { |
| 115 | IBinder b = ServiceManager.getService( |
| 116 | Context.INPUT_METHOD_SERVICE); |
| 117 | mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 118 | } |
| 119 | } |
| 120 | long ident = Binder.clearCallingIdentity(); |
| 121 | try { |
| 122 | // Note: it is safe to call in to the input method manager |
| 123 | // here because we are not holding our lock. |
| 124 | if (mService.mInputMethodManager != null) { |
| 125 | mService.mInputMethodManager.addClient(client, inputContext, |
| 126 | mUid, mPid); |
| 127 | } else { |
| 128 | client.setUsingInputMethod(false); |
| 129 | } |
| 130 | client.asBinder().linkToDeath(this, 0); |
| 131 | } catch (RemoteException e) { |
| 132 | // The caller has died, so we can just forget about this. |
| 133 | try { |
| 134 | if (mService.mInputMethodManager != null) { |
| 135 | mService.mInputMethodManager.removeClient(client); |
| 136 | } |
| 137 | } catch (RemoteException ee) { |
| 138 | } |
| 139 | } finally { |
| 140 | Binder.restoreCallingIdentity(ident); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 146 | throws RemoteException { |
| 147 | try { |
| 148 | return super.onTransact(code, data, reply, flags); |
| 149 | } catch (RuntimeException e) { |
| 150 | // Log all 'real' exceptions thrown to the caller |
| 151 | if (!(e instanceof SecurityException)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 152 | Slog.wtf(TAG_WM, "Window Session Crash", e); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 153 | } |
| 154 | throw e; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | public void binderDied() { |
| 159 | // Note: it is safe to call in to the input method manager |
| 160 | // here because we are not holding our lock. |
| 161 | try { |
| 162 | if (mService.mInputMethodManager != null) { |
| 163 | mService.mInputMethodManager.removeClient(mClient); |
| 164 | } |
| 165 | } catch (RemoteException e) { |
| 166 | } |
| 167 | synchronized(mService.mWindowMap) { |
| 168 | mClient.asBinder().unlinkToDeath(this, 0); |
| 169 | mClientDead = true; |
| 170 | killSessionLocked(); |
| 171 | } |
| 172 | } |
| 173 | |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 174 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 175 | public int add(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 176 | int viewVisibility, Rect outContentInsets, Rect outStableInsets, |
| 177 | InputChannel outInputChannel) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 178 | return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 179 | outContentInsets, outStableInsets, null /* outOutsets */, outInputChannel); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 180 | } |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 181 | |
| 182 | @Override |
| 183 | public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 184 | int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 185 | Rect outOutsets, InputChannel outInputChannel) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 186 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 187 | outContentInsets, outStableInsets, outOutsets, outInputChannel); |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 191 | public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 192 | int viewVisibility, Rect outContentInsets, Rect outStableInsets) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 193 | return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 194 | Display.DEFAULT_DISPLAY, outContentInsets, outStableInsets); |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 199 | int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 200 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 201 | outContentInsets, outStableInsets, null /* outOutsets */, null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | public void remove(IWindow window) { |
| 205 | mService.removeWindow(this, window); |
| 206 | } |
| 207 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 208 | @Override |
Robert Carr | 64aadd0 | 2015-11-06 13:54:20 -0800 | [diff] [blame] | 209 | public void repositionChild(IWindow window, int left, int top, int right, int bottom, |
Chong Zhang | 6136273 | 2016-03-21 16:13:10 -0700 | [diff] [blame] | 210 | long deferTransactionUntilFrame, Rect outFrame) { |
Robert Carr | 64aadd0 | 2015-11-06 13:54:20 -0800 | [diff] [blame] | 211 | mService.repositionChild(this, window, left, top, right, bottom, |
| 212 | deferTransactionUntilFrame, outFrame); |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 215 | @Override |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 216 | public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 217 | mService.setWillReplaceWindows(appToken, childrenOnly); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 220 | public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 221 | int requestedWidth, int requestedHeight, int viewFlags, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 222 | int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 223 | Rect outVisibleInsets, Rect outStableInsets, Rect outsets, Rect outBackdropFrame, |
| 224 | Configuration outConfig, Surface outSurface) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 225 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 226 | + Binder.getCallingPid()); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 227 | int res = mService.relayoutWindow(this, window, seq, attrs, |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 228 | requestedWidth, requestedHeight, viewFlags, flags, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 229 | outFrame, outOverscanInsets, outContentInsets, outVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 230 | outStableInsets, outsets, outBackdropFrame, outConfig, outSurface); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 231 | if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 232 | + Binder.getCallingPid()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 233 | return res; |
| 234 | } |
| 235 | |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 236 | public void performDeferredDestroy(IWindow window) { |
| 237 | mService.performDeferredDestroyWindow(this, window); |
| 238 | } |
| 239 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 240 | public boolean outOfMemory(IWindow window) { |
| 241 | return mService.outOfMemoryWindow(this, window); |
| 242 | } |
| 243 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 244 | public void setTransparentRegion(IWindow window, Region region) { |
| 245 | mService.setTransparentRegionWindow(this, window, region); |
| 246 | } |
| 247 | |
| 248 | public void setInsets(IWindow window, int touchableInsets, |
| 249 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
| 250 | mService.setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 251 | visibleInsets, touchableArea); |
| 252 | } |
| 253 | |
| 254 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 255 | mService.getWindowDisplayFrame(this, window, outDisplayFrame); |
| 256 | } |
| 257 | |
| 258 | public void finishDrawing(IWindow window) { |
| 259 | if (WindowManagerService.localLOGV) Slog.v( |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 260 | TAG_WM, "IWindow finishDrawing called for " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 261 | mService.finishDrawingWindow(this, window); |
| 262 | } |
| 263 | |
| 264 | public void setInTouchMode(boolean mode) { |
| 265 | synchronized(mService.mWindowMap) { |
| 266 | mService.mInTouchMode = mode; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | public boolean getInTouchMode() { |
| 271 | synchronized(mService.mWindowMap) { |
| 272 | return mService.mInTouchMode; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 277 | boolean always) { |
| 278 | synchronized(mService.mWindowMap) { |
| 279 | long ident = Binder.clearCallingIdentity(); |
| 280 | try { |
| 281 | return mService.mPolicy.performHapticFeedbackLw( |
| 282 | mService.windowForClientLocked(this, window, true), |
| 283 | effectId, always); |
| 284 | } finally { |
| 285 | Binder.restoreCallingIdentity(ident); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /* Drag/drop */ |
| 291 | public IBinder prepareDrag(IWindow window, int flags, |
| 292 | int width, int height, Surface outSurface) { |
| 293 | return mService.prepareDragSurface(window, mSurfaceSession, flags, |
| 294 | width, height, outSurface); |
| 295 | } |
| 296 | |
| 297 | public boolean performDrag(IWindow window, IBinder dragToken, |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 298 | int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 299 | ClipData data) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 300 | if (DEBUG_DRAG) { |
| 301 | Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | synchronized (mService.mWindowMap) { |
| 305 | if (mService.mDragState == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 306 | Slog.w(TAG_WM, "No drag prepared"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 307 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 308 | } |
| 309 | |
| 310 | if (dragToken != mService.mDragState.mToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 311 | Slog.w(TAG_WM, "Performing mismatched drag"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 312 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 313 | } |
| 314 | |
| 315 | WindowState callingWin = mService.windowForClientLocked(null, window, false); |
| 316 | if (callingWin == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 317 | Slog.w(TAG_WM, "Bad requesting window " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 318 | return false; // !!! TODO: throw here? |
| 319 | } |
| 320 | |
| 321 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 322 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 323 | // called performDrag() |
| 324 | |
| 325 | mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 326 | |
| 327 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 328 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| 329 | |
| 330 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 331 | // the actual drag event dispatch stuff in the dragstate |
| 332 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 333 | final DisplayContent displayContent = callingWin.getDisplayContent(); |
| 334 | if (displayContent == null) { |
| 335 | return false; |
| 336 | } |
| 337 | Display display = displayContent.getDisplay(); |
Jeff Brown | 14a9f2b | 2012-09-24 14:36:44 -0700 | [diff] [blame] | 338 | mService.mDragState.register(display); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 339 | if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 340 | mService.mDragState.getInputChannel())) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 341 | Slog.e(TAG_WM, "Unable to transfer touch focus"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 342 | mService.mDragState.unregister(); |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 343 | mService.mDragState.reset(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 344 | mService.mDragState = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 345 | return false; |
| 346 | } |
| 347 | |
Vladislav Kaznacheev | 64b103a | 2016-08-10 11:49:08 -0700 | [diff] [blame] | 348 | mService.mDragState.mDisplayContent = displayContent; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 349 | mService.mDragState.mData = data; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 350 | mService.mDragState.broadcastDragStartedLw(touchX, touchY); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 351 | mService.mDragState.overridePointerIconLw(touchSource); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 352 | |
| 353 | // remember the thumb offsets for later |
| 354 | mService.mDragState.mThumbOffsetX = thumbCenterX; |
| 355 | mService.mDragState.mThumbOffsetY = thumbCenterY; |
| 356 | |
| 357 | // Make the surface visible at the proper location |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 358 | final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 359 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 360 | TAG_WM, ">>> OPEN TRANSACTION performDrag"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 361 | mService.openSurfaceTransaction(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 362 | try { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 363 | surfaceControl.setPosition(touchX - thumbCenterX, |
Dianne Hackborn | d040edb | 2011-08-31 12:47:58 -0700 | [diff] [blame] | 364 | touchY - thumbCenterY); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 365 | surfaceControl.setLayer(mService.mDragState.getDragLayerLw()); |
| 366 | surfaceControl.setLayerStack(display.getLayerStack()); |
| 367 | surfaceControl.show(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 368 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 369 | mService.closeSurfaceTransaction(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 370 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 371 | TAG_WM, "<<< CLOSE TRANSACTION performDrag"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 372 | } |
Vladislav Kaznacheev | d0ed893 | 2016-01-15 15:37:05 -0800 | [diff] [blame] | 373 | |
| 374 | mService.mDragState.notifyLocationLw(touchX, touchY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | return true; // success! |
| 378 | } |
| 379 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 380 | public boolean startMovingTask(IWindow window, float startX, float startY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 381 | if (DEBUG_TASK_POSITIONING) Slog.d( |
| 382 | TAG_WM, "startMovingTask: {" + startX + "," + startY + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 383 | |
Wale Ogunwale | 09e1b8d | 2016-02-23 10:38:35 -0800 | [diff] [blame] | 384 | long ident = Binder.clearCallingIdentity(); |
| 385 | try { |
| 386 | return mService.startMovingTask(window, startX, startY); |
| 387 | } finally { |
| 388 | Binder.restoreCallingIdentity(ident); |
| 389 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 392 | public void reportDropResult(IWindow window, boolean consumed) { |
| 393 | IBinder token = window.asBinder(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 394 | if (DEBUG_DRAG) { |
| 395 | Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | synchronized (mService.mWindowMap) { |
| 399 | long ident = Binder.clearCallingIdentity(); |
| 400 | try { |
Christopher Tate | 05e9c65 | 2011-10-20 12:34:36 -0700 | [diff] [blame] | 401 | if (mService.mDragState == null) { |
| 402 | // Most likely the drop recipient ANRed and we ended the drag |
| 403 | // out from under it. Log the issue and move on. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 404 | Slog.w(TAG_WM, "Drop result given but no drag in progress"); |
Christopher Tate | 05e9c65 | 2011-10-20 12:34:36 -0700 | [diff] [blame] | 405 | return; |
| 406 | } |
| 407 | |
| 408 | if (mService.mDragState.mToken != token) { |
| 409 | // We're in a drag, but the wrong window has responded. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 410 | Slog.w(TAG_WM, "Invalid drop-result claim by " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 411 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 412 | } |
| 413 | |
| 414 | // The right window has responded, even if it's no longer around, |
| 415 | // so be sure to halt the timeout even if the later WindowState |
| 416 | // lookup fails. |
| 417 | mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 418 | WindowState callingWin = mService.windowForClientLocked(null, window, false); |
| 419 | if (callingWin == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 420 | Slog.w(TAG_WM, "Bad result-reporting window " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 421 | return; // !!! TODO: throw here? |
| 422 | } |
| 423 | |
| 424 | mService.mDragState.mDragResult = consumed; |
| 425 | mService.mDragState.endDragLw(); |
| 426 | } finally { |
| 427 | Binder.restoreCallingIdentity(ident); |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 432 | public void cancelDragAndDrop(IBinder dragToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 433 | if (DEBUG_DRAG) { |
| 434 | Slog.d(TAG_WM, "cancelDragAndDrop"); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | synchronized (mService.mWindowMap) { |
| 438 | long ident = Binder.clearCallingIdentity(); |
| 439 | try { |
| 440 | if (mService.mDragState == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 441 | Slog.w(TAG_WM, "cancelDragAndDrop() without prepareDrag()"); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 442 | throw new IllegalStateException("cancelDragAndDrop() without prepareDrag()"); |
| 443 | } |
| 444 | |
| 445 | if (mService.mDragState.mToken != dragToken) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 446 | Slog.w(TAG_WM, |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 447 | "cancelDragAndDrop() does not match prepareDrag()"); |
| 448 | throw new IllegalStateException( |
| 449 | "cancelDragAndDrop() does not match prepareDrag()"); |
| 450 | } |
| 451 | |
| 452 | mService.mDragState.mDragResult = false; |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 453 | mService.mDragState.cancelDragLw(); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 454 | } finally { |
| 455 | Binder.restoreCallingIdentity(ident); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 460 | public void dragRecipientEntered(IWindow window) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 461 | if (DEBUG_DRAG) { |
| 462 | Slog.d(TAG_WM, "Drag into new candidate view @ " + window.asBinder()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | public void dragRecipientExited(IWindow window) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 467 | if (DEBUG_DRAG) { |
| 468 | Slog.d(TAG_WM, "Drag from old candidate view @ " + window.asBinder()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
| 472 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
| 473 | synchronized(mService.mWindowMap) { |
| 474 | long ident = Binder.clearCallingIdentity(); |
| 475 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 476 | mService.mRoot.mWallpaperController.setWindowWallpaperPosition( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 477 | mService.windowForClientLocked(this, window, true), |
| 478 | x, y, xStep, yStep); |
| 479 | } finally { |
| 480 | Binder.restoreCallingIdentity(ident); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | public void wallpaperOffsetsComplete(IBinder window) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 486 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 487 | mService.mRoot.mWallpaperController.wallpaperOffsetsComplete(window); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 488 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 491 | public void setWallpaperDisplayOffset(IBinder window, int x, int y) { |
| 492 | synchronized(mService.mWindowMap) { |
| 493 | long ident = Binder.clearCallingIdentity(); |
| 494 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 495 | mService.mRoot.mWallpaperController.setWindowWallpaperDisplayOffset( |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 496 | mService.windowForClientLocked(this, window, true), x, y); |
| 497 | } finally { |
| 498 | Binder.restoreCallingIdentity(ident); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 503 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 504 | int z, Bundle extras, boolean sync) { |
| 505 | synchronized(mService.mWindowMap) { |
| 506 | long ident = Binder.clearCallingIdentity(); |
| 507 | try { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 508 | return mService.mRoot.mWallpaperController.sendWindowWallpaperCommand( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 509 | mService.windowForClientLocked(this, window, true), |
| 510 | action, x, y, z, extras, sync); |
| 511 | } finally { |
| 512 | Binder.restoreCallingIdentity(ident); |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 518 | synchronized (mService.mWindowMap) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 519 | mService.mRoot.mWallpaperController.wallpaperCommandComplete(window); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 520 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 523 | public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) { |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 524 | synchronized(mService.mWindowMap) { |
| 525 | final long identity = Binder.clearCallingIdentity(); |
| 526 | try { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 527 | mService.onRectangleOnScreenRequested(token, rectangle); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 528 | } finally { |
| 529 | Binder.restoreCallingIdentity(identity); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 534 | public IWindowId getWindowId(IBinder window) { |
| 535 | return mService.getWindowId(window); |
| 536 | } |
| 537 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 538 | @Override |
| 539 | public void pokeDrawLock(IBinder window) { |
| 540 | final long identity = Binder.clearCallingIdentity(); |
| 541 | try { |
| 542 | mService.pokeDrawLock(this, window); |
| 543 | } finally { |
| 544 | Binder.restoreCallingIdentity(identity); |
| 545 | } |
| 546 | } |
| 547 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 548 | @Override |
| 549 | public void updatePointerIcon(IWindow window) { |
| 550 | final long identity = Binder.clearCallingIdentity(); |
| 551 | try { |
| 552 | mService.updatePointerIcon(window); |
| 553 | } finally { |
| 554 | Binder.restoreCallingIdentity(identity); |
| 555 | } |
| 556 | } |
| 557 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 558 | void windowAddedLocked() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 559 | if (mSurfaceSession == null) { |
| 560 | if (WindowManagerService.localLOGV) Slog.v( |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 561 | TAG_WM, "First window added to " + this + ", creating SurfaceSession"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | mSurfaceSession = new SurfaceSession(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 563 | if (SHOW_TRANSACTIONS) Slog.i( |
| 564 | TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 565 | mService.mSessions.add(this); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 566 | if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) { |
| 567 | mService.dispatchNewAnimatorScaleLocked(this); |
| 568 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 569 | } |
| 570 | mNumWindow++; |
| 571 | } |
| 572 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 573 | void windowRemovedLocked() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 574 | mNumWindow--; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 575 | killSessionLocked(); |
| 576 | } |
| 577 | |
| 578 | |
| 579 | void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController, |
| 580 | boolean visible, int type) { |
| 581 | |
| 582 | if (!isSystemAlertWindowType(type)) { |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | boolean changed; |
| 587 | |
| 588 | if (!mCanAddInternalSystemWindow) { |
| 589 | // We want to track non-system signature apps adding alert windows so we can post an |
| 590 | // on-going notification for the user to control their visibility. |
| 591 | if (visible) { |
| 592 | changed = mAlertWindowSurfaces.add(surfaceController); |
| 593 | } else { |
| 594 | changed = mAlertWindowSurfaces.remove(surfaceController); |
| 595 | } |
| 596 | |
| 597 | if (changed) { |
| 598 | // TODO: Update notification. |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 599 | } |
| 600 | } |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 601 | |
| 602 | if (type != TYPE_APPLICATION_OVERLAY) { |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | if (visible) { |
| 607 | changed = mAppOverlaySurfaces.add(surfaceController); |
| 608 | } else { |
| 609 | changed = mAppOverlaySurfaces.remove(surfaceController); |
| 610 | } |
| 611 | |
| 612 | if (changed) { |
| 613 | // Notify activity manager of changes to app overlay windows so it can adjust the |
| 614 | // importance score for the process. |
| 615 | setHasOverlayUi(!mAppOverlaySurfaces.isEmpty()); |
| 616 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 619 | private void killSessionLocked() { |
| 620 | if (mNumWindow > 0 || !mClientDead) { |
| 621 | return; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 622 | } |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 623 | |
| 624 | mService.mSessions.remove(this); |
| 625 | if (mSurfaceSession == null) { |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | if (WindowManagerService.localLOGV) Slog.v(TAG_WM, "Last window removed from " + this |
| 630 | + ", destroying " + mSurfaceSession); |
| 631 | if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession); |
| 632 | try { |
| 633 | mSurfaceSession.kill(); |
| 634 | } catch (Exception e) { |
| 635 | Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession |
| 636 | + " in session " + this + ": " + e.toString()); |
| 637 | } |
| 638 | mSurfaceSession = null; |
| 639 | setHasOverlayUi(false); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 640 | // TODO: Update notification |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | private void setHasOverlayUi(boolean hasOverlayUi) { |
| 644 | mService.mH.obtainMessage(H.SET_HAS_OVERLAY_UI, mPid, hasOverlayUi ? 1 : 0).sendToTarget(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void dump(PrintWriter pw, String prefix) { |
| 648 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame^] | 649 | pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces); |
| 650 | pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 651 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 652 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| 653 | } |
| 654 | |
| 655 | @Override |
| 656 | public String toString() { |
| 657 | return mStringName; |
| 658 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 659 | } |