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