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; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 20 | import static android.view.MotionEvent.ACTION_CANCEL; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 21 | import static android.view.MotionEvent.ACTION_DOWN; |
| 22 | import static android.view.MotionEvent.ACTION_UP; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 23 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 24 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP; |
| 25 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON; |
| 26 | import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 27 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_INPUT_CHANNEL; |
| 28 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SUPPORTS_WINDOW_CORNERS; |
| 29 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY; |
| 30 | import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_WINDOW_CORNER_RADIUS; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 31 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 32 | import android.annotation.FloatRange; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 33 | import android.content.BroadcastReceiver; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
| 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 37 | import android.content.IntentFilter; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 38 | import android.content.ServiceConnection; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 39 | import android.graphics.Rect; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 40 | import android.graphics.Region; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 41 | import android.os.Binder; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 42 | import android.os.Bundle; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 43 | import android.os.Handler; |
| 44 | import android.os.IBinder; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 45 | import android.os.Looper; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 46 | import android.os.PatternMatcher; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 47 | import android.os.RemoteException; |
| 48 | import android.os.UserHandle; |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 49 | import android.provider.Settings; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 50 | import android.util.Log; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 51 | import android.view.InputChannel; |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 52 | import android.view.MotionEvent; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 53 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 54 | import com.android.internal.policy.ScreenDecorationsUtils; |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 55 | import com.android.systemui.Dumpable; |
| 56 | import com.android.systemui.Prefs; |
| 57 | import com.android.systemui.SysUiServiceProvider; |
| 58 | import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 59 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 60 | import com.android.systemui.shared.recents.ISystemUiProxy; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 61 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 62 | import com.android.systemui.shared.system.InputChannelCompat.InputEventDispatcher; |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 63 | import com.android.systemui.stackdivider.Divider; |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 64 | import com.android.systemui.statusbar.phone.StatusBar; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 65 | import com.android.systemui.statusbar.policy.CallbackController; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 66 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 67 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 68 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 69 | import java.io.FileDescriptor; |
| 70 | import java.io.PrintWriter; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 71 | import java.util.ArrayList; |
| 72 | import java.util.List; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 73 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 74 | import javax.inject.Inject; |
| 75 | import javax.inject.Singleton; |
| 76 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Class to send information from overview to launcher with a binder. |
| 79 | */ |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 80 | @Singleton |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 81 | public class OverviewProxyService implements CallbackController<OverviewProxyListener>, Dumpable { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 82 | |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 83 | private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE"; |
| 84 | |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 85 | public static final String TAG_OPS = "OverviewProxyService"; |
| 86 | public static final boolean DEBUG_OVERVIEW_PROXY = false; |
Matthew Ng | 9608748 | 2018-06-27 15:32:09 -0700 | [diff] [blame] | 87 | private static final long BACKOFF_MILLIS = 1000; |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 88 | private static final long DEFERRED_CALLBACK_MILLIS = 5000; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 89 | |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 90 | // Max backoff caps at 5 mins |
| 91 | private static final long MAX_BACKOFF_MILLIS = 10 * 60 * 1000; |
| 92 | |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 93 | // Default interaction flags if swipe up is disabled before connecting to launcher |
| 94 | private static final int DEFAULT_DISABLE_SWIPE_UP_STATE = FLAG_DISABLE_SWIPE_UP |
| 95 | | FLAG_SHOW_OVERVIEW_BUTTON; |
| 96 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 97 | private final Context mContext; |
| 98 | private final Handler mHandler; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 99 | private final Runnable mConnectionRunnable = this::internalConnectToCurrentUser; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 100 | private final ComponentName mRecentsComponentName; |
Jason Monk | 96a37f4 | 2018-12-21 14:45:26 -0500 | [diff] [blame] | 101 | private final DeviceProvisionedController mDeviceProvisionedController; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 102 | private final List<OverviewProxyListener> mConnectionCallbacks = new ArrayList<>(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 103 | private final Intent mQuickStepIntent; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 104 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 105 | private Region mActiveNavBarRegion; |
| 106 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 107 | private IOverviewProxy mOverviewProxy; |
| 108 | private int mConnectionBackoffAttempts; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 109 | private @InteractionType int mInteractionFlags; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 110 | private boolean mIsEnabled; |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 111 | private int mCurrentBoundedUserId = -1; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 112 | private float mBackButtonAlpha; |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 113 | private MotionEvent mStatusBarGestureDownEvent; |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 114 | private float mWindowCornerRadius; |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 115 | private boolean mSupportsRoundedCornersOnWindows; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 116 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 117 | private InputEventDispatcher mInputEventDispatcher; |
| 118 | |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 119 | private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() { |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 120 | |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 121 | public void startScreenPinning(int taskId) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 122 | if (!verifyCaller("startScreenPinning")) { |
| 123 | return; |
| 124 | } |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 125 | long token = Binder.clearCallingIdentity(); |
| 126 | try { |
| 127 | mHandler.post(() -> { |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 128 | StatusBar statusBar = SysUiServiceProvider.getComponent(mContext, |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 129 | StatusBar.class); |
| 130 | if (statusBar != null) { |
| 131 | statusBar.showScreenPinningRequest(taskId, false /* allowCancel */); |
| 132 | } |
| 133 | }); |
| 134 | } finally { |
| 135 | Binder.restoreCallingIdentity(token); |
| 136 | } |
| 137 | } |
| 138 | |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 139 | public void onStatusBarMotionEvent(MotionEvent event) { |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 140 | if (!verifyCaller("onStatusBarMotionEvent")) { |
| 141 | return; |
| 142 | } |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 143 | long token = Binder.clearCallingIdentity(); |
| 144 | try { |
| 145 | // TODO move this logic to message queue |
| 146 | mHandler.post(()->{ |
| 147 | StatusBar bar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); |
| 148 | if (bar != null) { |
| 149 | bar.dispatchNotificationsPanelTouchEvent(event); |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 150 | |
| 151 | int action = event.getActionMasked(); |
| 152 | if (action == ACTION_DOWN) { |
| 153 | mStatusBarGestureDownEvent = MotionEvent.obtain(event); |
| 154 | } |
| 155 | if (action == ACTION_UP || action == ACTION_CANCEL) { |
| 156 | mStatusBarGestureDownEvent.recycle(); |
| 157 | mStatusBarGestureDownEvent = null; |
| 158 | } |
| 159 | event.recycle(); |
Hyunyoung Song | c1647ea | 2018-08-20 12:23:46 -0700 | [diff] [blame] | 160 | } |
| 161 | }); |
| 162 | } finally { |
| 163 | Binder.restoreCallingIdentity(token); |
| 164 | } |
| 165 | } |
| 166 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 167 | public void onSplitScreenInvoked() { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 168 | if (!verifyCaller("onSplitScreenInvoked")) { |
| 169 | return; |
| 170 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 171 | long token = Binder.clearCallingIdentity(); |
| 172 | try { |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 173 | Divider divider = SysUiServiceProvider.getComponent(mContext, Divider.class); |
| 174 | if (divider != null) { |
| 175 | divider.onDockedFirstAnimationFrame(); |
| 176 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 177 | } finally { |
| 178 | Binder.restoreCallingIdentity(token); |
| 179 | } |
| 180 | } |
| 181 | |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 182 | public void onOverviewShown(boolean fromHome) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 183 | if (!verifyCaller("onOverviewShown")) { |
| 184 | return; |
| 185 | } |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 186 | long token = Binder.clearCallingIdentity(); |
| 187 | try { |
| 188 | mHandler.post(() -> { |
| 189 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 190 | mConnectionCallbacks.get(i).onOverviewShown(fromHome); |
| 191 | } |
| 192 | }); |
| 193 | } finally { |
| 194 | Binder.restoreCallingIdentity(token); |
| 195 | } |
| 196 | } |
| 197 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 198 | public void setInteractionState(@InteractionType int flags) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 199 | if (!verifyCaller("setInteractionState")) { |
| 200 | return; |
| 201 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 202 | long token = Binder.clearCallingIdentity(); |
| 203 | try { |
| 204 | if (mInteractionFlags != flags) { |
| 205 | mInteractionFlags = flags; |
| 206 | mHandler.post(() -> { |
| 207 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 208 | mConnectionCallbacks.get(i).onInteractionFlagsChanged(flags); |
| 209 | } |
| 210 | }); |
| 211 | } |
| 212 | } finally { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 213 | Prefs.putInt(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS, mInteractionFlags); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 214 | Binder.restoreCallingIdentity(token); |
| 215 | } |
| 216 | } |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 217 | |
| 218 | public Rect getNonMinimizedSplitScreenSecondaryBounds() { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 219 | if (!verifyCaller("getNonMinimizedSplitScreenSecondaryBounds")) { |
| 220 | return null; |
| 221 | } |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 222 | long token = Binder.clearCallingIdentity(); |
| 223 | try { |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 224 | Divider divider = SysUiServiceProvider.getComponent(mContext, Divider.class); |
Matthew Ng | c603a50 | 2018-04-18 17:14:22 -0700 | [diff] [blame] | 225 | if (divider != null) { |
| 226 | return divider.getView().getNonMinimizedSplitScreenSecondaryBounds(); |
| 227 | } |
| 228 | return null; |
| 229 | } finally { |
| 230 | Binder.restoreCallingIdentity(token); |
| 231 | } |
| 232 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 233 | |
| 234 | public void setBackButtonAlpha(float alpha, boolean animate) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 235 | if (!verifyCaller("setBackButtonAlpha")) { |
| 236 | return; |
| 237 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 238 | long token = Binder.clearCallingIdentity(); |
| 239 | try { |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 240 | mBackButtonAlpha = alpha; |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 241 | mHandler.post(() -> { |
Matthew Ng | 5389645 | 2018-05-30 11:27:39 -0700 | [diff] [blame] | 242 | notifyBackButtonAlphaChanged(alpha, animate); |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 243 | }); |
| 244 | } finally { |
| 245 | Binder.restoreCallingIdentity(token); |
| 246 | } |
| 247 | } |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 248 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 249 | public float getWindowCornerRadius() { |
| 250 | if (!verifyCaller("getWindowCornerRadius")) { |
| 251 | return 0; |
| 252 | } |
| 253 | long token = Binder.clearCallingIdentity(); |
| 254 | try { |
| 255 | return mWindowCornerRadius; |
| 256 | } finally { |
| 257 | Binder.restoreCallingIdentity(token); |
| 258 | } |
| 259 | } |
| 260 | |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 261 | public boolean supportsRoundedCornersOnWindows() { |
| 262 | if (!verifyCaller("supportsRoundedCornersOnWindows")) { |
| 263 | return false; |
| 264 | } |
| 265 | long token = Binder.clearCallingIdentity(); |
| 266 | try { |
| 267 | return mSupportsRoundedCornersOnWindows; |
| 268 | } finally { |
| 269 | Binder.restoreCallingIdentity(token); |
| 270 | } |
| 271 | } |
| 272 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 273 | public void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) { |
| 274 | if (!verifyCaller("onAssistantProgress")) { |
| 275 | return; |
| 276 | } |
| 277 | long token = Binder.clearCallingIdentity(); |
| 278 | try { |
| 279 | mHandler.post(() -> notifyAssistantProgress(progress)); |
| 280 | } finally { |
| 281 | Binder.restoreCallingIdentity(token); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | public void startAssistant(Bundle bundle) { |
| 286 | if (!verifyCaller("startAssistant")) { |
| 287 | return; |
| 288 | } |
| 289 | long token = Binder.clearCallingIdentity(); |
| 290 | try { |
| 291 | mHandler.post(() -> notifyStartAssistant(bundle)); |
| 292 | } finally { |
| 293 | Binder.restoreCallingIdentity(token); |
| 294 | } |
| 295 | } |
| 296 | |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 297 | private boolean verifyCaller(String reason) { |
| 298 | final int callerId = Binder.getCallingUserHandle().getIdentifier(); |
| 299 | if (callerId != mCurrentBoundedUserId) { |
| 300 | Log.w(TAG_OPS, "Launcher called sysui with invalid user: " + callerId + ", reason: " |
| 301 | + reason); |
| 302 | return false; |
| 303 | } |
| 304 | return true; |
| 305 | } |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 308 | private final Runnable mDeferredConnectionCallback = () -> { |
| 309 | Log.w(TAG_OPS, "Binder supposed established connection but actual connection to service " |
| 310 | + "timed out, trying again"); |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 311 | retryConnectionWithBackoff(); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 314 | private final BroadcastReceiver mLauncherStateChangedReceiver = new BroadcastReceiver() { |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 315 | @Override |
| 316 | public void onReceive(Context context, Intent intent) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 317 | updateEnabledState(); |
| 318 | |
| 319 | // When launcher service is disabled, reset interaction flags because it is inactive |
| 320 | if (!isEnabled()) { |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 321 | mInteractionFlags = getDefaultInteractionFlags(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 322 | Prefs.remove(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS); |
| 323 | } |
| 324 | |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 325 | // Reconnect immediately, instead of waiting for resume to arrive. |
| 326 | startConnectionToCurrentUser(); |
| 327 | } |
| 328 | }; |
| 329 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 330 | private final ServiceConnection mOverviewServiceConnection = new ServiceConnection() { |
| 331 | @Override |
| 332 | public void onServiceConnected(ComponentName name, IBinder service) { |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 333 | mHandler.removeCallbacks(mDeferredConnectionCallback); |
Matthew Ng | 4c3973d | 2018-10-15 17:21:24 -0700 | [diff] [blame] | 334 | mCurrentBoundedUserId = mDeviceProvisionedController.getCurrentUser(); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 335 | mConnectionBackoffAttempts = 0; |
| 336 | mOverviewProxy = IOverviewProxy.Stub.asInterface(service); |
| 337 | // Listen for launcher's death |
| 338 | try { |
| 339 | service.linkToDeath(mOverviewServiceDeathRcpt, 0); |
| 340 | } catch (RemoteException e) { |
| 341 | Log.e(TAG_OPS, "Lost connection to launcher service", e); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 342 | } |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 343 | try { |
| 344 | mOverviewProxy.onBind(mSysUiProxy); |
| 345 | } catch (RemoteException e) { |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 346 | mCurrentBoundedUserId = -1; |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 347 | Log.e(TAG_OPS, "Failed to call onBind()", e); |
| 348 | } |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 349 | |
| 350 | Bundle params = new Bundle(); |
| 351 | params.putBinder(KEY_EXTRA_SYSUI_PROXY, mSysUiProxy.asBinder()); |
| 352 | params.putParcelable(KEY_EXTRA_INPUT_CHANNEL, createNewInputDispatcher()); |
| 353 | params.putFloat(KEY_EXTRA_WINDOW_CORNER_RADIUS, mWindowCornerRadius); |
| 354 | params.putBoolean(KEY_EXTRA_SUPPORTS_WINDOW_CORNERS, mSupportsRoundedCornersOnWindows); |
| 355 | try { |
| 356 | mOverviewProxy.onInitialize(params); |
| 357 | } catch (RemoteException e) { |
| 358 | // Ignore error until the migration is complete. |
| 359 | Log.e(TAG_OPS, "Failed to call onBind()", e); |
| 360 | } |
| 361 | dispatchNavButtonBounds(); |
| 362 | |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 363 | notifyConnectionChanged(); |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void onNullBinding(ComponentName name) { |
| 368 | Log.w(TAG_OPS, "Null binding of '" + name + "', try reconnecting"); |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 369 | mCurrentBoundedUserId = -1; |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 370 | retryConnectionWithBackoff(); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 371 | disposeInputDispatcher(); |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void onBindingDied(ComponentName name) { |
| 376 | Log.w(TAG_OPS, "Binding died of '" + name + "', try reconnecting"); |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 377 | mCurrentBoundedUserId = -1; |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 378 | retryConnectionWithBackoff(); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 379 | disposeInputDispatcher(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void onServiceDisconnected(ComponentName name) { |
| 384 | // Do nothing |
Matthew Ng | ffb1737 | 2018-07-18 12:31:29 -0700 | [diff] [blame] | 385 | mCurrentBoundedUserId = -1; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 386 | disposeInputDispatcher(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 387 | } |
| 388 | }; |
| 389 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 390 | private void disposeInputDispatcher() { |
| 391 | if (mInputEventDispatcher != null) { |
| 392 | mInputEventDispatcher.dispose(); |
| 393 | mInputEventDispatcher = null; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | private InputChannel createNewInputDispatcher() { |
| 398 | disposeInputDispatcher(); |
| 399 | |
| 400 | InputChannel[] channels = InputChannel.openInputChannelPair("overview-proxy-service"); |
| 401 | mInputEventDispatcher = new InputEventDispatcher(channels[0], Looper.getMainLooper()); |
| 402 | return channels[1]; |
| 403 | } |
| 404 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 405 | private final DeviceProvisionedListener mDeviceProvisionedCallback = |
| 406 | new DeviceProvisionedListener() { |
| 407 | @Override |
Matthew Ng | dfab86c | 2017-11-07 15:46:51 -0800 | [diff] [blame] | 408 | public void onUserSetupChanged() { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 409 | if (mDeviceProvisionedController.isCurrentUserSetup()) { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 410 | internalConnectToCurrentUser(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void onUserSwitched() { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 416 | mConnectionBackoffAttempts = 0; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 417 | internalConnectToCurrentUser(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 418 | } |
| 419 | }; |
| 420 | |
| 421 | // This is the death handler for the binder from the launcher service |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 422 | private final IBinder.DeathRecipient mOverviewServiceDeathRcpt |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 423 | = this::cleanupAfterDeath; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 424 | |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 425 | @Inject |
Jason Monk | 96a37f4 | 2018-12-21 14:45:26 -0500 | [diff] [blame] | 426 | public OverviewProxyService(Context context, DeviceProvisionedController provisionController) { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 427 | mContext = context; |
| 428 | mHandler = new Handler(); |
Jason Monk | 96a37f4 | 2018-12-21 14:45:26 -0500 | [diff] [blame] | 429 | mDeviceProvisionedController = provisionController; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 430 | mConnectionBackoffAttempts = 0; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 431 | mRecentsComponentName = ComponentName.unflattenFromString(context.getString( |
| 432 | com.android.internal.R.string.config_recentsComponentName)); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 433 | mQuickStepIntent = new Intent(ACTION_QUICKSTEP) |
| 434 | .setPackage(mRecentsComponentName.getPackageName()); |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 435 | mInteractionFlags = Prefs.getInt(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS, |
| 436 | getDefaultInteractionFlags()); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 437 | mWindowCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(mContext.getResources()); |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 438 | mSupportsRoundedCornersOnWindows = ScreenDecorationsUtils |
| 439 | .supportsRoundedCornersOnWindows(mContext.getResources()); |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 440 | |
| 441 | // Listen for the package update changes. |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 442 | if (mDeviceProvisionedController.getCurrentUser() == UserHandle.USER_SYSTEM) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 443 | updateEnabledState(); |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 444 | mDeviceProvisionedController.addCallback(mDeviceProvisionedCallback); |
| 445 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 446 | filter.addDataScheme("package"); |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 447 | filter.addDataSchemeSpecificPart(mRecentsComponentName.getPackageName(), |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 448 | PatternMatcher.PATTERN_LITERAL); |
| 449 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 450 | mContext.registerReceiver(mLauncherStateChangedReceiver, filter); |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 451 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 454 | /** |
| 455 | * Sets the navbar region which can receive touch inputs |
| 456 | */ |
| 457 | public void onActiveNavBarRegionChanges(Region activeRegion) { |
| 458 | mActiveNavBarRegion = activeRegion; |
| 459 | dispatchNavButtonBounds(); |
| 460 | } |
| 461 | |
| 462 | private void dispatchNavButtonBounds() { |
| 463 | if (mOverviewProxy != null && mActiveNavBarRegion != null) { |
| 464 | try { |
| 465 | mOverviewProxy.onActiveNavBarRegionChanges(mActiveNavBarRegion); |
| 466 | } catch (RemoteException e) { |
| 467 | Log.e(TAG_OPS, "Failed to call onActiveNavBarRegionChanges()", e); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 472 | public float getBackButtonAlpha() { |
| 473 | return mBackButtonAlpha; |
| 474 | } |
| 475 | |
Hyunyoung Song | 547e11e | 2018-10-04 16:32:23 -0700 | [diff] [blame] | 476 | public void cleanupAfterDeath() { |
| 477 | if (mStatusBarGestureDownEvent != null) { |
| 478 | mHandler.post(()-> { |
| 479 | StatusBar bar = SysUiServiceProvider.getComponent(mContext, StatusBar.class); |
| 480 | if (bar != null) { |
| 481 | System.out.println("MERONG dispatchNotificationPanelTouchEvent"); |
| 482 | mStatusBarGestureDownEvent.setAction(MotionEvent.ACTION_CANCEL); |
| 483 | bar.dispatchNotificationsPanelTouchEvent(mStatusBarGestureDownEvent); |
| 484 | mStatusBarGestureDownEvent.recycle(); |
| 485 | mStatusBarGestureDownEvent = null; |
| 486 | } |
| 487 | }); |
| 488 | } |
| 489 | startConnectionToCurrentUser(); |
| 490 | } |
| 491 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 492 | public void startConnectionToCurrentUser() { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 493 | if (mHandler.getLooper() != Looper.myLooper()) { |
| 494 | mHandler.post(mConnectionRunnable); |
| 495 | } else { |
| 496 | internalConnectToCurrentUser(); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | private void internalConnectToCurrentUser() { |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 501 | disconnectFromLauncherService(); |
| 502 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 503 | // 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] | 504 | if (!mDeviceProvisionedController.isCurrentUserSetup() || !isEnabled()) { |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 505 | Log.v(TAG_OPS, "Cannot attempt connection, is setup " |
| 506 | + mDeviceProvisionedController.isCurrentUserSetup() + ", is enabled " |
| 507 | + isEnabled()); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 508 | return; |
| 509 | } |
| 510 | mHandler.removeCallbacks(mConnectionRunnable); |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 511 | Intent launcherServiceIntent = new Intent(ACTION_QUICKSTEP) |
| 512 | .setPackage(mRecentsComponentName.getPackageName()); |
Matthew Ng | 10b6c41a | 2018-03-26 18:01:37 -0700 | [diff] [blame] | 513 | boolean bound = false; |
| 514 | try { |
| 515 | bound = mContext.bindServiceAsUser(launcherServiceIntent, |
Winson Chung | e7cb0c1 | 2018-07-30 16:11:38 -0700 | [diff] [blame] | 516 | mOverviewServiceConnection, |
| 517 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
Matthew Ng | 10b6c41a | 2018-03-26 18:01:37 -0700 | [diff] [blame] | 518 | UserHandle.of(mDeviceProvisionedController.getCurrentUser())); |
| 519 | } catch (SecurityException e) { |
| 520 | Log.e(TAG_OPS, "Unable to bind because of security error", e); |
| 521 | } |
Matthew Ng | e3c5af4 | 2018-05-02 16:58:44 -0700 | [diff] [blame] | 522 | if (bound) { |
| 523 | // Ensure that connection has been established even if it thinks it is bound |
| 524 | mHandler.postDelayed(mDeferredConnectionCallback, DEFERRED_CALLBACK_MILLIS); |
| 525 | } else { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 526 | // Retry after exponential backoff timeout |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 527 | retryConnectionWithBackoff(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Matthew Ng | ead8e5a | 2018-08-20 17:20:05 -0700 | [diff] [blame] | 531 | private void retryConnectionWithBackoff() { |
| 532 | if (mHandler.hasCallbacks(mConnectionRunnable)) { |
| 533 | return; |
| 534 | } |
| 535 | final long timeoutMs = (long) Math.min( |
| 536 | Math.scalb(BACKOFF_MILLIS, mConnectionBackoffAttempts), MAX_BACKOFF_MILLIS); |
| 537 | mHandler.postDelayed(mConnectionRunnable, timeoutMs); |
| 538 | mConnectionBackoffAttempts++; |
| 539 | Log.w(TAG_OPS, "Failed to connect on attempt " + mConnectionBackoffAttempts |
| 540 | + " will try again in " + timeoutMs + "ms"); |
| 541 | } |
| 542 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 543 | @Override |
| 544 | public void addCallback(OverviewProxyListener listener) { |
| 545 | mConnectionCallbacks.add(listener); |
| 546 | listener.onConnectionChanged(mOverviewProxy != null); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 547 | listener.onInteractionFlagsChanged(mInteractionFlags); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | @Override |
| 551 | public void removeCallback(OverviewProxyListener listener) { |
| 552 | mConnectionCallbacks.remove(listener); |
| 553 | } |
| 554 | |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 555 | public boolean shouldShowSwipeUpUI() { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 556 | return isEnabled() && ((mInteractionFlags & FLAG_DISABLE_SWIPE_UP) == 0); |
| 557 | } |
| 558 | |
| 559 | public boolean isEnabled() { |
| 560 | return mIsEnabled; |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 563 | public IOverviewProxy getProxy() { |
| 564 | return mOverviewProxy; |
| 565 | } |
| 566 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 567 | public InputEventDispatcher getInputEventDispatcher() { |
| 568 | return mInputEventDispatcher; |
| 569 | } |
| 570 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 571 | public int getInteractionFlags() { |
| 572 | return mInteractionFlags; |
| 573 | } |
| 574 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 575 | private void disconnectFromLauncherService() { |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 576 | if (mOverviewProxy != null) { |
Matthew Ng | eb6893b | 2017-11-09 17:15:33 -0800 | [diff] [blame] | 577 | mOverviewProxy.asBinder().unlinkToDeath(mOverviewServiceDeathRcpt, 0); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 578 | mContext.unbindService(mOverviewServiceConnection); |
| 579 | mOverviewProxy = null; |
Matthew Ng | 5389645 | 2018-05-30 11:27:39 -0700 | [diff] [blame] | 580 | notifyBackButtonAlphaChanged(1f, false /* animate */); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 581 | notifyConnectionChanged(); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 582 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 583 | } |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 584 | |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 585 | private int getDefaultInteractionFlags() { |
| 586 | // If there is no settings available use device default or get it from settings |
| 587 | final boolean defaultState = getSwipeUpDefaultValue(); |
| 588 | final boolean swipeUpEnabled = getSwipeUpSettingAvailable() |
| 589 | ? getSwipeUpEnabledFromSettings(defaultState) |
| 590 | : defaultState; |
| 591 | return swipeUpEnabled ? 0 : DEFAULT_DISABLE_SWIPE_UP_STATE; |
| 592 | } |
| 593 | |
Matthew Ng | 5389645 | 2018-05-30 11:27:39 -0700 | [diff] [blame] | 594 | private void notifyBackButtonAlphaChanged(float alpha, boolean animate) { |
| 595 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 596 | mConnectionCallbacks.get(i).onBackButtonAlphaChanged(alpha, animate); |
| 597 | } |
| 598 | } |
| 599 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 600 | private void notifyConnectionChanged() { |
| 601 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 602 | mConnectionCallbacks.get(i).onConnectionChanged(mOverviewProxy != null); |
| 603 | } |
| 604 | } |
| 605 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 606 | public void notifyQuickStepStarted() { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 607 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 608 | mConnectionCallbacks.get(i).onQuickStepStarted(); |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 612 | public void notifyQuickScrubStarted() { |
| 613 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 614 | mConnectionCallbacks.get(i).onQuickScrubStarted(); |
| 615 | } |
| 616 | } |
| 617 | |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 618 | private void notifyAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) { |
| 619 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 620 | mConnectionCallbacks.get(i).onAssistantProgress(progress); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | private void notifyStartAssistant(Bundle bundle) { |
| 625 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 626 | mConnectionCallbacks.get(i).startAssistant(bundle); |
| 627 | } |
| 628 | } |
| 629 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 630 | private void updateEnabledState() { |
Winson Chung | 6e4b0b56 | 2018-04-04 09:13:37 -0700 | [diff] [blame] | 631 | mIsEnabled = mContext.getPackageManager().resolveServiceAsUser(mQuickStepIntent, |
Matthew Ng | a3fee34 | 2019-02-25 15:36:37 -0800 | [diff] [blame] | 632 | MATCH_SYSTEM_ONLY, |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 633 | ActivityManagerWrapper.getInstance().getCurrentUserId()) != null; |
| 634 | } |
| 635 | |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 636 | private boolean getSwipeUpDefaultValue() { |
| 637 | return mContext.getResources() |
| 638 | .getBoolean(com.android.internal.R.bool.config_swipe_up_gesture_default); |
| 639 | } |
| 640 | |
| 641 | private boolean getSwipeUpSettingAvailable() { |
| 642 | return mContext.getResources() |
| 643 | .getBoolean(com.android.internal.R.bool.config_swipe_up_gesture_setting_available); |
| 644 | } |
| 645 | |
| 646 | private boolean getSwipeUpEnabledFromSettings(boolean defaultValue) { |
| 647 | return Settings.Secure.getInt(mContext.getContentResolver(), |
| 648 | Settings.Secure.SWIPE_UP_TO_SWITCH_APPS_ENABLED, defaultValue ? 1 : 0) == 1; |
| 649 | } |
| 650 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 651 | @Override |
| 652 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 653 | pw.println(TAG_OPS + " state:"); |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 654 | pw.print(" recentsComponentName="); pw.println(mRecentsComponentName); |
| 655 | pw.print(" isConnected="); pw.println(mOverviewProxy != null); |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 656 | pw.print(" isCurrentUserSetup="); pw.println(mDeviceProvisionedController |
| 657 | .isCurrentUserSetup()); |
Winson Chung | 387e38b | 2018-07-09 14:30:54 -0700 | [diff] [blame] | 658 | pw.print(" connectionBackoffAttempts="); pw.println(mConnectionBackoffAttempts); |
| 659 | pw.print(" interactionFlags="); pw.println(mInteractionFlags); |
| 660 | |
| 661 | pw.print(" quickStepIntent="); pw.println(mQuickStepIntent); |
| 662 | pw.print(" quickStepIntentResolved="); pw.println(isEnabled()); |
| 663 | |
Matthew Ng | 0769e44 | 2018-08-06 15:05:33 -0700 | [diff] [blame] | 664 | final boolean swipeUpDefaultValue = getSwipeUpDefaultValue(); |
| 665 | final boolean swipeUpEnabled = getSwipeUpEnabledFromSettings(swipeUpDefaultValue); |
| 666 | pw.print(" swipeUpSetting="); pw.println(swipeUpEnabled); |
| 667 | pw.print(" swipeUpSettingDefault="); pw.println(swipeUpDefaultValue); |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 670 | public interface OverviewProxyListener { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 671 | default void onConnectionChanged(boolean isConnected) {} |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 672 | default void onQuickStepStarted() {} |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 673 | default void onInteractionFlagsChanged(@InteractionType int flags) {} |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 674 | default void onOverviewShown(boolean fromHome) {} |
| 675 | default void onQuickScrubStarted() {} |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 676 | default void onBackButtonAlphaChanged(float alpha, boolean animate) {} |
Matthew Ng | 42025e3 | 2019-02-20 15:02:58 -0800 | [diff] [blame] | 677 | default void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {} |
| 678 | default void startAssistant(Bundle bundle) {} |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 679 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 680 | } |