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 | |
| 17 | package com.android.systemui; |
| 18 | |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 19 | import android.content.BroadcastReceiver; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 23 | import android.content.IntentFilter; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 24 | import android.content.ServiceConnection; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 25 | import android.content.pm.PackageManager; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
| 27 | import android.os.Binder; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.IBinder; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 30 | import android.os.Looper; |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 31 | import android.os.PatternMatcher; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 32 | import android.os.RemoteException; |
| 33 | import android.os.UserHandle; |
| 34 | import android.util.Log; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 35 | import android.view.SurfaceControl; |
| 36 | |
Winson Chung | 11f53e9 | 2017-11-13 17:45:12 -0800 | [diff] [blame] | 37 | import com.android.systemui.OverviewProxyService.OverviewProxyListener; |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 38 | import com.android.systemui.recents.events.EventBus; |
| 39 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 40 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 41 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 42 | import com.android.systemui.shared.recents.ISystemUiProxy; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 43 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | 11f53e9 | 2017-11-13 17:45:12 -0800 | [diff] [blame] | 44 | import com.android.systemui.shared.system.GraphicBufferCompat; |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 45 | import com.android.systemui.statusbar.phone.StatusBar; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.CallbackController; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 48 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Winson Chung | 11f53e9 | 2017-11-13 17:45:12 -0800 | [diff] [blame] | 49 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 50 | import java.io.FileDescriptor; |
| 51 | import java.io.PrintWriter; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 52 | import java.util.ArrayList; |
| 53 | import java.util.List; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 54 | |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 55 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 56 | import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType; |
| 57 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Class to send information from overview to launcher with a binder. |
| 60 | */ |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 61 | public class OverviewProxyService implements CallbackController<OverviewProxyListener>, Dumpable { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 62 | |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 63 | private static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE"; |
| 64 | |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 65 | public static final String TAG_OPS = "OverviewProxyService"; |
| 66 | public static final boolean DEBUG_OVERVIEW_PROXY = false; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 67 | private static final long BACKOFF_MILLIS = 5000; |
| 68 | |
| 69 | private final Context mContext; |
| 70 | private final Handler mHandler; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 71 | private final Runnable mConnectionRunnable = this::internalConnectToCurrentUser; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 72 | private final ComponentName mRecentsComponentName; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 73 | private final DeviceProvisionedController mDeviceProvisionedController |
| 74 | = Dependency.get(DeviceProvisionedController.class); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 75 | private final List<OverviewProxyListener> mConnectionCallbacks = new ArrayList<>(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 76 | private final Intent mQuickStepIntent; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 77 | |
| 78 | private IOverviewProxy mOverviewProxy; |
| 79 | private int mConnectionBackoffAttempts; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 80 | private CharSequence mOnboardingText; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 81 | private @InteractionType int mInteractionFlags; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 82 | private boolean mIsEnabled; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 83 | |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 84 | private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() { |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 85 | |
Winson Chung | 11f53e9 | 2017-11-13 17:45:12 -0800 | [diff] [blame] | 86 | public GraphicBufferCompat screenshot(Rect sourceCrop, int width, int height, int minLayer, |
| 87 | int maxLayer, boolean useIdentityTransform, int rotation) { |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 88 | long token = Binder.clearCallingIdentity(); |
| 89 | try { |
Winson Chung | 11f53e9 | 2017-11-13 17:45:12 -0800 | [diff] [blame] | 90 | return new GraphicBufferCompat(SurfaceControl.screenshotToBuffer(sourceCrop, width, |
| 91 | height, minLayer, maxLayer, useIdentityTransform, rotation)); |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 92 | } finally { |
| 93 | Binder.restoreCallingIdentity(token); |
| 94 | } |
| 95 | } |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 96 | |
Winson Chung | caf2b81 | 2018-01-26 10:29:46 -0800 | [diff] [blame] | 97 | public void startScreenPinning(int taskId) { |
| 98 | long token = Binder.clearCallingIdentity(); |
| 99 | try { |
| 100 | mHandler.post(() -> { |
| 101 | StatusBar statusBar = ((SystemUIApplication) mContext).getComponent( |
| 102 | StatusBar.class); |
| 103 | if (statusBar != null) { |
| 104 | statusBar.showScreenPinningRequest(taskId, false /* allowCancel */); |
| 105 | } |
| 106 | }); |
| 107 | } finally { |
| 108 | Binder.restoreCallingIdentity(token); |
| 109 | } |
| 110 | } |
| 111 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 112 | public void onSplitScreenInvoked() { |
| 113 | long token = Binder.clearCallingIdentity(); |
| 114 | try { |
| 115 | EventBus.getDefault().post(new DockedFirstAnimationFrameEvent()); |
| 116 | } finally { |
| 117 | Binder.restoreCallingIdentity(token); |
| 118 | } |
| 119 | } |
| 120 | |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 121 | public void setRecentsOnboardingText(CharSequence text) { |
| 122 | mOnboardingText = text; |
| 123 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 124 | |
| 125 | public void setInteractionState(@InteractionType int flags) { |
| 126 | long token = Binder.clearCallingIdentity(); |
| 127 | try { |
| 128 | if (mInteractionFlags != flags) { |
| 129 | mInteractionFlags = flags; |
| 130 | mHandler.post(() -> { |
| 131 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 132 | mConnectionCallbacks.get(i).onInteractionFlagsChanged(flags); |
| 133 | } |
| 134 | }); |
| 135 | } |
| 136 | } finally { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 137 | Prefs.putInt(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS, mInteractionFlags); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 138 | Binder.restoreCallingIdentity(token); |
| 139 | } |
| 140 | } |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 143 | private final BroadcastReceiver mLauncherStateChangedReceiver = new BroadcastReceiver() { |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 144 | @Override |
| 145 | public void onReceive(Context context, Intent intent) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 146 | updateEnabledState(); |
| 147 | |
| 148 | // When launcher service is disabled, reset interaction flags because it is inactive |
| 149 | if (!isEnabled()) { |
| 150 | mInteractionFlags = 0; |
| 151 | Prefs.remove(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS); |
| 152 | } |
| 153 | |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 154 | // Reconnect immediately, instead of waiting for resume to arrive. |
| 155 | startConnectionToCurrentUser(); |
| 156 | } |
| 157 | }; |
| 158 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 159 | private final ServiceConnection mOverviewServiceConnection = new ServiceConnection() { |
| 160 | @Override |
| 161 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 162 | if (service != null) { |
| 163 | mConnectionBackoffAttempts = 0; |
| 164 | mOverviewProxy = IOverviewProxy.Stub.asInterface(service); |
| 165 | // Listen for launcher's death |
| 166 | try { |
| 167 | service.linkToDeath(mOverviewServiceDeathRcpt, 0); |
| 168 | } catch (RemoteException e) { |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 169 | Log.e(TAG_OPS, "Lost connection to launcher service", e); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 170 | } |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 171 | try { |
| 172 | mOverviewProxy.onBind(mSysUiProxy); |
| 173 | } catch (RemoteException e) { |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 174 | Log.e(TAG_OPS, "Failed to call onBind()", e); |
Winson Chung | 38d31c2 | 2017-11-08 14:32:32 -0800 | [diff] [blame] | 175 | } |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 176 | notifyConnectionChanged(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void onServiceDisconnected(ComponentName name) { |
| 182 | // Do nothing |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | private final DeviceProvisionedListener mDeviceProvisionedCallback = |
| 187 | new DeviceProvisionedListener() { |
| 188 | @Override |
Matthew Ng | dfab86c | 2017-11-07 15:46:51 -0800 | [diff] [blame] | 189 | public void onUserSetupChanged() { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 190 | if (mDeviceProvisionedController.isCurrentUserSetup()) { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 191 | internalConnectToCurrentUser(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void onUserSwitched() { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 197 | mConnectionBackoffAttempts = 0; |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 198 | internalConnectToCurrentUser(); |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 199 | } |
| 200 | }; |
| 201 | |
| 202 | // This is the death handler for the binder from the launcher service |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 203 | private final IBinder.DeathRecipient mOverviewServiceDeathRcpt |
| 204 | = this::startConnectionToCurrentUser; |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 205 | |
| 206 | public OverviewProxyService(Context context) { |
| 207 | mContext = context; |
| 208 | mHandler = new Handler(); |
| 209 | mConnectionBackoffAttempts = 0; |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 210 | mRecentsComponentName = ComponentName.unflattenFromString(context.getString( |
| 211 | com.android.internal.R.string.config_recentsComponentName)); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 212 | mQuickStepIntent = new Intent(ACTION_QUICKSTEP) |
| 213 | .setPackage(mRecentsComponentName.getPackageName()); |
| 214 | mInteractionFlags = Prefs.getInt(mContext, Prefs.Key.QUICK_STEP_INTERACTION_FLAGS, 0); |
Matthew Ng | 30c0a02 | 2017-11-10 14:06:29 -0800 | [diff] [blame] | 215 | |
| 216 | // Listen for the package update changes. |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 217 | if (SystemServicesProxy.getInstance(context) |
| 218 | .isSystemUser(mDeviceProvisionedController.getCurrentUser())) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 219 | updateEnabledState(); |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 220 | mDeviceProvisionedController.addCallback(mDeviceProvisionedCallback); |
| 221 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 222 | filter.addDataScheme("package"); |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 223 | filter.addDataSchemeSpecificPart(mRecentsComponentName.getPackageName(), |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 224 | PatternMatcher.PATTERN_LITERAL); |
| 225 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 226 | mContext.registerReceiver(mLauncherStateChangedReceiver, filter); |
Matthew Ng | 1b1d346 | 2018-03-02 11:43:38 -0800 | [diff] [blame] | 227 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | public void startConnectionToCurrentUser() { |
Matthew Ng | fac8783 | 2017-11-10 11:27:29 -0800 | [diff] [blame] | 231 | if (mHandler.getLooper() != Looper.myLooper()) { |
| 232 | mHandler.post(mConnectionRunnable); |
| 233 | } else { |
| 234 | internalConnectToCurrentUser(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | private void internalConnectToCurrentUser() { |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 239 | disconnectFromLauncherService(); |
| 240 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 241 | // 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^] | 242 | if (!mDeviceProvisionedController.isCurrentUserSetup() || !isEnabled()) { |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 243 | return; |
| 244 | } |
| 245 | mHandler.removeCallbacks(mConnectionRunnable); |
Sunny Goyal | 09c12d7 | 2018-03-27 10:14:49 -0700 | [diff] [blame] | 246 | Intent launcherServiceIntent = new Intent(ACTION_QUICKSTEP) |
| 247 | .setPackage(mRecentsComponentName.getPackageName()); |
Matthew Ng | 10b6c41a | 2018-03-26 18:01:37 -0700 | [diff] [blame] | 248 | boolean bound = false; |
| 249 | try { |
| 250 | bound = mContext.bindServiceAsUser(launcherServiceIntent, |
| 251 | mOverviewServiceConnection, Context.BIND_AUTO_CREATE, |
| 252 | UserHandle.of(mDeviceProvisionedController.getCurrentUser())); |
| 253 | } catch (SecurityException e) { |
| 254 | Log.e(TAG_OPS, "Unable to bind because of security error", e); |
| 255 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 256 | if (!bound) { |
| 257 | // Retry after exponential backoff timeout |
| 258 | final long timeoutMs = (long) Math.scalb(BACKOFF_MILLIS, mConnectionBackoffAttempts); |
| 259 | mHandler.postDelayed(mConnectionRunnable, timeoutMs); |
| 260 | mConnectionBackoffAttempts++; |
| 261 | } |
| 262 | } |
| 263 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 264 | @Override |
| 265 | public void addCallback(OverviewProxyListener listener) { |
| 266 | mConnectionCallbacks.add(listener); |
| 267 | listener.onConnectionChanged(mOverviewProxy != null); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 268 | listener.onInteractionFlagsChanged(mInteractionFlags); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public void removeCallback(OverviewProxyListener listener) { |
| 273 | mConnectionCallbacks.remove(listener); |
| 274 | } |
| 275 | |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 276 | public boolean shouldShowSwipeUpUI() { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 277 | return isEnabled() && ((mInteractionFlags & FLAG_DISABLE_SWIPE_UP) == 0); |
| 278 | } |
| 279 | |
| 280 | public boolean isEnabled() { |
| 281 | return mIsEnabled; |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 284 | public IOverviewProxy getProxy() { |
| 285 | return mOverviewProxy; |
| 286 | } |
| 287 | |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 288 | public CharSequence getOnboardingText() { |
| 289 | return mOnboardingText; |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 292 | public int getInteractionFlags() { |
| 293 | return mInteractionFlags; |
| 294 | } |
| 295 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 296 | private void disconnectFromLauncherService() { |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 297 | if (mOverviewProxy != null) { |
Matthew Ng | eb6893b | 2017-11-09 17:15:33 -0800 | [diff] [blame] | 298 | mOverviewProxy.asBinder().unlinkToDeath(mOverviewServiceDeathRcpt, 0); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 299 | mContext.unbindService(mOverviewServiceConnection); |
| 300 | mOverviewProxy = null; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 301 | notifyConnectionChanged(); |
Matthew Ng | 1fa3f7e | 2017-11-07 11:50:36 -0800 | [diff] [blame] | 302 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 303 | } |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 304 | |
| 305 | private void notifyConnectionChanged() { |
| 306 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
| 307 | mConnectionCallbacks.get(i).onConnectionChanged(mOverviewProxy != null); |
| 308 | } |
| 309 | } |
| 310 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 311 | public void notifyQuickStepStarted() { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 312 | for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 313 | mConnectionCallbacks.get(i).onQuickStepStarted(); |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame^] | 317 | private void updateEnabledState() { |
| 318 | mIsEnabled = mContext.getPackageManager().resolveServiceAsUser(mQuickStepIntent, 0, |
| 319 | ActivityManagerWrapper.getInstance().getCurrentUserId()) != null; |
| 320 | } |
| 321 | |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 322 | @Override |
| 323 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 324 | pw.println(TAG_OPS + " state:"); |
Matthew Ng | 1e43ebd | 2017-11-14 14:47:05 -0800 | [diff] [blame] | 325 | pw.print(" mConnectionBackoffAttempts="); pw.println(mConnectionBackoffAttempts); |
| 326 | pw.print(" isCurrentUserSetup="); pw.println(mDeviceProvisionedController |
| 327 | .isCurrentUserSetup()); |
| 328 | pw.print(" isConnected="); pw.println(mOverviewProxy != null); |
| 329 | } |
| 330 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 331 | public interface OverviewProxyListener { |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 332 | default void onConnectionChanged(boolean isConnected) {} |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 333 | default void onQuickStepStarted() {} |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 334 | default void onInteractionFlagsChanged(@InteractionType int flags) {} |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 335 | } |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 336 | } |