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