Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.recents; |
| 18 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 22 | import android.content.ServiceConnection; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 24 | import android.os.Build; |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 25 | import android.os.Handler; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 26 | import android.os.IBinder; |
| 27 | import android.os.RemoteException; |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 28 | import android.os.SystemProperties; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 30 | import android.util.Log; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 31 | import android.view.Display; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 32 | import android.view.View; |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 33 | import com.android.systemui.RecentsComponent; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 34 | import com.android.systemui.SystemUI; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 35 | import com.android.systemui.recents.events.EventBus; |
| 36 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 37 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 38 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 39 | import com.android.systemui.recents.model.RecentsTaskLoader; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 40 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 41 | import java.util.ArrayList; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 42 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 43 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 44 | /** |
| 45 | * An implementation of the SystemUI recents component, which supports both system and secondary |
| 46 | * users. |
| 47 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 48 | public class Recents extends SystemUI |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 49 | implements RecentsComponent { |
| 50 | |
| 51 | private final static String TAG = "Recents"; |
| 52 | private final static boolean DEBUG = false; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 53 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 54 | public final static int EVENT_BUS_PRIORITY = 1; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 55 | public final static int BIND_TO_SYSTEM_USER_RETRY_DELAY = 5000; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 56 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 57 | // Purely for experimentation |
| 58 | private final static String RECENTS_OVERRIDE_SYSPROP_KEY = "persist.recents_override_pkg"; |
| 59 | private final static String ACTION_SHOW_RECENTS = "com.android.systemui.recents.ACTION_SHOW"; |
| 60 | private final static String ACTION_HIDE_RECENTS = "com.android.systemui.recents.ACTION_HIDE"; |
| 61 | private final static String ACTION_TOGGLE_RECENTS = "com.android.systemui.recents.ACTION_TOGGLE"; |
| 62 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 63 | private static SystemServicesProxy sSystemServicesProxy; |
| 64 | private static RecentsTaskLoader sTaskLoader; |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 65 | private static RecentsConfiguration sConfiguration; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 66 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 67 | // For experiments only, allows another package to handle recents if it is defined in the system |
| 68 | // properties. This is limited to show/toggle/hide, and does not tie into the ActivityManager, |
| 69 | // and does not reside in the home stack. |
| 70 | private String mOverrideRecentsPackageName; |
| 71 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 72 | private Handler mHandler; |
| 73 | private RecentsImpl mImpl; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 74 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 75 | // Only For system user, this is the callbacks instance we return to each secondary user |
| 76 | private RecentsSystemUser mSystemUserCallbacks; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 77 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 78 | // Only for secondary users, this is the callbacks instance provided by the system user to make |
| 79 | // calls back |
| 80 | private IRecentsSystemUserCallbacks mCallbacksToSystemUser; |
Winson Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 81 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 82 | // The set of runnables to run after binding to the system user's service. |
| 83 | private final ArrayList<Runnable> mOnConnectRunnables = new ArrayList<>(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 84 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 85 | // Only for secondary users, this is the death handler for the binder from the system user |
| 86 | private final IBinder.DeathRecipient mCallbacksToSystemUserDeathRcpt = new IBinder.DeathRecipient() { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 87 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 88 | public void binderDied() { |
| 89 | mCallbacksToSystemUser = null; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 90 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 91 | // Retry after a fixed duration |
| 92 | mHandler.postDelayed(new Runnable() { |
| 93 | @Override |
| 94 | public void run() { |
| 95 | registerWithSystemUser(); |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 96 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 97 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 98 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 99 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 100 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 101 | // Only for secondary users, this is the service connection we use to connect to the system user |
| 102 | private final ServiceConnection mServiceConnectionToSystemUser = new ServiceConnection() { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 103 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 104 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 105 | if (service != null) { |
| 106 | mCallbacksToSystemUser = IRecentsSystemUserCallbacks.Stub.asInterface( |
| 107 | service); |
| 108 | |
| 109 | // Listen for system user's death, so that we can reconnect later |
| 110 | try { |
| 111 | service.linkToDeath(mCallbacksToSystemUserDeathRcpt, 0); |
| 112 | } catch (RemoteException e) { |
| 113 | Log.e(TAG, "Lost connection to (System) SystemUI", e); |
| 114 | } |
| 115 | |
| 116 | // Run each of the queued runnables |
| 117 | runAndFlushOnConnectRunnables(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 118 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 119 | |
| 120 | // Unbind ourselves now that we've registered our callbacks. The |
| 121 | // binder to the system user are still valid at this point. |
| 122 | mContext.unbindService(this); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 123 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 124 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 125 | @Override |
| 126 | public void onServiceDisconnected(ComponentName name) { |
| 127 | // Do nothing |
| 128 | } |
| 129 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 130 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 131 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 132 | * Returns the callbacks interface that non-system users can call. |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 133 | */ |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 134 | public IBinder getSystemUserCallbacks() { |
| 135 | return mSystemUserCallbacks; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 138 | public static RecentsTaskLoader getTaskLoader() { |
| 139 | return sTaskLoader; |
| 140 | } |
| 141 | |
| 142 | public static SystemServicesProxy getSystemServices() { |
| 143 | return sSystemServicesProxy; |
| 144 | } |
| 145 | |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 146 | public static RecentsConfiguration getConfiguration() { |
| 147 | return sConfiguration; |
| 148 | } |
| 149 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 150 | @Override |
| 151 | public void start() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 152 | sSystemServicesProxy = new SystemServicesProxy(mContext); |
| 153 | sTaskLoader = new RecentsTaskLoader(mContext); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 154 | sConfiguration = new RecentsConfiguration(mContext); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 155 | mHandler = new Handler(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 156 | mImpl = new RecentsImpl(mContext); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 157 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 158 | // Check if there is a recents override package |
| 159 | if ("userdebug".equals(Build.TYPE) || "eng".equals(Build.TYPE)) { |
| 160 | String cnStr = SystemProperties.get(RECENTS_OVERRIDE_SYSPROP_KEY); |
| 161 | if (!cnStr.isEmpty()) { |
| 162 | mOverrideRecentsPackageName = cnStr; |
| 163 | } |
| 164 | } |
| 165 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 166 | // Register with the event bus |
| 167 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 168 | EventBus.getDefault().register(sTaskLoader, EVENT_BUS_PRIORITY); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 169 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 170 | // Due to the fact that RecentsActivity is per-user, we need to establish and interface for |
| 171 | // the system user's Recents component to pass events (like show/hide/toggleRecents) to the |
| 172 | // secondary user, and vice versa (like visibility change, screen pinning). |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 173 | final int processUser = sSystemServicesProxy.getProcessUser(); |
| 174 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 175 | // For the system user, initialize an instance of the interface that we can pass to the |
| 176 | // secondary user |
| 177 | mSystemUserCallbacks = new RecentsSystemUser(mContext, mImpl); |
| 178 | } else { |
| 179 | // For the secondary user, bind to the primary user's service to get a persistent |
| 180 | // interface to register its implementation and to later update its state |
| 181 | registerWithSystemUser(); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 182 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 183 | putComponent(Recents.class, this); |
Winson Chung | 5abdceb | 2014-06-05 10:58:05 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 186 | @Override |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 187 | public void onBootCompleted() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 188 | mImpl.onBootCompleted(); |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 191 | /** |
| 192 | * Shows the Recents. |
| 193 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 194 | @Override |
| 195 | public void showRecents(boolean triggeredFromAltTab, View statusBarView) { |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 196 | if (proxyToOverridePackage(ACTION_SHOW_RECENTS)) { |
| 197 | return; |
| 198 | } |
| 199 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 200 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 201 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 202 | mImpl.showRecents(triggeredFromAltTab); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 203 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 204 | if (mSystemUserCallbacks != null) { |
| 205 | IRecentsNonSystemUserCallbacks callbacks = |
| 206 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 207 | if (callbacks != null) { |
| 208 | try { |
| 209 | callbacks.showRecents(triggeredFromAltTab); |
| 210 | } catch (RemoteException e) { |
| 211 | Log.e(TAG, "Callback failed", e); |
| 212 | } |
| 213 | } else { |
| 214 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 215 | } |
| 216 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 217 | } |
| 218 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 219 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 220 | /** |
| 221 | * Hides the Recents. |
| 222 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 223 | @Override |
| 224 | public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 225 | if (proxyToOverridePackage(ACTION_HIDE_RECENTS)) { |
| 226 | return; |
| 227 | } |
| 228 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 229 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 230 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 231 | mImpl.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 232 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 233 | if (mSystemUserCallbacks != null) { |
| 234 | IRecentsNonSystemUserCallbacks callbacks = |
| 235 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 236 | if (callbacks != null) { |
| 237 | try { |
| 238 | callbacks.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
| 239 | } catch (RemoteException e) { |
| 240 | Log.e(TAG, "Callback failed", e); |
| 241 | } |
| 242 | } else { |
| 243 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 244 | } |
| 245 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 248 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Toggles the Recents activity. |
| 251 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 252 | @Override |
| 253 | public void toggleRecents(Display display, int layoutDirection, View statusBarView) { |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 254 | if (proxyToOverridePackage(ACTION_TOGGLE_RECENTS)) { |
| 255 | return; |
| 256 | } |
| 257 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 258 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 259 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 260 | mImpl.toggleRecents(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 261 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 262 | if (mSystemUserCallbacks != null) { |
| 263 | IRecentsNonSystemUserCallbacks callbacks = |
| 264 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 265 | if (callbacks != null) { |
| 266 | try { |
| 267 | callbacks.toggleRecents(); |
| 268 | } catch (RemoteException e) { |
| 269 | Log.e(TAG, "Callback failed", e); |
| 270 | } |
| 271 | } else { |
| 272 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 273 | } |
| 274 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 277 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 278 | /** |
| 279 | * Preloads info for the Recents activity. |
| 280 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 281 | @Override |
| 282 | public void preloadRecents() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 283 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 284 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 285 | mImpl.preloadRecents(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 286 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 287 | if (mSystemUserCallbacks != null) { |
| 288 | IRecentsNonSystemUserCallbacks callbacks = |
| 289 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 290 | if (callbacks != null) { |
| 291 | try { |
| 292 | callbacks.preloadRecents(); |
| 293 | } catch (RemoteException e) { |
| 294 | Log.e(TAG, "Callback failed", e); |
| 295 | } |
| 296 | } else { |
| 297 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 298 | } |
Winson Chung | a278cae | 2015-06-09 13:51:13 -0700 | [diff] [blame] | 299 | } |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 300 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 303 | @Override |
| 304 | public void cancelPreloadingRecents() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 305 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 306 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 307 | mImpl.cancelPreloadingRecents(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 308 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 309 | if (mSystemUserCallbacks != null) { |
| 310 | IRecentsNonSystemUserCallbacks callbacks = |
| 311 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 312 | if (callbacks != null) { |
| 313 | try { |
| 314 | callbacks.cancelPreloadingRecents(); |
| 315 | } catch (RemoteException e) { |
| 316 | Log.e(TAG, "Callback failed", e); |
| 317 | } |
| 318 | } else { |
| 319 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 320 | } |
| 321 | } |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 325 | @Override |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 326 | public void dockTopTask() { |
| 327 | mImpl.dockTopTask(); |
| 328 | } |
| 329 | |
| 330 | @Override |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 331 | public void showNextAffiliatedTask() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 332 | mImpl.showNextAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 335 | @Override |
| 336 | public void showPrevAffiliatedTask() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 337 | mImpl.showPrevAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 340 | /** |
| 341 | * Updates on configuration change. |
| 342 | */ |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 343 | public void onConfigurationChanged(Configuration newConfig) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 344 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 345 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 346 | mImpl.onConfigurationChanged(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 347 | } else { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 348 | if (mSystemUserCallbacks != null) { |
| 349 | IRecentsNonSystemUserCallbacks callbacks = |
| 350 | mSystemUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 351 | if (callbacks != null) { |
| 352 | try { |
| 353 | callbacks.onConfigurationChanged(); |
| 354 | } catch (RemoteException e) { |
| 355 | Log.e(TAG, "Callback failed", e); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 356 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 357 | } else { |
| 358 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 359 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 360 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 363 | |
| 364 | /** |
| 365 | * Handle Recents activity visibility changed. |
| 366 | */ |
| 367 | public final void onBusEvent(final RecentsVisibilityChangedEvent event) { |
| 368 | int processUser = event.systemServicesProxy.getProcessUser(); |
| 369 | if (event.systemServicesProxy.isSystemUser(processUser)) { |
| 370 | mImpl.onVisibilityChanged(event.applicationContext, event.visible); |
| 371 | } else { |
| 372 | postToSystemUser(new Runnable() { |
| 373 | @Override |
| 374 | public void run() { |
| 375 | try { |
| 376 | mCallbacksToSystemUser.updateRecentsVisibility(event.visible); |
| 377 | } catch (RemoteException e) { |
| 378 | Log.e(TAG, "Callback failed", e); |
| 379 | } |
| 380 | } |
| 381 | }); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Handle screen pinning request. |
| 387 | */ |
| 388 | public final void onBusEvent(final ScreenPinningRequestEvent event) { |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 389 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 390 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 391 | mImpl.onStartScreenPinning(event.applicationContext); |
| 392 | } else { |
| 393 | postToSystemUser(new Runnable() { |
| 394 | @Override |
| 395 | public void run() { |
| 396 | try { |
| 397 | mCallbacksToSystemUser.startScreenPinning(); |
| 398 | } catch (RemoteException e) { |
| 399 | Log.e(TAG, "Callback failed", e); |
| 400 | } |
| 401 | } |
| 402 | }); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Attempts to register with the system user. |
| 408 | */ |
| 409 | private void registerWithSystemUser() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 410 | final int processUser = sSystemServicesProxy.getProcessUser(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 411 | postToSystemUser(new Runnable() { |
| 412 | @Override |
| 413 | public void run() { |
| 414 | try { |
| 415 | mCallbacksToSystemUser.registerNonSystemUserCallbacks(mImpl, processUser); |
| 416 | } catch (RemoteException e) { |
| 417 | Log.e(TAG, "Failed to register", e); |
| 418 | } |
| 419 | } |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Runs the runnable in the system user's Recents context, connecting to the service if |
| 425 | * necessary. |
| 426 | */ |
| 427 | private void postToSystemUser(final Runnable onConnectRunnable) { |
| 428 | mOnConnectRunnables.add(onConnectRunnable); |
| 429 | if (mCallbacksToSystemUser == null) { |
| 430 | Intent systemUserServiceIntent = new Intent(); |
| 431 | systemUserServiceIntent.setClass(mContext, RecentsSystemUserService.class); |
| 432 | boolean bound = mContext.bindServiceAsUser(systemUserServiceIntent, |
| 433 | mServiceConnectionToSystemUser, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM); |
| 434 | if (!bound) { |
| 435 | // Retry after a fixed duration |
| 436 | mHandler.postDelayed(new Runnable() { |
| 437 | @Override |
| 438 | public void run() { |
| 439 | registerWithSystemUser(); |
| 440 | } |
| 441 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
| 442 | } |
| 443 | } else { |
| 444 | runAndFlushOnConnectRunnables(); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Runs all the queued runnables after a service connection is made. |
| 450 | */ |
| 451 | private void runAndFlushOnConnectRunnables() { |
| 452 | for (Runnable r : mOnConnectRunnables) { |
| 453 | r.run(); |
| 454 | } |
| 455 | mOnConnectRunnables.clear(); |
| 456 | } |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 457 | |
| 458 | /** |
| 459 | * Attempts to proxy the following action to the override recents package. |
| 460 | * @return whether the proxying was successful |
| 461 | */ |
| 462 | private boolean proxyToOverridePackage(String action) { |
| 463 | if (mOverrideRecentsPackageName != null) { |
| 464 | Intent intent = new Intent(action); |
| 465 | intent.setPackage(mOverrideRecentsPackageName); |
| 466 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
| 467 | mContext.sendBroadcast(intent); |
| 468 | return true; |
| 469 | } |
| 470 | return false; |
| 471 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 472 | } |