blob: 70642edde3ef4caa3c983c3e34aff6e60c0672eb [file] [log] [blame]
Winson Chung303e1ff2014-03-07 15:06:19 -08001/*
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 *
Peter Schillerb124d562015-12-11 21:31:17 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Winson Chung303e1ff2014-03-07 15:06:19 -08009 *
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
17package com.android.systemui.recents;
18
19import android.app.Activity;
Winsona4fab412016-09-15 16:28:22 -070020import android.app.ActivityManager;
Winson Chungd543c1b2014-06-23 15:06:45 -070021import android.app.ActivityOptions;
Winson2536c7e2015-10-01 15:49:31 -070022import android.app.TaskStackBuilder;
Winson Chung47c4c692014-03-17 10:17:11 -070023import android.content.BroadcastReceiver;
24import android.content.Context;
Winson Chung303e1ff2014-03-07 15:06:19 -080025import android.content.Intent;
Winson Chung47c4c692014-03-17 10:17:11 -070026import android.content.IntentFilter;
Winsona1809852016-03-15 11:41:37 -070027import android.content.res.Configuration;
Winson2536c7e2015-10-01 15:49:31 -070028import android.net.Uri;
Winson Chung303e1ff2014-03-07 15:06:19 -080029import android.os.Bundle;
Winson3f32e7e2016-04-20 17:18:08 -070030import android.os.Handler;
Winson Chung15a2ba82014-11-18 11:19:24 -080031import android.os.SystemClock;
Winson Chungd543c1b2014-06-23 15:06:45 -070032import android.os.UserHandle;
Winson2536c7e2015-10-01 15:49:31 -070033import android.provider.Settings;
Winson1b585612015-11-06 09:16:26 -080034import android.util.Log;
Winson Chung1e8d71b2014-05-16 17:05:22 -070035import android.view.KeyEvent;
Winson Chung303e1ff2014-03-07 15:06:19 -080036import android.view.View;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -080037import android.view.ViewTreeObserver;
Jorim Jaggi3273f312016-05-05 17:32:44 -070038import android.view.ViewTreeObserver.OnPreDrawListener;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -080039import android.view.WindowManager;
Jorim Jaggic69bd222016-03-15 14:38:37 +010040import android.view.WindowManager.LayoutParams;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050041
Winson Chung5c9f4b92015-06-25 16:16:46 -070042import com.android.internal.logging.MetricsLogger;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050043import com.android.internal.logging.MetricsProto.MetricsEvent;
Winson9b001392016-04-08 14:54:02 -070044import com.android.systemui.Interpolators;
Winson6976f7b2016-05-03 14:58:12 -070045import com.android.systemui.Prefs;
Winson Chung47c4c692014-03-17 10:17:11 -070046import com.android.systemui.R;
Winsonb78bb4f2015-09-24 17:22:57 -070047import com.android.systemui.recents.events.EventBus;
Winson13d30662015-11-06 15:30:29 -080048import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
Winsone693aaf2016-03-01 12:05:59 -080049import com.android.systemui.recents.events.activity.ConfigurationChangedEvent;
Winsonb1e71d02015-11-23 12:40:23 -080050import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent;
Winsonef064132016-01-05 12:11:31 -080051import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
Jorim Jaggi192086e2016-03-11 17:17:03 +010052import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent;
Jorim Jaggi3273f312016-05-05 17:32:44 -070053import com.android.systemui.recents.events.activity.DockedTopTaskEvent;
Winson3fb67562015-11-11 10:39:03 -080054import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
Winson1b585612015-11-06 09:16:26 -080055import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent;
Winsonef064132016-01-05 12:11:31 -080056import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent;
Winson412e1802015-10-20 16:57:57 -070057import com.android.systemui.recents.events.activity.HideRecentsEvent;
Winson0d14d4d2015-10-26 17:05:04 -070058import com.android.systemui.recents.events.activity.IterateRecentsEvent;
Winson83c1b072015-11-09 10:48:04 -080059import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent;
60import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent;
Winson88737542016-02-17 13:27:33 -080061import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent;
Winson412e1802015-10-20 16:57:57 -070062import com.android.systemui.recents.events.activity.ToggleRecentsEvent;
Winson190fe3bf2015-10-20 14:57:24 -070063import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
64import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
Winson397ae742015-11-20 11:27:33 -080065import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent;
Winsonef064132016-01-05 12:11:31 -080066import com.android.systemui.recents.events.ui.DeleteTaskDataEvent;
Winson9b001392016-04-08 14:54:02 -070067import com.android.systemui.recents.events.ui.HideIncompatibleAppOverlayEvent;
Jorim Jaggi11cc01d2016-01-22 19:39:23 -080068import com.android.systemui.recents.events.ui.RecentsDrawnEvent;
Winson2536c7e2015-10-01 15:49:31 -070069import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent;
Winson9b001392016-04-08 14:54:02 -070070import com.android.systemui.recents.events.ui.ShowIncompatibleAppOverlayEvent;
Winsone5f1faa2015-11-20 12:26:23 -080071import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
Winsonb1e71d02015-11-23 12:40:23 -080072import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent;
Winsone7f138c2015-10-22 16:15:21 -070073import com.android.systemui.recents.events.ui.UserInteractionEvent;
Winson0d14d4d2015-10-26 17:05:04 -070074import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent;
75import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent;
76import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent;
Winson0d14d4d2015-10-26 17:05:04 -070077import com.android.systemui.recents.misc.DozeTrigger;
Winson Chungffa2ec62014-07-03 15:54:42 -070078import com.android.systemui.recents.misc.SystemServicesProxy;
Winson9b001392016-04-08 14:54:02 -070079import com.android.systemui.recents.misc.Utilities;
Winsone6c90732015-09-24 16:06:29 -070080import com.android.systemui.recents.model.RecentsPackageMonitor;
Winson Chunga91c2932014-11-07 15:02:38 -080081import com.android.systemui.recents.model.RecentsTaskLoadPlan;
Winson Chungf1fbd772014-06-24 18:06:58 -070082import com.android.systemui.recents.model.RecentsTaskLoader;
Winson Chungdcfa7972014-07-22 12:27:13 -070083import com.android.systemui.recents.model.Task;
Winson Chung303e1ff2014-03-07 15:06:19 -080084import com.android.systemui.recents.model.TaskStack;
85import com.android.systemui.recents.views.RecentsView;
Winson Chungcdbbb7e2014-06-24 12:11:49 -070086import com.android.systemui.recents.views.SystemBarScrimViews;
Winsond8b1d632016-01-04 17:51:18 -080087import com.android.systemui.statusbar.BaseStatusBar;
Winson Chung303e1ff2014-03-07 15:06:19 -080088
Winsond72c3152016-04-05 15:33:35 -070089import java.io.FileDescriptor;
90import java.io.PrintWriter;
Winsona4fab412016-09-15 16:28:22 -070091import java.util.List;
Winsond72c3152016-04-05 15:33:35 -070092
Winson Chung85cfec82014-07-14 14:16:04 -070093/**
Winson27c28f82016-05-05 16:16:50 -070094 * The main Recents activity that is started from RecentsComponent.
Winson Chung85cfec82014-07-14 14:16:04 -070095 */
Winson397ae742015-11-20 11:27:33 -080096public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreDrawListener {
Winson Chungd42a6cf2014-06-03 16:24:04 -070097
Winson0d14d4d2015-10-26 17:05:04 -070098 private final static String TAG = "RecentsActivity";
99 private final static boolean DEBUG = false;
100
Winsone6c90732015-09-24 16:06:29 -0700101 public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1;
Winson9b001392016-04-08 14:54:02 -0700102 public final static int INCOMPATIBLE_APP_ALPHA_DURATION = 150;
Winsone6c90732015-09-24 16:06:29 -0700103
Winsone5f1faa2015-11-20 12:26:23 -0800104 private RecentsPackageMonitor mPackageMonitor;
Winson3f32e7e2016-04-20 17:18:08 -0700105 private Handler mHandler = new Handler();
Winsone5f1faa2015-11-20 12:26:23 -0800106 private long mLastTabKeyEventTime;
Winson67c79572016-04-13 14:02:18 -0700107 private int mLastDeviceOrientation = Configuration.ORIENTATION_UNDEFINED;
Jorim Jaggi25160db2016-04-18 16:03:36 -0700108 private int mLastDisplayDensity;
Winsone5f1faa2015-11-20 12:26:23 -0800109 private boolean mFinishedOnStartup;
110 private boolean mIgnoreAltTabRelease;
Winson88737542016-02-17 13:27:33 -0800111 private boolean mIsVisible;
Winson449a4e22016-05-11 14:29:33 -0700112 private boolean mReceivedNewIntent;
Winson Chung85cfec82014-07-14 14:16:04 -0700113
114 // Top level views
Winsone5f1faa2015-11-20 12:26:23 -0800115 private RecentsView mRecentsView;
116 private SystemBarScrimViews mScrimViews;
Winson9b001392016-04-08 14:54:02 -0700117 private View mIncompatibleAppOverlay;
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700118
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700119 // Runnables to finish the Recents activity
Winsone693aaf2016-03-01 12:05:59 -0800120 private Intent mHomeIntent;
Winson Chungcdbbb7e2014-06-24 12:11:49 -0700121
Winson0d14d4d2015-10-26 17:05:04 -0700122 // The trigger to automatically launch the current task
Peter Schillerb124d562015-12-11 21:31:17 -0800123 private int mFocusTimerDuration;
124 private DozeTrigger mIterateTrigger;
Winson4b9cded2016-01-26 16:26:47 -0800125 private final UserInteractionEvent mUserInteractionEvent = new UserInteractionEvent();
Winson449a4e22016-05-11 14:29:33 -0700126 private final Runnable mSendEnterWindowAnimationCompleteRunnable = () -> {
127 EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
128 };
Winson0d14d4d2015-10-26 17:05:04 -0700129
Winson Chungd543c1b2014-06-23 15:06:45 -0700130 /**
Winson3fb67562015-11-11 10:39:03 -0800131 * A common Runnable to finish Recents by launching Home with an animation depending on the
Peter Schillerb124d562015-12-11 21:31:17 -0800132 * last activity launch state. Generally we always launch home when we exit Recents rather than
Winson3fb67562015-11-11 10:39:03 -0800133 * just finishing the activity since we don't know what is behind Recents in the task stack.
Winson Chungd543c1b2014-06-23 15:06:45 -0700134 */
Winsone693aaf2016-03-01 12:05:59 -0800135 class LaunchHomeRunnable implements Runnable {
Winson49df4202016-01-25 17:33:34 -0800136
Winson Chungd543c1b2014-06-23 15:06:45 -0700137 Intent mLaunchIntent;
Winson49df4202016-01-25 17:33:34 -0800138 ActivityOptions mOpts;
Winson Chungd543c1b2014-06-23 15:06:45 -0700139
Winson Chungd7b2cb12014-06-26 15:08:50 -0700140 /**
Winson3fb67562015-11-11 10:39:03 -0800141 * Creates a finish runnable that starts the specified intent.
Winson Chungd7b2cb12014-06-26 15:08:50 -0700142 */
Winsone693aaf2016-03-01 12:05:59 -0800143 public LaunchHomeRunnable(Intent launchIntent, ActivityOptions opts) {
Winson Chungd543c1b2014-06-23 15:06:45 -0700144 mLaunchIntent = launchIntent;
Winson40a22732016-02-02 18:07:00 -0800145 mOpts = opts;
Winson Chungd543c1b2014-06-23 15:06:45 -0700146 }
147
148 @Override
149 public void run() {
Winson2b9c1d32015-10-05 15:44:23 -0700150 try {
Winson3f32e7e2016-04-20 17:18:08 -0700151 mHandler.post(() -> {
152 ActivityOptions opts = mOpts;
153 if (opts == null) {
154 opts = ActivityOptions.makeCustomAnimation(RecentsActivity.this,
155 R.anim.recents_to_launcher_enter, R.anim.recents_to_launcher_exit);
156 }
157 startActivityAsUser(mLaunchIntent, opts.toBundle(), UserHandle.CURRENT);
158 });
Winson2b9c1d32015-10-05 15:44:23 -0700159 } catch (Exception e) {
Winson1b585612015-11-06 09:16:26 -0800160 Log.e(TAG, getString(R.string.recents_launch_error_message, "Home"), e);
Winson Chungd543c1b2014-06-23 15:06:45 -0700161 }
162 }
163 }
164
Winson Chung85cfec82014-07-14 14:16:04 -0700165 /**
Winson Chung85cfec82014-07-14 14:16:04 -0700166 * Broadcast receiver to handle messages from the system
167 */
Winson Chung31d66c62014-06-30 13:12:54 -0700168 final BroadcastReceiver mSystemBroadcastReceiver = new BroadcastReceiver() {
Winson Chung67369052014-04-07 17:35:48 -0700169 @Override
Winsona4fab412016-09-15 16:28:22 -0700170 public void onReceive(Context ctx, Intent intent) {
Winson Chung31d66c62014-06-30 13:12:54 -0700171 String action = intent.getAction();
Winson Chung85cfec82014-07-14 14:16:04 -0700172 if (action.equals(Intent.ACTION_SCREEN_OFF)) {
173 // When the screen turns off, dismiss Recents to Home
Winson2b9c1d32015-10-05 15:44:23 -0700174 dismissRecentsToHomeIfVisible(false);
Winson Chung36f3f032016-09-08 23:29:43 +0000175 } else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
Winsona4fab412016-09-15 16:28:22 -0700176 // If the time shifts but the currentTime >= lastStackActiveTime, then that boundary
177 // is still valid. Otherwise, we need to reset the lastStackactiveTime to the
178 // currentTime and remove the old tasks in between which would not be previously
179 // visible, but currently would be in the new currentTime
180 long oldLastStackActiveTime = Prefs.getLong(RecentsActivity.this,
181 Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
182 if (oldLastStackActiveTime != -1) {
183 long currentTime = System.currentTimeMillis();
184 if (currentTime < oldLastStackActiveTime) {
185 // We are only removing tasks that are between the new current time
186 // and the old last stack active time, they were not visible and in the
187 // TaskStack so we don't need to remove any associated TaskViews but we do
188 // need to load the task id's from the system
189 RecentsTaskLoadPlan loadPlan = Recents.getTaskLoader().createLoadPlan(ctx);
190 loadPlan.preloadRawTasks(false /* includeFrontMostExcludedTask */);
191 List<ActivityManager.RecentTaskInfo> tasks = loadPlan.getRawTasks();
192 for (int i = tasks.size() - 1; i >= 0; i--) {
193 ActivityManager.RecentTaskInfo task = tasks.get(i);
194 if (currentTime <= task.lastActiveTime && task.lastActiveTime <
195 oldLastStackActiveTime) {
196 Recents.getSystemServices().removeTask(task.persistentId);
197 }
198 }
199 Prefs.putLong(RecentsActivity.this,
200 Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, currentTime);
201 }
202 }
Winson Chung31d66c62014-06-30 13:12:54 -0700203 }
Winson Chungd42a6cf2014-06-03 16:24:04 -0700204 }
205 };
206
Jorim Jaggi3273f312016-05-05 17:32:44 -0700207 private final OnPreDrawListener mRecentsDrawnEventListener =
208 new ViewTreeObserver.OnPreDrawListener() {
209 @Override
210 public boolean onPreDraw() {
211 mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
212 EventBus.getDefault().post(new RecentsDrawnEvent());
213 return true;
214 }
215 };
216
Winson0d14d4d2015-10-26 17:05:04 -0700217 /**
218 * Dismisses recents if we are already visible and the intent is to toggle the recents view.
219 */
Winson42329522016-02-05 10:39:46 -0800220 boolean dismissRecentsToFocusedTask(int logCategory) {
Winson0d14d4d2015-10-26 17:05:04 -0700221 SystemServicesProxy ssp = Recents.getSystemServices();
Winsond46b7272016-04-20 11:54:27 -0700222 if (ssp.isRecentsActivityVisible()) {
Winson0d14d4d2015-10-26 17:05:04 -0700223 // If we have a focused Task, launch that Task now
Winson42329522016-02-05 10:39:46 -0800224 if (mRecentsView.launchFocusedTask(logCategory)) return true;
Winson0d14d4d2015-10-26 17:05:04 -0700225 }
226 return false;
227 }
228
229 /**
Winsona0731a12015-12-02 15:10:14 -0800230 * Dismisses recents back to the launch target task.
231 */
232 boolean dismissRecentsToLaunchTargetTaskOrHome() {
233 SystemServicesProxy ssp = Recents.getSystemServices();
Winsond46b7272016-04-20 11:54:27 -0700234 if (ssp.isRecentsActivityVisible()) {
Winsona0731a12015-12-02 15:10:14 -0800235 // If we have a focused Task, launch that Task now
236 if (mRecentsView.launchPreviousTask()) return true;
237 // If none of the other cases apply, then just go Home
Winsonef064132016-01-05 12:11:31 -0800238 dismissRecentsToHome(true /* animateTaskViews */);
Winsona0731a12015-12-02 15:10:14 -0800239 }
240 return false;
241 }
242
243 /**
Winson0d14d4d2015-10-26 17:05:04 -0700244 * Dismisses recents if we are already visible and the intent is to toggle the recents view.
245 */
Winson397ae742015-11-20 11:27:33 -0800246 boolean dismissRecentsToFocusedTaskOrHome() {
Winsone7f138c2015-10-22 16:15:21 -0700247 SystemServicesProxy ssp = Recents.getSystemServices();
Winsond46b7272016-04-20 11:54:27 -0700248 if (ssp.isRecentsActivityVisible()) {
Winson Chung85cfec82014-07-14 14:16:04 -0700249 // If we have a focused Task, launch that Task now
Winson42329522016-02-05 10:39:46 -0800250 if (mRecentsView.launchFocusedTask(0 /* logCategory */)) return true;
Winson Chung85cfec82014-07-14 14:16:04 -0700251 // If none of the other cases apply, then just go Home
Winsonef064132016-01-05 12:11:31 -0800252 dismissRecentsToHome(true /* animateTaskViews */);
Winson Chung85cfec82014-07-14 14:16:04 -0700253 return true;
254 }
255 return false;
256 }
257
Winson2b9c1d32015-10-05 15:44:23 -0700258 /**
259 * Dismisses Recents directly to Home without checking whether it is currently visible.
260 */
Winsonef064132016-01-05 12:11:31 -0800261 void dismissRecentsToHome(boolean animateTaskViews) {
Winson49df4202016-01-25 17:33:34 -0800262 dismissRecentsToHome(animateTaskViews, null);
263 }
264
265 /**
266 * Dismisses Recents directly to Home without checking whether it is currently visible.
267 *
268 * @param overrideAnimation If not null, will override the default animation that is based on
269 * how Recents was launched.
270 */
271 void dismissRecentsToHome(boolean animateTaskViews, ActivityOptions overrideAnimation) {
Winsonef064132016-01-05 12:11:31 -0800272 DismissRecentsToHomeAnimationStarted dismissEvent =
273 new DismissRecentsToHomeAnimationStarted(animateTaskViews);
Winsone693aaf2016-03-01 12:05:59 -0800274 dismissEvent.addPostAnimationCallback(new LaunchHomeRunnable(mHomeIntent,
275 overrideAnimation));
Winson3ca10282016-04-21 15:20:21 -0700276 Recents.getSystemServices().sendCloseSystemWindows(
277 BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY);
Winsonef064132016-01-05 12:11:31 -0800278 EventBus.getDefault().send(dismissEvent);
Wale Ogunwaled351ada2015-04-04 11:53:14 -0700279 }
280
Winson Chung85cfec82014-07-14 14:16:04 -0700281 /** Dismisses Recents directly to Home if we currently aren't transitioning. */
Winson2b9c1d32015-10-05 15:44:23 -0700282 boolean dismissRecentsToHomeIfVisible(boolean animated) {
Winsone7f138c2015-10-22 16:15:21 -0700283 SystemServicesProxy ssp = Recents.getSystemServices();
Winsond46b7272016-04-20 11:54:27 -0700284 if (ssp.isRecentsActivityVisible()) {
Winson Chung85cfec82014-07-14 14:16:04 -0700285 // Return to Home
Winson2b9c1d32015-10-05 15:44:23 -0700286 dismissRecentsToHome(animated);
Winson Chung47c4c692014-03-17 10:17:11 -0700287 return true;
Winson Chung303e1ff2014-03-07 15:06:19 -0800288 }
289 return false;
290 }
291
292 /** Called with the activity is first created. */
293 @Override
294 public void onCreate(Bundle savedInstanceState) {
295 super.onCreate(savedInstanceState);
Winson3150e572015-10-23 15:07:24 -0700296 mFinishedOnStartup = false;
297
298 // In the case that the activity starts up before the Recents component has initialized
299 // (usually when debugging/pushing the SysUI apk), just finish this activity.
300 SystemServicesProxy ssp = Recents.getSystemServices();
301 if (ssp == null) {
302 mFinishedOnStartup = true;
303 finish();
304 return;
305 }
Winsonb78bb4f2015-09-24 17:22:57 -0700306
307 // Register this activity with the event bus
308 EventBus.getDefault().register(this, EVENT_BUS_PRIORITY);
309
Winson008ee15f2016-03-18 17:17:25 -0700310 // Initialize the package monitor
Winsone7f138c2015-10-22 16:15:21 -0700311 mPackageMonitor = new RecentsPackageMonitor();
312 mPackageMonitor.register(this);
Winson Chungf7bca432014-04-30 17:11:13 -0700313
Winson Chung8e548f72014-06-24 14:40:53 -0700314 // Set the Recents layout
315 setContentView(R.layout.recents);
Winson88737542016-02-17 13:27:33 -0800316 takeKeyEvents(true);
Winson Chung8e548f72014-06-24 14:40:53 -0700317 mRecentsView = (RecentsView) findViewById(R.id.recents_view);
Winson Chung653f70c22014-05-19 14:49:42 -0700318 mRecentsView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
319 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
320 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Winson35f30502015-09-28 11:24:36 -0700321 mScrimViews = new SystemBarScrimViews(this);
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800322 getWindow().getAttributes().privateFlags |=
323 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY;
Winson Chung303e1ff2014-03-07 15:06:19 -0800324
Jorim Jaggi25160db2016-04-18 16:03:36 -0700325 Configuration appConfiguration = Utilities.getAppConfiguration(this);
326 mLastDeviceOrientation = appConfiguration.orientation;
327 mLastDisplayDensity = appConfiguration.densityDpi;
Peter Schillerb124d562015-12-11 21:31:17 -0800328 mFocusTimerDuration = getResources().getInteger(R.integer.recents_auto_advance_duration);
329 mIterateTrigger = new DozeTrigger(mFocusTimerDuration, new Runnable() {
330 @Override
331 public void run() {
Winson42329522016-02-05 10:39:46 -0800332 dismissRecentsToFocusedTask(MetricsEvent.OVERVIEW_SELECT_TIMEOUT);
Peter Schillerb124d562015-12-11 21:31:17 -0800333 }
334 });
335
Winsone8a4eff2016-03-28 16:20:35 -0700336 // Set the window background
337 getWindow().setBackgroundDrawable(mRecentsView.getBackgroundScrim());
338
Winson3fb67562015-11-11 10:39:03 -0800339 // Create the home intent runnable
Winsone693aaf2016-03-01 12:05:59 -0800340 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
341 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
342 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Winson3fb67562015-11-11 10:39:03 -0800343 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Winson3fb67562015-11-11 10:39:03 -0800344
Winson Chung31d66c62014-06-30 13:12:54 -0700345 // Register the broadcast receiver to handle messages when the screen is turned off
346 IntentFilter filter = new IntentFilter();
347 filter.addAction(Intent.ACTION_SCREEN_OFF);
Winson Chung36f3f032016-09-08 23:29:43 +0000348 filter.addAction(Intent.ACTION_TIME_CHANGED);
Winson Chung31d66c62014-06-30 13:12:54 -0700349 registerReceiver(mSystemBroadcastReceiver, filter);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100350
351 getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION);
Winsona1ededd2016-03-25 12:23:12 -0700352
353 // Reload the stack view
354 reloadStackView();
Winson Chung521e7dc2014-06-02 15:31:56 -0700355 }
356
Winson Chung303e1ff2014-03-07 15:06:19 -0800357 @Override
Winson Chung303e1ff2014-03-07 15:06:19 -0800358 protected void onStart() {
Winson Chung303e1ff2014-03-07 15:06:19 -0800359 super.onStart();
Winson Chung303e1ff2014-03-07 15:06:19 -0800360
Winsone7f138c2015-10-22 16:15:21 -0700361 // Notify that recents is now visible
Winson88737542016-02-17 13:27:33 -0800362 EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true));
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500363 MetricsLogger.visible(this, MetricsEvent.OVERVIEW_ACTIVITY);
Jorim Jaggid6a39492016-04-25 17:31:22 -0700364
365 // Notify of the next draw
Jorim Jaggi3273f312016-05-05 17:32:44 -0700366 mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener);
Winson Chung67369052014-04-07 17:35:48 -0700367 }
368
369 @Override
Winsona1ededd2016-03-25 12:23:12 -0700370 protected void onNewIntent(Intent intent) {
371 super.onNewIntent(intent);
Winson449a4e22016-05-11 14:29:33 -0700372 mReceivedNewIntent = true;
Winsona1ededd2016-03-25 12:23:12 -0700373
374 // Reload the stack view
375 reloadStackView();
Winson3fb67562015-11-11 10:39:03 -0800376 }
377
Winsona1ededd2016-03-25 12:23:12 -0700378 /**
379 * Reloads the stack views upon launching Recents.
380 */
381 private void reloadStackView() {
Winson88737542016-02-17 13:27:33 -0800382 // If the Recents component has preloaded a load plan, then use that to prevent
383 // reconstructing the task stack
384 RecentsTaskLoader loader = Recents.getTaskLoader();
385 RecentsTaskLoadPlan loadPlan = RecentsImpl.consumeInstanceLoadPlan();
386 if (loadPlan == null) {
387 loadPlan = loader.createLoadPlan(this);
388 }
389
390 // Start loading tasks according to the load plan
391 RecentsConfiguration config = Recents.getConfiguration();
392 RecentsActivityLaunchState launchState = config.getLaunchState();
393 if (!loadPlan.hasTasks()) {
Winson96e61342016-03-15 16:47:19 -0700394 loader.preloadTasks(loadPlan, launchState.launchedToTaskId,
Winsondfd7be02016-05-10 13:30:37 -0700395 !launchState.launchedFromHome);
Winson88737542016-02-17 13:27:33 -0800396 }
397
398 RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
399 loadOpts.runningTaskId = launchState.launchedToTaskId;
400 loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
401 loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
402 loader.loadTasks(this, loadPlan, loadOpts);
403 TaskStack stack = loadPlan.getTaskStack();
Winsona1ededd2016-03-25 12:23:12 -0700404 mRecentsView.onReload(mIsVisible, stack.getTaskCount() == 0);
Winsond2a03062016-04-15 11:19:07 -0700405 mRecentsView.updateStack(stack, true /* setStackViewTasks */);
Winson88737542016-02-17 13:27:33 -0800406
Winsona1ededd2016-03-25 12:23:12 -0700407 // Update the nav bar scrim, but defer the animation until the enter-window event
Winsonc69249f2016-03-28 13:38:39 -0700408 boolean animateNavBarScrim = !launchState.launchedViaDockGesture;
Winson500ba752016-03-30 11:59:22 -0700409 mScrimViews.updateNavBarScrim(animateNavBarScrim, stack.getTaskCount() > 0, null);
Winson88737542016-02-17 13:27:33 -0800410
Winsona1ededd2016-03-25 12:23:12 -0700411 // If this is a new instance relaunched by AM, without going through the normal mechanisms,
412 // then we have to manually trigger the enter animation state
Winson88737542016-02-17 13:27:33 -0800413 boolean wasLaunchedByAm = !launchState.launchedFromHome &&
414 !launchState.launchedFromApp;
Winsona1ededd2016-03-25 12:23:12 -0700415 if (wasLaunchedByAm) {
Winson88737542016-02-17 13:27:33 -0800416 EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
417 }
418
Winson88737542016-02-17 13:27:33 -0800419 // Keep track of whether we launched from the nav bar button or via alt-tab
420 if (launchState.launchedWithAltTab) {
421 MetricsLogger.count(this, "overview_trigger_alttab", 1);
422 } else {
423 MetricsLogger.count(this, "overview_trigger_nav_btn", 1);
424 }
425
426 // Keep track of whether we launched from an app or from home
427 if (launchState.launchedFromApp) {
Winsona1ededd2016-03-25 12:23:12 -0700428 Task launchTarget = stack.getLaunchTarget();
429 int launchTaskIndexInStack = launchTarget != null
430 ? stack.indexOfStackTask(launchTarget)
431 : 0;
Winson88737542016-02-17 13:27:33 -0800432 MetricsLogger.count(this, "overview_source_app", 1);
433 // If from an app, track the stack index of the app in the stack (for affiliated tasks)
434 MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack);
435 } else {
436 MetricsLogger.count(this, "overview_source_home", 1);
437 }
438
439 // Keep track of the total stack task count
Winsona1ededd2016-03-25 12:23:12 -0700440 int taskCount = mRecentsView.getStack().getTaskCount();
Winson88737542016-02-17 13:27:33 -0800441 MetricsLogger.histogram(this, "overview_task_count", taskCount);
442
443 // After we have resumed, set the visible state until the next onStop() call
444 mIsVisible = true;
Jorim Jaggi6e18e002015-06-02 17:07:39 -0700445 }
446
447 @Override
Winsona1ededd2016-03-25 12:23:12 -0700448 public void onEnterAnimationComplete() {
449 super.onEnterAnimationComplete();
Winson449a4e22016-05-11 14:29:33 -0700450
451 // Workaround for b/28705801, on first docking, we may receive the enter animation callback
452 // before the first layout, so in such cases, send the event on the next frame after all
453 // the views are laid out and attached (and registered to the EventBus).
454 mHandler.removeCallbacks(mSendEnterWindowAnimationCompleteRunnable);
455 if (!mReceivedNewIntent) {
456 mHandler.post(mSendEnterWindowAnimationCompleteRunnable);
457 } else {
458 mSendEnterWindowAnimationCompleteRunnable.run();
459 }
Winsona1ededd2016-03-25 12:23:12 -0700460 }
461
462 @Override
Winson88737542016-02-17 13:27:33 -0800463 protected void onPause() {
464 super.onPause();
Winson190fe3bf2015-10-20 14:57:24 -0700465
Winsone5f1faa2015-11-20 12:26:23 -0800466 mIgnoreAltTabRelease = false;
Winson88737542016-02-17 13:27:33 -0800467 mIterateTrigger.stopDozing();
Winson88737542016-02-17 13:27:33 -0800468 }
Winsone7f138c2015-10-22 16:15:21 -0700469
Winson88737542016-02-17 13:27:33 -0800470 @Override
Winsona1809852016-03-15 11:41:37 -0700471 public void onConfigurationChanged(Configuration newConfig) {
472 super.onConfigurationChanged(newConfig);
473
Winson44849b82016-03-29 10:45:45 -0700474 // Notify of the config change
Jorim Jaggi25160db2016-04-18 16:03:36 -0700475 Configuration newDeviceConfiguration = Utilities.getAppConfiguration(this);
Winson500ba752016-03-30 11:59:22 -0700476 int numStackTasks = mRecentsView.getStack().getStackTaskCount();
Winson44849b82016-03-29 10:45:45 -0700477 EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */,
Jorim Jaggi25160db2016-04-18 16:03:36 -0700478 mLastDeviceOrientation != newDeviceConfiguration.orientation,
479 mLastDisplayDensity != newDeviceConfiguration.densityDpi, numStackTasks > 0));
480 mLastDeviceOrientation = newDeviceConfiguration.orientation;
481 mLastDisplayDensity = newDeviceConfiguration.densityDpi;
Winsona1809852016-03-15 11:41:37 -0700482 }
483
484 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700485 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
486 super.onMultiWindowModeChanged(isInMultiWindowMode);
Winson500ba752016-03-30 11:59:22 -0700487
488 // Reload the task stack completely
489 RecentsConfiguration config = Recents.getConfiguration();
490 RecentsActivityLaunchState launchState = config.getLaunchState();
491 RecentsTaskLoader loader = Recents.getTaskLoader();
492 RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
Winsondfd7be02016-05-10 13:30:37 -0700493 loader.preloadTasks(loadPlan, -1 /* runningTaskId */,
494 false /* includeFrontMostExcludedTask */);
Winson500ba752016-03-30 11:59:22 -0700495
496 RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
497 loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
498 loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
499 loader.loadTasks(this, loadPlan, loadOpts);
500
501 TaskStack stack = loadPlan.getTaskStack();
502 int numStackTasks = stack.getStackTaskCount();
Winson95ee8732016-04-26 14:46:58 -0700503 boolean showDeferredAnimation = numStackTasks > 0;
Winson500ba752016-03-30 11:59:22 -0700504
Winson44849b82016-03-29 10:45:45 -0700505 EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */,
Jorim Jaggi25160db2016-04-18 16:03:36 -0700506 false /* fromDeviceOrientationChange */, false /* fromDisplayDensityChange */,
507 numStackTasks > 0));
Winson95ee8732016-04-26 14:46:58 -0700508 EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode,
509 showDeferredAnimation, stack));
Winsona1ededd2016-03-25 12:23:12 -0700510 }
511
512 @Override
Winson88737542016-02-17 13:27:33 -0800513 protected void onStop() {
514 super.onStop();
515
Winson88737542016-02-17 13:27:33 -0800516 // Notify that recents is now hidden
517 mIsVisible = false;
Winson449a4e22016-05-11 14:29:33 -0700518 mReceivedNewIntent = false;
Winson88737542016-02-17 13:27:33 -0800519 EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, false));
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500520 MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY);
Winson73492c52016-03-09 17:44:54 -0800521
522 // Workaround for b/22542869, if the RecentsActivity is started again, but without going
523 // through SystemUI, we need to reset the config launch flags to ensure that we do not
524 // wait on the system to send a signal that was never queued.
525 RecentsConfiguration config = Recents.getConfiguration();
526 RecentsActivityLaunchState launchState = config.getLaunchState();
527 launchState.reset();
Winson Chung47c4c692014-03-17 10:17:11 -0700528 }
529
530 @Override
531 protected void onDestroy() {
Winson Chung47c4c692014-03-17 10:17:11 -0700532 super.onDestroy();
Winson Chung31d66c62014-06-30 13:12:54 -0700533
Winson3150e572015-10-23 15:07:24 -0700534 // In the case that the activity finished on startup, just skip the unregistration below
535 if (mFinishedOnStartup) {
536 return;
537 }
538
Winson Chung85cfec82014-07-14 14:16:04 -0700539 // Unregister the system broadcast receivers
Winson Chung31d66c62014-06-30 13:12:54 -0700540 unregisterReceiver(mSystemBroadcastReceiver);
Winson Chung905950a2014-09-17 09:25:27 +0200541
Winsone7f138c2015-10-22 16:15:21 -0700542 // Unregister any broadcast receivers for the task loader
543 mPackageMonitor.unregister();
544
Winsonb78bb4f2015-09-24 17:22:57 -0700545 EventBus.getDefault().unregister(this);
Winson Chung303e1ff2014-03-07 15:06:19 -0800546 }
547
Winson412e1802015-10-20 16:57:57 -0700548 @Override
549 public void onAttachedToWindow() {
550 super.onAttachedToWindow();
551 EventBus.getDefault().register(mScrimViews, EVENT_BUS_PRIORITY);
552 }
Winson Chungaf3bb692015-06-03 17:31:39 -0700553
Winson412e1802015-10-20 16:57:57 -0700554 @Override
555 public void onDetachedFromWindow() {
556 super.onDetachedFromWindow();
557 EventBus.getDefault().unregister(mScrimViews);
Winson Chung353c0b92014-10-16 17:43:23 -0700558 }
559
560 @Override
Winson Chung4d7b0922014-03-13 17:14:17 -0700561 public void onTrimMemory(int level) {
Winsone7f138c2015-10-22 16:15:21 -0700562 RecentsTaskLoader loader = Recents.getTaskLoader();
Winson Chung4d7b0922014-03-13 17:14:17 -0700563 if (loader != null) {
564 loader.onTrimMemory(level);
565 }
566 }
567
568 @Override
Winson Chung1e8d71b2014-05-16 17:05:22 -0700569 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chunga0e88b52014-08-11 19:25:42 -0700570 switch (keyCode) {
571 case KeyEvent.KEYCODE_TAB: {
Winson35f30502015-09-28 11:24:36 -0700572 int altTabKeyDelay = getResources().getInteger(R.integer.recents_alt_tab_key_delay);
Winson Chung15a2ba82014-11-18 11:19:24 -0800573 boolean hasRepKeyTimeElapsed = (SystemClock.elapsedRealtime() -
Winson35f30502015-09-28 11:24:36 -0700574 mLastTabKeyEventTime) > altTabKeyDelay;
Winson Chunga0e88b52014-08-11 19:25:42 -0700575 if (event.getRepeatCount() <= 0 || hasRepKeyTimeElapsed) {
576 // Focus the next task in the stack
577 final boolean backward = event.isShiftPressed();
Winson0d14d4d2015-10-26 17:05:04 -0700578 if (backward) {
579 EventBus.getDefault().send(new FocusPreviousTaskViewEvent());
580 } else {
Peter Schillerb124d562015-12-11 21:31:17 -0800581 EventBus.getDefault().send(
Winson4b9cded2016-01-26 16:26:47 -0800582 new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */));
Winson0d14d4d2015-10-26 17:05:04 -0700583 }
Winson Chung15a2ba82014-11-18 11:19:24 -0800584 mLastTabKeyEventTime = SystemClock.elapsedRealtime();
Winsone5f1faa2015-11-20 12:26:23 -0800585
586 // In the case of another ALT event, don't ignore the next release
587 if (event.isAltPressed()) {
588 mIgnoreAltTabRelease = false;
589 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700590 }
591 return true;
592 }
593 case KeyEvent.KEYCODE_DPAD_UP: {
Peter Schillerb124d562015-12-11 21:31:17 -0800594 EventBus.getDefault().send(
Winson4b9cded2016-01-26 16:26:47 -0800595 new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */));
Winson Chunga0e88b52014-08-11 19:25:42 -0700596 return true;
597 }
598 case KeyEvent.KEYCODE_DPAD_DOWN: {
Winson0d14d4d2015-10-26 17:05:04 -0700599 EventBus.getDefault().send(new FocusPreviousTaskViewEvent());
Winson Chunga0e88b52014-08-11 19:25:42 -0700600 return true;
601 }
602 case KeyEvent.KEYCODE_DEL:
603 case KeyEvent.KEYCODE_FORWARD_DEL: {
Winsondf3012b2016-01-12 15:35:05 -0800604 if (event.getRepeatCount() <= 0) {
605 EventBus.getDefault().send(new DismissFocusedTaskViewEvent());
Winson0d14d4d2015-10-26 17:05:04 -0700606
Winsondf3012b2016-01-12 15:35:05 -0800607 // Keep track of deletions by keyboard
608 MetricsLogger.histogram(this, "overview_task_dismissed_source",
609 Constants.Metrics.DismissSourceKeyboard);
610 return true;
611 }
Winson Chunga0e88b52014-08-11 19:25:42 -0700612 }
613 default:
614 break;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700615 }
Winson Chung1e8d71b2014-05-16 17:05:22 -0700616 return super.onKeyDown(keyCode, event);
617 }
618
619 @Override
Winson Chunga26fb782014-06-12 17:52:39 -0700620 public void onUserInteraction() {
Winson4b9cded2016-01-26 16:26:47 -0800621 EventBus.getDefault().send(mUserInteractionEvent);
Winson Chunga26fb782014-06-12 17:52:39 -0700622 }
623
624 @Override
Winson Chung303e1ff2014-03-07 15:06:19 -0800625 public void onBackPressed() {
Winsona0731a12015-12-02 15:10:14 -0800626 // Back behaves like the recents button so just trigger a toggle event
627 EventBus.getDefault().send(new ToggleRecentsEvent());
Winson Chung303e1ff2014-03-07 15:06:19 -0800628 }
Winson Chung47c4c692014-03-17 10:17:11 -0700629
Winsonb78bb4f2015-09-24 17:22:57 -0700630 /**** EventBus events ****/
Winson Chungd543c1b2014-06-23 15:06:45 -0700631
Winson412e1802015-10-20 16:57:57 -0700632 public final void onBusEvent(ToggleRecentsEvent event) {
Winson8f6ee482016-03-18 17:51:48 -0700633 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
634 if (launchState.launchedFromHome) {
635 dismissRecentsToHome(true /* animateTaskViews */);
636 } else {
637 dismissRecentsToLaunchTargetTaskOrHome();
Winsonc29ff002015-11-20 16:00:45 -0800638 }
Winson412e1802015-10-20 16:57:57 -0700639 }
640
Winson0d14d4d2015-10-26 17:05:04 -0700641 public final void onBusEvent(IterateRecentsEvent event) {
Winson8f6ee482016-03-18 17:51:48 -0700642 final RecentsDebugFlags debugFlags = Recents.getDebugFlags();
Peter Schillerb124d562015-12-11 21:31:17 -0800643
Winson8f6ee482016-03-18 17:51:48 -0700644 // Start dozing after the recents button is clicked
645 int timerIndicatorDuration = 0;
646 if (debugFlags.isFastToggleRecentsEnabled()) {
647 timerIndicatorDuration = getResources().getInteger(
648 R.integer.recents_subsequent_auto_advance_duration);
Winson4b9cded2016-01-26 16:26:47 -0800649
Winson8f6ee482016-03-18 17:51:48 -0700650 mIterateTrigger.setDozeDuration(timerIndicatorDuration);
651 if (!mIterateTrigger.isDozing()) {
652 mIterateTrigger.startDozing();
653 } else {
654 mIterateTrigger.poke();
Winson8b1871d2015-11-20 09:56:20 -0800655 }
656 }
Winson8f6ee482016-03-18 17:51:48 -0700657
658 // Focus the next task
659 EventBus.getDefault().send(new FocusNextTaskViewEvent(timerIndicatorDuration));
660
661 MetricsLogger.action(this, MetricsEvent.ACTION_OVERVIEW_PAGE);
Winson0d14d4d2015-10-26 17:05:04 -0700662 }
663
664 public final void onBusEvent(UserInteractionEvent event) {
Winsonb61e6542016-02-04 14:37:18 -0800665 // Stop the fast-toggle dozer
Winson0d14d4d2015-10-26 17:05:04 -0700666 mIterateTrigger.stopDozing();
667 }
668
Winson412e1802015-10-20 16:57:57 -0700669 public final void onBusEvent(HideRecentsEvent event) {
670 if (event.triggeredFromAltTab) {
671 // If we are hiding from releasing Alt-Tab, dismiss Recents to the focused app
Winsone5f1faa2015-11-20 12:26:23 -0800672 if (!mIgnoreAltTabRelease) {
673 dismissRecentsToFocusedTaskOrHome();
674 }
Winson412e1802015-10-20 16:57:57 -0700675 } else if (event.triggeredFromHomeKey) {
Winson8f6ee482016-03-18 17:51:48 -0700676 dismissRecentsToHome(true /* animateTaskViews */);
Winson4b9cded2016-01-26 16:26:47 -0800677
678 // Cancel any pending dozes
679 EventBus.getDefault().send(mUserInteractionEvent);
Winson412e1802015-10-20 16:57:57 -0700680 } else {
681 // Do nothing
682 }
683 }
684
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700685 public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) {
Winsonb1e71d02015-11-23 12:40:23 -0800686 EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(true));
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800687 mRecentsView.getViewTreeObserver().addOnPreDrawListener(this);
Winsonb1e71d02015-11-23 12:40:23 -0800688 mRecentsView.invalidate();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700689 }
690
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800691 public final void onBusEvent(ExitRecentsWindowFirstAnimationFrameEvent event) {
Winsonb1e71d02015-11-23 12:40:23 -0800692 if (mRecentsView.isLastTaskLaunchedFreeform()) {
693 EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(false));
694 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800695 mRecentsView.getViewTreeObserver().addOnPreDrawListener(this);
Winsonb1e71d02015-11-23 12:40:23 -0800696 mRecentsView.invalidate();
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800697 }
698
Jorim Jaggi192086e2016-03-11 17:17:03 +0100699 public final void onBusEvent(DockedFirstAnimationFrameEvent event) {
700 mRecentsView.getViewTreeObserver().addOnPreDrawListener(this);
701 mRecentsView.invalidate();
702 }
703
Winson13d30662015-11-06 15:30:29 -0800704 public final void onBusEvent(CancelEnterRecentsWindowAnimationEvent event) {
705 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
706 int launchToTaskId = launchState.launchedToTaskId;
707 if (launchToTaskId != -1 &&
708 (event.launchTask == null || launchToTaskId != event.launchTask.key.id)) {
709 SystemServicesProxy ssp = Recents.getSystemServices();
710 ssp.cancelWindowTransition(launchState.launchedToTaskId);
711 ssp.cancelThumbnailTransition(getTaskId());
712 }
713 }
714
Winson2536c7e2015-10-01 15:49:31 -0700715 public final void onBusEvent(ShowApplicationInfoEvent event) {
716 // Create a new task stack with the application info details activity
Winson2536c7e2015-10-01 15:49:31 -0700717 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Winsone7f138c2015-10-22 16:15:21 -0700718 Uri.fromParts("package", event.task.key.getComponent().getPackageName(), null));
Winson2536c7e2015-10-01 15:49:31 -0700719 intent.setComponent(intent.resolveActivity(getPackageManager()));
720 TaskStackBuilder.create(this)
721 .addNextIntentWithParentStack(intent).startActivities(null,
Peter Schillerb124d562015-12-11 21:31:17 -0800722 new UserHandle(event.task.key.userId));
Winson2536c7e2015-10-01 15:49:31 -0700723
724 // Keep track of app-info invocations
725 MetricsLogger.count(this, "overview_app_info", 1);
726 }
727
Winson9b001392016-04-08 14:54:02 -0700728 public final void onBusEvent(ShowIncompatibleAppOverlayEvent event) {
729 if (mIncompatibleAppOverlay == null) {
730 mIncompatibleAppOverlay = Utilities.findViewStubById(this,
731 R.id.incompatible_app_overlay_stub).inflate();
732 mIncompatibleAppOverlay.setWillNotDraw(false);
733 mIncompatibleAppOverlay.setVisibility(View.VISIBLE);
734 }
735 mIncompatibleAppOverlay.animate()
736 .alpha(1f)
737 .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION)
738 .setInterpolator(Interpolators.ALPHA_IN)
739 .start();
740 }
741
742 public final void onBusEvent(HideIncompatibleAppOverlayEvent event) {
743 if (mIncompatibleAppOverlay != null) {
744 mIncompatibleAppOverlay.animate()
745 .alpha(0f)
746 .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION)
747 .setInterpolator(Interpolators.ALPHA_OUT)
748 .start();
749 }
750 }
751
Winsonef064132016-01-05 12:11:31 -0800752 public final void onBusEvent(DeleteTaskDataEvent event) {
Winson2536c7e2015-10-01 15:49:31 -0700753 // Remove any stored data from the loader
Winsone7f138c2015-10-22 16:15:21 -0700754 RecentsTaskLoader loader = Recents.getTaskLoader();
Winson2536c7e2015-10-01 15:49:31 -0700755 loader.deleteTaskData(event.task, false);
756
757 // Remove the task from activity manager
Winsone7f138c2015-10-22 16:15:21 -0700758 SystemServicesProxy ssp = Recents.getSystemServices();
759 ssp.removeTask(event.task.key.id);
Winson2536c7e2015-10-01 15:49:31 -0700760 }
761
Winson397ae742015-11-20 11:27:33 -0800762 public final void onBusEvent(AllTaskViewsDismissedEvent event) {
Winson Chung9a742902015-12-11 10:25:40 -0500763 SystemServicesProxy ssp = Recents.getSystemServices();
764 if (ssp.hasDockedTask()) {
Winson20684082016-03-16 17:13:34 -0700765 mRecentsView.showEmptyView(event.msgResId);
Winson Chung9a742902015-12-11 10:25:40 -0500766 } else {
767 // Just go straight home (no animation necessary because there are no more task views)
Winsonef064132016-01-05 12:11:31 -0800768 dismissRecentsToHome(false /* animateTaskViews */);
Winson Chung9a742902015-12-11 10:25:40 -0500769 }
Winson397ae742015-11-20 11:27:33 -0800770
771 // Keep track of all-deletions
772 MetricsLogger.count(this, "overview_task_all_dismissed", 1);
773 }
774
Winson83c1b072015-11-09 10:48:04 -0800775 public final void onBusEvent(LaunchTaskSucceededEvent event) {
776 MetricsLogger.histogram(this, "overview_task_launch_index", event.taskIndexFromStackFront);
777 }
778
779 public final void onBusEvent(LaunchTaskFailedEvent event) {
780 // Return to Home
Winsonef064132016-01-05 12:11:31 -0800781 dismissRecentsToHome(true /* animateTaskViews */);
Winson83c1b072015-11-09 10:48:04 -0800782
783 MetricsLogger.count(this, "overview_task_launch_failed", 1);
784 }
785
Winson412e1802015-10-20 16:57:57 -0700786 public final void onBusEvent(ScreenPinningRequestEvent event) {
787 MetricsLogger.count(this, "overview_screen_pinned", 1);
788 }
789
Winsonc742f972015-11-12 11:32:21 -0800790 public final void onBusEvent(DebugFlagsChangedEvent event) {
791 // Just finish recents so that we can reload the flags anew on the next instantiation
792 finish();
793 }
794
Winsone5f1faa2015-11-20 12:26:23 -0800795 public final void onBusEvent(StackViewScrolledEvent event) {
796 // Once the user has scrolled while holding alt-tab, then we should ignore the release of
797 // the key
798 mIgnoreAltTabRelease = true;
799 }
800
Jorim Jaggi3273f312016-05-05 17:32:44 -0700801 public final void onBusEvent(final DockedTopTaskEvent event) {
802 mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener);
803 mRecentsView.invalidate();
804 }
805
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800806 @Override
807 public boolean onPreDraw() {
808 mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
809 // We post to make sure that this information is delivered after this traversals is
810 // finished.
811 mRecentsView.post(new Runnable() {
812 @Override
813 public void run() {
814 Recents.getSystemServices().endProlongedAnimations();
815 }
816 });
817 return true;
818 }
Winsond72c3152016-04-05 15:33:35 -0700819
820 @Override
821 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
822 super.dump(prefix, fd, writer, args);
Winson67c79572016-04-13 14:02:18 -0700823 EventBus.getDefault().dump(prefix, writer);
Winson29a763b2016-04-20 10:50:40 -0700824 Recents.getTaskLoader().dump(prefix, writer);
Winson67c79572016-04-13 14:02:18 -0700825
Winsond72c3152016-04-05 15:33:35 -0700826 String id = Integer.toHexString(System.identityHashCode(this));
Winson Chung36f3f032016-09-08 23:29:43 +0000827 long lastStackActiveTime = Prefs.getLong(this,
828 Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1);
Winsond72c3152016-04-05 15:33:35 -0700829
830 writer.print(prefix); writer.print(TAG);
831 writer.print(" visible="); writer.print(mIsVisible ? "Y" : "N");
Winson Chung36f3f032016-09-08 23:29:43 +0000832 writer.print(" lastStackTaskActiveTime="); writer.print(lastStackActiveTime);
833 writer.print(" currentTime="); writer.print(System.currentTimeMillis());
Winsond72c3152016-04-05 15:33:35 -0700834 writer.print(" [0x"); writer.print(id); writer.print("]");
835 writer.println();
836
837 if (mRecentsView != null) {
838 mRecentsView.dump(prefix, writer);
839 }
Winsond72c3152016-04-05 15:33:35 -0700840 }
Winson Chung303e1ff2014-03-07 15:06:19 -0800841}