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 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 22 | import static com.android.systemui.statusbar.phone.StatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS; |
| 23 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 25 | import android.app.trust.TrustManager; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 27 | import android.content.ContentResolver; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 30 | import android.content.ServiceConnection; |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 31 | import android.content.pm.ActivityInfo; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Winson Chung | 6519c1b | 2017-10-13 17:12:56 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Muyuan Li | a212999 | 2016-03-03 18:30:39 -0800 | [diff] [blame] | 34 | import android.graphics.Point; |
Jorim Jaggi | 9ea2f7b | 2015-11-23 18:08:28 -0800 | [diff] [blame] | 35 | import android.graphics.Rect; |
Muyuan Li | a212999 | 2016-03-03 18:30:39 -0800 | [diff] [blame] | 36 | import android.hardware.display.DisplayManager; |
Jim Miller | a237a31 | 2014-11-06 18:05:59 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 38 | import android.os.IBinder; |
| 39 | import android.os.RemoteException; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 41 | import android.provider.Settings; |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 42 | import android.util.EventLog; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 43 | import android.util.Log; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 44 | import android.view.Display; |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 45 | import android.widget.Toast; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 46 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 47 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 48 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 49 | import com.android.systemui.Dependency; |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 50 | import com.android.systemui.EventLogConstants; |
| 51 | import com.android.systemui.EventLogTags; |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 52 | import com.android.systemui.OverviewProxyService; |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 53 | import com.android.systemui.R; |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 54 | import com.android.systemui.RecentsComponent; |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 55 | import com.android.systemui.SystemUIApplication; |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 56 | import com.android.systemui.shared.recents.IOverviewProxy; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 57 | import com.android.systemui.SystemUI; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.events.EventBus; |
Winson | 003eda6 | 2016-03-11 14:56:00 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Matthew Ng | 534e854 | 2017-10-16 14:34:52 -0700 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.DockedTopTaskEvent; |
Matthew Ng | c422f80 | 2017-08-02 14:00:59 -0700 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 64 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 65 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 66 | import com.android.systemui.recents.events.component.SetWaitingForTransitionStartEvent; |
Winson | 675c5d8 | 2016-08-23 17:12:22 -0700 | [diff] [blame] | 67 | import com.android.systemui.recents.events.component.ShowUserToastEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 68 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 6519c1b | 2017-10-13 17:12:56 -0700 | [diff] [blame] | 70 | import com.android.systemui.shared.recents.model.RecentsTaskLoader; |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 71 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 72 | import com.android.systemui.stackdivider.Divider; |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 73 | import com.android.systemui.statusbar.CommandQueue; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 74 | |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 75 | import com.android.systemui.statusbar.phone.StatusBar; |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 76 | import java.io.FileDescriptor; |
| 77 | import java.io.PrintWriter; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Manu Cornet | 906a3a8 | 2016-11-04 06:58:15 -0700 | [diff] [blame] | 79 | import java.util.HashSet; |
| 80 | import java.util.Set; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 81 | |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 82 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 83 | /** |
| 84 | * An implementation of the SystemUI recents component, which supports both system and secondary |
| 85 | * users. |
| 86 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 87 | public class Recents extends SystemUI |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 88 | implements RecentsComponent, CommandQueue.Callbacks { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 89 | |
| 90 | private final static String TAG = "Recents"; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 91 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 92 | public final static int EVENT_BUS_PRIORITY = 1; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 93 | public final static int BIND_TO_SYSTEM_USER_RETRY_DELAY = 5000; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 94 | |
Manu Cornet | 906a3a8 | 2016-11-04 06:58:15 -0700 | [diff] [blame] | 95 | public final static Set<String> RECENTS_ACTIVITIES = new HashSet<>(); |
| 96 | static { |
| 97 | RECENTS_ACTIVITIES.add(RecentsImpl.RECENTS_ACTIVITY); |
Manu Cornet | 906a3a8 | 2016-11-04 06:58:15 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 100 | private static final String COUNTER_WINDOW_SUPPORTED = "window_enter_supported"; |
| 101 | private static final String COUNTER_WINDOW_UNSUPPORTED = "window_enter_unsupported"; |
| 102 | private static final String COUNTER_WINDOW_INCOMPATIBLE = "window_enter_incompatible"; |
| 103 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 104 | private static SystemServicesProxy sSystemServicesProxy; |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 105 | private static RecentsDebugFlags sDebugFlags; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 106 | private static RecentsTaskLoader sTaskLoader; |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 107 | private static RecentsConfiguration sConfiguration; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 108 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 109 | private OverviewProxyService mOverviewProxyService; |
| 110 | |
Winson Chung | 501d59d | 2016-10-05 17:49:09 +0000 | [diff] [blame] | 111 | private Handler mHandler; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 112 | private RecentsImpl mImpl; |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 113 | private TrustManager mTrustManager; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 114 | private int mDraggingInRecentsCurrentUser; |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 115 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 116 | // 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] | 117 | private RecentsSystemUser mSystemToUserCallbacks; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 118 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 119 | // Only for secondary users, this is the callbacks instance provided by the system user to make |
| 120 | // calls back |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 121 | private IRecentsSystemUserCallbacks mUserToSystemCallbacks; |
Winson Chung | b44c24f | 2014-04-09 15:17:43 -0700 | [diff] [blame] | 122 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 123 | // The set of runnables to run after binding to the system user's service. |
| 124 | private final ArrayList<Runnable> mOnConnectRunnables = new ArrayList<>(); |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 125 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 126 | // 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] | 127 | private final IBinder.DeathRecipient mUserToSystemCallbacksDeathRcpt = new IBinder.DeathRecipient() { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 128 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 129 | public void binderDied() { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 130 | mUserToSystemCallbacks = null; |
| 131 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 132 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_SYSTEM_UNBOUND, |
| 133 | sSystemServicesProxy.getProcessUser()); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 134 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 135 | // Retry after a fixed duration |
| 136 | mHandler.postDelayed(new Runnable() { |
| 137 | @Override |
| 138 | public void run() { |
| 139 | registerWithSystemUser(); |
Winson Chung | 0eae557 | 2014-12-11 11:04:19 -0800 | [diff] [blame] | 140 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 141 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
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 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 144 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 145 | // 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] | 146 | private final ServiceConnection mUserToSystemServiceConnection = new ServiceConnection() { |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 147 | @Override |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 148 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 149 | if (service != null) { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 150 | mUserToSystemCallbacks = IRecentsSystemUserCallbacks.Stub.asInterface( |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 151 | service); |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 152 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 153 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_SYSTEM_BOUND, |
| 154 | sSystemServicesProxy.getProcessUser()); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 155 | |
| 156 | // Listen for system user's death, so that we can reconnect later |
| 157 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 158 | service.linkToDeath(mUserToSystemCallbacksDeathRcpt, 0); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 159 | } catch (RemoteException e) { |
| 160 | Log.e(TAG, "Lost connection to (System) SystemUI", e); |
| 161 | } |
| 162 | |
| 163 | // Run each of the queued runnables |
| 164 | runAndFlushOnConnectRunnables(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 165 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 166 | |
| 167 | // Unbind ourselves now that we've registered our callbacks. The |
| 168 | // binder to the system user are still valid at this point. |
| 169 | mContext.unbindService(this); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 170 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 171 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 172 | @Override |
| 173 | public void onServiceDisconnected(ComponentName name) { |
| 174 | // Do nothing |
| 175 | } |
| 176 | }; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 177 | |
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 | * Returns the callbacks interface that non-system users can call. |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 180 | */ |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 181 | public IBinder getSystemUserCallbacks() { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 182 | return mSystemToUserCallbacks; |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 185 | public static RecentsTaskLoader getTaskLoader() { |
| 186 | return sTaskLoader; |
| 187 | } |
| 188 | |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 189 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 190 | public static SystemServicesProxy getSystemServices() { |
| 191 | return sSystemServicesProxy; |
| 192 | } |
| 193 | |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 194 | public static RecentsConfiguration getConfiguration() { |
| 195 | return sConfiguration; |
| 196 | } |
| 197 | |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 198 | public static RecentsDebugFlags getDebugFlags() { |
| 199 | return sDebugFlags; |
| 200 | } |
| 201 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 202 | @Override |
| 203 | public void start() { |
Winson Chung | 6519c1b | 2017-10-13 17:12:56 -0700 | [diff] [blame] | 204 | final Resources res = mContext.getResources(); |
| 205 | final int defaultTaskBarBackgroundColor = |
| 206 | mContext.getColor(R.color.recents_task_bar_default_background_color); |
| 207 | final int defaultTaskViewBackgroundColor = |
| 208 | mContext.getColor(R.color.recents_task_view_default_background_color); |
Winson Chung | 247f1d4 | 2017-10-06 15:53:08 -0700 | [diff] [blame] | 209 | sDebugFlags = new RecentsDebugFlags(); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 210 | sSystemServicesProxy = SystemServicesProxy.getInstance(mContext); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 211 | sConfiguration = new RecentsConfiguration(mContext); |
Winson Chung | 6519c1b | 2017-10-13 17:12:56 -0700 | [diff] [blame] | 212 | sTaskLoader = new RecentsTaskLoader(mContext, |
| 213 | // TODO: Once we start building the AAR, move these into the loader |
| 214 | res.getInteger(R.integer.config_recents_max_thumbnail_count), |
| 215 | res.getInteger(R.integer.config_recents_max_icon_count), |
| 216 | res.getInteger(R.integer.recents_svelte_level)); |
| 217 | sTaskLoader.setDefaultColors(defaultTaskBarBackgroundColor, defaultTaskViewBackgroundColor); |
Winson Chung | 501d59d | 2016-10-05 17:49:09 +0000 | [diff] [blame] | 218 | mHandler = new Handler(); |
Sid Soundararajan | 0e88d32 | 2017-03-07 15:37:30 -0800 | [diff] [blame] | 219 | mImpl = new RecentsImpl(mContext); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 220 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 221 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 222 | // Register with the event bus |
| 223 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 224 | EventBus.getDefault().register(sSystemServicesProxy, EVENT_BUS_PRIORITY); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 225 | EventBus.getDefault().register(sTaskLoader, EVENT_BUS_PRIORITY); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 226 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 227 | // Due to the fact that RecentsActivity is per-user, we need to establish and interface for |
| 228 | // the system user's Recents component to pass events (like show/hide/toggleRecents) to the |
| 229 | // secondary user, and vice versa (like visibility change, screen pinning). |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 230 | final int processUser = sSystemServicesProxy.getProcessUser(); |
| 231 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 232 | // For the system user, initialize an instance of the interface that we can pass to the |
| 233 | // secondary user |
Winson Chung | 0c7592f | 2017-02-06 09:04:07 -0800 | [diff] [blame] | 234 | getComponent(CommandQueue.class).addCallbacks(this); |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 235 | mSystemToUserCallbacks = new RecentsSystemUser(mContext, mImpl); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 236 | } else { |
| 237 | // For the secondary user, bind to the primary user's service to get a persistent |
| 238 | // interface to register its implementation and to later update its state |
| 239 | registerWithSystemUser(); |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 240 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 241 | putComponent(Recents.class, this); |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 242 | |
| 243 | mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE); |
Winson Chung | 5abdceb | 2014-06-05 10:58:05 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 246 | @Override |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 247 | public void onBootCompleted() { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 248 | mImpl.onBootCompleted(); |
Winson Chung | 8bf05af | 2014-09-29 13:42:49 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 251 | /** |
| 252 | * Shows the Recents. |
| 253 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 254 | @Override |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 255 | public void showRecentApps(boolean triggeredFromAltTab) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 256 | // Ensure the device has been provisioned before allowing the user to interact with |
| 257 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 258 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 262 | IOverviewProxy overviewProxy = mOverviewProxyService.getProxy(); |
| 263 | if (overviewProxy != null) { |
| 264 | try { |
| 265 | overviewProxy.onOverviewShown(triggeredFromAltTab); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 266 | return; |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 267 | } catch (RemoteException e) { |
| 268 | Log.e(TAG, "Failed to send overview show event to launcher.", e); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 272 | ActivityManagerWrapper.getInstance().closeSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 273 | int recentsGrowTarget = getComponent(Divider.class).getView().growsRecents(); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 274 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 275 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Jorim Jaggi | 435b2e4 | 2015-11-24 15:09:30 -0800 | [diff] [blame] | 276 | mImpl.showRecents(triggeredFromAltTab, false /* draggingInRecents */, |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 277 | true /* animate */, recentsGrowTarget); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 278 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 279 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 280 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 281 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 282 | if (callbacks != null) { |
| 283 | try { |
Jorim Jaggi | bb42a46 | 2015-11-20 16:27:16 -0800 | [diff] [blame] | 284 | callbacks.showRecents(triggeredFromAltTab, false /* draggingInRecents */, |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 285 | true /* animate */, recentsGrowTarget); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 286 | } catch (RemoteException e) { |
| 287 | Log.e(TAG, "Callback failed", e); |
| 288 | } |
| 289 | } else { |
| 290 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 291 | } |
| 292 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 295 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Hides the Recents. |
| 298 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 299 | @Override |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 300 | public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 301 | // Ensure the device has been provisioned before allowing the user to interact with |
| 302 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 303 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 304 | return; |
| 305 | } |
| 306 | |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 307 | IOverviewProxy overviewProxy = mOverviewProxyService.getProxy(); |
| 308 | if (overviewProxy != null) { |
| 309 | try { |
| 310 | overviewProxy.onOverviewHidden(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 311 | return; |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 312 | } catch (RemoteException e) { |
| 313 | Log.e(TAG, "Failed to send overview hide event to launcher.", e); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 317 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 318 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 319 | mImpl.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 320 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 321 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 322 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 323 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 324 | if (callbacks != null) { |
| 325 | try { |
| 326 | callbacks.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
| 327 | } catch (RemoteException e) { |
| 328 | Log.e(TAG, "Callback failed", e); |
| 329 | } |
| 330 | } else { |
| 331 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 332 | } |
| 333 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 334 | } |
| 335 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 336 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 337 | /** |
| 338 | * Toggles the Recents activity. |
| 339 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 340 | @Override |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 341 | public void toggleRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 342 | // Ensure the device has been provisioned before allowing the user to interact with |
| 343 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 344 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 348 | // If connected to launcher service, let it handle the toggle logic |
| 349 | IOverviewProxy overviewProxy = mOverviewProxyService.getProxy(); |
| 350 | if (overviewProxy != null) { |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 351 | final Runnable toggleRecents = () -> { |
| 352 | try { |
| 353 | if (mOverviewProxyService.getProxy() != null) { |
| 354 | mOverviewProxyService.getProxy().onOverviewToggle(); |
| 355 | } |
| 356 | } catch (RemoteException e) { |
| 357 | Log.e(TAG, "Cannot send toggle recents through proxy service.", e); |
| 358 | } |
| 359 | }; |
| 360 | // Preload only if device for current user is unlocked |
| 361 | final StatusBar statusBar = getComponent(StatusBar.class); |
| 362 | if (statusBar != null && statusBar.isKeyguardShowing()) { |
| 363 | statusBar.executeRunnableDismissingKeyguard(() -> { |
| 364 | // Flush trustmanager before checking device locked per user |
| 365 | mTrustManager.reportKeyguardShowingChanged(); |
| 366 | mHandler.post(toggleRecents); |
| 367 | }, null, true /* dismissShade */, false /* afterKeyguardGone */, |
| 368 | true /* deferred */); |
| 369 | } else { |
| 370 | toggleRecents.run(); |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 371 | } |
Winson Chung | e3dd59c | 2018-04-02 15:28:40 -0700 | [diff] [blame] | 372 | return; |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 375 | int growTarget = getComponent(Divider.class).getView().growsRecents(); |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 376 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 377 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 378 | mImpl.toggleRecents(growTarget); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 379 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 380 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 381 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 382 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 383 | if (callbacks != null) { |
| 384 | try { |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 385 | callbacks.toggleRecents(growTarget); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 386 | } catch (RemoteException e) { |
| 387 | Log.e(TAG, "Callback failed", e); |
| 388 | } |
| 389 | } else { |
| 390 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 391 | } |
| 392 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 393 | } |
| 394 | } |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 395 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 396 | /** |
| 397 | * Preloads info for the Recents activity. |
| 398 | */ |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 399 | @Override |
Winson Chung | ebe1ba1 | 2017-05-18 15:47:14 -0700 | [diff] [blame] | 400 | public void preloadRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 401 | // Ensure the device has been provisioned before allowing the user to interact with |
| 402 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 403 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 404 | return; |
| 405 | } |
| 406 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 407 | if (mOverviewProxyService.getProxy() != null) { |
| 408 | // TODO: Proxy to Launcher |
| 409 | return; |
| 410 | } |
| 411 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 412 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 413 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 414 | mImpl.preloadRecents(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 415 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 416 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 417 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 418 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 419 | if (callbacks != null) { |
| 420 | try { |
| 421 | callbacks.preloadRecents(); |
| 422 | } catch (RemoteException e) { |
| 423 | Log.e(TAG, "Callback failed", e); |
| 424 | } |
| 425 | } else { |
| 426 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 427 | } |
Winson Chung | a278cae | 2015-06-09 13:51:13 -0700 | [diff] [blame] | 428 | } |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 429 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 432 | @Override |
Jason Monk | 764da99 | 2017-02-02 14:11:20 -0500 | [diff] [blame] | 433 | public void cancelPreloadRecentApps() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 434 | // Ensure the device has been provisioned before allowing the user to interact with |
| 435 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 436 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 440 | if (mOverviewProxyService.getProxy() != null) { |
| 441 | // TODO: Proxy to Launcher |
| 442 | return; |
| 443 | } |
| 444 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 445 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 446 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 447 | mImpl.cancelPreloadingRecents(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 448 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 449 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 450 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 451 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 452 | if (callbacks != null) { |
| 453 | try { |
| 454 | callbacks.cancelPreloadingRecents(); |
| 455 | } catch (RemoteException e) { |
| 456 | Log.e(TAG, "Callback failed", e); |
| 457 | } |
| 458 | } else { |
| 459 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 460 | } |
| 461 | } |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 465 | @Override |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 466 | public boolean splitPrimaryTask(int dragMode, int stackCreateMode, Rect initialBounds, |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 467 | int metricsDockAction) { |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 468 | // Ensure the device has been provisioned before allowing the user to interact with |
| 469 | // recents |
| 470 | if (!isUserSetup()) { |
| 471 | return false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 472 | } |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 473 | |
Muyuan Li | a212999 | 2016-03-03 18:30:39 -0800 | [diff] [blame] | 474 | Point realSize = new Point(); |
| 475 | if (initialBounds == null) { |
| 476 | mContext.getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY) |
| 477 | .getRealSize(realSize); |
| 478 | initialBounds = new Rect(0, 0, realSize.x, realSize.y); |
| 479 | } |
| 480 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 481 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
Winson Chung | b05b398 | 2017-11-01 18:02:43 -0700 | [diff] [blame] | 482 | ActivityManager.RunningTaskInfo runningTask = |
| 483 | ActivityManagerWrapper.getInstance().getRunningTask(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 484 | final int activityType = runningTask != null |
| 485 | ? runningTask.configuration.windowConfiguration.getActivityType() |
| 486 | : ACTIVITY_TYPE_UNDEFINED; |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 487 | boolean screenPinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 488 | boolean isRunningTaskInHomeOrRecentsStack = |
| 489 | activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 490 | if (runningTask != null && !isRunningTaskInHomeOrRecentsStack && !screenPinningActive) { |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 491 | logDockAttempt(mContext, runningTask.topActivity, runningTask.resizeMode); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 492 | if (runningTask.supportsSplitScreenMultiWindow) { |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 493 | if (metricsDockAction != -1) { |
| 494 | MetricsLogger.action(mContext, metricsDockAction, |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 495 | runningTask.topActivity.flattenToShortString()); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 496 | } |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 497 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 498 | mImpl.splitPrimaryTask(runningTask.id, dragMode, stackCreateMode, |
| 499 | initialBounds); |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 500 | } else { |
| 501 | if (mSystemToUserCallbacks != null) { |
| 502 | IRecentsNonSystemUserCallbacks callbacks = |
| 503 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 504 | if (callbacks != null) { |
| 505 | try { |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 506 | callbacks.splitPrimaryTask(runningTask.id, dragMode, |
| 507 | stackCreateMode, initialBounds); |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 508 | } catch (RemoteException e) { |
| 509 | Log.e(TAG, "Callback failed", e); |
| 510 | } |
| 511 | } else { |
| 512 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 513 | } |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 514 | } |
| 515 | } |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 516 | mDraggingInRecentsCurrentUser = currentUser; |
Winson Chung | 68f5430 | 2018-03-29 18:36:17 -0700 | [diff] [blame] | 517 | |
| 518 | if (mOverviewProxyService.getProxy() != null) { |
| 519 | // The overview service is handling split screen, so just skip the wait for the |
| 520 | // first draw and notify the divider to start animating now |
| 521 | EventBus.getDefault().post(new RecentsDrawnEvent()); |
| 522 | } |
| 523 | |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 524 | return true; |
| 525 | } else { |
Winson | 675c5d8 | 2016-08-23 17:12:22 -0700 | [diff] [blame] | 526 | EventBus.getDefault().send(new ShowUserToastEvent( |
Winson Chung | 80f7b01 | 2017-03-28 21:33:28 -0700 | [diff] [blame] | 527 | R.string.dock_non_resizeble_failed_to_dock_text, Toast.LENGTH_SHORT)); |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 528 | return false; |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 529 | } |
Jorim Jaggi | aa6c574 | 2016-03-01 14:10:14 +0100 | [diff] [blame] | 530 | } else { |
| 531 | return false; |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 532 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 535 | public static void logDockAttempt(Context ctx, ComponentName activity, int resizeMode) { |
| 536 | if (resizeMode == ActivityInfo.RESIZE_MODE_UNRESIZEABLE) { |
| 537 | MetricsLogger.action(ctx, MetricsEvent.ACTION_WINDOW_DOCK_UNRESIZABLE, |
| 538 | activity.flattenToShortString()); |
| 539 | } |
| 540 | MetricsLogger.count(ctx, getMetricsCounterForResizeMode(resizeMode), 1); |
| 541 | } |
| 542 | |
| 543 | private static String getMetricsCounterForResizeMode(int resizeMode) { |
| 544 | switch (resizeMode) { |
| 545 | case ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE: |
| 546 | return COUNTER_WINDOW_UNSUPPORTED; |
| 547 | case ActivityInfo.RESIZE_MODE_RESIZEABLE: |
Wale Ogunwale | 72a73e3 | 2016-10-13 12:16:39 -0700 | [diff] [blame] | 548 | case ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION: |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 549 | return COUNTER_WINDOW_SUPPORTED; |
| 550 | default: |
| 551 | return COUNTER_WINDOW_INCOMPATIBLE; |
| 552 | } |
| 553 | } |
| 554 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 555 | @Override |
| 556 | public void onDraggingInRecents(float distanceFromTop) { |
| 557 | if (sSystemServicesProxy.isSystemUser(mDraggingInRecentsCurrentUser)) { |
| 558 | mImpl.onDraggingInRecents(distanceFromTop); |
| 559 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 560 | if (mSystemToUserCallbacks != null) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 561 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 562 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser( |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 563 | mDraggingInRecentsCurrentUser); |
| 564 | if (callbacks != null) { |
| 565 | try { |
| 566 | callbacks.onDraggingInRecents(distanceFromTop); |
| 567 | } catch (RemoteException e) { |
| 568 | Log.e(TAG, "Callback failed", e); |
| 569 | } |
| 570 | } else { |
| 571 | Log.e(TAG, "No SystemUI callbacks found for user: " |
| 572 | + mDraggingInRecentsCurrentUser); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | public void onDraggingInRecentsEnded(float velocity) { |
| 580 | if (sSystemServicesProxy.isSystemUser(mDraggingInRecentsCurrentUser)) { |
| 581 | mImpl.onDraggingInRecentsEnded(velocity); |
| 582 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 583 | if (mSystemToUserCallbacks != null) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 584 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 585 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser( |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 586 | mDraggingInRecentsCurrentUser); |
| 587 | if (callbacks != null) { |
| 588 | try { |
| 589 | callbacks.onDraggingInRecentsEnded(velocity); |
| 590 | } catch (RemoteException e) { |
| 591 | Log.e(TAG, "Callback failed", e); |
| 592 | } |
| 593 | } else { |
| 594 | Log.e(TAG, "No SystemUI callbacks found for user: " |
| 595 | + mDraggingInRecentsCurrentUser); |
| 596 | } |
| 597 | } |
| 598 | } |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Override |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 602 | public void showNextAffiliatedTask() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 603 | // Ensure the device has been provisioned before allowing the user to interact with |
| 604 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 605 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 606 | return; |
| 607 | } |
| 608 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 609 | mImpl.showNextAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 612 | @Override |
| 613 | public void showPrevAffiliatedTask() { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 614 | // Ensure the device has been provisioned before allowing the user to interact with |
| 615 | // recents |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 616 | if (!isUserSetup()) { |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 617 | return; |
| 618 | } |
| 619 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 620 | mImpl.showPrevAffiliatedTask(); |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Winson Chung | ee70fbd | 2017-08-29 14:56:01 -0700 | [diff] [blame] | 623 | @Override |
| 624 | public void appTransitionFinished() { |
Matthew Ng | 46bc92f | 2017-09-13 12:53:50 -0700 | [diff] [blame] | 625 | if (!Recents.getConfiguration().isLowRamDevice) { |
| 626 | // Fallback, reset the flag once an app transition ends |
| 627 | EventBus.getDefault().send(new SetWaitingForTransitionStartEvent( |
| 628 | false /* waitingForTransitionStart */)); |
| 629 | } |
Winson Chung | ee70fbd | 2017-08-29 14:56:01 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Updates on configuration change. |
| 634 | */ |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 635 | public void onConfigurationChanged(Configuration newConfig) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 636 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 637 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 638 | mImpl.onConfigurationChanged(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 639 | } else { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 640 | if (mSystemToUserCallbacks != null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 641 | IRecentsNonSystemUserCallbacks callbacks = |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 642 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 643 | if (callbacks != null) { |
| 644 | try { |
| 645 | callbacks.onConfigurationChanged(); |
| 646 | } catch (RemoteException e) { |
| 647 | Log.e(TAG, "Callback failed", e); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 648 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 649 | } else { |
| 650 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 651 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 652 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 655 | |
| 656 | /** |
| 657 | * Handle Recents activity visibility changed. |
| 658 | */ |
| 659 | public final void onBusEvent(final RecentsVisibilityChangedEvent event) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 660 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 661 | int processUser = ssp.getProcessUser(); |
| 662 | if (ssp.isSystemUser(processUser)) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 663 | mImpl.onVisibilityChanged(event.applicationContext, event.visible); |
| 664 | } else { |
| 665 | postToSystemUser(new Runnable() { |
| 666 | @Override |
| 667 | public void run() { |
| 668 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 669 | mUserToSystemCallbacks.updateRecentsVisibility(event.visible); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 670 | } catch (RemoteException e) { |
| 671 | Log.e(TAG, "Callback failed", e); |
| 672 | } |
| 673 | } |
| 674 | }); |
| 675 | } |
Matthew Ng | c422f80 | 2017-08-02 14:00:59 -0700 | [diff] [blame] | 676 | |
| 677 | // This will catch the cases when a user launches from recents to another app |
| 678 | // (and vice versa) that is not in the recents stack (such as home or bugreport) and it |
| 679 | // would not reset the wait for transition flag. This will catch it and make sure that the |
| 680 | // flag is reset. |
| 681 | if (!event.visible) { |
| 682 | mImpl.setWaitingForTransitionStart(false); |
| 683 | } |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Matthew Ng | 534e854 | 2017-10-16 14:34:52 -0700 | [diff] [blame] | 686 | public final void onBusEvent(DockedFirstAnimationFrameEvent event) { |
| 687 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 688 | int processUser = ssp.getProcessUser(); |
| 689 | if (!ssp.isSystemUser(processUser)) { |
| 690 | postToSystemUser(new Runnable() { |
| 691 | @Override |
| 692 | public void run() { |
| 693 | try { |
| 694 | mUserToSystemCallbacks.sendDockedFirstAnimationFrameEvent(); |
| 695 | } catch (RemoteException e) { |
| 696 | Log.e(TAG, "Callback failed", e); |
| 697 | } |
| 698 | } |
| 699 | }); |
| 700 | } |
| 701 | } |
| 702 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 703 | /** |
| 704 | * Handle screen pinning request. |
| 705 | */ |
| 706 | public final void onBusEvent(final ScreenPinningRequestEvent event) { |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 707 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 708 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
Andrii Kulian | 0f051f5 | 2016-04-14 00:41:51 -0700 | [diff] [blame] | 709 | mImpl.onStartScreenPinning(event.applicationContext, event.taskId); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 710 | } else { |
| 711 | postToSystemUser(new Runnable() { |
| 712 | @Override |
| 713 | public void run() { |
| 714 | try { |
Andrii Kulian | 0f051f5 | 2016-04-14 00:41:51 -0700 | [diff] [blame] | 715 | mUserToSystemCallbacks.startScreenPinning(event.taskId); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 716 | } catch (RemoteException e) { |
| 717 | Log.e(TAG, "Callback failed", e); |
| 718 | } |
| 719 | } |
| 720 | }); |
| 721 | } |
| 722 | } |
| 723 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 724 | public final void onBusEvent(final RecentsDrawnEvent event) { |
| 725 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 726 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 727 | postToSystemUser(new Runnable() { |
| 728 | @Override |
| 729 | public void run() { |
| 730 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 731 | mUserToSystemCallbacks.sendRecentsDrawnEvent(); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 732 | } catch (RemoteException e) { |
| 733 | Log.e(TAG, "Callback failed", e); |
| 734 | } |
| 735 | } |
| 736 | }); |
| 737 | } |
| 738 | } |
| 739 | |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 740 | public final void onBusEvent(final DockedTopTaskEvent event) { |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 741 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 742 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 743 | postToSystemUser(new Runnable() { |
| 744 | @Override |
| 745 | public void run() { |
| 746 | try { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 747 | mUserToSystemCallbacks.sendDockingTopTaskEvent(event.dragMode, |
| 748 | event.initialRect); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 749 | } catch (RemoteException e) { |
| 750 | Log.e(TAG, "Callback failed", e); |
| 751 | } |
| 752 | } |
| 753 | }); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | public final void onBusEvent(final RecentsActivityStartingEvent event) { |
| 758 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 759 | if (!sSystemServicesProxy.isSystemUser(processUser)) { |
| 760 | postToSystemUser(new Runnable() { |
| 761 | @Override |
| 762 | public void run() { |
| 763 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 764 | mUserToSystemCallbacks.sendLaunchRecentsEvent(); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 765 | } catch (RemoteException e) { |
| 766 | Log.e(TAG, "Callback failed", e); |
| 767 | } |
| 768 | } |
| 769 | }); |
| 770 | } |
| 771 | } |
| 772 | |
Matthew Ng | c422f80 | 2017-08-02 14:00:59 -0700 | [diff] [blame] | 773 | public final void onBusEvent(LaunchTaskFailedEvent event) { |
| 774 | // Reset the transition when tasks fail to launch |
| 775 | mImpl.setWaitingForTransitionStart(false); |
| 776 | } |
| 777 | |
Winson | 003eda6 | 2016-03-11 14:56:00 -0800 | [diff] [blame] | 778 | public final void onBusEvent(ConfigurationChangedEvent event) { |
| 779 | // Update the configuration for the Recents component when the activity configuration |
| 780 | // changes as well |
| 781 | mImpl.onConfigurationChanged(); |
| 782 | } |
| 783 | |
Winson | 675c5d8 | 2016-08-23 17:12:22 -0700 | [diff] [blame] | 784 | public final void onBusEvent(ShowUserToastEvent event) { |
| 785 | int currentUser = sSystemServicesProxy.getCurrentUser(); |
| 786 | if (sSystemServicesProxy.isSystemUser(currentUser)) { |
| 787 | mImpl.onShowCurrentUserToast(event.msgResId, event.msgLength); |
| 788 | } else { |
| 789 | if (mSystemToUserCallbacks != null) { |
| 790 | IRecentsNonSystemUserCallbacks callbacks = |
| 791 | mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser); |
| 792 | if (callbacks != null) { |
| 793 | try { |
| 794 | callbacks.showCurrentUserToast(event.msgResId, event.msgLength); |
| 795 | } catch (RemoteException e) { |
| 796 | Log.e(TAG, "Callback failed", e); |
| 797 | } |
| 798 | } else { |
| 799 | Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser); |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
Matthew Ng | 912c7f7 | 2017-08-02 22:12:04 +0000 | [diff] [blame] | 805 | public final void onBusEvent(SetWaitingForTransitionStartEvent event) { |
| 806 | int processUser = sSystemServicesProxy.getProcessUser(); |
| 807 | if (sSystemServicesProxy.isSystemUser(processUser)) { |
| 808 | mImpl.setWaitingForTransitionStart(event.waitingForTransitionStart); |
| 809 | } else { |
| 810 | postToSystemUser(new Runnable() { |
| 811 | @Override |
| 812 | public void run() { |
| 813 | try { |
| 814 | mUserToSystemCallbacks.setWaitingForTransitionStartEvent( |
| 815 | event.waitingForTransitionStart); |
| 816 | } catch (RemoteException e) { |
| 817 | Log.e(TAG, "Callback failed", e); |
| 818 | } |
| 819 | } |
| 820 | }); |
| 821 | } |
| 822 | } |
| 823 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 824 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 825 | * Attempts to register with the system user. |
| 826 | */ |
| 827 | private void registerWithSystemUser() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 828 | final int processUser = sSystemServicesProxy.getProcessUser(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 829 | postToSystemUser(new Runnable() { |
| 830 | @Override |
| 831 | public void run() { |
| 832 | try { |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 833 | mUserToSystemCallbacks.registerNonSystemUserCallbacks( |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 834 | new RecentsImplProxy(mImpl), processUser); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 835 | } catch (RemoteException e) { |
| 836 | Log.e(TAG, "Failed to register", e); |
| 837 | } |
| 838 | } |
| 839 | }); |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Runs the runnable in the system user's Recents context, connecting to the service if |
| 844 | * necessary. |
| 845 | */ |
| 846 | private void postToSystemUser(final Runnable onConnectRunnable) { |
| 847 | mOnConnectRunnables.add(onConnectRunnable); |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 848 | if (mUserToSystemCallbacks == null) { |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 849 | Intent systemUserServiceIntent = new Intent(); |
| 850 | systemUserServiceIntent.setClass(mContext, RecentsSystemUserService.class); |
| 851 | boolean bound = mContext.bindServiceAsUser(systemUserServiceIntent, |
Winson | a00a785 | 2016-02-16 11:05:28 -0800 | [diff] [blame] | 852 | mUserToSystemServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM); |
| 853 | EventLog.writeEvent(EventLogTags.SYSUI_RECENTS_CONNECTION, |
| 854 | EventLogConstants.SYSUI_RECENTS_CONNECTION_USER_BIND_SERVICE, |
| 855 | sSystemServicesProxy.getProcessUser()); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 856 | if (!bound) { |
| 857 | // Retry after a fixed duration |
| 858 | mHandler.postDelayed(new Runnable() { |
| 859 | @Override |
| 860 | public void run() { |
| 861 | registerWithSystemUser(); |
| 862 | } |
| 863 | }, BIND_TO_SYSTEM_USER_RETRY_DELAY); |
| 864 | } |
| 865 | } else { |
| 866 | runAndFlushOnConnectRunnables(); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Runs all the queued runnables after a service connection is made. |
| 872 | */ |
| 873 | private void runAndFlushOnConnectRunnables() { |
| 874 | for (Runnable r : mOnConnectRunnables) { |
| 875 | r.run(); |
| 876 | } |
| 877 | mOnConnectRunnables.clear(); |
| 878 | } |
Winson | 4727ab9 | 2015-11-02 14:35:34 -0800 | [diff] [blame] | 879 | |
| 880 | /** |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 881 | * @return whether this device is provisioned and the current user is set up. |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 882 | */ |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 883 | private boolean isUserSetup() { |
| 884 | ContentResolver cr = mContext.getContentResolver(); |
| 885 | return (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) != 0) && |
| 886 | (Settings.Secure.getInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 0) != 0); |
Winson | e924356 | 2015-11-10 16:07:13 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Winson Chung | ee69756 | 2017-05-18 14:29:43 -0700 | [diff] [blame] | 889 | @Override |
| 890 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 891 | pw.println("Recents"); |
| 892 | pw.println(" currentUserId=" + SystemServicesProxy.getInstance(mContext).getCurrentUser()); |
| 893 | } |
Winson Chung | 7048fea | 2014-03-18 12:21:24 -0700 | [diff] [blame] | 894 | } |