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 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 21 | import android.content.ContentResolver; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 24 | import android.content.ServiceConnection; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 27 | import android.os.Build; |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 29 | import android.os.IBinder; |
| 30 | import android.os.RemoteException; |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 31 | import android.os.SystemProperties; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 32 | import android.os.UserHandle; |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 33 | import android.provider.Settings; |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 34 | import android.util.EventLog; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 35 | import android.util.Log; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 36 | import android.view.Display; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 37 | import android.view.View; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 38 | |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 39 | import com.android.systemui.EventLogConstants; |
| 40 | import com.android.systemui.EventLogTags; |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 41 | import com.android.systemui.RecentsComponent; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 42 | import com.android.systemui.SystemUI; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 43 | import com.android.systemui.recents.events.EventBus; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 44 | import com.android.systemui.recents.events.activity.DockingTopTaskEvent; |
| 45 | import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 46 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 47 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 48 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 49 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 50 | import com.android.systemui.recents.model.RecentsTaskLoader; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 51 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 52 | import java.util.ArrayList; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 53 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 54 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 55 | /** |
| 56 | * An implementation of the SystemUI recents component, which supports both system and secondary |
| 57 | * users. |
| 58 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 59 | public class Recents extends SystemUI |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 60 | implements RecentsComponent { |
| 61 | |
| 62 | private final static String TAG = "Recents"; |
| 63 | private final static boolean DEBUG = false; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 64 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 65 | public final static int EVENT_BUS_PRIORITY = 1; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 66 | public final static int BIND_TO_SYSTEM_USER_RETRY_DELAY = 5000; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 67 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 68 | // Purely for experimentation |
| 69 | private final static String RECENTS_OVERRIDE_SYSPROP_KEY = "persist.recents_override_pkg"; |
| 70 | private final static String ACTION_SHOW_RECENTS = "com.android.systemui.recents.ACTION_SHOW"; |
| 71 | private final static String ACTION_HIDE_RECENTS = "com.android.systemui.recents.ACTION_HIDE"; |
| 72 | private final static String ACTION_TOGGLE_RECENTS = "com.android.systemui.recents.ACTION_TOGGLE"; |
| 73 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 74 | private static SystemServicesProxy sSystemServicesProxy; |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 75 | private static RecentsDebugFlags sDebugFlags; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 76 | private static RecentsTaskLoader sTaskLoader; |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 77 | private static RecentsConfiguration sConfiguration; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 78 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 79 | // For experiments only, allows another package to handle recents if it is defined in the system |
| 80 | // properties. This is limited to show/toggle/hide, and does not tie into the ActivityManager, |
| 81 | // and does not reside in the home stack. |
| 82 | private String mOverrideRecentsPackageName; |
| 83 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 84 | private Handler mHandler; |
| 85 | private RecentsImpl mImpl; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 86 | private int mDraggingInRecentsCurrentUser; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 87 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 88 | // Only For system user, this is the callbacks instance we return to each secondary user |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 89 | private RecentsSystemUser mSystemToUserCallbacks; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 90 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 91 | // Only for secondary users, this is the callbacks instance provided by the system user to make |
| 92 | // calls back |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 93 | private IRecentsSystemUserCallbacks mUserToSystemCallbacks; |
Winson Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 94 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 95 | // The set of runnables to run after binding to the system user's service. |
| 96 | private final ArrayList<Runnable> mOnConnectRunnables = new ArrayList<>(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 97 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 98 | // Only for secondary users, this is the death handler for the binder from the system user |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 99 | private final IBinder.DeathRecipient mUserToSystemCallbacksDeathRcpt = new IBinder.DeathRecipient() { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 100 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 101 | public void binderDied() { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 102 | mUserToSystemCallbacks = null; |
| 103 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 104 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_SYSTEM_UNBOUND, |
| 105 | sSystemServicesProxy.getProcessUser()); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 106 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 107 | // Retry after a fixed duration |
| 108 | mHandler.postDelayed(new Runnable() { |
| 109 | @Override |
| 110 | public void run() { |
| 111 | registerWithSystemUser(); |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 112 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 113 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 114 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 115 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 116 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 117 | // Only for secondary users, this is the service connection we use to connect to the system user |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 118 | private final ServiceConnection mUserToSystemServiceConnection = new ServiceConnection() { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 119 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 120 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 121 | if (service != null) { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 122 | mUserToSystemCallbacks = IRecentsSystemUserCallbacks.Stub.asInterface( |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 123 | service); |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 124 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 125 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_SYSTEM_BOUND, |
| 126 | sSystemServicesProxy.getProcessUser()); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 127 | |
| 128 | // Listen for system user's death, so that we can reconnect later |
| 129 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 130 | service.linkToDeath(mUserToSystemCallbacksDeathRcpt, 0); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 131 | } catch (RemoteException e) { |
| 132 | Log.e(TAG, "Lost connection to (System) SystemUI", e); |
| 133 | } |
| 134 | |
| 135 | // Run each of the queued runnables |
| 136 | runAndFlushOnConnectRunnables(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 137 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 138 | |
| 139 | // Unbind ourselves now that we've registered our callbacks. The |
| 140 | // binder to the system user are still valid at this point. |
| 141 | mContext.unbindService(this); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 142 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 143 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 144 | @Override |
| 145 | public void onServiceDisconnected(ComponentName name) { |
| 146 | // Do nothing |
| 147 | } |
| 148 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 149 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 150 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 151 | * Returns the callbacks interface that non-system users can call. |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 152 | */ |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 153 | public IBinder getSystemUserCallbacks() { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 154 | return mSystemToUserCallbacks; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 157 | public static RecentsTaskLoader getTaskLoader() { |
| 158 | return sTaskLoader; |
| 159 | } |
| 160 | |
| 161 | public static SystemServicesProxy getSystemServices() { |
| 162 | return sSystemServicesProxy; |
| 163 | } |
| 164 | |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 165 | public static RecentsConfiguration getConfiguration() { |
| 166 | return sConfiguration; |
| 167 | } |
| 168 | |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 169 | public static RecentsDebugFlags getDebugFlags() { |
| 170 | return sDebugFlags; |
| 171 | } |
| 172 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 173 | @Override |
| 174 | public void start() { |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 175 | sDebugFlags = new RecentsDebugFlags(mContext); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 176 | sSystemServicesProxy = new SystemServicesProxy(mContext); |
| 177 | sTaskLoader = new RecentsTaskLoader(mContext); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 178 | sConfiguration = new RecentsConfiguration(mContext); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 179 | mHandler = new Handler(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 180 | mImpl = new RecentsImpl(mContext); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 181 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 182 | // Check if there is a recents override package |
| 183 | if ("userdebug".equals(Build.TYPE) || "eng".equals(Build.TYPE)) { |
| 184 | String cnStr = SystemProperties.get(RECENTS_OVERRIDE_SYSPROP_KEY); |
| 185 | if (!cnStr.isEmpty()) { |
| 186 | mOverrideRecentsPackageName = cnStr; |
| 187 | } |
| 188 | } |
| 189 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 190 | // Register with the event bus |
| 191 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 192 | EventBus.getDefault().register(sSystemServicesProxy, EVENT_BUS_PRIORITY); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 193 | EventBus.getDefault().register(sTaskLoader, EVENT_BUS_PRIORITY); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 194 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 195 | // Due to the fact that RecentsActivity is per-user, we need to establish and interface for |
| 196 | // the system user's Recents component to pass events (like show/hide/toggleRecents) to the |
| 197 | // secondary user, and vice versa (like visibility change, screen pinning). |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 198 | final int processUser = sSystemServicesProxy.getProcessUser(); |
| 199 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 200 | // For the system user, initialize an instance of the interface that we can pass to the |
| 201 | // secondary user |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 202 | mSystemToUserCallbacks = new RecentsSystemUser(mContext, mImpl); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 203 | } else { |
| 204 | // For the secondary user, bind to the primary user's service to get a persistent |
| 205 | // interface to register its implementation and to later update its state |
| 206 | registerWithSystemUser(); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 207 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 208 | putComponent(Recents.class, this); |
Winson Chung | 5abdceb | 2014-06-05 10:58:05 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 211 | @Override |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 212 | public void onBootCompleted() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 213 | mImpl.onBootCompleted(); |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 216 | /** |
| 217 | * Shows the Recents. |
| 218 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 219 | @Override |
| 220 | public void showRecents(boolean triggeredFromAltTab, View statusBarView) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 221 | // Ensure the device has been provisioned before allowing the user to interact with |
| 222 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 223 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 227 | if (proxyToOverridePackage(ACTION_SHOW_RECENTS)) { |
| 228 | return; |
| 229 | } |
| 230 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 231 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 232 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 233 | mImpl.showRecents(triggeredFromAltTab, false /* draggingInRecents */, |
| 234 | true /* animate */, false /* reloadTasks */); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 235 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 236 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 237 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 238 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 239 | if (callbacks != null) { |
| 240 | try { |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 241 | callbacks.showRecents(triggeredFromAltTab, false /* draggingInRecents */, |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 242 | true /* animate */, false /* reloadTasks */); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 243 | } catch (RemoteException e) { |
| 244 | Log.e(TAG, "Callback failed", e); |
| 245 | } |
| 246 | } else { |
| 247 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 248 | } |
| 249 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 250 | } |
| 251 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 252 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 253 | /** |
| 254 | * Hides the Recents. |
| 255 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 256 | @Override |
| 257 | public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 258 | // Ensure the device has been provisioned before allowing the user to interact with |
| 259 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 260 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 261 | return; |
| 262 | } |
| 263 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 264 | if (proxyToOverridePackage(ACTION_HIDE_RECENTS)) { |
| 265 | return; |
| 266 | } |
| 267 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 268 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 269 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 270 | mImpl.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 271 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 272 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 273 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 274 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 275 | if (callbacks != null) { |
| 276 | try { |
| 277 | callbacks.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
| 278 | } catch (RemoteException e) { |
| 279 | Log.e(TAG, "Callback failed", e); |
| 280 | } |
| 281 | } else { |
| 282 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 283 | } |
| 284 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 285 | } |
| 286 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 287 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Toggles the Recents activity. |
| 290 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 291 | @Override |
| 292 | public void toggleRecents(Display display, int layoutDirection, View statusBarView) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 293 | // Ensure the device has been provisioned before allowing the user to interact with |
| 294 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 295 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 299 | if (proxyToOverridePackage(ACTION_TOGGLE_RECENTS)) { |
| 300 | return; |
| 301 | } |
| 302 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 303 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 304 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 305 | mImpl.toggleRecents(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 306 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 307 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 308 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 309 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 310 | if (callbacks != null) { |
| 311 | try { |
| 312 | callbacks.toggleRecents(); |
| 313 | } catch (RemoteException e) { |
| 314 | Log.e(TAG, "Callback failed", e); |
| 315 | } |
| 316 | } else { |
| 317 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 318 | } |
| 319 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 320 | } |
| 321 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 322 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 323 | /** |
| 324 | * Preloads info for the Recents activity. |
| 325 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 326 | @Override |
| 327 | public void preloadRecents() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 328 | // Ensure the device has been provisioned before allowing the user to interact with |
| 329 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 330 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 334 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 335 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 336 | mImpl.preloadRecents(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 337 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 338 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 339 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 340 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 341 | if (callbacks != null) { |
| 342 | try { |
| 343 | callbacks.preloadRecents(); |
| 344 | } catch (RemoteException e) { |
| 345 | Log.e(TAG, "Callback failed", e); |
| 346 | } |
| 347 | } else { |
| 348 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 349 | } |
Winson Chung | a278cae | 2015-06-09 13:51:13 -0700 | [diff] [blame] | 350 | } |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 351 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 354 | @Override |
| 355 | public void cancelPreloadingRecents() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 356 | // Ensure the device has been provisioned before allowing the user to interact with |
| 357 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 358 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 362 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 363 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 364 | mImpl.cancelPreloadingRecents(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 365 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 366 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 367 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 368 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 369 | if (callbacks != null) { |
| 370 | try { |
| 371 | callbacks.cancelPreloadingRecents(); |
| 372 | } catch (RemoteException e) { |
| 373 | Log.e(TAG, "Callback failed", e); |
| 374 | } |
| 375 | } else { |
| 376 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 377 | } |
| 378 | } |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 382 | @Override |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 383 | public boolean dockTopTask(int dragMode, int stackCreateMode, Rect initialBounds) { |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 384 | // Ensure the device has been provisioned before allowing the user to interact with |
| 385 | // recents |
| 386 | if (!isUserSetup()) { |
| 387 | return false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 388 | } |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 389 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 390 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 391 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 392 | ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask(); |
| 393 | boolean screenPinningActive = ssp.isScreenPinningActive(); |
| 394 | boolean isTopTaskHome = topTask != null && SystemServicesProxy.isHomeStack(topTask.stackId); |
| 395 | if (topTask != null && !isTopTaskHome && !screenPinningActive) { |
| 396 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
| 397 | mImpl.dockTopTask(topTask.id, dragMode, stackCreateMode, initialBounds); |
| 398 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 399 | if (mSystemToUserCallbacks != null) { |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 400 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 401 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 402 | if (callbacks != null) { |
| 403 | try { |
| 404 | callbacks.dockTopTask(topTask.id, dragMode, stackCreateMode, |
| 405 | initialBounds); |
| 406 | } catch (RemoteException e) { |
| 407 | Log.e(TAG, "Callback failed", e); |
| 408 | } |
| 409 | } else { |
| 410 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 411 | } |
| 412 | } |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 413 | } |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 414 | mDraggingInRecentsCurrentUser = currentUser; |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 415 | return true; |
| 416 | } |
| 417 | return false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void onDraggingInRecents(float distanceFromTop) { |
| 422 | if (sSystemServicesProxy.isSystemUser(mDraggingInRecentsCurrentUser)) { |
| 423 | mImpl.onDraggingInRecents(distanceFromTop); |
| 424 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 425 | if (mSystemToUserCallbacks != null) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 426 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 427 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser( |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 428 | mDraggingInRecentsCurrentUser); |
| 429 | if (callbacks != null) { |
| 430 | try { |
| 431 | callbacks.onDraggingInRecents(distanceFromTop); |
| 432 | } catch (RemoteException e) { |
| 433 | Log.e(TAG, "Callback failed", e); |
| 434 | } |
| 435 | } else { |
| 436 | Log.e(TAG, "No SystemUI callbacks found for user: " |
| 437 | + mDraggingInRecentsCurrentUser); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void onDraggingInRecentsEnded(float velocity) { |
| 445 | if (sSystemServicesProxy.isSystemUser(mDraggingInRecentsCurrentUser)) { |
| 446 | mImpl.onDraggingInRecentsEnded(velocity); |
| 447 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 448 | if (mSystemToUserCallbacks != null) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 449 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 450 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser( |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 451 | mDraggingInRecentsCurrentUser); |
| 452 | if (callbacks != null) { |
| 453 | try { |
| 454 | callbacks.onDraggingInRecentsEnded(velocity); |
| 455 | } catch (RemoteException e) { |
| 456 | Log.e(TAG, "Callback failed", e); |
| 457 | } |
| 458 | } else { |
| 459 | Log.e(TAG, "No SystemUI callbacks found for user: " |
| 460 | + mDraggingInRecentsCurrentUser); |
| 461 | } |
| 462 | } |
| 463 | } |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | @Override |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 467 | public void showNextAffiliatedTask() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 468 | // Ensure the device has been provisioned before allowing the user to interact with |
| 469 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 470 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 471 | return; |
| 472 | } |
| 473 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 474 | mImpl.showNextAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 477 | @Override |
| 478 | public void showPrevAffiliatedTask() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 479 | // Ensure the device has been provisioned before allowing the user to interact with |
| 480 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 481 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 482 | return; |
| 483 | } |
| 484 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 485 | mImpl.showPrevAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 488 | /** |
| 489 | * Updates on configuration change. |
| 490 | */ |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 491 | public void onConfigurationChanged(Configuration newConfig) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 492 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 493 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 494 | mImpl.onConfigurationChanged(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 495 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 496 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 497 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 498 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 499 | if (callbacks != null) { |
| 500 | try { |
| 501 | callbacks.onConfigurationChanged(); |
| 502 | } catch (RemoteException e) { |
| 503 | Log.e(TAG, "Callback failed", e); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 504 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 505 | } else { |
| 506 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 507 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 508 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * Handle Recents activity visibility changed. |
| 514 | */ |
| 515 | public final void onBusEvent(final RecentsVisibilityChangedEvent event) { |
| 516 | int processUser = event.systemServicesProxy.getProcessUser(); |
| 517 | if (event.systemServicesProxy.isSystemUser(processUser)) { |
| 518 | mImpl.onVisibilityChanged(event.applicationContext, event.visible); |
| 519 | } else { |
| 520 | postToSystemUser(new Runnable() { |
| 521 | @Override |
| 522 | public void run() { |
| 523 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 524 | mUserToSystemCallbacks.updateRecentsVisibility(event.visible); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 525 | } catch (RemoteException e) { |
| 526 | Log.e(TAG, "Callback failed", e); |
| 527 | } |
| 528 | } |
| 529 | }); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Handle screen pinning request. |
| 535 | */ |
| 536 | public final void onBusEvent(final ScreenPinningRequestEvent event) { |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 537 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 538 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 539 | mImpl.onStartScreenPinning(event.applicationContext); |
| 540 | } else { |
| 541 | postToSystemUser(new Runnable() { |
| 542 | @Override |
| 543 | public void run() { |
| 544 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 545 | mUserToSystemCallbacks.startScreenPinning(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 546 | } catch (RemoteException e) { |
| 547 | Log.e(TAG, "Callback failed", e); |
| 548 | } |
| 549 | } |
| 550 | }); |
| 551 | } |
| 552 | } |
| 553 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 554 | public final void onBusEvent(final RecentsDrawnEvent event) { |
| 555 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 556 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 557 | postToSystemUser(new Runnable() { |
| 558 | @Override |
| 559 | public void run() { |
| 560 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 561 | mUserToSystemCallbacks.sendRecentsDrawnEvent(); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 562 | } catch (RemoteException e) { |
| 563 | Log.e(TAG, "Callback failed", e); |
| 564 | } |
| 565 | } |
| 566 | }); |
| 567 | } |
| 568 | } |
| 569 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 570 | public final void onBusEvent(final DockingTopTaskEvent event) { |
| 571 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 572 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 573 | postToSystemUser(new Runnable() { |
| 574 | @Override |
| 575 | public void run() { |
| 576 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 577 | mUserToSystemCallbacks.sendDockingTopTaskEvent(event.dragMode); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 578 | } catch (RemoteException e) { |
| 579 | Log.e(TAG, "Callback failed", e); |
| 580 | } |
| 581 | } |
| 582 | }); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | public final void onBusEvent(final RecentsActivityStartingEvent event) { |
| 587 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 588 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 589 | postToSystemUser(new Runnable() { |
| 590 | @Override |
| 591 | public void run() { |
| 592 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 593 | mUserToSystemCallbacks.sendLaunchRecentsEvent(); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 594 | } catch (RemoteException e) { |
| 595 | Log.e(TAG, "Callback failed", e); |
| 596 | } |
| 597 | } |
| 598 | }); |
| 599 | } |
| 600 | } |
| 601 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 602 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 603 | * Attempts to register with the system user. |
| 604 | */ |
| 605 | private void registerWithSystemUser() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 606 | final int processUser = sSystemServicesProxy.getProcessUser(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 607 | postToSystemUser(new Runnable() { |
| 608 | @Override |
| 609 | public void run() { |
| 610 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 611 | mUserToSystemCallbacks.registerNonSystemUserCallbacks( |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 612 | new RecentsImplProxy(mImpl), processUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 613 | } catch (RemoteException e) { |
| 614 | Log.e(TAG, "Failed to register", e); |
| 615 | } |
| 616 | } |
| 617 | }); |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Runs the runnable in the system user's Recents context, connecting to the service if |
| 622 | * necessary. |
| 623 | */ |
| 624 | private void postToSystemUser(final Runnable onConnectRunnable) { |
| 625 | mOnConnectRunnables.add(onConnectRunnable); |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 626 | if (mUserToSystemCallbacks == null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 627 | Intent systemUserServiceIntent = new Intent(); |
| 628 | systemUserServiceIntent.setClass(mContext, RecentsSystemUserService.class); |
| 629 | boolean bound = mContext.bindServiceAsUser(systemUserServiceIntent, |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame^] | 630 | mUserToSystemServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM); |
| 631 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 632 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_BIND_SERVICE, |
| 633 | sSystemServicesProxy.getProcessUser()); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 634 | if (!bound) { |
| 635 | // Retry after a fixed duration |
| 636 | mHandler.postDelayed(new Runnable() { |
| 637 | @Override |
| 638 | public void run() { |
| 639 | registerWithSystemUser(); |
| 640 | } |
| 641 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
| 642 | } |
| 643 | } else { |
| 644 | runAndFlushOnConnectRunnables(); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Runs all the queued runnables after a service connection is made. |
| 650 | */ |
| 651 | private void runAndFlushOnConnectRunnables() { |
| 652 | for (Runnable r : mOnConnectRunnables) { |
| 653 | r.run(); |
| 654 | } |
| 655 | mOnConnectRunnables.clear(); |
| 656 | } |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 657 | |
| 658 | /** |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 659 | * @return whether this device is provisioned and the current user is set up. |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 660 | */ |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 661 | private boolean isUserSetup() { |
| 662 | ContentResolver cr = mContext.getContentResolver(); |
| 663 | return (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) != 0) && |
| 664 | (Settings.Secure.getInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 0) != 0); |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 668 | * Attempts to proxy the following action to the override recents package. |
| 669 | * @return whether the proxying was successful |
| 670 | */ |
| 671 | private boolean proxyToOverridePackage(String action) { |
| 672 | if (mOverrideRecentsPackageName != null) { |
| 673 | Intent intent = new Intent(action); |
| 674 | intent.setPackage(mOverrideRecentsPackageName); |
| 675 | intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
| 676 | mContext.sendBroadcast(intent); |
| 677 | return true; |
| 678 | } |
| 679 | return false; |
| 680 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 681 | } |