blob: 98815d7e18c7c8307d19a6e70df877b28e89a585 [file] [log] [blame]
Filip Gruszczynski77d94482015-12-11 13:59:52 -08001package com.android.server.am;
2
Jorim Jaggi3878ca32017-02-02 17:13:05 -08003import static android.app.ActivityManager.START_SUCCESS;
4import static android.app.ActivityManager.START_TASK_TO_FRONT;
Winson Chung83471632016-12-13 11:02:12 -08005import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
Filip Gruszczynski77d94482015-12-11 13:59:52 -08006import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
7import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
8import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
Jorim Jaggi3878ca32017-02-02 17:13:05 -08009import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -080010import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080011import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT;
12import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION;
Jorim Jaggi515dd682017-05-05 15:05:07 +020013import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_BIND_APPLICATION_DELAY_MS;
Todd Kennedy50d946c12017-03-17 13:55:38 -070014import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_CALLING_PACKAGE_NAME;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080015import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DELAY_MS;
16import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DEVICE_UPTIME_SECONDS;
Todd Kennedy50d946c12017-03-17 13:55:38 -070017import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_IS_EPHEMERAL;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080018import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS;
19import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS;
Jorim Jaggicdfc04e2017-04-28 19:06:24 +020020import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CLASS_NAME;
Todd Kennedy50d946c12017-03-17 13:55:38 -070021import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_INSTANT_APP_LAUNCH_TOKEN;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080022import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH;
23import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_HOT_LAUNCH;
24import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_WARM_LAUNCH;
Jorim Jaggif9704102016-05-05 19:14:22 -070025import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
26import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0e381e22016-01-14 16:31:33 -080027import static com.android.server.am.ActivityStack.STACK_INVISIBLE;
Filip Gruszczynski77d94482015-12-11 13:59:52 -080028
29import android.app.ActivityManager.StackId;
30import android.content.Context;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080031import android.metrics.LogMaker;
Filip Gruszczynski77d94482015-12-11 13:59:52 -080032import android.os.SystemClock;
Jorim Jaggif9704102016-05-05 19:14:22 -070033import android.util.Slog;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080034import android.util.SparseArray;
35import android.util.SparseIntArray;
Filip Gruszczynski77d94482015-12-11 13:59:52 -080036
37import com.android.internal.logging.MetricsLogger;
38
Jorim Jaggi1e630c02016-05-16 12:13:13 -070039import java.util.ArrayList;
40
Filip Gruszczynski77d94482015-12-11 13:59:52 -080041/**
42 * Handles logging into Tron.
43 */
44class ActivityMetricsLogger {
Jorim Jaggif9704102016-05-05 19:14:22 -070045
46 private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityMetricsLogger" : TAG_AM;
47
Filip Gruszczynski77d94482015-12-11 13:59:52 -080048 // Window modes we are interested in logging. If we ever introduce a new type, we need to add
49 // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array.
50 private static final int WINDOW_STATE_STANDARD = 0;
51 private static final int WINDOW_STATE_SIDE_BY_SIDE = 1;
52 private static final int WINDOW_STATE_FREEFORM = 2;
Winson Chung83471632016-12-13 11:02:12 -080053 private static final int WINDOW_STATE_ASSISTANT = 3;
Filip Gruszczynski77d94482015-12-11 13:59:52 -080054 private static final int WINDOW_STATE_INVALID = -1;
55
Jorim Jaggi275561a2016-02-23 10:11:02 -050056 private static final long INVALID_START_TIME = -1;
57
Filip Gruszczynski77d94482015-12-11 13:59:52 -080058 // Preallocated strings we are sending to tron, so we don't have to allocate a new one every
59 // time we log.
60 private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = {
Winson Chung83471632016-12-13 11:02:12 -080061 "window_time_0", "window_time_1", "window_time_2", "window_time_3"};
Filip Gruszczynski77d94482015-12-11 13:59:52 -080062
63 private int mWindowState = WINDOW_STATE_STANDARD;
64 private long mLastLogTimeSecs;
65 private final ActivityStackSupervisor mSupervisor;
66 private final Context mContext;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080067 private final MetricsLogger mMetricsLogger = new MetricsLogger();
Filip Gruszczynski77d94482015-12-11 13:59:52 -080068
Jorim Jaggi275561a2016-02-23 10:11:02 -050069 private long mCurrentTransitionStartTime = INVALID_START_TIME;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080070
71 private int mCurrentTransitionDeviceUptime;
72 private int mCurrentTransitionDelayMs;
Jorim Jaggi275561a2016-02-23 10:11:02 -050073 private boolean mLoggedTransitionStarting;
74
Jorim Jaggi3878ca32017-02-02 17:13:05 -080075 private final SparseArray<StackTransitionInfo> mStackTransitionInfo = new SparseArray<>();
76
77 private final class StackTransitionInfo {
78 private ActivityRecord launchedActivity;
79 private int startResult;
80 private boolean currentTransitionProcessRunning;
81 private int windowsDrawnDelayMs;
Jorim Jaggi515dd682017-05-05 15:05:07 +020082 private int startingWindowDelayMs = -1;
83 private int bindApplicationDelayMs = -1;
Jorim Jaggi3878ca32017-02-02 17:13:05 -080084 private int reason = APP_TRANSITION_TIMEOUT;
85 private boolean loggedWindowsDrawn;
86 private boolean loggedStartingWindowDrawn;
87 }
88
Filip Gruszczynski77d94482015-12-11 13:59:52 -080089 ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context) {
90 mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000;
91 mSupervisor = supervisor;
92 mContext = context;
93 }
94
95 void logWindowState() {
96 final long now = SystemClock.elapsedRealtime() / 1000;
97 if (mWindowState != WINDOW_STATE_INVALID) {
98 // We log even if the window state hasn't changed, because the user might remain in
99 // home/fullscreen move forever and we would like to track this kind of behavior
100 // too.
101 MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState],
102 (int) (now - mLastLogTimeSecs));
103 }
104 mLastLogTimeSecs = now;
105
Filip Gruszczynski77d94482015-12-11 13:59:52 -0800106 ActivityStack stack = mSupervisor.getStack(DOCKED_STACK_ID);
Wale Ogunwalecd501ec2017-04-07 08:53:41 -0700107 if (stack != null && stack.shouldBeVisible(null) != STACK_INVISIBLE) {
Filip Gruszczynski77d94482015-12-11 13:59:52 -0800108 mWindowState = WINDOW_STATE_SIDE_BY_SIDE;
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -0800109 return;
Filip Gruszczynski77d94482015-12-11 13:59:52 -0800110 }
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -0800111 mWindowState = WINDOW_STATE_INVALID;
112 stack = mSupervisor.getFocusedStack();
113 if (stack.mStackId == PINNED_STACK_ID) {
114 stack = mSupervisor.findStackBehind(stack);
115 }
Matthew Ngae1ff4f2016-11-10 15:49:14 -0800116 if (StackId.isHomeOrRecentsStack(stack.mStackId)
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -0800117 || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) {
118 mWindowState = WINDOW_STATE_STANDARD;
119 } else if (stack.mStackId == DOCKED_STACK_ID) {
Jorim Jaggif9704102016-05-05 19:14:22 -0700120 Slog.wtf(TAG, "Docked stack shouldn't be the focused stack, because it reported not"
121 + " being visible.");
122 mWindowState = WINDOW_STATE_INVALID;
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -0800123 } else if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
124 mWindowState = WINDOW_STATE_FREEFORM;
Winson Chung83471632016-12-13 11:02:12 -0800125 } else if (stack.mStackId == ASSISTANT_STACK_ID) {
126 mWindowState = WINDOW_STATE_ASSISTANT;
Filip Gruszczynskicaae14e2015-12-16 14:40:04 -0800127 } else if (StackId.isStaticStack(stack.mStackId)) {
128 throw new IllegalStateException("Unknown stack=" + stack);
Filip Gruszczynski77d94482015-12-11 13:59:52 -0800129 }
130 }
Jorim Jaggi275561a2016-02-23 10:11:02 -0500131
132 /**
133 * Notifies the tracker at the earliest possible point when we are starting to launch an
134 * activity.
135 */
136 void notifyActivityLaunching() {
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800137 if (!isAnyTransitionActive()) {
Alison Cichowlasb7f67ab2017-04-25 18:04:40 -0400138 mCurrentTransitionStartTime = SystemClock.uptimeMillis();
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800139 }
Jorim Jaggi275561a2016-02-23 10:11:02 -0500140 }
141
142 /**
Jorim Jaggi1e630c02016-05-16 12:13:13 -0700143 * Notifies the tracker that the activity is actually launching.
144 *
145 * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the
146 * launch
147 * @param launchedActivity the activity that is being launched
148 */
149 void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) {
150 final ProcessRecord processRecord = launchedActivity != null
151 ? mSupervisor.mService.mProcessNames.get(launchedActivity.processName,
152 launchedActivity.appInfo.uid)
153 : null;
154 final boolean processRunning = processRecord != null;
Jorim Jaggi1e630c02016-05-16 12:13:13 -0700155
156 // We consider this a "process switch" if the process of the activity that gets launched
157 // didn't have an activity that was in started state. In this case, we assume that lot
158 // of caches might be purged so the time until it produces the first frame is very
159 // interesting.
160 final boolean processSwitch = processRecord == null
161 || !hasStartedActivity(processRecord, launchedActivity);
162
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800163 notifyActivityLaunched(resultCode, launchedActivity, processRunning, processSwitch);
Jorim Jaggi1e630c02016-05-16 12:13:13 -0700164 }
165
166 private boolean hasStartedActivity(ProcessRecord record, ActivityRecord launchedActivity) {
167 final ArrayList<ActivityRecord> activities = record.activities;
168 for (int i = activities.size() - 1; i >= 0; i--) {
169 final ActivityRecord activity = activities.get(i);
170 if (launchedActivity == activity) {
171 continue;
172 }
173 if (!activity.stopped) {
174 return true;
175 }
176 }
177 return false;
178 }
179
180 /**
Jorim Jaggi275561a2016-02-23 10:11:02 -0500181 * Notifies the tracker the the activity is actually launching.
182 *
183 * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the
184 * launch
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800185 * @param launchedActivity the activity being launched
Jorim Jaggi275561a2016-02-23 10:11:02 -0500186 * @param processRunning whether the process that will contains the activity is already running
Jorim Jaggibe67c902016-04-12 00:53:16 -0700187 * @param processSwitch whether the process that will contain the activity didn't have any
188 * activity that was stopped, i.e. the started activity is "switching"
189 * processes
Jorim Jaggi275561a2016-02-23 10:11:02 -0500190 */
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800191 private void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity,
Jorim Jaggibe67c902016-04-12 00:53:16 -0700192 boolean processRunning, boolean processSwitch) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500193
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800194 // If we are already in an existing transition, only update the activity name, but not the
195 // other attributes.
196 final int stackId = launchedActivity != null && launchedActivity.getStack() != null
197 ? launchedActivity.getStack().mStackId
198 : INVALID_STACK_ID;
Jorim Jaggicdfc04e2017-04-28 19:06:24 +0200199
200 if (mCurrentTransitionStartTime == INVALID_START_TIME) {
201 return;
202 }
203
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800204 final StackTransitionInfo info = mStackTransitionInfo.get(stackId);
205 if (launchedActivity != null && info != null) {
206 info.launchedActivity = launchedActivity;
Jorim Jaggi275561a2016-02-23 10:11:02 -0500207 return;
208 }
209
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800210 final boolean otherStacksLaunching = mStackTransitionInfo.size() > 0 && info == null;
211 if ((resultCode < 0 || launchedActivity == null || !processSwitch
212 || stackId == INVALID_STACK_ID) && !otherStacksLaunching) {
Alison Cichowlas803054d2016-12-13 14:38:01 -0500213
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800214 // Failed to launch or it was not a process switch, so we don't care about the timing.
215 reset(true /* abort */);
216 return;
217 } else if (otherStacksLaunching) {
218 // Don't log this stack but continue with the other stacks.
219 return;
220 }
221
222 final StackTransitionInfo newInfo = new StackTransitionInfo();
223 newInfo.launchedActivity = launchedActivity;
224 newInfo.currentTransitionProcessRunning = processRunning;
225 newInfo.startResult = resultCode;
226 mStackTransitionInfo.append(stackId, newInfo);
227 mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500228 }
229
230 /**
231 * Notifies the tracker that all windows of the app have been drawn.
232 */
Sudheer Shankac766db02017-06-12 10:37:29 -0700233 void notifyWindowsDrawn(int stackId, long timestamp) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800234 final StackTransitionInfo info = mStackTransitionInfo.get(stackId);
235 if (info == null || info.loggedWindowsDrawn) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500236 return;
237 }
Sudheer Shankac766db02017-06-12 10:37:29 -0700238 info.windowsDrawnDelayMs = calculateDelay(timestamp);
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800239 info.loggedWindowsDrawn = true;
240 if (allStacksWindowsDrawn() && mLoggedTransitionStarting) {
241 reset(false /* abort */);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500242 }
243 }
244
245 /**
246 * Notifies the tracker that the starting window was drawn.
247 */
Sudheer Shankac766db02017-06-12 10:37:29 -0700248 void notifyStartingWindowDrawn(int stackId, long timestamp) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800249 final StackTransitionInfo info = mStackTransitionInfo.get(stackId);
250 if (info == null || info.loggedStartingWindowDrawn) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500251 return;
252 }
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800253 info.loggedStartingWindowDrawn = true;
Sudheer Shankac766db02017-06-12 10:37:29 -0700254 info.startingWindowDelayMs = calculateDelay(timestamp);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500255 }
256
257 /**
258 * Notifies the tracker that the app transition is starting.
259 *
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800260 * @param stackIdReasons A map from stack id to a reason integer, which must be on of
261 * ActivityManagerInternal.APP_TRANSITION_* reasons.
Jorim Jaggi275561a2016-02-23 10:11:02 -0500262 */
Sudheer Shankac766db02017-06-12 10:37:29 -0700263 void notifyTransitionStarting(SparseIntArray stackIdReasons, long timestamp) {
Jorim Jaggid8a57772017-04-14 16:50:42 -0700264 if (!isAnyTransitionActive() || mLoggedTransitionStarting) {
Jorim Jaggi275561a2016-02-23 10:11:02 -0500265 return;
266 }
Sudheer Shankac766db02017-06-12 10:37:29 -0700267 mCurrentTransitionDelayMs = calculateDelay(timestamp);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500268 mLoggedTransitionStarting = true;
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800269 for (int index = stackIdReasons.size() - 1; index >= 0; index--) {
270 final int stackId = stackIdReasons.keyAt(index);
271 final StackTransitionInfo info = mStackTransitionInfo.get(stackId);
272 if (info == null) {
273 continue;
274 }
275 info.reason = stackIdReasons.valueAt(index);
276 }
277 if (allStacksWindowsDrawn()) {
278 reset(false /* abort */);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500279 }
280 }
281
Jorim Jaggicdfc04e2017-04-28 19:06:24 +0200282 /**
283 * Notifies the tracker that the visibility of an app is changing.
284 *
285 * @param activityRecord the app that is changing its visibility
286 * @param visible whether it's going to be visible or not
287 */
288 void notifyVisibilityChanged(ActivityRecord activityRecord, boolean visible) {
289 final StackTransitionInfo info = mStackTransitionInfo.get(activityRecord.getStackId());
290
291 // If we have an active transition that's waiting on a certain activity that will be
292 // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary.
293 if (info != null && !visible && info.launchedActivity == activityRecord) {
294 mStackTransitionInfo.remove(activityRecord.getStackId());
295 if (mStackTransitionInfo.size() == 0) {
296 reset(true /* abort */);
297 }
298 }
299 }
300
Jorim Jaggi515dd682017-05-05 15:05:07 +0200301 /**
302 * Notifies the tracker that we called immediately before we call bindApplication on the client.
303 *
304 * @param app The client into which we'll call bindApplication.
305 */
306 void notifyBindApplication(ProcessRecord app) {
307 for (int i = mStackTransitionInfo.size() - 1; i >= 0; i--) {
308 final StackTransitionInfo info = mStackTransitionInfo.valueAt(i);
309
310 // App isn't attached to record yet, so match with info.
311 if (info.launchedActivity.appInfo == app.info) {
312 info.bindApplicationDelayMs = calculateCurrentDelay();
313 }
314 }
315 }
316
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800317 private boolean allStacksWindowsDrawn() {
318 for (int index = mStackTransitionInfo.size() - 1; index >= 0; index--) {
319 if (!mStackTransitionInfo.valueAt(index).loggedWindowsDrawn) {
320 return false;
321 }
322 }
323 return true;
Jorim Jaggi275561a2016-02-23 10:11:02 -0500324 }
325
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800326 private boolean isAnyTransitionActive() {
327 return mCurrentTransitionStartTime != INVALID_START_TIME
328 && mStackTransitionInfo.size() > 0;
329 }
330
331 private void reset(boolean abort) {
332 if (!abort && isAnyTransitionActive()) {
333 logAppTransitionMultiEvents();
334 }
Jorim Jaggi275561a2016-02-23 10:11:02 -0500335 mCurrentTransitionStartTime = INVALID_START_TIME;
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800336 mCurrentTransitionDelayMs = -1;
Jorim Jaggi275561a2016-02-23 10:11:02 -0500337 mLoggedTransitionStarting = false;
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800338 mStackTransitionInfo.clear();
Jorim Jaggi275561a2016-02-23 10:11:02 -0500339 }
340
341 private int calculateCurrentDelay() {
342
343 // Shouldn't take more than 25 days to launch an app, so int is fine here.
Alison Cichowlasb7f67ab2017-04-25 18:04:40 -0400344 return (int) (SystemClock.uptimeMillis() - mCurrentTransitionStartTime);
Jorim Jaggi275561a2016-02-23 10:11:02 -0500345 }
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800346
Sudheer Shankac766db02017-06-12 10:37:29 -0700347 private int calculateDelay(long timestamp) {
348 // Shouldn't take more than 25 days to launch an app, so int is fine here.
349 return (int) (timestamp - mCurrentTransitionStartTime);
350 }
351
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800352 private void logAppTransitionMultiEvents() {
353 for (int index = mStackTransitionInfo.size() - 1; index >= 0; index--) {
354 final StackTransitionInfo info = mStackTransitionInfo.valueAt(index);
355 final int type = getTransitionType(info);
356 if (type == -1) {
357 return;
358 }
359 final LogMaker builder = new LogMaker(APP_TRANSITION);
360 builder.setPackageName(info.launchedActivity.packageName);
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800361 builder.setType(type);
Jason Monk8c09ac72017-03-16 11:53:40 -0400362 builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name);
Todd Kennedy56279cb2017-04-17 14:53:49 -0700363 final boolean isInstantApp = info.launchedActivity.info.applicationInfo.isInstantApp();
364 if (isInstantApp && info.launchedActivity.launchedFromPackage != null) {
Todd Kennedy50d946c12017-03-17 13:55:38 -0700365 builder.addTaggedData(APP_TRANSITION_CALLING_PACKAGE_NAME,
366 info.launchedActivity.launchedFromPackage);
367 }
368 if (info.launchedActivity.info.launchToken != null) {
369 builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN,
370 info.launchedActivity.info.launchToken);
Todd Kennedyb3b431302017-03-20 16:05:48 -0700371 info.launchedActivity.info.launchToken = null;
Todd Kennedy50d946c12017-03-17 13:55:38 -0700372 }
Todd Kennedy56279cb2017-04-17 14:53:49 -0700373 builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0);
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800374 builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS,
375 mCurrentTransitionDeviceUptime);
376 builder.addTaggedData(APP_TRANSITION_DELAY_MS, mCurrentTransitionDelayMs);
377 builder.setSubtype(info.reason);
378 if (info.startingWindowDelayMs != -1) {
379 builder.addTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS,
380 info.startingWindowDelayMs);
381 }
Jorim Jaggi515dd682017-05-05 15:05:07 +0200382 if (info.bindApplicationDelayMs != -1) {
383 builder.addTaggedData(APP_TRANSITION_BIND_APPLICATION_DELAY_MS,
384 info.bindApplicationDelayMs);
385 }
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800386 builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs);
387 mMetricsLogger.write(builder);
388 }
389 }
390
391 private int getTransitionType(StackTransitionInfo info) {
392 if (info.currentTransitionProcessRunning) {
393 if (info.startResult == START_SUCCESS) {
394 return TYPE_TRANSITION_WARM_LAUNCH;
395 } else if (info.startResult == START_TASK_TO_FRONT) {
396 return TYPE_TRANSITION_HOT_LAUNCH;
397 }
398 } else if (info.startResult == START_SUCCESS) {
399 return TYPE_TRANSITION_COLD_LAUNCH;
400 }
401 return -1;
402 }
Filip Gruszczynski77d94482015-12-11 13:59:52 -0800403}