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