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