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