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