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