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