Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [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 | * |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 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 | |
| 19 | import android.app.Activity; |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 21 | import android.app.ActivityOptions; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 22 | import android.app.TaskStackBuilder; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 23 | import android.app.WallpaperManager; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 28 | import android.content.res.Configuration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 32 | import android.os.SystemClock; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 33 | import android.os.UserHandle; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 34 | import android.provider.Settings; |
Winson Chung | 28217a4 | 2017-02-15 13:46:52 -0800 | [diff] [blame] | 35 | import android.provider.Settings.Secure; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 36 | import android.util.Log; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 37 | import android.view.KeyEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 38 | import android.view.View; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 39 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 40 | import android.view.ViewTreeObserver.OnPreDrawListener; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 41 | import android.view.WindowManager; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 42 | import android.view.WindowManager.LayoutParams; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 43 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 44 | import com.android.internal.colorextraction.ColorExtractor; |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 45 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 46 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 47 | import com.android.keyguard.LatencyTracker; |
Jorim Jaggi | e05256e | 2016-09-08 14:58:20 -0700 | [diff] [blame] | 48 | import com.android.systemui.DejankUtils; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 49 | import com.android.systemui.Dependency; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 50 | import com.android.systemui.Interpolators; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 51 | import com.android.systemui.R; |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 52 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 53 | import com.android.systemui.recents.events.EventBus; |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 54 | import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 59 | import com.android.systemui.recents.events.activity.DockedTopTaskEvent; |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 63 | import com.android.systemui.recents.events.activity.HideRecentsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 64 | import com.android.systemui.recents.events.activity.IterateRecentsEvent; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 65 | import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent; |
| 66 | import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 67 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 68 | import com.android.systemui.recents.events.activity.ToggleRecentsEvent; |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.events.component.ActivityUnpinnedEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 70 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 71 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Winson Chung | a9c4127 | 2017-08-14 16:44:20 -0700 | [diff] [blame] | 72 | import com.android.systemui.recents.events.component.SetWaitingForTransitionStartEvent; |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 73 | import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 74 | import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 75 | import com.android.systemui.recents.events.ui.HideIncompatibleAppOverlayEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 76 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 77 | import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 78 | import com.android.systemui.recents.events.ui.ShowIncompatibleAppOverlayEvent; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 79 | import com.android.systemui.recents.events.ui.StackViewScrolledEvent; |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 81 | import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 82 | import com.android.systemui.recents.events.ui.UserInteractionEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 83 | import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent; |
| 84 | import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent; |
| 85 | import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent; |
Jiaquan He | c0e1813 | 2017-01-11 14:47:00 -0800 | [diff] [blame] | 86 | import com.android.systemui.recents.events.ui.focus.NavigateTaskViewEvent; |
| 87 | import com.android.systemui.recents.events.ui.focus.NavigateTaskViewEvent.Direction; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 88 | import com.android.systemui.recents.misc.DozeTrigger; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 89 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 90 | import com.android.systemui.recents.misc.Utilities; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 91 | import com.android.systemui.recents.model.RecentsPackageMonitor; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 92 | import com.android.systemui.recents.model.RecentsTaskLoadPlan; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 93 | import com.android.systemui.recents.model.RecentsTaskLoader; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 94 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 95 | import com.android.systemui.recents.model.TaskStack; |
| 96 | import com.android.systemui.recents.views.RecentsView; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 97 | import com.android.systemui.recents.views.SystemBarScrimViews; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 98 | import com.android.systemui.statusbar.phone.StatusBar; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 99 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 100 | import java.io.FileDescriptor; |
| 101 | import java.io.PrintWriter; |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 102 | import java.util.List; |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 103 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 104 | /** |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 105 | * The main Recents activity that is started from RecentsComponent. |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 106 | */ |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 107 | public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreDrawListener, |
| 108 | ColorExtractor.OnColorsChangedListener { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 109 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 110 | private final static String TAG = "RecentsActivity"; |
| 111 | private final static boolean DEBUG = false; |
| 112 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 113 | public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 114 | public final static int INCOMPATIBLE_APP_ALPHA_DURATION = 150; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 115 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 116 | private RecentsPackageMonitor mPackageMonitor; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 117 | private Handler mHandler = new Handler(); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 118 | private long mLastTabKeyEventTime; |
| 119 | private boolean mFinishedOnStartup; |
| 120 | private boolean mIgnoreAltTabRelease; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 121 | private boolean mIsVisible; |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 122 | private Configuration mLastConfig; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 123 | |
| 124 | // Top level views |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 125 | private RecentsView mRecentsView; |
| 126 | private SystemBarScrimViews mScrimViews; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 127 | private View mIncompatibleAppOverlay; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 128 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 129 | // Runnables to finish the Recents activity |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 130 | private Intent mHomeIntent; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 131 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 132 | // The trigger to automatically launch the current task |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 133 | private int mFocusTimerDuration; |
| 134 | private DozeTrigger mIterateTrigger; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 135 | private final UserInteractionEvent mUserInteractionEvent = new UserInteractionEvent(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 136 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 137 | // Theme and colors |
| 138 | private SysuiColorExtractor mColorExtractor; |
| 139 | private boolean mUsingDarkText; |
| 140 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 141 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 142 | * A common Runnable to finish Recents by launching Home with an animation depending on the |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 143 | * last activity launch state. Generally we always launch home when we exit Recents rather than |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 144 | * just finishing the activity since we don't know what is behind Recents in the task stack. |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 145 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 146 | class LaunchHomeRunnable implements Runnable { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 147 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 148 | Intent mLaunchIntent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 149 | ActivityOptions mOpts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 150 | |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 151 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 152 | * Creates a finish runnable that starts the specified intent. |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 153 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 154 | public LaunchHomeRunnable(Intent launchIntent, ActivityOptions opts) { |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 155 | mLaunchIntent = launchIntent; |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 156 | mOpts = opts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public void run() { |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 161 | try { |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 162 | mHandler.post(() -> { |
| 163 | ActivityOptions opts = mOpts; |
| 164 | if (opts == null) { |
| 165 | opts = ActivityOptions.makeCustomAnimation(RecentsActivity.this, |
| 166 | R.anim.recents_to_launcher_enter, R.anim.recents_to_launcher_exit); |
| 167 | } |
| 168 | startActivityAsUser(mLaunchIntent, opts.toBundle(), UserHandle.CURRENT); |
| 169 | }); |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 170 | } catch (Exception e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 171 | Log.e(TAG, getString(R.string.recents_launch_error_message, "Home"), e); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 176 | /** |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 177 | * Broadcast receiver to handle messages from the system |
| 178 | */ |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 179 | final BroadcastReceiver mSystemBroadcastReceiver = new BroadcastReceiver() { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 180 | @Override |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 181 | public void onReceive(Context ctx, Intent intent) { |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 182 | String action = intent.getAction(); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 183 | if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| 184 | // When the screen turns off, dismiss Recents to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 185 | dismissRecentsToHomeIfVisible(false); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 186 | } else if (action.equals(Intent.ACTION_TIME_CHANGED)) { |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 187 | // If the time shifts but the currentTime >= lastStackActiveTime, then that boundary |
| 188 | // is still valid. Otherwise, we need to reset the lastStackactiveTime to the |
| 189 | // currentTime and remove the old tasks in between which would not be previously |
| 190 | // visible, but currently would be in the new currentTime |
Winson Chung | 28217a4 | 2017-02-15 13:46:52 -0800 | [diff] [blame] | 191 | int currentUser = SystemServicesProxy.getInstance(RecentsActivity.this) |
| 192 | .getCurrentUser(); |
| 193 | long oldLastStackActiveTime = Settings.Secure.getLongForUser(getContentResolver(), |
| 194 | Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, -1, currentUser); |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 195 | if (oldLastStackActiveTime != -1) { |
| 196 | long currentTime = System.currentTimeMillis(); |
| 197 | if (currentTime < oldLastStackActiveTime) { |
| 198 | // We are only removing tasks that are between the new current time |
| 199 | // and the old last stack active time, they were not visible and in the |
| 200 | // TaskStack so we don't need to remove any associated TaskViews but we do |
| 201 | // need to load the task id's from the system |
Winson Chung | f3cfa89 | 2017-04-24 12:23:47 -0700 | [diff] [blame] | 202 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 203 | RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(ctx); |
| 204 | loader.preloadRawTasks(loadPlan, false /* includeFrontMostExcludedTask */); |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 205 | List<ActivityManager.RecentTaskInfo> tasks = loadPlan.getRawTasks(); |
| 206 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 207 | ActivityManager.RecentTaskInfo task = tasks.get(i); |
| 208 | if (currentTime <= task.lastActiveTime && task.lastActiveTime < |
| 209 | oldLastStackActiveTime) { |
| 210 | Recents.getSystemServices().removeTask(task.persistentId); |
| 211 | } |
| 212 | } |
Jorim Jaggi | 6b46038 | 2017-05-13 23:16:44 +0200 | [diff] [blame] | 213 | Recents.getSystemServices().updateOverviewLastStackActiveTimeAsync( |
| 214 | currentTime, currentUser); |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 215 | |
| 216 | // Clear the last PiP task time, it's an edge case and we'd rather it |
| 217 | // not relaunch the PiP task if the user double taps |
| 218 | RecentsImpl.clearLastPipTime(); |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 221 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 222 | } |
| 223 | }; |
| 224 | |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 225 | private final OnPreDrawListener mRecentsDrawnEventListener = |
| 226 | new ViewTreeObserver.OnPreDrawListener() { |
| 227 | @Override |
| 228 | public boolean onPreDraw() { |
| 229 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 230 | EventBus.getDefault().post(new RecentsDrawnEvent()); |
Jorim Jaggi | e05256e | 2016-09-08 14:58:20 -0700 | [diff] [blame] | 231 | if (LatencyTracker.isEnabled(getApplicationContext())) { |
| 232 | DejankUtils.postAfterTraversal(() -> LatencyTracker.getInstance( |
| 233 | getApplicationContext()).onActionEnd( |
| 234 | LatencyTracker.ACTION_TOGGLE_RECENTS)); |
| 235 | } |
Jorim Jaggi | 44f4bcb | 2017-05-12 15:40:43 +0200 | [diff] [blame] | 236 | DejankUtils.postAfterTraversal(() -> { |
| 237 | Recents.getTaskLoader().startLoader(RecentsActivity.this); |
| 238 | Recents.getTaskLoader().getHighResThumbnailLoader().setVisible(true); |
| 239 | }); |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 240 | return true; |
| 241 | } |
| 242 | }; |
| 243 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 246 | */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 247 | boolean dismissRecentsToFocusedTask(int logCategory) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 248 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 249 | if (ssp.isRecentsActivityVisible()) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 250 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 251 | if (mRecentsView.launchFocusedTask(logCategory)) return true; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | /** |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 257 | * Dismisses recents back to the launch target task. |
| 258 | */ |
| 259 | boolean dismissRecentsToLaunchTargetTaskOrHome() { |
| 260 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 261 | if (ssp.isRecentsActivityVisible()) { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 262 | // If we have a focused Task, launch that Task now |
| 263 | if (mRecentsView.launchPreviousTask()) return true; |
| 264 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 265 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 266 | } |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | /** |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 271 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 272 | */ |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 273 | boolean dismissRecentsToFocusedTaskOrHome() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 274 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 275 | if (ssp.isRecentsActivityVisible()) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 276 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 277 | if (mRecentsView.launchFocusedTask(0 /* logCategory */)) return true; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 278 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 279 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 280 | return true; |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 287 | */ |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 288 | void dismissRecentsToHome(boolean animateTaskViews) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 289 | dismissRecentsToHome(animateTaskViews, null); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 294 | * |
| 295 | * @param overrideAnimation If not null, will override the default animation that is based on |
| 296 | * how Recents was launched. |
| 297 | */ |
| 298 | void dismissRecentsToHome(boolean animateTaskViews, ActivityOptions overrideAnimation) { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 299 | DismissRecentsToHomeAnimationStarted dismissEvent = |
| 300 | new DismissRecentsToHomeAnimationStarted(animateTaskViews); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 301 | dismissEvent.addPostAnimationCallback(new LaunchHomeRunnable(mHomeIntent, |
| 302 | overrideAnimation)); |
Winson | 3ca1028 | 2016-04-21 15:20:21 -0700 | [diff] [blame] | 303 | Recents.getSystemServices().sendCloseSystemWindows( |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 304 | StatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 305 | EventBus.getDefault().send(dismissEvent); |
Wale Ogunwale | d351ada | 2015-04-04 11:53:14 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 308 | /** Dismisses Recents directly to Home if we currently aren't transitioning. */ |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 309 | boolean dismissRecentsToHomeIfVisible(boolean animated) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 310 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 311 | if (ssp.isRecentsActivityVisible()) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 312 | // Return to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 313 | dismissRecentsToHome(animated); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 314 | return true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 315 | } |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | /** Called with the activity is first created. */ |
| 320 | @Override |
| 321 | public void onCreate(Bundle savedInstanceState) { |
| 322 | super.onCreate(savedInstanceState); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 323 | mFinishedOnStartup = false; |
| 324 | |
| 325 | // In the case that the activity starts up before the Recents component has initialized |
| 326 | // (usually when debugging/pushing the SysUI apk), just finish this activity. |
| 327 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 328 | if (ssp == null) { |
| 329 | mFinishedOnStartup = true; |
| 330 | finish(); |
| 331 | return; |
| 332 | } |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 333 | |
| 334 | // Register this activity with the event bus |
| 335 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
| 336 | |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 337 | // Initialize the package monitor |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 338 | mPackageMonitor = new RecentsPackageMonitor(); |
| 339 | mPackageMonitor.register(this); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 340 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 341 | // Select theme based on wallpaper colors |
| 342 | mColorExtractor = Dependency.get(SysuiColorExtractor.class); |
| 343 | mColorExtractor.addOnColorsChangedListener(this); |
| 344 | mUsingDarkText = mColorExtractor.getColors(ColorExtractor.TYPE_DARK, |
| 345 | WallpaperManager.FLAG_SYSTEM, true).supportsDarkText(); |
| 346 | setTheme(mUsingDarkText ? R.style.RecentsTheme_Wallpaper_Light |
| 347 | : R.style.RecentsTheme_Wallpaper); |
| 348 | |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 349 | // Set the Recents layout |
| 350 | setContentView(R.layout.recents); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 351 | takeKeyEvents(true); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 352 | mRecentsView = findViewById(R.id.recents_view); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 353 | mScrimViews = new SystemBarScrimViews(this); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 354 | getWindow().getAttributes().privateFlags |= |
| 355 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 356 | |
Winson Chung | 427cec4 | 2017-07-17 11:35:39 -0700 | [diff] [blame] | 357 | mLastConfig = new Configuration(Utilities.getAppConfiguration(this)); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 358 | mFocusTimerDuration = getResources().getInteger(R.integer.recents_auto_advance_duration); |
| 359 | mIterateTrigger = new DozeTrigger(mFocusTimerDuration, new Runnable() { |
| 360 | @Override |
| 361 | public void run() { |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 362 | dismissRecentsToFocusedTask(MetricsEvent.OVERVIEW_SELECT_TIMEOUT); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 363 | } |
| 364 | }); |
| 365 | |
Winson | e8a4eff | 2016-03-28 16:20:35 -0700 | [diff] [blame] | 366 | // Set the window background |
| 367 | getWindow().setBackgroundDrawable(mRecentsView.getBackgroundScrim()); |
| 368 | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 369 | // Create the home intent runnable |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 370 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 371 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 372 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 373 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 374 | |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 375 | // Register the broadcast receiver to handle messages when the screen is turned off |
| 376 | IntentFilter filter = new IntentFilter(); |
| 377 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 378 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 379 | registerReceiver(mSystemBroadcastReceiver, filter); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 380 | |
| 381 | getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 382 | |
| 383 | // Reload the stack view |
| 384 | reloadStackView(); |
Winson Chung | 521e7dc | 2014-06-02 15:31:56 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 387 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 388 | protected void onStart() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 389 | super.onStart(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 390 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 391 | // Notify that recents is now visible |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 392 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 393 | MetricsLogger.visible(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Jorim Jaggi | d6a3949 | 2016-04-25 17:31:22 -0700 | [diff] [blame] | 394 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 395 | // Getting system scrim colors ignoring wallpaper visibility since it should never be grey. |
| 396 | ColorExtractor.GradientColors systemColors = mColorExtractor.getColors( |
| 397 | ColorExtractor.TYPE_DARK, WallpaperManager.FLAG_SYSTEM, true); |
| 398 | // We don't want to interpolate colors because we're defining the initial state. |
| 399 | // Gradient should be set/ready when you open "Recents". |
| 400 | mRecentsView.setScrimColors(systemColors, false); |
| 401 | |
Jorim Jaggi | d6a3949 | 2016-04-25 17:31:22 -0700 | [diff] [blame] | 402 | // Notify of the next draw |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 403 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | @Override |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 407 | public void onColorsChanged(ColorExtractor colorExtractor, int which) { |
| 408 | if ((which & WallpaperManager.FLAG_SYSTEM) != 0) { |
| 409 | // Recents doesn't care about the wallpaper being visible or not, it always |
| 410 | // wants to scrim with wallpaper colors |
| 411 | ColorExtractor.GradientColors colors = mColorExtractor.getColors( |
| 412 | WallpaperManager.FLAG_SYSTEM, |
| 413 | ColorExtractor.TYPE_DARK, true /* ignoreVis */); |
| 414 | boolean darkText = colors.supportsDarkText(); |
| 415 | if (darkText != mUsingDarkText) { |
| 416 | mUsingDarkText = darkText; |
| 417 | setTheme(mUsingDarkText ? R.style.RecentsTheme_Wallpaper_Light |
| 418 | : R.style.RecentsTheme_Wallpaper); |
| 419 | mRecentsView.reevaluateStyles(); |
| 420 | } |
| 421 | mRecentsView.setScrimColors(colors, true /* animated */); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | @Override |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 426 | protected void onNewIntent(Intent intent) { |
| 427 | super.onNewIntent(intent); |
| 428 | |
| 429 | // Reload the stack view |
| 430 | reloadStackView(); |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Reloads the stack views upon launching Recents. |
| 435 | */ |
| 436 | private void reloadStackView() { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 437 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 438 | // If the Recents component has preloaded a load plan, then use that to prevent |
| 439 | // reconstructing the task stack |
| 440 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 441 | RecentsTaskLoadPlan loadPlan = RecentsImpl.consumeInstanceLoadPlan(); |
| 442 | if (loadPlan == null) { |
| 443 | loadPlan = loader.createLoadPlan(this); |
| 444 | } |
| 445 | |
| 446 | // Start loading tasks according to the load plan |
| 447 | RecentsConfiguration config = Recents.getConfiguration(); |
| 448 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 449 | if (!loadPlan.hasTasks()) { |
Winson | 96e6134 | 2016-03-15 16:47:19 -0700 | [diff] [blame] | 450 | loader.preloadTasks(loadPlan, launchState.launchedToTaskId, |
Yoshinori Hirano | 7bccd43 | 2016-11-21 15:42:20 +0900 | [diff] [blame] | 451 | !launchState.launchedFromHome && !launchState.launchedViaDockGesture); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 455 | loadOpts.runningTaskId = launchState.launchedToTaskId; |
| 456 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 457 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 458 | loader.loadTasks(this, loadPlan, loadOpts); |
| 459 | TaskStack stack = loadPlan.getTaskStack(); |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 460 | mRecentsView.onReload(stack, mIsVisible); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 461 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 462 | // Update the nav bar scrim, but defer the animation until the enter-window event |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 463 | boolean animateNavBarScrim = !launchState.launchedViaDockGesture; |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 464 | mScrimViews.updateNavBarScrim(animateNavBarScrim, stack.getTaskCount() > 0, null); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 465 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 466 | // If this is a new instance relaunched by AM, without going through the normal mechanisms, |
| 467 | // then we have to manually trigger the enter animation state |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 468 | boolean wasLaunchedByAm = !launchState.launchedFromHome && |
| 469 | !launchState.launchedFromApp; |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 470 | if (wasLaunchedByAm) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 471 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
| 472 | } |
| 473 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 474 | // Keep track of whether we launched from the nav bar button or via alt-tab |
| 475 | if (launchState.launchedWithAltTab) { |
| 476 | MetricsLogger.count(this, "overview_trigger_alttab", 1); |
| 477 | } else { |
| 478 | MetricsLogger.count(this, "overview_trigger_nav_btn", 1); |
| 479 | } |
| 480 | |
| 481 | // Keep track of whether we launched from an app or from home |
| 482 | if (launchState.launchedFromApp) { |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 483 | Task launchTarget = stack.getLaunchTarget(); |
| 484 | int launchTaskIndexInStack = launchTarget != null |
| 485 | ? stack.indexOfStackTask(launchTarget) |
| 486 | : 0; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 487 | MetricsLogger.count(this, "overview_source_app", 1); |
| 488 | // If from an app, track the stack index of the app in the stack (for affiliated tasks) |
| 489 | MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack); |
| 490 | } else { |
| 491 | MetricsLogger.count(this, "overview_source_home", 1); |
| 492 | } |
| 493 | |
| 494 | // Keep track of the total stack task count |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 495 | int taskCount = mRecentsView.getStack().getTaskCount(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 496 | MetricsLogger.histogram(this, "overview_task_count", taskCount); |
| 497 | |
| 498 | // After we have resumed, set the visible state until the next onStop() call |
| 499 | mIsVisible = true; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | @Override |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 503 | public void onEnterAnimationComplete() { |
| 504 | super.onEnterAnimationComplete(); |
Winson Chung | ed0e2b4 | 2017-05-18 23:12:27 -0700 | [diff] [blame] | 505 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
Winson Chung | a9c4127 | 2017-08-14 16:44:20 -0700 | [diff] [blame] | 506 | |
| 507 | // Workaround for b/64694148: The animation started callback is not made (see |
| 508 | // RecentsImpl.getThumbnailTransitionActivityOptions) so reset the transition-waiting state |
| 509 | // once the enter animation has completed. |
| 510 | EventBus.getDefault().send(new SetWaitingForTransitionStartEvent(false)); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 514 | protected void onPause() { |
| 515 | super.onPause(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 516 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 517 | mIgnoreAltTabRelease = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 518 | mIterateTrigger.stopDozing(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 519 | } |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 520 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 521 | @Override |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 522 | public void onConfigurationChanged(Configuration newConfig) { |
| 523 | super.onConfigurationChanged(newConfig); |
| 524 | |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 525 | // Notify of the config change |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 526 | Configuration newDeviceConfiguration = Utilities.getAppConfiguration(this); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 527 | int numStackTasks = mRecentsView.getStack().getStackTaskCount(); |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 528 | EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */, |
Lucas Dupin | 3ceaa0a | 2017-06-27 18:17:40 -0700 | [diff] [blame] | 529 | mLastConfig.orientation != newDeviceConfiguration.orientation, |
| 530 | mLastConfig.densityDpi != newDeviceConfiguration.densityDpi, numStackTasks > 0)); |
| 531 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 532 | mLastConfig.updateFrom(newDeviceConfiguration); |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 536 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
| 537 | super.onMultiWindowModeChanged(isInMultiWindowMode); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 538 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 539 | reloadTaskStack(isInMultiWindowMode, true /* sendConfigChangedEvent */); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 543 | protected void onStop() { |
| 544 | super.onStop(); |
| 545 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 546 | // Notify that recents is now hidden |
| 547 | mIsVisible = false; |
| 548 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, false)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 549 | MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Jorim Jaggi | 6f9dbcb | 2017-03-17 17:22:47 +0100 | [diff] [blame] | 550 | Recents.getTaskLoader().getHighResThumbnailLoader().setVisible(false); |
Winson | 73492c5 | 2016-03-09 17:44:54 -0800 | [diff] [blame] | 551 | |
Yoshinori Hirano | 7bccd43 | 2016-11-21 15:42:20 +0900 | [diff] [blame] | 552 | if (!isChangingConfigurations()) { |
| 553 | // Workaround for b/22542869, if the RecentsActivity is started again, but without going |
| 554 | // through SystemUI, we need to reset the config launch flags to ensure that we do not |
| 555 | // wait on the system to send a signal that was never queued. |
| 556 | RecentsConfiguration config = Recents.getConfiguration(); |
| 557 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 558 | launchState.reset(); |
| 559 | } |
Winson Chung | 69a9c17 | 2017-06-06 14:01:29 -0700 | [diff] [blame] | 560 | |
| 561 | // Force a gc to attempt to clean up bitmap references more quickly (b/38258699) |
| 562 | Recents.getSystemServices().gc(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | @Override |
| 566 | protected void onDestroy() { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 567 | super.onDestroy(); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 568 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 569 | // In the case that the activity finished on startup, just skip the unregistration below |
| 570 | if (mFinishedOnStartup) { |
| 571 | return; |
| 572 | } |
| 573 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 574 | // Unregister the system broadcast receivers |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 575 | unregisterReceiver(mSystemBroadcastReceiver); |
Winson Chung | 905950a | 2014-09-17 09:25:27 +0200 | [diff] [blame] | 576 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 577 | // Unregister any broadcast receivers for the task loader |
| 578 | mPackageMonitor.unregister(); |
| 579 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 580 | EventBus.getDefault().unregister(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 583 | @Override |
| 584 | public void onAttachedToWindow() { |
| 585 | super.onAttachedToWindow(); |
| 586 | EventBus.getDefault().register(mScrimViews, EVENT_BUS_PRIORITY); |
| 587 | } |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 588 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 589 | @Override |
| 590 | public void onDetachedFromWindow() { |
| 591 | super.onDetachedFromWindow(); |
| 592 | EventBus.getDefault().unregister(mScrimViews); |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | @Override |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 596 | public void onTrimMemory(int level) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 597 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 598 | if (loader != null) { |
| 599 | loader.onTrimMemory(level); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | @Override |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 604 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 605 | switch (keyCode) { |
| 606 | case KeyEvent.KEYCODE_TAB: { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 607 | int altTabKeyDelay = getResources().getInteger(R.integer.recents_alt_tab_key_delay); |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 608 | boolean hasRepKeyTimeElapsed = (SystemClock.elapsedRealtime() - |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 609 | mLastTabKeyEventTime) > altTabKeyDelay; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 610 | if (event.getRepeatCount() <= 0 || hasRepKeyTimeElapsed) { |
| 611 | // Focus the next task in the stack |
| 612 | final boolean backward = event.isShiftPressed(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 613 | if (backward) { |
| 614 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
| 615 | } else { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 616 | EventBus.getDefault().send( |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 617 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 618 | } |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 619 | mLastTabKeyEventTime = SystemClock.elapsedRealtime(); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 620 | |
| 621 | // In the case of another ALT event, don't ignore the next release |
| 622 | if (event.isAltPressed()) { |
| 623 | mIgnoreAltTabRelease = false; |
| 624 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 625 | } |
| 626 | return true; |
| 627 | } |
Jiaquan He | c0e1813 | 2017-01-11 14:47:00 -0800 | [diff] [blame] | 628 | case KeyEvent.KEYCODE_DPAD_UP: |
| 629 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 630 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 631 | case KeyEvent.KEYCODE_DPAD_RIGHT: { |
| 632 | final Direction direction = NavigateTaskViewEvent.getDirectionFromKeyCode(keyCode); |
| 633 | EventBus.getDefault().send(new NavigateTaskViewEvent(direction)); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 634 | return true; |
| 635 | } |
| 636 | case KeyEvent.KEYCODE_DEL: |
| 637 | case KeyEvent.KEYCODE_FORWARD_DEL: { |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 638 | if (event.getRepeatCount() <= 0) { |
| 639 | EventBus.getDefault().send(new DismissFocusedTaskViewEvent()); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 640 | |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 641 | // Keep track of deletions by keyboard |
| 642 | MetricsLogger.histogram(this, "overview_task_dismissed_source", |
| 643 | Constants.Metrics.DismissSourceKeyboard); |
| 644 | return true; |
| 645 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 646 | } |
| 647 | default: |
| 648 | break; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 649 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 650 | return super.onKeyDown(keyCode, event); |
| 651 | } |
| 652 | |
| 653 | @Override |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 654 | public void onUserInteraction() { |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 655 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 659 | public void onBackPressed() { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 660 | // Back behaves like the recents button so just trigger a toggle event |
| 661 | EventBus.getDefault().send(new ToggleRecentsEvent()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 662 | } |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 663 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 664 | /**** EventBus events ****/ |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 665 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 666 | public final void onBusEvent(ToggleRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 667 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 668 | if (launchState.launchedFromHome) { |
| 669 | dismissRecentsToHome(true /* animateTaskViews */); |
| 670 | } else { |
| 671 | dismissRecentsToLaunchTargetTaskOrHome(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 672 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 675 | public final void onBusEvent(IterateRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 676 | final RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 677 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 678 | // Start dozing after the recents button is clicked |
| 679 | int timerIndicatorDuration = 0; |
| 680 | if (debugFlags.isFastToggleRecentsEnabled()) { |
| 681 | timerIndicatorDuration = getResources().getInteger( |
| 682 | R.integer.recents_subsequent_auto_advance_duration); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 683 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 684 | mIterateTrigger.setDozeDuration(timerIndicatorDuration); |
| 685 | if (!mIterateTrigger.isDozing()) { |
| 686 | mIterateTrigger.startDozing(); |
| 687 | } else { |
| 688 | mIterateTrigger.poke(); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 689 | } |
| 690 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 691 | |
| 692 | // Focus the next task |
| 693 | EventBus.getDefault().send(new FocusNextTaskViewEvent(timerIndicatorDuration)); |
| 694 | |
| 695 | MetricsLogger.action(this, MetricsEvent.ACTION_OVERVIEW_PAGE); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | public final void onBusEvent(UserInteractionEvent event) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 699 | // Stop the fast-toggle dozer |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 700 | mIterateTrigger.stopDozing(); |
| 701 | } |
| 702 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 703 | public final void onBusEvent(HideRecentsEvent event) { |
| 704 | if (event.triggeredFromAltTab) { |
| 705 | // If we are hiding from releasing Alt-Tab, dismiss Recents to the focused app |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 706 | if (!mIgnoreAltTabRelease) { |
| 707 | dismissRecentsToFocusedTaskOrHome(); |
| 708 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 709 | } else if (event.triggeredFromHomeKey) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 710 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 711 | |
| 712 | // Cancel any pending dozes |
| 713 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 714 | } else { |
| 715 | // Do nothing |
| 716 | } |
| 717 | } |
| 718 | |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 719 | public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 720 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(true)); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 721 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 722 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 725 | public final void onBusEvent(ExitRecentsWindowFirstAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 726 | if (mRecentsView.isLastTaskLaunchedFreeform()) { |
| 727 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(false)); |
| 728 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 729 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 730 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 731 | } |
| 732 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 733 | public final void onBusEvent(DockedFirstAnimationFrameEvent event) { |
| 734 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
| 735 | mRecentsView.invalidate(); |
| 736 | } |
| 737 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 738 | public final void onBusEvent(CancelEnterRecentsWindowAnimationEvent event) { |
| 739 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 740 | int launchToTaskId = launchState.launchedToTaskId; |
| 741 | if (launchToTaskId != -1 && |
| 742 | (event.launchTask == null || launchToTaskId != event.launchTask.key.id)) { |
| 743 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 744 | ssp.cancelWindowTransition(launchState.launchedToTaskId); |
| 745 | ssp.cancelThumbnailTransition(getTaskId()); |
| 746 | } |
| 747 | } |
| 748 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 749 | public final void onBusEvent(ShowApplicationInfoEvent event) { |
| 750 | // Create a new task stack with the application info details activity |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 751 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 752 | Uri.fromParts("package", event.task.key.getComponent().getPackageName(), null)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 753 | intent.setComponent(intent.resolveActivity(getPackageManager())); |
| 754 | TaskStackBuilder.create(this) |
| 755 | .addNextIntentWithParentStack(intent).startActivities(null, |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 756 | new UserHandle(event.task.key.userId)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 757 | |
| 758 | // Keep track of app-info invocations |
| 759 | MetricsLogger.count(this, "overview_app_info", 1); |
| 760 | } |
| 761 | |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 762 | public final void onBusEvent(ShowIncompatibleAppOverlayEvent event) { |
| 763 | if (mIncompatibleAppOverlay == null) { |
| 764 | mIncompatibleAppOverlay = Utilities.findViewStubById(this, |
| 765 | R.id.incompatible_app_overlay_stub).inflate(); |
| 766 | mIncompatibleAppOverlay.setWillNotDraw(false); |
| 767 | mIncompatibleAppOverlay.setVisibility(View.VISIBLE); |
| 768 | } |
| 769 | mIncompatibleAppOverlay.animate() |
| 770 | .alpha(1f) |
| 771 | .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION) |
| 772 | .setInterpolator(Interpolators.ALPHA_IN) |
| 773 | .start(); |
| 774 | } |
| 775 | |
| 776 | public final void onBusEvent(HideIncompatibleAppOverlayEvent event) { |
| 777 | if (mIncompatibleAppOverlay != null) { |
| 778 | mIncompatibleAppOverlay.animate() |
| 779 | .alpha(0f) |
| 780 | .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION) |
| 781 | .setInterpolator(Interpolators.ALPHA_OUT) |
| 782 | .start(); |
| 783 | } |
| 784 | } |
| 785 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 786 | public final void onBusEvent(DeleteTaskDataEvent event) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 787 | // Remove any stored data from the loader |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 788 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 789 | loader.deleteTaskData(event.task, false); |
| 790 | |
| 791 | // Remove the task from activity manager |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 792 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 793 | ssp.removeTask(event.task.key.id); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Lucas Dupin | ae90ba8 | 2017-06-16 16:45:59 -0700 | [diff] [blame] | 796 | public final void onBusEvent(TaskViewDismissedEvent event) { |
| 797 | mRecentsView.updateScrimOpacity(); |
| 798 | } |
| 799 | |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 800 | public final void onBusEvent(AllTaskViewsDismissedEvent event) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 801 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 802 | if (ssp.hasDockedTask()) { |
Winson | 2068408 | 2016-03-16 17:13:34 -0700 | [diff] [blame] | 803 | mRecentsView.showEmptyView(event.msgResId); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 804 | } else { |
| 805 | // Just go straight home (no animation necessary because there are no more task views) |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 806 | dismissRecentsToHome(false /* animateTaskViews */); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 807 | } |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 808 | |
| 809 | // Keep track of all-deletions |
| 810 | MetricsLogger.count(this, "overview_task_all_dismissed", 1); |
| 811 | } |
| 812 | |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 813 | public final void onBusEvent(LaunchTaskSucceededEvent event) { |
| 814 | MetricsLogger.histogram(this, "overview_task_launch_index", event.taskIndexFromStackFront); |
| 815 | } |
| 816 | |
| 817 | public final void onBusEvent(LaunchTaskFailedEvent event) { |
| 818 | // Return to Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 819 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 820 | |
| 821 | MetricsLogger.count(this, "overview_task_launch_failed", 1); |
| 822 | } |
| 823 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 824 | public final void onBusEvent(ScreenPinningRequestEvent event) { |
| 825 | MetricsLogger.count(this, "overview_screen_pinned", 1); |
| 826 | } |
| 827 | |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 828 | public final void onBusEvent(DebugFlagsChangedEvent event) { |
| 829 | // Just finish recents so that we can reload the flags anew on the next instantiation |
| 830 | finish(); |
| 831 | } |
| 832 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 833 | public final void onBusEvent(StackViewScrolledEvent event) { |
| 834 | // Once the user has scrolled while holding alt-tab, then we should ignore the release of |
| 835 | // the key |
| 836 | mIgnoreAltTabRelease = true; |
| 837 | } |
| 838 | |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 839 | public final void onBusEvent(final DockedTopTaskEvent event) { |
| 840 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener); |
| 841 | mRecentsView.invalidate(); |
| 842 | } |
| 843 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 844 | public final void onBusEvent(final ActivityUnpinnedEvent event) { |
| 845 | if (mIsVisible) { |
| 846 | // Skip the configuration change event as the PiP activity does not actually affect the |
| 847 | // config of recents |
| 848 | reloadTaskStack(isInMultiWindowMode(), false /* sendConfigChangedEvent */); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | private void reloadTaskStack(boolean isInMultiWindowMode, boolean sendConfigChangedEvent) { |
| 853 | // Reload the task stack completely |
| 854 | RecentsConfiguration config = Recents.getConfiguration(); |
| 855 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 856 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 857 | RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); |
| 858 | loader.preloadTasks(loadPlan, -1 /* runningTaskId */, |
| 859 | false /* includeFrontMostExcludedTask */); |
| 860 | |
| 861 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 862 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 863 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 864 | loader.loadTasks(this, loadPlan, loadOpts); |
| 865 | |
| 866 | TaskStack stack = loadPlan.getTaskStack(); |
| 867 | int numStackTasks = stack.getStackTaskCount(); |
| 868 | boolean showDeferredAnimation = numStackTasks > 0; |
| 869 | |
| 870 | if (sendConfigChangedEvent) { |
| 871 | EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */, |
| 872 | false /* fromDeviceOrientationChange */, false /* fromDisplayDensityChange */, |
| 873 | numStackTasks > 0)); |
| 874 | } |
| 875 | EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode, |
| 876 | showDeferredAnimation, stack)); |
| 877 | } |
| 878 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 879 | @Override |
| 880 | public boolean onPreDraw() { |
| 881 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 882 | // We post to make sure that this information is delivered after this traversals is |
| 883 | // finished. |
| 884 | mRecentsView.post(new Runnable() { |
| 885 | @Override |
| 886 | public void run() { |
| 887 | Recents.getSystemServices().endProlongedAnimations(); |
| 888 | } |
| 889 | }); |
| 890 | return true; |
| 891 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 892 | |
| 893 | @Override |
| 894 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 895 | super.dump(prefix, fd, writer, args); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 896 | EventBus.getDefault().dump(prefix, writer); |
Winson | 29a763b | 2016-04-20 10:50:40 -0700 | [diff] [blame] | 897 | Recents.getTaskLoader().dump(prefix, writer); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 898 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 899 | String id = Integer.toHexString(System.identityHashCode(this)); |
Winson Chung | 28217a4 | 2017-02-15 13:46:52 -0800 | [diff] [blame] | 900 | long lastStackActiveTime = Settings.Secure.getLongForUser(getContentResolver(), |
| 901 | Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, -1, |
| 902 | SystemServicesProxy.getInstance(this).getCurrentUser()); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 903 | |
| 904 | writer.print(prefix); writer.print(TAG); |
| 905 | writer.print(" visible="); writer.print(mIsVisible ? "Y" : "N"); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 906 | writer.print(" lastStackTaskActiveTime="); writer.print(lastStackActiveTime); |
| 907 | writer.print(" currentTime="); writer.print(System.currentTimeMillis()); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 908 | writer.print(" [0x"); writer.print(id); writer.print("]"); |
| 909 | writer.println(); |
| 910 | |
| 911 | if (mRecentsView != null) { |
| 912 | mRecentsView.dump(prefix, writer); |
| 913 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 914 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 915 | } |