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; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 5 | import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 6 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 7 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 8 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 9 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 10 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 11 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 12 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION; |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 13 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_BIND_APPLICATION_DELAY_MS; |
Todd Kennedy | 50d946c1 | 2017-03-17 13:55:38 -0700 | [diff] [blame] | 14 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_CALLING_PACKAGE_NAME; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 15 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_CANCELLED; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 16 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DELAY_MS; |
| 17 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DEVICE_UPTIME_SECONDS; |
Todd Kennedy | 50d946c1 | 2017-03-17 13:55:38 -0700 | [diff] [blame] | 18 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_IS_EPHEMERAL; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 19 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_PROCESS_RUNNING; |
| 20 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_REPORTED_DRAWN; |
| 21 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_REPORTED_DRAWN_MS; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 22 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS; |
| 23 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS; |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 24 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CLASS_NAME; |
Todd Kennedy | 50d946c1 | 2017-03-17 13:55:38 -0700 | [diff] [blame] | 25 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_INSTANT_APP_LAUNCH_TOKEN; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 26 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH; |
| 27 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_HOT_LAUNCH; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 28 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE; |
| 29 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_REPORTED_DRAWN_WITH_BUNDLE; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 30 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_WARM_LAUNCH; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 31 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_METRICS; |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 32 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 33 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 34 | import static com.android.server.am.MemoryStatUtil.MemoryStat; |
| 35 | import static com.android.server.am.MemoryStatUtil.readMemoryStatFromMemcg; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 36 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 37 | import android.content.Context; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 38 | import android.metrics.LogMaker; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 39 | import android.os.Handler; |
| 40 | import android.os.Looper; |
| 41 | import android.os.Message; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 42 | import android.os.SystemClock; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 43 | import android.util.Slog; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 44 | import android.util.SparseArray; |
| 45 | import android.util.SparseIntArray; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 46 | import android.util.StatsLog; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 47 | |
| 48 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 49 | import com.android.internal.os.SomeArgs; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 50 | |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 51 | import java.util.ArrayList; |
| 52 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 53 | /** |
| 54 | * Handles logging into Tron. |
| 55 | */ |
| 56 | class ActivityMetricsLogger { |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 57 | |
| 58 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityMetricsLogger" : TAG_AM; |
| 59 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 60 | // Window modes we are interested in logging. If we ever introduce a new type, we need to add |
| 61 | // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array. |
| 62 | private static final int WINDOW_STATE_STANDARD = 0; |
| 63 | private static final int WINDOW_STATE_SIDE_BY_SIDE = 1; |
| 64 | private static final int WINDOW_STATE_FREEFORM = 2; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 65 | private static final int WINDOW_STATE_ASSISTANT = 3; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 66 | private static final int WINDOW_STATE_INVALID = -1; |
| 67 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 68 | private static final long INVALID_START_TIME = -1; |
| 69 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 70 | private static final int MSG_CHECK_VISIBILITY = 0; |
Narayan Kamath | 203a9ab | 2018-02-20 17:06:21 +0000 | [diff] [blame] | 71 | private static final int MSG_LOG_APP_START_MEMORY_STATE_CAPTURE = 1; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 72 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 73 | // Preallocated strings we are sending to tron, so we don't have to allocate a new one every |
| 74 | // time we log. |
| 75 | private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 76 | "window_time_0", "window_time_1", "window_time_2", "window_time_3"}; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 77 | |
| 78 | private int mWindowState = WINDOW_STATE_STANDARD; |
| 79 | private long mLastLogTimeSecs; |
| 80 | private final ActivityStackSupervisor mSupervisor; |
| 81 | private final Context mContext; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 82 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 83 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 84 | private long mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 85 | private long mLastTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 86 | |
| 87 | private int mCurrentTransitionDeviceUptime; |
| 88 | private int mCurrentTransitionDelayMs; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 89 | private boolean mLoggedTransitionStarting; |
| 90 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 91 | private final SparseArray<WindowingModeTransitionInfo> mWindowingModeTransitionInfo = |
| 92 | new SparseArray<>(); |
| 93 | private final SparseArray<WindowingModeTransitionInfo> mLastWindowingModeTransitionInfo = |
| 94 | new SparseArray<>(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 95 | private final H mHandler; |
| 96 | private final class H extends Handler { |
| 97 | |
| 98 | public H(Looper looper) { |
| 99 | super(looper); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void handleMessage(Message msg) { |
| 104 | switch (msg.what) { |
| 105 | case MSG_CHECK_VISIBILITY: |
| 106 | final SomeArgs args = (SomeArgs) msg.obj; |
| 107 | checkVisibility((TaskRecord) args.arg1, (ActivityRecord) args.arg2); |
| 108 | break; |
Narayan Kamath | 203a9ab | 2018-02-20 17:06:21 +0000 | [diff] [blame] | 109 | case MSG_LOG_APP_START_MEMORY_STATE_CAPTURE: |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 110 | logAppStartMemoryStateCapture((WindowingModeTransitionInfo) msg.obj); |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 111 | break; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 112 | } |
| 113 | } |
Narayan Kamath | 203a9ab | 2018-02-20 17:06:21 +0000 | [diff] [blame] | 114 | }; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 115 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 116 | private final class WindowingModeTransitionInfo { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 117 | private ActivityRecord launchedActivity; |
| 118 | private int startResult; |
| 119 | private boolean currentTransitionProcessRunning; |
| 120 | private int windowsDrawnDelayMs; |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 121 | private int startingWindowDelayMs = -1; |
| 122 | private int bindApplicationDelayMs = -1; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 123 | private int reason = APP_TRANSITION_TIMEOUT; |
| 124 | private boolean loggedWindowsDrawn; |
| 125 | private boolean loggedStartingWindowDrawn; |
| 126 | } |
| 127 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 128 | ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context, Looper looper) { |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 129 | mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000; |
| 130 | mSupervisor = supervisor; |
| 131 | mContext = context; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 132 | mHandler = new H(looper); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void logWindowState() { |
| 136 | final long now = SystemClock.elapsedRealtime() / 1000; |
| 137 | if (mWindowState != WINDOW_STATE_INVALID) { |
| 138 | // We log even if the window state hasn't changed, because the user might remain in |
| 139 | // home/fullscreen move forever and we would like to track this kind of behavior |
| 140 | // too. |
| 141 | MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState], |
| 142 | (int) (now - mLastLogTimeSecs)); |
| 143 | } |
| 144 | mLastLogTimeSecs = now; |
| 145 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 146 | mWindowState = WINDOW_STATE_INVALID; |
| 147 | ActivityStack stack = mSupervisor.getFocusedStack(); |
| 148 | if (stack.isActivityTypeAssistant()) { |
| 149 | mWindowState = WINDOW_STATE_ASSISTANT; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 150 | return; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 151 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 152 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 153 | int windowingMode = stack.getWindowingMode(); |
| 154 | if (windowingMode == WINDOWING_MODE_PINNED) { |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 155 | stack = mSupervisor.findStackBehind(stack); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 156 | windowingMode = stack.getWindowingMode(); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 157 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 158 | switch (windowingMode) { |
| 159 | case WINDOWING_MODE_FULLSCREEN: |
| 160 | mWindowState = WINDOW_STATE_STANDARD; |
| 161 | break; |
| 162 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 163 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 164 | mWindowState = WINDOW_STATE_SIDE_BY_SIDE; |
| 165 | break; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 166 | case WINDOWING_MODE_FREEFORM: |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 167 | mWindowState = WINDOW_STATE_FREEFORM; |
| 168 | break; |
| 169 | default: |
| 170 | if (windowingMode != WINDOWING_MODE_UNDEFINED) { |
| 171 | throw new IllegalStateException("Unknown windowing mode for stack=" + stack |
| 172 | + " windowingMode=" + windowingMode); |
| 173 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 174 | } |
| 175 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * Notifies the tracker at the earliest possible point when we are starting to launch an |
| 179 | * activity. |
| 180 | */ |
| 181 | void notifyActivityLaunching() { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 182 | if (!isAnyTransitionActive()) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 183 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunching"); |
Alison Cichowlas | b7f67ab | 2017-04-25 18:04:40 -0400 | [diff] [blame] | 184 | mCurrentTransitionStartTime = SystemClock.uptimeMillis(); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 185 | mLastTransitionStartTime = mCurrentTransitionStartTime; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 186 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 190 | * Notifies the tracker that the activity is actually launching. |
| 191 | * |
| 192 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 193 | * launch |
| 194 | * @param launchedActivity the activity that is being launched |
| 195 | */ |
| 196 | void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 197 | final ProcessRecord processRecord = findProcessForActivity(launchedActivity); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 198 | final boolean processRunning = processRecord != null; |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 199 | |
| 200 | // We consider this a "process switch" if the process of the activity that gets launched |
| 201 | // didn't have an activity that was in started state. In this case, we assume that lot |
| 202 | // of caches might be purged so the time until it produces the first frame is very |
| 203 | // interesting. |
| 204 | final boolean processSwitch = processRecord == null |
| 205 | || !hasStartedActivity(processRecord, launchedActivity); |
| 206 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 207 | notifyActivityLaunched(resultCode, launchedActivity, processRunning, processSwitch); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | private boolean hasStartedActivity(ProcessRecord record, ActivityRecord launchedActivity) { |
| 211 | final ArrayList<ActivityRecord> activities = record.activities; |
| 212 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 213 | final ActivityRecord activity = activities.get(i); |
| 214 | if (launchedActivity == activity) { |
| 215 | continue; |
| 216 | } |
| 217 | if (!activity.stopped) { |
| 218 | return true; |
| 219 | } |
| 220 | } |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 225 | * Notifies the tracker the the activity is actually launching. |
| 226 | * |
| 227 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 228 | * launch |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 229 | * @param launchedActivity the activity being launched |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 230 | * @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] | 231 | * @param processSwitch whether the process that will contain the activity didn't have any |
| 232 | * activity that was stopped, i.e. the started activity is "switching" |
| 233 | * processes |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 234 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 235 | private void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity, |
Jorim Jaggi | be67c90 | 2016-04-12 00:53:16 -0700 | [diff] [blame] | 236 | boolean processRunning, boolean processSwitch) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 237 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 238 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched" |
| 239 | + " resultCode=" + resultCode |
| 240 | + " launchedActivity=" + launchedActivity |
| 241 | + " processRunning=" + processRunning |
| 242 | + " processSwitch=" + processSwitch); |
| 243 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 244 | // If we are already in an existing transition, only update the activity name, but not the |
| 245 | // other attributes. |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 246 | final int windowingMode = launchedActivity != null |
| 247 | ? launchedActivity.getWindowingMode() |
| 248 | : WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 249 | |
| 250 | if (mCurrentTransitionStartTime == INVALID_START_TIME) { |
| 251 | return; |
| 252 | } |
| 253 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 254 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 255 | if (launchedActivity != null && info != null) { |
| 256 | info.launchedActivity = launchedActivity; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 260 | final boolean otherWindowModesLaunching = |
| 261 | mWindowingModeTransitionInfo.size() > 0 && info == null; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 262 | if ((resultCode < 0 || launchedActivity == null || !processSwitch |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 263 | || windowingMode == WINDOWING_MODE_UNDEFINED) && !otherWindowModesLaunching) { |
Alison Cichowlas | 803054d | 2016-12-13 14:38:01 -0500 | [diff] [blame] | 264 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 265 | // Failed to launch or it was not a process switch, so we don't care about the timing. |
| 266 | reset(true /* abort */); |
| 267 | return; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 268 | } else if (otherWindowModesLaunching) { |
| 269 | // Don't log this windowing mode but continue with the other windowing modes. |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 273 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched successful"); |
| 274 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 275 | final WindowingModeTransitionInfo newInfo = new WindowingModeTransitionInfo(); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 276 | newInfo.launchedActivity = launchedActivity; |
| 277 | newInfo.currentTransitionProcessRunning = processRunning; |
| 278 | newInfo.startResult = resultCode; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 279 | mWindowingModeTransitionInfo.put(windowingMode, newInfo); |
| 280 | mLastWindowingModeTransitionInfo.put(windowingMode, newInfo); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 281 | mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Notifies the tracker that all windows of the app have been drawn. |
| 286 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 287 | void notifyWindowsDrawn(int windowingMode, long timestamp) { |
| 288 | if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn windowingMode=" + windowingMode); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 289 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 290 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 291 | if (info == null || info.loggedWindowsDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 292 | return; |
| 293 | } |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 294 | info.windowsDrawnDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 295 | info.loggedWindowsDrawn = true; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 296 | if (allWindowsDrawn() && mLoggedTransitionStarting) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 297 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Notifies the tracker that the starting window was drawn. |
| 303 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 304 | void notifyStartingWindowDrawn(int windowingMode, long timestamp) { |
| 305 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 306 | if (info == null || info.loggedStartingWindowDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 307 | return; |
| 308 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 309 | info.loggedStartingWindowDrawn = true; |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 310 | info.startingWindowDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Notifies the tracker that the app transition is starting. |
| 315 | * |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 316 | * @param windowingModeToReason A map from windowing mode to a reason integer, which must be on |
| 317 | * of ActivityManagerInternal.APP_TRANSITION_* reasons. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 318 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 319 | void notifyTransitionStarting(SparseIntArray windowingModeToReason, long timestamp) { |
Jorim Jaggi | d8a5777 | 2017-04-14 16:50:42 -0700 | [diff] [blame] | 320 | if (!isAnyTransitionActive() || mLoggedTransitionStarting) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 321 | return; |
| 322 | } |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 323 | if (DEBUG_METRICS) Slog.i(TAG, "notifyTransitionStarting"); |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 324 | mCurrentTransitionDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 325 | mLoggedTransitionStarting = true; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 326 | for (int index = windowingModeToReason.size() - 1; index >= 0; index--) { |
| 327 | final int windowingMode = windowingModeToReason.keyAt(index); |
| 328 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 329 | windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 330 | if (info == null) { |
| 331 | continue; |
| 332 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 333 | info.reason = windowingModeToReason.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 334 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 335 | if (allWindowsDrawn()) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 336 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 340 | /** |
| 341 | * Notifies the tracker that the visibility of an app is changing. |
| 342 | * |
| 343 | * @param activityRecord the app that is changing its visibility |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 344 | */ |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 345 | void notifyVisibilityChanged(ActivityRecord activityRecord) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 346 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 347 | activityRecord.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 348 | if (info == null) { |
| 349 | return; |
| 350 | } |
| 351 | if (info.launchedActivity != activityRecord) { |
| 352 | return; |
| 353 | } |
| 354 | final TaskRecord t = activityRecord.getTask(); |
| 355 | final SomeArgs args = SomeArgs.obtain(); |
| 356 | args.arg1 = t; |
| 357 | args.arg2 = activityRecord; |
| 358 | mHandler.obtainMessage(MSG_CHECK_VISIBILITY, args).sendToTarget(); |
| 359 | } |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 360 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 361 | private void checkVisibility(TaskRecord t, ActivityRecord r) { |
| 362 | synchronized (mSupervisor.mService) { |
| 363 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 364 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 365 | r.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 366 | |
| 367 | // If we have an active transition that's waiting on a certain activity that will be |
| 368 | // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. |
| 369 | if (info != null && !t.isVisible()) { |
| 370 | if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible" |
| 371 | + " activity=" + r); |
| 372 | logAppTransitionCancel(info); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 373 | mWindowingModeTransitionInfo.remove(r.getWindowingMode()); |
| 374 | if (mWindowingModeTransitionInfo.size() == 0) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 375 | reset(true /* abort */); |
| 376 | } |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 381 | /** |
| 382 | * Notifies the tracker that we called immediately before we call bindApplication on the client. |
| 383 | * |
| 384 | * @param app The client into which we'll call bindApplication. |
| 385 | */ |
| 386 | void notifyBindApplication(ProcessRecord app) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 387 | for (int i = mWindowingModeTransitionInfo.size() - 1; i >= 0; i--) { |
| 388 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(i); |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 389 | |
| 390 | // App isn't attached to record yet, so match with info. |
| 391 | if (info.launchedActivity.appInfo == app.info) { |
| 392 | info.bindApplicationDelayMs = calculateCurrentDelay(); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 397 | private boolean allWindowsDrawn() { |
| 398 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 399 | if (!mWindowingModeTransitionInfo.valueAt(index).loggedWindowsDrawn) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 400 | return false; |
| 401 | } |
| 402 | } |
| 403 | return true; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 404 | } |
| 405 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 406 | private boolean isAnyTransitionActive() { |
| 407 | return mCurrentTransitionStartTime != INVALID_START_TIME |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 408 | && mWindowingModeTransitionInfo.size() > 0; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | private void reset(boolean abort) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 412 | if (DEBUG_METRICS) Slog.i(TAG, "reset abort=" + abort); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 413 | if (!abort && isAnyTransitionActive()) { |
| 414 | logAppTransitionMultiEvents(); |
| 415 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 416 | mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 417 | mCurrentTransitionDelayMs = -1; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 418 | mLoggedTransitionStarting = false; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 419 | mWindowingModeTransitionInfo.clear(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | private int calculateCurrentDelay() { |
| 423 | |
| 424 | // Shouldn't take more than 25 days to launch an app, so int is fine here. |
Alison Cichowlas | b7f67ab | 2017-04-25 18:04:40 -0400 | [diff] [blame] | 425 | return (int) (SystemClock.uptimeMillis() - mCurrentTransitionStartTime); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 426 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 427 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 428 | private int calculateDelay(long timestamp) { |
| 429 | // Shouldn't take more than 25 days to launch an app, so int is fine here. |
| 430 | return (int) (timestamp - mCurrentTransitionStartTime); |
| 431 | } |
| 432 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 433 | private void logAppTransitionCancel(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 434 | final int type = getTransitionType(info); |
| 435 | if (type == -1) { |
| 436 | return; |
| 437 | } |
| 438 | final LogMaker builder = new LogMaker(APP_TRANSITION_CANCELLED); |
| 439 | builder.setPackageName(info.launchedActivity.packageName); |
| 440 | builder.setType(type); |
| 441 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name); |
| 442 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 443 | StatsLog.write( |
| 444 | StatsLog.APP_START_CANCEL_CHANGED, |
| 445 | info.launchedActivity.appInfo.uid, |
| 446 | info.launchedActivity.packageName, |
| 447 | convertAppStartTransitionType(type), |
| 448 | info.launchedActivity.info.name); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 451 | private void logAppTransitionMultiEvents() { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 452 | if (DEBUG_METRICS) Slog.i(TAG, "logging transition events"); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 453 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 454 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 455 | final int type = getTransitionType(info); |
| 456 | if (type == -1) { |
| 457 | return; |
| 458 | } |
Narayan Kamath | 203a9ab | 2018-02-20 17:06:21 +0000 | [diff] [blame] | 459 | final LogMaker builder = new LogMaker(APP_TRANSITION); |
| 460 | builder.setPackageName(info.launchedActivity.packageName); |
| 461 | builder.setType(type); |
| 462 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name); |
| 463 | final boolean isInstantApp = info.launchedActivity.info.applicationInfo.isInstantApp(); |
| 464 | if (info.launchedActivity.launchedFromPackage != null) { |
| 465 | builder.addTaggedData(APP_TRANSITION_CALLING_PACKAGE_NAME, |
| 466 | info.launchedActivity.launchedFromPackage); |
| 467 | } |
| 468 | String launchToken = info.launchedActivity.info.launchToken; |
| 469 | if (launchToken != null) { |
| 470 | builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN, launchToken); |
| 471 | info.launchedActivity.info.launchToken = null; |
| 472 | } |
| 473 | builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0); |
| 474 | builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS, |
| 475 | mCurrentTransitionDeviceUptime); |
| 476 | builder.addTaggedData(APP_TRANSITION_DELAY_MS, mCurrentTransitionDelayMs); |
| 477 | builder.setSubtype(info.reason); |
| 478 | if (info.startingWindowDelayMs != -1) { |
| 479 | builder.addTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS, |
| 480 | info.startingWindowDelayMs); |
| 481 | } |
| 482 | if (info.bindApplicationDelayMs != -1) { |
| 483 | builder.addTaggedData(APP_TRANSITION_BIND_APPLICATION_DELAY_MS, |
| 484 | info.bindApplicationDelayMs); |
| 485 | } |
| 486 | builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs); |
| 487 | mMetricsLogger.write(builder); |
| 488 | StatsLog.write( |
| 489 | StatsLog.APP_START_CHANGED, |
| 490 | info.launchedActivity.appInfo.uid, |
| 491 | info.launchedActivity.packageName, |
| 492 | convertAppStartTransitionType(type), |
| 493 | info.launchedActivity.info.name, |
| 494 | info.launchedActivity.launchedFromPackage, |
| 495 | isInstantApp, |
| 496 | mCurrentTransitionDeviceUptime * 1000, |
| 497 | info.reason, |
| 498 | mCurrentTransitionDelayMs, |
| 499 | info.startingWindowDelayMs, |
| 500 | info.bindApplicationDelayMs, |
| 501 | info.windowsDrawnDelayMs, |
| 502 | launchToken); |
| 503 | mHandler.obtainMessage(MSG_LOG_APP_START_MEMORY_STATE_CAPTURE, info).sendToTarget(); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 507 | private int convertAppStartTransitionType(int tronType) { |
| 508 | if (tronType == TYPE_TRANSITION_COLD_LAUNCH) { |
| 509 | return StatsLog.APP_START_CHANGED__TYPE__COLD; |
| 510 | } |
| 511 | if (tronType == TYPE_TRANSITION_WARM_LAUNCH) { |
| 512 | return StatsLog.APP_START_CHANGED__TYPE__WARM; |
| 513 | } |
| 514 | if (tronType == TYPE_TRANSITION_HOT_LAUNCH) { |
| 515 | return StatsLog.APP_START_CHANGED__TYPE__HOT; |
| 516 | } |
| 517 | return StatsLog.APP_START_CHANGED__TYPE__APP_START_TRANSITION_TYPE_UNKNOWN; |
| 518 | } |
| 519 | |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 520 | void logAppTransitionReportedDrawn(ActivityRecord r, boolean restoredFromBundle) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 521 | final WindowingModeTransitionInfo info = mLastWindowingModeTransitionInfo.get( |
| 522 | r.getWindowingMode()); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 523 | if (info == null) { |
| 524 | return; |
| 525 | } |
| 526 | final LogMaker builder = new LogMaker(APP_TRANSITION_REPORTED_DRAWN); |
| 527 | builder.setPackageName(r.packageName); |
| 528 | builder.addTaggedData(FIELD_CLASS_NAME, r.info.name); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 529 | long startupTimeMs = SystemClock.uptimeMillis() - mLastTransitionStartTime; |
| 530 | builder.addTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS, startupTimeMs); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 531 | builder.setType(restoredFromBundle |
| 532 | ? TYPE_TRANSITION_REPORTED_DRAWN_WITH_BUNDLE |
| 533 | : TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE); |
| 534 | builder.addTaggedData(APP_TRANSITION_PROCESS_RUNNING, |
| 535 | info.currentTransitionProcessRunning ? 1 : 0); |
| 536 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 537 | StatsLog.write( |
| 538 | StatsLog.APP_START_FULLY_DRAWN_CHANGED, |
| 539 | info.launchedActivity.appInfo.uid, |
| 540 | info.launchedActivity.packageName, |
| 541 | restoredFromBundle |
| 542 | ? StatsLog.APP_START_FULLY_DRAWN_CHANGED__TYPE__WITH_BUNDLE |
| 543 | : StatsLog.APP_START_FULLY_DRAWN_CHANGED__TYPE__WITHOUT_BUNDLE, |
| 544 | info.launchedActivity.info.name, |
| 545 | info.currentTransitionProcessRunning, |
| 546 | startupTimeMs); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 549 | private int getTransitionType(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 550 | if (info.currentTransitionProcessRunning) { |
| 551 | if (info.startResult == START_SUCCESS) { |
| 552 | return TYPE_TRANSITION_WARM_LAUNCH; |
| 553 | } else if (info.startResult == START_TASK_TO_FRONT) { |
| 554 | return TYPE_TRANSITION_HOT_LAUNCH; |
| 555 | } |
| 556 | } else if (info.startResult == START_SUCCESS) { |
| 557 | return TYPE_TRANSITION_COLD_LAUNCH; |
| 558 | } |
| 559 | return -1; |
| 560 | } |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 561 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame^] | 562 | private void logAppStartMemoryStateCapture(WindowingModeTransitionInfo info) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 563 | final ProcessRecord processRecord = findProcessForActivity(info.launchedActivity); |
| 564 | if (processRecord == null) { |
| 565 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture processRecord null"); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | final int pid = processRecord.pid; |
| 570 | final int uid = info.launchedActivity.appInfo.uid; |
| 571 | final MemoryStat memoryStat = readMemoryStatFromMemcg(uid, pid); |
| 572 | if (memoryStat == null) { |
| 573 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture memoryStat null"); |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | StatsLog.write( |
| 578 | StatsLog.APP_START_MEMORY_STATE_CAPTURED, |
| 579 | uid, |
| 580 | info.launchedActivity.processName, |
| 581 | info.launchedActivity.info.name, |
| 582 | memoryStat.pgfault, |
| 583 | memoryStat.pgmajfault, |
| 584 | memoryStat.rssInBytes, |
| 585 | memoryStat.cacheInBytes, |
| 586 | memoryStat.swapInBytes); |
| 587 | } |
| 588 | |
| 589 | private ProcessRecord findProcessForActivity(ActivityRecord launchedActivity) { |
| 590 | return launchedActivity != null |
| 591 | ? mSupervisor.mService.mProcessNames.get(launchedActivity.processName, |
| 592 | launchedActivity.appInfo.uid) |
| 593 | : null; |
| 594 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 595 | } |