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