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; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 26 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame^] | 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 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 | |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 33 | import android.content.ClipData; |
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; |
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; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 44 | import android.util.ArraySet; |
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; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 47 | import android.view.DisplayCutout; |
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; |
Tiger Huang | dda14a7 | 2019-01-10 17:20:27 +0800 | [diff] [blame] | 53 | import android.view.InsetsState; |
Daichi Hirono | a1fb9be | 2017-12-18 17:02:54 +0900 | [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 | |
Chenjie Yu | e890419 | 2017-12-08 19:12:57 -0800 | [diff] [blame] | 58 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 59 | import com.android.server.wm.WindowManagerService.H; |
| 60 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 61 | import java.io.PrintWriter; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 62 | import java.util.List; |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 63 | import java.util.function.BiConsumer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * This class represents an active client session. There is generally one |
| 67 | * Session object per process that is interacting with the window manager. |
| 68 | */ |
Bryce Lee | a559286 | 2017-10-23 12:57:37 -0700 | [diff] [blame] | 69 | class Session extends IWindowSession.Stub implements IBinder.DeathRecipient { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 70 | final WindowManagerService mService; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 71 | final IWindowSessionCallback mCallback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 72 | final int mUid; |
| 73 | final int mPid; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 74 | private final String mStringName; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 75 | SurfaceSession mSurfaceSession; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 76 | private int mNumWindow = 0; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 77 | // Set of visible application overlay window surfaces connected to this session. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 78 | private final ArraySet<WindowSurfaceController> mAppOverlaySurfaces = new ArraySet<>(); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 79 | // Set of visible alert window surfaces connected to this session. |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 80 | private final ArraySet<WindowSurfaceController> mAlertWindowSurfaces = new ArraySet<>(); |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 81 | private final DragDropController mDragDropController; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 82 | final boolean mCanAddInternalSystemWindow; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 83 | final boolean mCanHideNonSystemOverlayWindows; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 84 | final boolean mCanAcquireSleepToken; |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 85 | private AlertWindowNotification mAlertWindowNotification; |
Wale Ogunwale | a10fc7e | 2017-04-06 07:09:51 -0700 | [diff] [blame] | 86 | private boolean mShowingAlertWindowNotificationAllowed; |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 87 | private boolean mClientDead = false; |
| 88 | private float mLastReportedAnimatorScale; |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 89 | private String mPackageName; |
Wale Ogunwale | 4958ad2 | 2017-06-22 09:08:14 -0700 | [diff] [blame] | 90 | private String mRelayoutTag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 91 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 92 | public Session(WindowManagerService service, IWindowSessionCallback callback) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 93 | mService = service; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 94 | mCallback = callback; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 95 | mUid = Binder.getCallingUid(); |
| 96 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 97 | mLastReportedAnimatorScale = service.getCurrentAnimatorScale(); |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 98 | mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission( |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 99 | INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 100 | mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission( |
| 101 | HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED; |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 102 | mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER) |
| 103 | == PERMISSION_GRANTED; |
Wale Ogunwale | a10fc7e | 2017-04-06 07:09:51 -0700 | [diff] [blame] | 104 | mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications; |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 105 | mDragDropController = mService.mDragDropController; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 106 | StringBuilder sb = new StringBuilder(); |
| 107 | sb.append("Session{"); |
| 108 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 109 | sb.append(" "); |
| 110 | sb.append(mPid); |
| 111 | if (mUid < Process.FIRST_APPLICATION_UID) { |
| 112 | sb.append(":"); |
| 113 | sb.append(mUid); |
| 114 | } else { |
| 115 | sb.append(":u"); |
| 116 | sb.append(UserHandle.getUserId(mUid)); |
| 117 | sb.append('a'); |
| 118 | sb.append(UserHandle.getAppId(mUid)); |
| 119 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 120 | sb.append("}"); |
| 121 | mStringName = sb.toString(); |
| 122 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 123 | try { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 124 | mCallback.asBinder().linkToDeath(this, 0); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 125 | } catch (RemoteException e) { |
| 126 | // The caller has died, so we can just forget about this. |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 127 | // Hmmm, should we call killSessionLocked()?? |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 133 | throws RemoteException { |
| 134 | try { |
| 135 | return super.onTransact(code, data, reply, flags); |
| 136 | } catch (RuntimeException e) { |
| 137 | // Log all 'real' exceptions thrown to the caller |
| 138 | if (!(e instanceof SecurityException)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 139 | Slog.wtf(TAG_WM, "Window Session Crash", e); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 140 | } |
| 141 | throw e; |
| 142 | } |
| 143 | } |
| 144 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 145 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 146 | public void binderDied() { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 147 | synchronized (mService.mGlobalLock) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 148 | mCallback.asBinder().unlinkToDeath(this, 0); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 149 | mClientDead = true; |
| 150 | killSessionLocked(); |
| 151 | } |
| 152 | } |
| 153 | |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 154 | @Override |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 155 | public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 156 | int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets, |
| 157 | Rect outStableInsets, Rect outOutsets, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 158 | DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, |
| 159 | InsetsState outInsetsState) { |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 160 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, outFrame, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 161 | outContentInsets, outStableInsets, outOutsets, outDisplayCutout, outInputChannel, |
| 162 | outInsetsState); |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 166 | public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 167 | int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets, |
| 168 | InsetsState outInsetsState) { |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 169 | return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId, |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 170 | new Rect() /* outFrame */, outContentInsets, outStableInsets, null /* outOutsets */, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 171 | new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */, |
| 172 | outInsetsState); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 175 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 176 | public void remove(IWindow window) { |
| 177 | mService.removeWindow(this, window); |
| 178 | } |
| 179 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 180 | @Override |
Robert Carr | 77bdfb5 | 2016-05-02 18:18:31 -0700 | [diff] [blame] | 181 | public void prepareToReplaceWindows(IBinder appToken, boolean childrenOnly) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 182 | mService.setWillReplaceWindows(appToken, childrenOnly); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 185 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 186 | public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs, |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 187 | int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber, |
| 188 | Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets, |
| 189 | Rect outStableInsets, Rect outsets, Rect outBackdropFrame, |
| 190 | DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration, |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 191 | SurfaceControl outSurfaceControl, InsetsState outInsetsState) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 192 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 193 | + Binder.getCallingPid()); |
Wale Ogunwale | 4958ad2 | 2017-06-22 09:08:14 -0700 | [diff] [blame] | 194 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 195 | int res = mService.relayoutWindow(this, window, seq, attrs, |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 196 | requestedWidth, requestedHeight, viewFlags, flags, frameNumber, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 197 | outFrame, outOverscanInsets, outContentInsets, outVisibleInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 198 | outStableInsets, outsets, outBackdropFrame, cutout, |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 199 | mergedConfiguration, outSurfaceControl, outInsetsState); |
Wale Ogunwale | 4958ad2 | 2017-06-22 09:08:14 -0700 | [diff] [blame] | 200 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 201 | if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to " |
Dianne Hackborn | b961cd2 | 2011-06-21 12:13:37 -0700 | [diff] [blame] | 202 | + Binder.getCallingPid()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 203 | return res; |
| 204 | } |
| 205 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 206 | @Override |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 207 | public boolean outOfMemory(IWindow window) { |
| 208 | return mService.outOfMemoryWindow(this, window); |
| 209 | } |
| 210 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 211 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 212 | public void setTransparentRegion(IWindow window, Region region) { |
| 213 | mService.setTransparentRegionWindow(this, window, region); |
| 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 setInsets(IWindow window, int touchableInsets, |
| 218 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
| 219 | mService.setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 220 | visibleInsets, touchableArea); |
| 221 | } |
| 222 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 223 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 224 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 225 | mService.getWindowDisplayFrame(this, window, outDisplayFrame); |
| 226 | } |
| 227 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 228 | @Override |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 229 | public void finishDrawing(IWindow window, |
| 230 | @Nullable SurfaceControl.Transaction postDrawTransaction) { |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame^] | 231 | if (DEBUG) Slog.v(TAG_WM, "IWindow finishDrawing called for " + window); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 232 | mService.finishDrawingWindow(this, window, postDrawTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 235 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 236 | public void setInTouchMode(boolean mode) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 237 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 238 | mService.mInTouchMode = mode; |
| 239 | } |
| 240 | } |
| 241 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 242 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 243 | public boolean getInTouchMode() { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 244 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 245 | return mService.mInTouchMode; |
| 246 | } |
| 247 | } |
| 248 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 249 | @Override |
Arthur Hung | a4c5206 | 2019-02-19 11:31:44 +0800 | [diff] [blame] | 250 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 251 | long ident = Binder.clearCallingIdentity(); |
| 252 | try { |
| 253 | return mService.mPolicy.performHapticFeedback(mUid, mPackageName, |
Alexey Kuzmin | e1f06b8 | 2018-06-20 17:48:43 +0100 | [diff] [blame] | 254 | effectId, always, null); |
Arthur Hung | a4c5206 | 2019-02-19 11:31:44 +0800 | [diff] [blame] | 255 | } finally { |
| 256 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | /* Drag/drop */ |
Daichi Hirono | fabca09 | 2017-12-19 15:02:50 +0900 | [diff] [blame] | 261 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 262 | @Override |
Daichi Hirono | fabca09 | 2017-12-19 15:02:50 +0900 | [diff] [blame] | 263 | public IBinder performDrag(IWindow window, int flags, SurfaceControl surface, int touchSource, |
| 264 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) { |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 265 | final int callerPid = Binder.getCallingPid(); |
| 266 | final int callerUid = Binder.getCallingUid(); |
| 267 | final long ident = Binder.clearCallingIdentity(); |
| 268 | try { |
Daichi Hirono | fabca09 | 2017-12-19 15:02:50 +0900 | [diff] [blame] | 269 | return mDragDropController.performDrag(mSurfaceSession, callerPid, callerUid, window, |
| 270 | flags, surface, touchSource, touchX, touchY, thumbCenterX, thumbCenterY, data); |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 271 | } finally { |
| 272 | Binder.restoreCallingIdentity(ident); |
| 273 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 276 | @Override |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 277 | public void reportDropResult(IWindow window, boolean consumed) { |
| 278 | final long ident = Binder.clearCallingIdentity(); |
| 279 | try { |
Daichi Hirono | 58e25e1 | 2017-10-25 15:48:08 +0900 | [diff] [blame] | 280 | mDragDropController.reportDropResult(window, consumed); |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 281 | } finally { |
| 282 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 283 | } |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 284 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 285 | |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 286 | @Override |
Daichi Hirono | 3e9d510 | 2019-04-15 15:58:11 +0900 | [diff] [blame] | 287 | public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) { |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 288 | final long ident = Binder.clearCallingIdentity(); |
| 289 | try { |
Daichi Hirono | 3e9d510 | 2019-04-15 15:58:11 +0900 | [diff] [blame] | 290 | mDragDropController.cancelDragAndDrop(dragToken, skipAnimation); |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 291 | } finally { |
| 292 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 293 | } |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 294 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 295 | |
Daichi Hirono | df5cf62 | 2017-09-11 14:59:26 +0900 | [diff] [blame] | 296 | @Override |
| 297 | public void dragRecipientEntered(IWindow window) { |
| 298 | mDragDropController.dragRecipientEntered(window); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void dragRecipientExited(IWindow window) { |
| 303 | mDragDropController.dragRecipientExited(window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 306 | @Override |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 307 | public boolean startMovingTask(IWindow window, float startX, float startY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 308 | if (DEBUG_TASK_POSITIONING) Slog.d( |
| 309 | TAG_WM, "startMovingTask: {" + startX + "," + startY + "}"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 310 | |
Wale Ogunwale | 09e1b8d | 2016-02-23 10:38:35 -0800 | [diff] [blame] | 311 | long ident = Binder.clearCallingIdentity(); |
| 312 | try { |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 313 | return mService.mTaskPositioningController.startMovingTask(window, startX, startY); |
Wale Ogunwale | 09e1b8d | 2016-02-23 10:38:35 -0800 | [diff] [blame] | 314 | } finally { |
| 315 | Binder.restoreCallingIdentity(ident); |
| 316 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 319 | @Override |
yj81.kwon | 19585ff | 2019-04-23 18:53:57 -0700 | [diff] [blame] | 320 | public void finishMovingTask(IWindow window) { |
| 321 | if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishMovingTask"); |
| 322 | |
| 323 | long ident = Binder.clearCallingIdentity(); |
| 324 | try { |
| 325 | mService.mTaskPositioningController.finishTaskPositioning(window); |
| 326 | } finally { |
| 327 | Binder.restoreCallingIdentity(ident); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | @Override |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 332 | public void reportSystemGestureExclusionChanged(IWindow window, List<Rect> exclusionRects) { |
| 333 | long ident = Binder.clearCallingIdentity(); |
| 334 | try { |
| 335 | mService.reportSystemGestureExclusionChanged(this, window, exclusionRects); |
| 336 | } finally { |
| 337 | Binder.restoreCallingIdentity(ident); |
| 338 | } |
| 339 | } |
| 340 | |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 341 | private void actionOnWallpaper(IBinder window, |
| 342 | BiConsumer<WallpaperController, WindowState> action) { |
| 343 | final WindowState windowState = mService.windowForClientLocked(this, window, true); |
| 344 | action.accept(windowState.getDisplayContent().mWallpaperController, windowState); |
| 345 | } |
| 346 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 347 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 348 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 349 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 350 | long ident = Binder.clearCallingIdentity(); |
| 351 | try { |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 352 | actionOnWallpaper(window, (wpController, windowState) -> |
| 353 | wpController.setWindowWallpaperPosition(windowState, x, y, xStep, yStep)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 354 | } finally { |
| 355 | Binder.restoreCallingIdentity(ident); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 360 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 361 | public void wallpaperOffsetsComplete(IBinder window) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 362 | synchronized (mService.mGlobalLock) { |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 363 | actionOnWallpaper(window, (wpController, windowState) -> |
| 364 | wpController.wallpaperOffsetsComplete(window)); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 365 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 368 | @Override |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 369 | public void setWallpaperDisplayOffset(IBinder window, int x, int y) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 370 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 371 | long ident = Binder.clearCallingIdentity(); |
| 372 | try { |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 373 | actionOnWallpaper(window, (wpController, windowState) -> |
| 374 | wpController.setWindowWallpaperDisplayOffset(windowState, x, y)); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 375 | } finally { |
| 376 | Binder.restoreCallingIdentity(ident); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 381 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 382 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 383 | int z, Bundle extras, boolean sync) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 384 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 385 | long ident = Binder.clearCallingIdentity(); |
| 386 | try { |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 387 | final WindowState windowState = mService.windowForClientLocked(this, window, true); |
| 388 | return windowState.getDisplayContent().mWallpaperController |
| 389 | .sendWindowWallpaperCommand(windowState, action, x, y, z, extras, sync); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 390 | } finally { |
| 391 | Binder.restoreCallingIdentity(ident); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 396 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 397 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 398 | synchronized (mService.mGlobalLock) { |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 399 | actionOnWallpaper(window, (wpController, windowState) -> |
| 400 | wpController.wallpaperCommandComplete(window)); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 401 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 404 | @Override |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 405 | public void onRectangleOnScreenRequested(IBinder token, Rect rectangle) { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 406 | synchronized (mService.mGlobalLock) { |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 407 | final long identity = Binder.clearCallingIdentity(); |
| 408 | try { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 409 | mService.onRectangleOnScreenRequested(token, rectangle); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 410 | } finally { |
| 411 | Binder.restoreCallingIdentity(identity); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
Andrew Scull | 26f830d | 2017-05-19 12:16:10 +0100 | [diff] [blame] | 416 | @Override |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 417 | public IWindowId getWindowId(IBinder window) { |
| 418 | return mService.getWindowId(window); |
| 419 | } |
| 420 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 421 | @Override |
| 422 | public void pokeDrawLock(IBinder window) { |
| 423 | final long identity = Binder.clearCallingIdentity(); |
| 424 | try { |
| 425 | mService.pokeDrawLock(this, window); |
| 426 | } finally { |
| 427 | Binder.restoreCallingIdentity(identity); |
| 428 | } |
| 429 | } |
| 430 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 431 | @Override |
| 432 | public void updatePointerIcon(IWindow window) { |
| 433 | final long identity = Binder.clearCallingIdentity(); |
| 434 | try { |
| 435 | mService.updatePointerIcon(window); |
| 436 | } finally { |
| 437 | Binder.restoreCallingIdentity(identity); |
| 438 | } |
| 439 | } |
| 440 | |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 441 | @Override |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 442 | public void reparentDisplayContent(IWindow window, SurfaceControl sc, int displayId) { |
| 443 | mService.reparentDisplayContent(window, sc, displayId); |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void updateDisplayContentLocation(IWindow window, int x, int y, int displayId) { |
| 448 | mService.updateDisplayContentLocation(window, x, y, displayId); |
| 449 | } |
| 450 | |
| 451 | @Override |
Tiger Huang | 2b210c2 | 2019-03-18 21:21:26 +0800 | [diff] [blame] | 452 | public void updateTapExcludeRegion(IWindow window, int regionId, Region region) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 453 | final long identity = Binder.clearCallingIdentity(); |
| 454 | try { |
Tiger Huang | 2b210c2 | 2019-03-18 21:21:26 +0800 | [diff] [blame] | 455 | mService.updateTapExcludeRegion(window, regionId, region); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 456 | } finally { |
| 457 | Binder.restoreCallingIdentity(identity); |
| 458 | } |
| 459 | } |
| 460 | |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 461 | @Override |
| 462 | public void insetsModified(IWindow window, InsetsState state) { |
Tiger Huang | dda14a7 | 2019-01-10 17:20:27 +0800 | [diff] [blame] | 463 | synchronized (mService.mGlobalLock) { |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame] | 464 | final WindowState windowState = mService.windowForClientLocked(this, window, |
| 465 | false /* throwOnError */); |
| 466 | if (windowState != null) { |
| 467 | windowState.getDisplayContent().getInsetsStateController().onInsetsModified( |
| 468 | windowState, state); |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 473 | void windowAddedLocked(String packageName) { |
| 474 | mPackageName = packageName; |
Wale Ogunwale | 4958ad2 | 2017-06-22 09:08:14 -0700 | [diff] [blame] | 475 | mRelayoutTag = "relayoutWindow: " + mPackageName; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 476 | if (mSurfaceSession == null) { |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame^] | 477 | if (DEBUG) { |
| 478 | Slog.v(TAG_WM, "First window added to " + this + ", creating SurfaceSession"); |
| 479 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 480 | mSurfaceSession = new SurfaceSession(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 481 | if (SHOW_TRANSACTIONS) Slog.i( |
| 482 | TAG_WM, " NEW SURFACE SESSION " + mSurfaceSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 483 | mService.mSessions.add(this); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 484 | if (mLastReportedAnimatorScale != mService.getCurrentAnimatorScale()) { |
| 485 | mService.dispatchNewAnimatorScaleLocked(this); |
| 486 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 487 | } |
| 488 | mNumWindow++; |
| 489 | } |
| 490 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 491 | void windowRemovedLocked() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 492 | mNumWindow--; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 493 | killSessionLocked(); |
| 494 | } |
| 495 | |
| 496 | |
| 497 | void onWindowSurfaceVisibilityChanged(WindowSurfaceController surfaceController, |
| 498 | boolean visible, int type) { |
| 499 | |
| 500 | if (!isSystemAlertWindowType(type)) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | boolean changed; |
| 505 | |
| 506 | if (!mCanAddInternalSystemWindow) { |
| 507 | // We want to track non-system signature apps adding alert windows so we can post an |
| 508 | // on-going notification for the user to control their visibility. |
| 509 | if (visible) { |
| 510 | changed = mAlertWindowSurfaces.add(surfaceController); |
Chenjie Yu | 08d6d72 | 2018-02-28 10:19:54 -0800 | [diff] [blame] | 511 | MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, true); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 512 | } else { |
| 513 | changed = mAlertWindowSurfaces.remove(surfaceController); |
Chenjie Yu | 08d6d72 | 2018-02-28 10:19:54 -0800 | [diff] [blame] | 514 | MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, true); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | if (changed) { |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 518 | if (mAlertWindowSurfaces.isEmpty()) { |
| 519 | cancelAlertWindowNotification(); |
| 520 | } else if (mAlertWindowNotification == null){ |
Wale Ogunwale | d76881e | 2017-03-10 13:17:56 -0800 | [diff] [blame] | 521 | mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName); |
Wale Ogunwale | a10fc7e | 2017-04-06 07:09:51 -0700 | [diff] [blame] | 522 | if (mShowingAlertWindowNotificationAllowed) { |
| 523 | mAlertWindowNotification.post(); |
| 524 | } |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 525 | } |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 526 | } |
| 527 | } |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 528 | |
| 529 | if (type != TYPE_APPLICATION_OVERLAY) { |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | if (visible) { |
| 534 | changed = mAppOverlaySurfaces.add(surfaceController); |
Chenjie Yu | 08d6d72 | 2018-02-28 10:19:54 -0800 | [diff] [blame] | 535 | MetricsLoggerWrapper.logAppOverlayEnter(mUid, mPackageName, changed, type, false); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 536 | } else { |
| 537 | changed = mAppOverlaySurfaces.remove(surfaceController); |
Chenjie Yu | 08d6d72 | 2018-02-28 10:19:54 -0800 | [diff] [blame] | 538 | MetricsLoggerWrapper.logAppOverlayExit(mUid, mPackageName, changed, type, false); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | if (changed) { |
| 542 | // Notify activity manager of changes to app overlay windows so it can adjust the |
| 543 | // importance score for the process. |
| 544 | setHasOverlayUi(!mAppOverlaySurfaces.isEmpty()); |
| 545 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Wale Ogunwale | a10fc7e | 2017-04-06 07:09:51 -0700 | [diff] [blame] | 548 | void setShowingAlertWindowNotificationAllowed(boolean allowed) { |
| 549 | mShowingAlertWindowNotificationAllowed = allowed; |
| 550 | if (mAlertWindowNotification != null) { |
| 551 | if (allowed) { |
| 552 | mAlertWindowNotification.post(); |
| 553 | } else { |
Wale Ogunwale | 6c8f2e4 | 2018-02-01 09:07:34 -0800 | [diff] [blame] | 554 | mAlertWindowNotification.cancel(false /* deleteChannel */); |
Wale Ogunwale | a10fc7e | 2017-04-06 07:09:51 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 559 | private void killSessionLocked() { |
| 560 | if (mNumWindow > 0 || !mClientDead) { |
| 561 | return; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | } |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 563 | |
| 564 | mService.mSessions.remove(this); |
| 565 | if (mSurfaceSession == null) { |
| 566 | return; |
| 567 | } |
| 568 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame^] | 569 | if (DEBUG) { |
| 570 | Slog.v(TAG_WM, "Last window removed from " + this |
| 571 | + ", destroying " + mSurfaceSession); |
| 572 | } |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 573 | if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " KILL SURFACE SESSION " + mSurfaceSession); |
| 574 | try { |
| 575 | mSurfaceSession.kill(); |
| 576 | } catch (Exception e) { |
| 577 | Slog.w(TAG_WM, "Exception thrown when killing surface session " + mSurfaceSession |
| 578 | + " in session " + this + ": " + e.toString()); |
| 579 | } |
| 580 | mSurfaceSession = null; |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 581 | mAlertWindowSurfaces.clear(); |
| 582 | mAppOverlaySurfaces.clear(); |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 583 | setHasOverlayUi(false); |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 584 | cancelAlertWindowNotification(); |
Wale Ogunwale | d993a57 | 2017-02-05 13:52:09 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | private void setHasOverlayUi(boolean hasOverlayUi) { |
| 588 | 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] | 589 | } |
| 590 | |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 591 | private void cancelAlertWindowNotification() { |
| 592 | if (mAlertWindowNotification == null) { |
| 593 | return; |
| 594 | } |
Wale Ogunwale | 6c8f2e4 | 2018-02-01 09:07:34 -0800 | [diff] [blame] | 595 | mAlertWindowNotification.cancel(true /* deleteChannel */); |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 596 | mAlertWindowNotification = null; |
| 597 | } |
| 598 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 599 | void dump(PrintWriter pw, String prefix) { |
| 600 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
Wale Ogunwale | 5aa8683 | 2017-02-28 10:40:27 -0800 | [diff] [blame] | 601 | pw.print(" mCanAddInternalSystemWindow="); pw.print(mCanAddInternalSystemWindow); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 602 | pw.print(" mAppOverlaySurfaces="); pw.print(mAppOverlaySurfaces); |
| 603 | pw.print(" mAlertWindowSurfaces="); pw.print(mAlertWindowSurfaces); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 604 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 605 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
Wale Ogunwale | 4958ad2 | 2017-06-22 09:08:14 -0700 | [diff] [blame] | 606 | pw.print(prefix); pw.print("mPackageName="); pw.println(mPackageName); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public String toString() { |
| 611 | return mStringName; |
| 612 | } |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 613 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 614 | /** @return {@code true} if there is an alert window surface on the given display. */ |
| 615 | boolean hasAlertWindowSurfaces(DisplayContent displayContent) { |
| 616 | for (int i = mAlertWindowSurfaces.size() - 1; i >= 0; i--) { |
| 617 | final WindowSurfaceController surfaceController = mAlertWindowSurfaces.valueAt(i); |
| 618 | if (surfaceController.mAnimator.mWin.getDisplayContent() == displayContent) { |
| 619 | return true; |
| 620 | } |
| 621 | } |
| 622 | return false; |
Robert Carr | 0e00727 | 2017-10-02 13:00:55 -0700 | [diff] [blame] | 623 | } |
Robert Carr | 9d431e1 | 2018-12-17 13:11:48 -0800 | [diff] [blame] | 624 | |
| 625 | public void blessInputSurface(int displayId, SurfaceControl surface, |
| 626 | InputChannel outInputChannel) { |
| 627 | final int callerUid = Binder.getCallingUid(); |
| 628 | final int callerPid = Binder.getCallingPid(); |
| 629 | final long identity = Binder.clearCallingIdentity(); |
| 630 | try { |
| 631 | mService.blessInputSurface(callerUid, callerPid, displayId, surface, outInputChannel); |
| 632 | } finally { |
| 633 | Binder.restoreCallingIdentity(identity); |
| 634 | } |
| 635 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 636 | } |