Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 1 | package com.android.server.am; |
| 2 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 3 | import static android.app.ActivityManager.START_SUCCESS; |
| 4 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 5 | import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 6 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 7 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 8 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 9 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 10 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 11 | import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT; |
| 12 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION; |
| 13 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_ACTIVITY_NAME; |
| 14 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DELAY_MS; |
| 15 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DEVICE_UPTIME_SECONDS; |
| 16 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS; |
| 17 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS; |
| 18 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH; |
| 19 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_HOT_LAUNCH; |
| 20 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_WARM_LAUNCH; |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 21 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 22 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 23 | import static com.android.server.am.ActivityStack.STACK_INVISIBLE; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 24 | |
| 25 | import android.app.ActivityManager.StackId; |
| 26 | import android.content.Context; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 27 | import android.metrics.LogMaker; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 28 | import android.os.SystemClock; |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 29 | import android.util.Slog; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 30 | import android.util.SparseArray; |
| 31 | import android.util.SparseIntArray; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 32 | |
| 33 | import com.android.internal.logging.MetricsLogger; |
| 34 | |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 35 | import java.util.ArrayList; |
| 36 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Handles logging into Tron. |
| 39 | */ |
| 40 | class ActivityMetricsLogger { |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 41 | |
| 42 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityMetricsLogger" : TAG_AM; |
| 43 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 44 | // Window modes we are interested in logging. If we ever introduce a new type, we need to add |
| 45 | // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array. |
| 46 | private static final int WINDOW_STATE_STANDARD = 0; |
| 47 | private static final int WINDOW_STATE_SIDE_BY_SIDE = 1; |
| 48 | private static final int WINDOW_STATE_FREEFORM = 2; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 49 | private static final int WINDOW_STATE_ASSISTANT = 3; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 50 | private static final int WINDOW_STATE_INVALID = -1; |
| 51 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 52 | private static final long INVALID_START_TIME = -1; |
| 53 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 54 | // Preallocated strings we are sending to tron, so we don't have to allocate a new one every |
| 55 | // time we log. |
| 56 | private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 57 | "window_time_0", "window_time_1", "window_time_2", "window_time_3"}; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 58 | |
| 59 | private int mWindowState = WINDOW_STATE_STANDARD; |
| 60 | private long mLastLogTimeSecs; |
| 61 | private final ActivityStackSupervisor mSupervisor; |
| 62 | private final Context mContext; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 63 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 64 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 65 | private long mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 66 | |
| 67 | private int mCurrentTransitionDeviceUptime; |
| 68 | private int mCurrentTransitionDelayMs; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 69 | private boolean mLoggedTransitionStarting; |
| 70 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 71 | private final SparseArray<StackTransitionInfo> mStackTransitionInfo = new SparseArray<>(); |
| 72 | |
| 73 | private final class StackTransitionInfo { |
| 74 | private ActivityRecord launchedActivity; |
| 75 | private int startResult; |
| 76 | private boolean currentTransitionProcessRunning; |
| 77 | private int windowsDrawnDelayMs; |
| 78 | private int startingWindowDelayMs; |
| 79 | private int reason = APP_TRANSITION_TIMEOUT; |
| 80 | private boolean loggedWindowsDrawn; |
| 81 | private boolean loggedStartingWindowDrawn; |
| 82 | } |
| 83 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 84 | ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context) { |
| 85 | mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000; |
| 86 | mSupervisor = supervisor; |
| 87 | mContext = context; |
| 88 | } |
| 89 | |
| 90 | void logWindowState() { |
| 91 | final long now = SystemClock.elapsedRealtime() / 1000; |
| 92 | if (mWindowState != WINDOW_STATE_INVALID) { |
| 93 | // We log even if the window state hasn't changed, because the user might remain in |
| 94 | // home/fullscreen move forever and we would like to track this kind of behavior |
| 95 | // too. |
| 96 | MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState], |
| 97 | (int) (now - mLastLogTimeSecs)); |
| 98 | } |
| 99 | mLastLogTimeSecs = now; |
| 100 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 101 | ActivityStack stack = mSupervisor.getStack(DOCKED_STACK_ID); |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 102 | if (stack != null && stack.getStackVisibilityLocked(null) != STACK_INVISIBLE) { |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 103 | mWindowState = WINDOW_STATE_SIDE_BY_SIDE; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 104 | return; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 105 | } |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 106 | mWindowState = WINDOW_STATE_INVALID; |
| 107 | stack = mSupervisor.getFocusedStack(); |
| 108 | if (stack.mStackId == PINNED_STACK_ID) { |
| 109 | stack = mSupervisor.findStackBehind(stack); |
| 110 | } |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 111 | if (StackId.isHomeOrRecentsStack(stack.mStackId) |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 112 | || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) { |
| 113 | mWindowState = WINDOW_STATE_STANDARD; |
| 114 | } else if (stack.mStackId == DOCKED_STACK_ID) { |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 115 | Slog.wtf(TAG, "Docked stack shouldn't be the focused stack, because it reported not" |
| 116 | + " being visible."); |
| 117 | mWindowState = WINDOW_STATE_INVALID; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 118 | } else if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 119 | mWindowState = WINDOW_STATE_FREEFORM; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 120 | } else if (stack.mStackId == ASSISTANT_STACK_ID) { |
| 121 | mWindowState = WINDOW_STATE_ASSISTANT; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 122 | } else if (StackId.isStaticStack(stack.mStackId)) { |
| 123 | throw new IllegalStateException("Unknown stack=" + stack); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 124 | } |
| 125 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * Notifies the tracker at the earliest possible point when we are starting to launch an |
| 129 | * activity. |
| 130 | */ |
| 131 | void notifyActivityLaunching() { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 132 | if (!isAnyTransitionActive()) { |
| 133 | mCurrentTransitionStartTime = System.currentTimeMillis(); |
| 134 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 138 | * Notifies the tracker that the activity is actually launching. |
| 139 | * |
| 140 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 141 | * launch |
| 142 | * @param launchedActivity the activity that is being launched |
| 143 | */ |
| 144 | void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) { |
| 145 | final ProcessRecord processRecord = launchedActivity != null |
| 146 | ? mSupervisor.mService.mProcessNames.get(launchedActivity.processName, |
| 147 | launchedActivity.appInfo.uid) |
| 148 | : null; |
| 149 | final boolean processRunning = processRecord != null; |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 150 | |
| 151 | // We consider this a "process switch" if the process of the activity that gets launched |
| 152 | // didn't have an activity that was in started state. In this case, we assume that lot |
| 153 | // of caches might be purged so the time until it produces the first frame is very |
| 154 | // interesting. |
| 155 | final boolean processSwitch = processRecord == null |
| 156 | || !hasStartedActivity(processRecord, launchedActivity); |
| 157 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 158 | notifyActivityLaunched(resultCode, launchedActivity, processRunning, processSwitch); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | private boolean hasStartedActivity(ProcessRecord record, ActivityRecord launchedActivity) { |
| 162 | final ArrayList<ActivityRecord> activities = record.activities; |
| 163 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 164 | final ActivityRecord activity = activities.get(i); |
| 165 | if (launchedActivity == activity) { |
| 166 | continue; |
| 167 | } |
| 168 | if (!activity.stopped) { |
| 169 | return true; |
| 170 | } |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 176 | * Notifies the tracker the the activity is actually launching. |
| 177 | * |
| 178 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 179 | * launch |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 180 | * @param launchedActivity the activity being launched |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 181 | * @param processRunning whether the process that will contains the activity is already running |
Jorim Jaggi | be67c90 | 2016-04-12 00:53:16 -0700 | [diff] [blame] | 182 | * @param processSwitch whether the process that will contain the activity didn't have any |
| 183 | * activity that was stopped, i.e. the started activity is "switching" |
| 184 | * processes |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 185 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 186 | private void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity, |
Jorim Jaggi | be67c90 | 2016-04-12 00:53:16 -0700 | [diff] [blame] | 187 | boolean processRunning, boolean processSwitch) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 188 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 189 | // If we are already in an existing transition, only update the activity name, but not the |
| 190 | // other attributes. |
| 191 | final int stackId = launchedActivity != null && launchedActivity.getStack() != null |
| 192 | ? launchedActivity.getStack().mStackId |
| 193 | : INVALID_STACK_ID; |
| 194 | final StackTransitionInfo info = mStackTransitionInfo.get(stackId); |
| 195 | if (launchedActivity != null && info != null) { |
| 196 | info.launchedActivity = launchedActivity; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 197 | return; |
| 198 | } |
| 199 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 200 | final boolean otherStacksLaunching = mStackTransitionInfo.size() > 0 && info == null; |
| 201 | if ((resultCode < 0 || launchedActivity == null || !processSwitch |
| 202 | || stackId == INVALID_STACK_ID) && !otherStacksLaunching) { |
Alison Cichowlas | 803054d | 2016-12-13 14:38:01 -0500 | [diff] [blame] | 203 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 204 | // Failed to launch or it was not a process switch, so we don't care about the timing. |
| 205 | reset(true /* abort */); |
| 206 | return; |
| 207 | } else if (otherStacksLaunching) { |
| 208 | // Don't log this stack but continue with the other stacks. |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | final StackTransitionInfo newInfo = new StackTransitionInfo(); |
| 213 | newInfo.launchedActivity = launchedActivity; |
| 214 | newInfo.currentTransitionProcessRunning = processRunning; |
| 215 | newInfo.startResult = resultCode; |
| 216 | mStackTransitionInfo.append(stackId, newInfo); |
| 217 | mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Notifies the tracker that all windows of the app have been drawn. |
| 222 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 223 | void notifyWindowsDrawn(int stackId) { |
| 224 | final StackTransitionInfo info = mStackTransitionInfo.get(stackId); |
| 225 | if (info == null || info.loggedWindowsDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 226 | return; |
| 227 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 228 | info.windowsDrawnDelayMs = calculateCurrentDelay(); |
| 229 | info.loggedWindowsDrawn = true; |
| 230 | if (allStacksWindowsDrawn() && mLoggedTransitionStarting) { |
| 231 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Notifies the tracker that the starting window was drawn. |
| 237 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 238 | void notifyStartingWindowDrawn(int stackId) { |
| 239 | final StackTransitionInfo info = mStackTransitionInfo.get(stackId); |
| 240 | if (info == null || info.loggedStartingWindowDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 241 | return; |
| 242 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 243 | info.loggedStartingWindowDrawn = true; |
| 244 | info.startingWindowDelayMs = calculateCurrentDelay(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Notifies the tracker that the app transition is starting. |
| 249 | * |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 250 | * @param stackIdReasons A map from stack id to a reason integer, which must be on of |
| 251 | * ActivityManagerInternal.APP_TRANSITION_* reasons. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 252 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 253 | void notifyTransitionStarting(SparseIntArray stackIdReasons) { |
Jorim Jaggi | 453cae3 | 2017-03-16 15:41:40 +0100 | [diff] [blame] | 254 | // TODO (b/36339388): Figure out why stackIdReasons can be null |
| 255 | if (stackIdReasons == null || !isAnyTransitionActive() || mLoggedTransitionStarting) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 256 | return; |
| 257 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 258 | mCurrentTransitionDelayMs = calculateCurrentDelay(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 259 | mLoggedTransitionStarting = true; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 260 | for (int index = stackIdReasons.size() - 1; index >= 0; index--) { |
| 261 | final int stackId = stackIdReasons.keyAt(index); |
| 262 | final StackTransitionInfo info = mStackTransitionInfo.get(stackId); |
| 263 | if (info == null) { |
| 264 | continue; |
| 265 | } |
| 266 | info.reason = stackIdReasons.valueAt(index); |
| 267 | } |
| 268 | if (allStacksWindowsDrawn()) { |
| 269 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 273 | private boolean allStacksWindowsDrawn() { |
| 274 | for (int index = mStackTransitionInfo.size() - 1; index >= 0; index--) { |
| 275 | if (!mStackTransitionInfo.valueAt(index).loggedWindowsDrawn) { |
| 276 | return false; |
| 277 | } |
| 278 | } |
| 279 | return true; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 280 | } |
| 281 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 282 | private boolean isAnyTransitionActive() { |
| 283 | return mCurrentTransitionStartTime != INVALID_START_TIME |
| 284 | && mStackTransitionInfo.size() > 0; |
| 285 | } |
| 286 | |
| 287 | private void reset(boolean abort) { |
| 288 | if (!abort && isAnyTransitionActive()) { |
| 289 | logAppTransitionMultiEvents(); |
| 290 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 291 | mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 292 | mCurrentTransitionDelayMs = -1; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 293 | mLoggedTransitionStarting = false; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 294 | mStackTransitionInfo.clear(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | private int calculateCurrentDelay() { |
| 298 | |
| 299 | // Shouldn't take more than 25 days to launch an app, so int is fine here. |
| 300 | return (int) (System.currentTimeMillis() - mCurrentTransitionStartTime); |
| 301 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 302 | |
| 303 | private void logAppTransitionMultiEvents() { |
| 304 | for (int index = mStackTransitionInfo.size() - 1; index >= 0; index--) { |
| 305 | final StackTransitionInfo info = mStackTransitionInfo.valueAt(index); |
| 306 | final int type = getTransitionType(info); |
| 307 | if (type == -1) { |
| 308 | return; |
| 309 | } |
| 310 | final LogMaker builder = new LogMaker(APP_TRANSITION); |
| 311 | builder.setPackageName(info.launchedActivity.packageName); |
| 312 | builder.addTaggedData(APP_TRANSITION_ACTIVITY_NAME, info.launchedActivity.info.name); |
| 313 | builder.setType(type); |
| 314 | builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS, |
| 315 | mCurrentTransitionDeviceUptime); |
| 316 | builder.addTaggedData(APP_TRANSITION_DELAY_MS, mCurrentTransitionDelayMs); |
| 317 | builder.setSubtype(info.reason); |
| 318 | if (info.startingWindowDelayMs != -1) { |
| 319 | builder.addTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS, |
| 320 | info.startingWindowDelayMs); |
| 321 | } |
| 322 | builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs); |
| 323 | mMetricsLogger.write(builder); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | private int getTransitionType(StackTransitionInfo info) { |
| 328 | if (info.currentTransitionProcessRunning) { |
| 329 | if (info.startResult == START_SUCCESS) { |
| 330 | return TYPE_TRANSITION_WARM_LAUNCH; |
| 331 | } else if (info.startResult == START_TASK_TO_FRONT) { |
| 332 | return TYPE_TRANSITION_HOT_LAUNCH; |
| 333 | } |
| 334 | } else if (info.startResult == START_SUCCESS) { |
| 335 | return TYPE_TRANSITION_COLD_LAUNCH; |
| 336 | } |
| 337 | return -1; |
| 338 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 339 | } |