Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 17 | package com.android.systemui.recents; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 18 | |
Matthew Ng | a3fee34 | 2019-02-25 15:36:37 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY; |
Winson Chung | 7e48691 | 2019-04-30 11:11:47 -0700 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 21 | import static android.view.MotionEvent.ACTION_CANCEL; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 22 | import static android.view.MotionEvent.ACTION_DOWN; |
| 23 | import static android.view.MotionEvent.ACTION_UP; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 24 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 25 | |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 26 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_INPUT_MONITOR; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 27 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SUPPORTS_WINDOW_CORNERS; |
| 28 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY; |
| 29 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_WINDOW_CORNER_RADIUS; |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 30 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING; |
| 31 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING; |
| 32 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 33 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 34 | import android.annotation.FloatRange; |
Winson Chung | 4d30e9e | 2019-04-24 15:13:38 -0700 | [diff] [blame] | 35 | import android.app.ActivityTaskManager; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 37 | import android.content.ComponentName; |
| 38 | import android.content.Context; |
| 39 | import android.content.Intent; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 40 | import android.content.IntentFilter; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 41 | import android.content.ServiceConnection; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 42 | import android.graphics.Rect; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 43 | import android.graphics.Region; |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 44 | import android.hardware.input.InputManager; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 45 | import android.os.Binder; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 46 | import android.os.Bundle; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.IBinder; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 49 | import android.os.Looper; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 50 | import android.os.PatternMatcher; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 51 | import android.os.RemoteException; |
| 52 | import android.os.UserHandle; |
| 53 | import android.util.Log; |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 54 | import android.view.InputMonitor; |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 55 | import android.view.MotionEvent; |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 56 | import android.view.accessibility.AccessibilityManager; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 57 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 58 | import com.android.internal.policy.ScreenDecorationsUtils; |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 59 | import com.android.systemui.Dumpable; |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 60 | import com.android.systemui.SysUiServiceProvider; |
| 61 | import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 62 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 63 | import com.android.systemui.shared.recents.ISystemUiProxy; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 64 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | e108b67 | 2019-03-06 16:11:28 -0800 | [diff] [blame] | 65 | import com.android.systemui.shared.system.QuickStepContract; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 66 | import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags; |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 67 | import com.android.systemui.stackdivider.Divider; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 68 | import com.android.systemui.statusbar.NavigationBarController; |
| 69 | import com.android.systemui.statusbar.phone.NavigationBarFragment; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.phone.NavigationBarView; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.NavigationModeController; |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 72 | import com.android.systemui.statusbar.phone.StatusBar; |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.StatusBarWindowCallback; |
Winson Chung | 7bbeb45 | 2019-06-04 10:25:50 -0700 | [diff] [blame] | 74 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.CallbackController; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 77 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 78 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 79 | import java.io.FileDescriptor; |
| 80 | import java.io.PrintWriter; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 81 | import java.util.ArrayList; |
| 82 | import java.util.List; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 83 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 84 | import javax.inject.Inject; |
| 85 | import javax.inject.Singleton; |
| 86 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Class to send information from overview to launcher with a binder. |
| 89 | */ |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 90 | @Singleton |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 91 | public class OverviewProxyService implements CallbackController<OverviewProxyListener>, |
| 92 | NavigationModeController.ModeChangedListener, Dumpable { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 93 | |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 94 | private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE"; |
| 95 | |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 96 | public static final String TAG_OPS = "OverviewProxyService"; |
Matthew Ng | 9608748 | 2018-06-27 15:32:09 -0700 | [diff] [blame] | 97 | private static final long BACKOFF_MILLIS = 1000; |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 98 | private static final long DEFERRED_CALLBACK_MILLIS = 5000; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 99 | |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 100 | // Max backoff caps at 5 mins |
| 101 | private static final long MAX_BACKOFF_MILLIS = 10 * 60 * 1000; |
| 102 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 103 | private final Context mContext; |
| 104 | private final Handler mHandler; |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 105 | private final NavigationBarController mNavBarController; |
| 106 | private final StatusBarWindowController mStatusBarWinController; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 107 | private final Runnable mConnectionRunnable = this::internalConnectToCurrentUser; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 108 | private final ComponentName mRecentsComponentName; |
Jason Monk | 96a37f4 | 2018-12-21 14:45:26 -0500 | [diff] [blame] | 109 | private final DeviceProvisionedController mDeviceProvisionedController; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 110 | private final List<OverviewProxyListener> mConnectionCallbacks = new ArrayList<>(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 111 | private final Intent mQuickStepIntent; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 112 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 113 | private Region mActiveNavBarRegion; |
| 114 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 115 | private IOverviewProxy mOverviewProxy; |
| 116 | private int mConnectionBackoffAttempts; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 117 | private @SystemUiStateFlags int mSysUiStateFlags; |
Winson Chung | 67f2028 | 2019-03-12 23:53:24 -0700 | [diff] [blame] | 118 | private boolean mBound; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 119 | private boolean mIsEnabled; |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 120 | private int mCurrentBoundedUserId = -1; |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 121 | private float mNavBarButtonAlpha; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 122 | private MotionEvent mStatusBarGestureDownEvent; |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 123 | private float mWindowCornerRadius; |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 124 | private boolean mSupportsRoundedCornersOnWindows; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 125 | private int mNavBarMode = NAV_BAR_MODE_3BUTTON; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 126 | |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 127 | private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() { |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 128 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 129 | @Override |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 130 | public void startScreenPinning(int taskId) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 131 | if (!verifyCaller("startScreenPinning")) { |
| 132 | return; |
| 133 | } |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 134 | long token = Binder.clearCallingIdentity(); |
| 135 | try { |
| 136 | mHandler.post(() -> { |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 137 | StatusBar statusBar = SysUiServiceProvider.getComponent(mContext, |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 138 | StatusBar.class); |
| 139 | if (statusBar != null) { |
| 140 | statusBar.showScreenPinningRequest(taskId, false /* allowCancel */); |
| 141 | } |
| 142 | }); |
| 143 | } finally { |
| 144 | Binder.restoreCallingIdentity(token); |
| 145 | } |
| 146 | } |
| 147 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 148 | @Override |
Winson Chung | 4d30e9e | 2019-04-24 15:13:38 -0700 | [diff] [blame] | 149 | public void stopScreenPinning() { |
| 150 | if (!verifyCaller("stopScreenPinning")) { |
| 151 | return; |
| 152 | } |
| 153 | long token = Binder.clearCallingIdentity(); |
| 154 | try { |
| 155 | mHandler.post(() -> { |
| 156 | try { |
| 157 | ActivityTaskManager.getService().stopSystemLockTaskMode(); |
| 158 | } catch (RemoteException e) { |
| 159 | Log.e(TAG_OPS, "Failed to stop screen pinning"); |
| 160 | } |
| 161 | }); |
| 162 | } finally { |
| 163 | Binder.restoreCallingIdentity(token); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | @Override |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 168 | public void onStatusBarMotionEvent(MotionEvent event) { |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 169 | if (!verifyCaller("onStatusBarMotionEvent")) { |
| 170 | return; |
| 171 | } |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 172 | long token = Binder.clearCallingIdentity(); |
| 173 | try { |
| 174 | // TODO move this logic to message queue |
| 175 | mHandler.post(()->{ |
| 176 | StatusBar bar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); |
| 177 | if (bar != null) { |
| 178 | bar.dispatchNotificationsPanelTouchEvent(event); |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 179 | |
| 180 | int action = event.getActionMasked(); |
| 181 | if (action == ACTION_DOWN) { |
| 182 | mStatusBarGestureDownEvent = MotionEvent.obtain(event); |
| 183 | } |
| 184 | if (action == ACTION_UP || action == ACTION_CANCEL) { |
| 185 | mStatusBarGestureDownEvent.recycle(); |
| 186 | mStatusBarGestureDownEvent = null; |
| 187 | } |
| 188 | event.recycle(); |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 189 | } |
| 190 | }); |
| 191 | } finally { |
| 192 | Binder.restoreCallingIdentity(token); |
| 193 | } |
| 194 | } |
| 195 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 196 | @Override |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 197 | public void onSplitScreenInvoked() { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 198 | if (!verifyCaller("onSplitScreenInvoked")) { |
| 199 | return; |
| 200 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 201 | long token = Binder.clearCallingIdentity(); |
| 202 | try { |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 203 | Divider divider = SysUiServiceProvider.getComponent(mContext, Divider.class); |
| 204 | if (divider != null) { |
| 205 | divider.onDockedFirstAnimationFrame(); |
| 206 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 207 | } finally { |
| 208 | Binder.restoreCallingIdentity(token); |
| 209 | } |
| 210 | } |
| 211 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 212 | @Override |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 213 | public void onOverviewShown(boolean fromHome) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 214 | if (!verifyCaller("onOverviewShown")) { |
| 215 | return; |
| 216 | } |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 217 | long token = Binder.clearCallingIdentity(); |
| 218 | try { |
| 219 | mHandler.post(() -> { |
| 220 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 221 | mConnectionCallbacks.get(i).onOverviewShown(fromHome); |
| 222 | } |
| 223 | }); |
| 224 | } finally { |
| 225 | Binder.restoreCallingIdentity(token); |
| 226 | } |
| 227 | } |
| 228 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 229 | @Override |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 230 | public Rect getNonMinimizedSplitScreenSecondaryBounds() { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 231 | if (!verifyCaller("getNonMinimizedSplitScreenSecondaryBounds")) { |
| 232 | return null; |
| 233 | } |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 234 | long token = Binder.clearCallingIdentity(); |
| 235 | try { |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 236 | Divider divider = SysUiServiceProvider.getComponent(mContext, Divider.class); |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 237 | if (divider != null) { |
| 238 | return divider.getView().getNonMinimizedSplitScreenSecondaryBounds(); |
| 239 | } |
| 240 | return null; |
| 241 | } finally { |
| 242 | Binder.restoreCallingIdentity(token); |
| 243 | } |
| 244 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 245 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 246 | @Override |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 247 | public void setNavBarButtonAlpha(float alpha, boolean animate) { |
| 248 | if (!verifyCaller("setNavBarButtonAlpha")) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 249 | return; |
| 250 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 251 | long token = Binder.clearCallingIdentity(); |
| 252 | try { |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 253 | mNavBarButtonAlpha = alpha; |
| 254 | mHandler.post(() -> notifyNavBarButtonAlphaChanged(alpha, animate)); |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 255 | } finally { |
| 256 | Binder.restoreCallingIdentity(token); |
| 257 | } |
| 258 | } |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 259 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 260 | @Override |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 261 | public void setBackButtonAlpha(float alpha, boolean animate) { |
| 262 | setNavBarButtonAlpha(alpha, animate); |
| 263 | } |
| 264 | |
| 265 | @Override |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 266 | public void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) { |
| 267 | if (!verifyCaller("onAssistantProgress")) { |
| 268 | return; |
| 269 | } |
| 270 | long token = Binder.clearCallingIdentity(); |
| 271 | try { |
| 272 | mHandler.post(() -> notifyAssistantProgress(progress)); |
| 273 | } finally { |
| 274 | Binder.restoreCallingIdentity(token); |
| 275 | } |
| 276 | } |
| 277 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 278 | @Override |
Miranda Kephart | 4be2690 | 2019-05-17 13:55:37 -0400 | [diff] [blame] | 279 | public void onAssistantGestureCompletion(float velocity) { |
| 280 | if (!verifyCaller("onAssistantGestureCompletion")) { |
| 281 | return; |
| 282 | } |
| 283 | long token = Binder.clearCallingIdentity(); |
| 284 | try { |
| 285 | mHandler.post(() -> notifyAssistantGestureCompletion(velocity)); |
| 286 | } finally { |
| 287 | Binder.restoreCallingIdentity(token); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | @Override |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 292 | public void startAssistant(Bundle bundle) { |
| 293 | if (!verifyCaller("startAssistant")) { |
| 294 | return; |
| 295 | } |
| 296 | long token = Binder.clearCallingIdentity(); |
| 297 | try { |
| 298 | mHandler.post(() -> notifyStartAssistant(bundle)); |
| 299 | } finally { |
| 300 | Binder.restoreCallingIdentity(token); |
| 301 | } |
| 302 | } |
| 303 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 304 | @Override |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 305 | public Bundle monitorGestureInput(String name, int displayId) { |
| 306 | if (!verifyCaller("monitorGestureInput")) { |
| 307 | return null; |
| 308 | } |
| 309 | long token = Binder.clearCallingIdentity(); |
| 310 | try { |
| 311 | InputMonitor monitor = |
| 312 | InputManager.getInstance().monitorGestureInput(name, displayId); |
| 313 | Bundle result = new Bundle(); |
| 314 | result.putParcelable(KEY_EXTRA_INPUT_MONITOR, monitor); |
| 315 | return result; |
| 316 | } finally { |
| 317 | Binder.restoreCallingIdentity(token); |
| 318 | } |
| 319 | } |
| 320 | |
Sunny Goyal | 247eb89 | 2019-04-24 11:36:37 -0700 | [diff] [blame] | 321 | @Override |
| 322 | public void notifyAccessibilityButtonClicked(int displayId) { |
| 323 | if (!verifyCaller("notifyAccessibilityButtonClicked")) { |
| 324 | return; |
| 325 | } |
| 326 | long token = Binder.clearCallingIdentity(); |
| 327 | try { |
| 328 | AccessibilityManager.getInstance(mContext) |
| 329 | .notifyAccessibilityButtonClicked(displayId); |
| 330 | } finally { |
| 331 | Binder.restoreCallingIdentity(token); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void notifyAccessibilityButtonLongClicked() { |
| 337 | if (!verifyCaller("notifyAccessibilityButtonLongClicked")) { |
| 338 | return; |
| 339 | } |
| 340 | long token = Binder.clearCallingIdentity(); |
| 341 | try { |
| 342 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 343 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 344 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 345 | } finally { |
| 346 | Binder.restoreCallingIdentity(token); |
| 347 | } |
| 348 | } |
| 349 | |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 350 | private boolean verifyCaller(String reason) { |
| 351 | final int callerId = Binder.getCallingUserHandle().getIdentifier(); |
| 352 | if (callerId != mCurrentBoundedUserId) { |
| 353 | Log.w(TAG_OPS, "Launcher called sysui with invalid user: " + callerId + ", reason: " |
| 354 | + reason); |
| 355 | return false; |
| 356 | } |
| 357 | return true; |
| 358 | } |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 359 | }; |
| 360 | |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 361 | private final Runnable mDeferredConnectionCallback = () -> { |
| 362 | Log.w(TAG_OPS, "Binder supposed established connection but actual connection to service " |
| 363 | + "timed out, trying again"); |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 364 | retryConnectionWithBackoff(); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 365 | }; |
| 366 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 367 | private final BroadcastReceiver mLauncherStateChangedReceiver = new BroadcastReceiver() { |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 368 | @Override |
| 369 | public void onReceive(Context context, Intent intent) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 370 | updateEnabledState(); |
| 371 | |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 372 | // Reconnect immediately, instead of waiting for resume to arrive. |
| 373 | startConnectionToCurrentUser(); |
| 374 | } |
| 375 | }; |
| 376 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 377 | private final ServiceConnection mOverviewServiceConnection = new ServiceConnection() { |
| 378 | @Override |
| 379 | public void onServiceConnected(ComponentName name, IBinder service) { |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 380 | mConnectionBackoffAttempts = 0; |
Winson Chung | 7378d28 | 2019-04-19 13:56:44 -0700 | [diff] [blame] | 381 | mHandler.removeCallbacks(mDeferredConnectionCallback); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 382 | try { |
| 383 | service.linkToDeath(mOverviewServiceDeathRcpt, 0); |
| 384 | } catch (RemoteException e) { |
Winson Chung | 7378d28 | 2019-04-19 13:56:44 -0700 | [diff] [blame] | 385 | // Failed to link to death (process may have died between binding and connecting), |
| 386 | // just unbind the service for now and retry again |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 387 | Log.e(TAG_OPS, "Lost connection to launcher service", e); |
Winson Chung | 7378d28 | 2019-04-19 13:56:44 -0700 | [diff] [blame] | 388 | disconnectFromLauncherService(); |
| 389 | retryConnectionWithBackoff(); |
| 390 | return; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 391 | } |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 392 | |
Winson Chung | 7378d28 | 2019-04-19 13:56:44 -0700 | [diff] [blame] | 393 | mCurrentBoundedUserId = mDeviceProvisionedController.getCurrentUser(); |
| 394 | mOverviewProxy = IOverviewProxy.Stub.asInterface(service); |
| 395 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 396 | Bundle params = new Bundle(); |
| 397 | params.putBinder(KEY_EXTRA_SYSUI_PROXY, mSysUiProxy.asBinder()); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 398 | params.putFloat(KEY_EXTRA_WINDOW_CORNER_RADIUS, mWindowCornerRadius); |
| 399 | params.putBoolean(KEY_EXTRA_SUPPORTS_WINDOW_CORNERS, mSupportsRoundedCornersOnWindows); |
| 400 | try { |
| 401 | mOverviewProxy.onInitialize(params); |
| 402 | } catch (RemoteException e) { |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 403 | mCurrentBoundedUserId = -1; |
| 404 | Log.e(TAG_OPS, "Failed to call onInitialize()", e); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 405 | } |
| 406 | dispatchNavButtonBounds(); |
| 407 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 408 | // Update the systemui state flags |
| 409 | updateSystemUiStateFlags(); |
| 410 | |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 411 | notifyConnectionChanged(); |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void onNullBinding(ComponentName name) { |
| 416 | Log.w(TAG_OPS, "Null binding of '" + name + "', try reconnecting"); |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 417 | mCurrentBoundedUserId = -1; |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 418 | retryConnectionWithBackoff(); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public void onBindingDied(ComponentName name) { |
| 423 | Log.w(TAG_OPS, "Binding died of '" + name + "', try reconnecting"); |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 424 | mCurrentBoundedUserId = -1; |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 425 | retryConnectionWithBackoff(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void onServiceDisconnected(ComponentName name) { |
| 430 | // Do nothing |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 431 | mCurrentBoundedUserId = -1; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 432 | } |
| 433 | }; |
| 434 | |
| 435 | private final DeviceProvisionedListener mDeviceProvisionedCallback = |
| 436 | new DeviceProvisionedListener() { |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 437 | @Override |
| 438 | public void onUserSetupChanged() { |
| 439 | if (mDeviceProvisionedController.isCurrentUserSetup()) { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 440 | internalConnectToCurrentUser(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 441 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Override |
| 445 | public void onUserSwitched() { |
| 446 | mConnectionBackoffAttempts = 0; |
| 447 | internalConnectToCurrentUser(); |
| 448 | } |
| 449 | }; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 450 | |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 451 | private final StatusBarWindowCallback mStatusBarWindowCallback = this::onStatusBarStateChanged; |
| 452 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 453 | // This is the death handler for the binder from the launcher service |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 454 | private final IBinder.DeathRecipient mOverviewServiceDeathRcpt |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 455 | = this::cleanupAfterDeath; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 456 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 457 | @Inject |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 458 | public OverviewProxyService(Context context, DeviceProvisionedController provisionController, |
| 459 | NavigationBarController navBarController, NavigationModeController navModeController, |
| 460 | StatusBarWindowController statusBarWinController) { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 461 | mContext = context; |
| 462 | mHandler = new Handler(); |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 463 | mNavBarController = navBarController; |
| 464 | mStatusBarWinController = statusBarWinController; |
Jason Monk | 96a37f4 | 2018-12-21 14:45:26 -0500 | [diff] [blame] | 465 | mDeviceProvisionedController = provisionController; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 466 | mConnectionBackoffAttempts = 0; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 467 | mRecentsComponentName = ComponentName.unflattenFromString(context.getString( |
| 468 | com.android.internal.R.string.config_recentsComponentName)); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 469 | mQuickStepIntent = new Intent(ACTION_QUICKSTEP) |
| 470 | .setPackage(mRecentsComponentName.getPackageName()); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 471 | mWindowCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(mContext.getResources()); |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 472 | mSupportsRoundedCornersOnWindows = ScreenDecorationsUtils |
| 473 | .supportsRoundedCornersOnWindows(mContext.getResources()); |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 474 | |
Matthew Ng | 33b5e98 | 2019-03-27 17:15:10 -0700 | [diff] [blame] | 475 | // Assumes device always starts with back button until launcher tells it that it does not |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 476 | mNavBarButtonAlpha = 1.0f; |
Matthew Ng | 33b5e98 | 2019-03-27 17:15:10 -0700 | [diff] [blame] | 477 | |
Winson Chung | 1bb7455 | 2019-05-15 16:09:22 -0700 | [diff] [blame] | 478 | // Listen for nav bar mode changes |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 479 | mNavBarMode = navModeController.addListener(this); |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 480 | |
Winson Chung | 1bb7455 | 2019-05-15 16:09:22 -0700 | [diff] [blame] | 481 | // Listen for device provisioned/user setup |
| 482 | updateEnabledState(); |
| 483 | mDeviceProvisionedController.addCallback(mDeviceProvisionedCallback); |
| 484 | |
| 485 | // Listen for launcher package changes |
| 486 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 487 | filter.addDataScheme("package"); |
| 488 | filter.addDataSchemeSpecificPart(mRecentsComponentName.getPackageName(), |
| 489 | PatternMatcher.PATTERN_LITERAL); |
| 490 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 491 | mContext.registerReceiver(mLauncherStateChangedReceiver, filter); |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 492 | |
| 493 | // Listen for status bar state changes |
| 494 | statusBarWinController.registerCallback(mStatusBarWindowCallback); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Winson Chung | 04ff8bda | 2019-04-02 15:08:59 -0700 | [diff] [blame] | 497 | public void notifyBackAction(boolean completed, int downX, int downY, boolean isButton, |
| 498 | boolean gestureSwipeLeft) { |
| 499 | try { |
| 500 | if (mOverviewProxy != null) { |
| 501 | mOverviewProxy.onBackAction(completed, downX, downY, isButton, gestureSwipeLeft); |
| 502 | } |
| 503 | } catch (RemoteException e) { |
| 504 | Log.e(TAG_OPS, "Failed to notify back action", e); |
| 505 | } |
| 506 | } |
| 507 | |
Winson Chung | 7e48691 | 2019-04-30 11:11:47 -0700 | [diff] [blame] | 508 | public void setSystemUiStateFlag(int flag, boolean enabled, int displayId) { |
| 509 | if (displayId != DEFAULT_DISPLAY) { |
| 510 | // Ignore non-default displays for now |
| 511 | return; |
| 512 | } |
| 513 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 514 | int newState = mSysUiStateFlags; |
| 515 | if (enabled) { |
| 516 | newState |= flag; |
| 517 | } else { |
| 518 | newState &= ~flag; |
| 519 | } |
| 520 | if (mSysUiStateFlags != newState) { |
| 521 | mSysUiStateFlags = newState; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 522 | notifySystemUiStateChanged(mSysUiStateFlags); |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 523 | notifySystemUiStateFlags(mSysUiStateFlags); |
| 524 | } |
| 525 | } |
| 526 | |
Winson Chung | e2a686d | 2019-04-17 16:54:23 -0700 | [diff] [blame] | 527 | public int getSystemUiStateFlags() { |
| 528 | return mSysUiStateFlags; |
| 529 | } |
| 530 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 531 | private void updateSystemUiStateFlags() { |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 532 | final NavigationBarFragment navBarFragment = |
| 533 | mNavBarController.getDefaultNavigationBarFragment(); |
| 534 | final NavigationBarView navBarView = |
| 535 | mNavBarController.getNavigationBarView(mContext.getDisplayId()); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 536 | |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 537 | mSysUiStateFlags = 0; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 538 | if (navBarFragment != null) { |
| 539 | navBarFragment.updateSystemUiStateFlags(-1); |
| 540 | } |
| 541 | if (navBarView != null) { |
| 542 | navBarView.updateSystemUiStateFlags(); |
| 543 | } |
Winson Chung | 9e57249 | 2019-06-07 10:48:45 -0700 | [diff] [blame] | 544 | if (mStatusBarWinController != null) { |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 545 | mStatusBarWinController.notifyStateChangedCallbacks(); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 546 | } |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 547 | notifySystemUiStateFlags(mSysUiStateFlags); |
| 548 | } |
| 549 | |
| 550 | private void notifySystemUiStateFlags(int flags) { |
| 551 | try { |
| 552 | if (mOverviewProxy != null) { |
| 553 | mOverviewProxy.onSystemUiStateChanged(flags); |
| 554 | } |
| 555 | } catch (RemoteException e) { |
| 556 | Log.e(TAG_OPS, "Failed to notify sysui state change", e); |
| 557 | } |
| 558 | } |
| 559 | |
Winson Chung | 6088793 | 2019-06-13 22:37:31 -0700 | [diff] [blame] | 560 | private void onStatusBarStateChanged(boolean keyguardShowing, boolean keyguardOccluded, |
| 561 | boolean bouncerShowing) { |
| 562 | int displayId = mContext.getDisplayId(); |
| 563 | setSystemUiStateFlag(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING, |
| 564 | keyguardShowing && !keyguardOccluded, displayId); |
| 565 | setSystemUiStateFlag(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED, |
| 566 | keyguardShowing && keyguardOccluded, displayId); |
| 567 | setSystemUiStateFlag(SYSUI_STATE_BOUNCER_SHOWING, bouncerShowing, displayId); |
| 568 | } |
| 569 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 570 | /** |
| 571 | * Sets the navbar region which can receive touch inputs |
| 572 | */ |
| 573 | public void onActiveNavBarRegionChanges(Region activeRegion) { |
| 574 | mActiveNavBarRegion = activeRegion; |
| 575 | dispatchNavButtonBounds(); |
| 576 | } |
| 577 | |
| 578 | private void dispatchNavButtonBounds() { |
| 579 | if (mOverviewProxy != null && mActiveNavBarRegion != null) { |
| 580 | try { |
| 581 | mOverviewProxy.onActiveNavBarRegionChanges(mActiveNavBarRegion); |
| 582 | } catch (RemoteException e) { |
| 583 | Log.e(TAG_OPS, "Failed to call onActiveNavBarRegionChanges()", e); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 588 | public float getBackButtonAlpha() { |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 589 | return mNavBarButtonAlpha; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 592 | public void cleanupAfterDeath() { |
| 593 | if (mStatusBarGestureDownEvent != null) { |
| 594 | mHandler.post(()-> { |
| 595 | StatusBar bar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); |
| 596 | if (bar != null) { |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 597 | mStatusBarGestureDownEvent.setAction(MotionEvent.ACTION_CANCEL); |
| 598 | bar.dispatchNotificationsPanelTouchEvent(mStatusBarGestureDownEvent); |
| 599 | mStatusBarGestureDownEvent.recycle(); |
| 600 | mStatusBarGestureDownEvent = null; |
| 601 | } |
| 602 | }); |
| 603 | } |
| 604 | startConnectionToCurrentUser(); |
| 605 | } |
| 606 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 607 | public void startConnectionToCurrentUser() { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 608 | if (mHandler.getLooper() != Looper.myLooper()) { |
| 609 | mHandler.post(mConnectionRunnable); |
| 610 | } else { |
| 611 | internalConnectToCurrentUser(); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | private void internalConnectToCurrentUser() { |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 616 | disconnectFromLauncherService(); |
| 617 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 618 | // If user has not setup yet or already connected, do not try to connect |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 619 | if (!mDeviceProvisionedController.isCurrentUserSetup() || !isEnabled()) { |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 620 | Log.v(TAG_OPS, "Cannot attempt connection, is setup " |
| 621 | + mDeviceProvisionedController.isCurrentUserSetup() + ", is enabled " |
| 622 | + isEnabled()); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 623 | return; |
| 624 | } |
| 625 | mHandler.removeCallbacks(mConnectionRunnable); |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 626 | Intent launcherServiceIntent = new Intent(ACTION_QUICKSTEP) |
| 627 | .setPackage(mRecentsComponentName.getPackageName()); |
Matthew Ng | 10b6c41a | 2018-03-26 18:01:37 -0700 | [diff] [blame] | 628 | try { |
Winson Chung | 67f2028 | 2019-03-12 23:53:24 -0700 | [diff] [blame] | 629 | mBound = mContext.bindServiceAsUser(launcherServiceIntent, |
Winson Chung | e7cb0c1 | 2018-07-30 16:11:38 -0700 | [diff] [blame] | 630 | mOverviewServiceConnection, |
| 631 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
Matthew Ng | 10b6c41a | 2018-03-26 18:01:37 -0700 | [diff] [blame] | 632 | UserHandle.of(mDeviceProvisionedController.getCurrentUser())); |
| 633 | } catch (SecurityException e) { |
| 634 | Log.e(TAG_OPS, "Unable to bind because of security error", e); |
| 635 | } |
Winson Chung | 67f2028 | 2019-03-12 23:53:24 -0700 | [diff] [blame] | 636 | if (mBound) { |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 637 | // Ensure that connection has been established even if it thinks it is bound |
| 638 | mHandler.postDelayed(mDeferredConnectionCallback, DEFERRED_CALLBACK_MILLIS); |
| 639 | } else { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 640 | // Retry after exponential backoff timeout |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 641 | retryConnectionWithBackoff(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 645 | private void retryConnectionWithBackoff() { |
| 646 | if (mHandler.hasCallbacks(mConnectionRunnable)) { |
| 647 | return; |
| 648 | } |
| 649 | final long timeoutMs = (long) Math.min( |
| 650 | Math.scalb(BACKOFF_MILLIS, mConnectionBackoffAttempts), MAX_BACKOFF_MILLIS); |
| 651 | mHandler.postDelayed(mConnectionRunnable, timeoutMs); |
| 652 | mConnectionBackoffAttempts++; |
| 653 | Log.w(TAG_OPS, "Failed to connect on attempt " + mConnectionBackoffAttempts |
| 654 | + " will try again in " + timeoutMs + "ms"); |
| 655 | } |
| 656 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 657 | @Override |
| 658 | public void addCallback(OverviewProxyListener listener) { |
| 659 | mConnectionCallbacks.add(listener); |
| 660 | listener.onConnectionChanged(mOverviewProxy != null); |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 661 | listener.onNavBarButtonAlphaChanged(mNavBarButtonAlpha, false); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 662 | listener.onSystemUiStateChanged(mSysUiStateFlags); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public void removeCallback(OverviewProxyListener listener) { |
| 667 | mConnectionCallbacks.remove(listener); |
| 668 | } |
| 669 | |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 670 | public boolean shouldShowSwipeUpUI() { |
Matthew Ng | b2f89d3 | 2019-04-24 11:40:12 -0700 | [diff] [blame] | 671 | return isEnabled() && !QuickStepContract.isLegacyMode(mNavBarMode); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | public boolean isEnabled() { |
| 675 | return mIsEnabled; |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 678 | public IOverviewProxy getProxy() { |
| 679 | return mOverviewProxy; |
| 680 | } |
| 681 | |
| 682 | private void disconnectFromLauncherService() { |
Winson Chung | 67f2028 | 2019-03-12 23:53:24 -0700 | [diff] [blame] | 683 | if (mBound) { |
| 684 | // Always unbind the service (ie. if called through onNullBinding or onBindingDied) |
| 685 | mContext.unbindService(mOverviewServiceConnection); |
| 686 | mBound = false; |
| 687 | } |
| 688 | |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 689 | if (mOverviewProxy != null) { |
Matthew Ng | eb6893b | 2017-11-09 17:15:33 -0800 | [diff] [blame] | 690 | mOverviewProxy.asBinder().unlinkToDeath(mOverviewServiceDeathRcpt, 0); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 691 | mOverviewProxy = null; |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 692 | notifyNavBarButtonAlphaChanged(1f, false /* animate */); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 693 | notifyConnectionChanged(); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 694 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 695 | } |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 696 | |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 697 | private void notifyNavBarButtonAlphaChanged(float alpha, boolean animate) { |
Matthew Ng | 5389645 | 2018-05-30 11:27:39 -0700 | [diff] [blame] | 698 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 699 | mConnectionCallbacks.get(i).onNavBarButtonAlphaChanged(alpha, animate); |
Matthew Ng | 5389645 | 2018-05-30 11:27:39 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 703 | private void notifyConnectionChanged() { |
| 704 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 705 | mConnectionCallbacks.get(i).onConnectionChanged(mOverviewProxy != null); |
| 706 | } |
| 707 | } |
| 708 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 709 | public void notifyQuickStepStarted() { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 710 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 711 | mConnectionCallbacks.get(i).onQuickStepStarted(); |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 715 | public void notifyQuickScrubStarted() { |
| 716 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 717 | mConnectionCallbacks.get(i).onQuickScrubStarted(); |
| 718 | } |
| 719 | } |
| 720 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 721 | private void notifyAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) { |
| 722 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 723 | mConnectionCallbacks.get(i).onAssistantProgress(progress); |
| 724 | } |
| 725 | } |
| 726 | |
Miranda Kephart | 4be2690 | 2019-05-17 13:55:37 -0400 | [diff] [blame] | 727 | private void notifyAssistantGestureCompletion(float velocity) { |
| 728 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 729 | mConnectionCallbacks.get(i).onAssistantGestureCompletion(velocity); |
| 730 | } |
| 731 | } |
| 732 | |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 733 | private void notifySystemUiStateChanged(int sysuiStateFlags) { |
| 734 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 735 | mConnectionCallbacks.get(i).onSystemUiStateChanged(sysuiStateFlags); |
| 736 | } |
| 737 | } |
| 738 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 739 | private void notifyStartAssistant(Bundle bundle) { |
| 740 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 741 | mConnectionCallbacks.get(i).startAssistant(bundle); |
| 742 | } |
| 743 | } |
| 744 | |
Govinda Wasserman | c4c70f3 | 2019-03-28 11:18:14 -0400 | [diff] [blame] | 745 | public void notifyAssistantVisibilityChanged(float visibility) { |
| 746 | try { |
Winson Chung | 0620c3b | 2019-04-10 09:47:13 -0700 | [diff] [blame] | 747 | if (mOverviewProxy != null) { |
| 748 | mOverviewProxy.onAssistantVisibilityChanged(visibility); |
| 749 | } |
Govinda Wasserman | c4c70f3 | 2019-03-28 11:18:14 -0400 | [diff] [blame] | 750 | } catch (RemoteException e) { |
| 751 | Log.e(TAG_OPS, "Failed to call onAssistantVisibilityChanged()", e); |
| 752 | } |
| 753 | } |
| 754 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 755 | private void updateEnabledState() { |
Winson Chung | 6e4b0b56 | 2018-04-04 09:13:37 -0700 | [diff] [blame] | 756 | mIsEnabled = mContext.getPackageManager().resolveServiceAsUser(mQuickStepIntent, |
Matthew Ng | a3fee34 | 2019-02-25 15:36:37 -0800 | [diff] [blame] | 757 | MATCH_SYSTEM_ONLY, |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 758 | ActivityManagerWrapper.getInstance().getCurrentUserId()) != null; |
| 759 | } |
| 760 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 761 | @Override |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 762 | public void onNavigationModeChanged(int mode) { |
| 763 | mNavBarMode = mode; |
| 764 | } |
| 765 | |
| 766 | @Override |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 767 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 768 | pw.println(TAG_OPS + " state:"); |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 769 | pw.print(" recentsComponentName="); pw.println(mRecentsComponentName); |
| 770 | pw.print(" isConnected="); pw.println(mOverviewProxy != null); |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 771 | pw.print(" isCurrentUserSetup="); pw.println(mDeviceProvisionedController |
| 772 | .isCurrentUserSetup()); |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 773 | pw.print(" connectionBackoffAttempts="); pw.println(mConnectionBackoffAttempts); |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 774 | |
| 775 | pw.print(" quickStepIntent="); pw.println(mQuickStepIntent); |
| 776 | pw.print(" quickStepIntentResolved="); pw.println(isEnabled()); |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 777 | pw.print(" mSysUiStateFlags="); pw.println(mSysUiStateFlags); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 778 | pw.println(" " + QuickStepContract.getSystemUiStateString(mSysUiStateFlags)); |
| 779 | pw.print(" backGestureDisabled="); |
| 780 | pw.println(QuickStepContract.isBackGestureDisabled(mSysUiStateFlags)); |
| 781 | pw.print(" assistantGestureDisabled="); |
| 782 | pw.println(QuickStepContract.isAssistantGestureDisabled(mSysUiStateFlags)); |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 785 | public interface OverviewProxyListener { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 786 | default void onConnectionChanged(boolean isConnected) {} |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 787 | default void onQuickStepStarted() {} |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 788 | default void onOverviewShown(boolean fromHome) {} |
| 789 | default void onQuickScrubStarted() {} |
Sunny Goyal | c73ce70 | 2019-06-16 13:50:07 -0700 | [diff] [blame] | 790 | /** Notify changes in the nav bar button alpha */ |
| 791 | default void onNavBarButtonAlphaChanged(float alpha, boolean animate) {} |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 792 | default void onSystemUiStateChanged(int sysuiStateFlags) {} |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 793 | default void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {} |
Miranda Kephart | 4be2690 | 2019-05-17 13:55:37 -0400 | [diff] [blame] | 794 | default void onAssistantGestureCompletion(float velocity) {} |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 795 | default void startAssistant(Bundle bundle) {} |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 796 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 797 | } |