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; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 5 | import static android.app.ActivityManager.processStateAmToProto; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 6 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 7 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 8 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 9 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
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; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 12 | |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 13 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_ACTIVITY_START; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 14 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION; |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 15 | 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] | 16 | 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] | 17 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_CANCELLED; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 18 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DELAY_MS; |
| 19 | 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] | 20 | 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] | 21 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_PROCESS_RUNNING; |
| 22 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_REPORTED_DRAWN; |
| 23 | 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] | 24 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS; |
| 25 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 26 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_FLAGS; |
| 27 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_IS_FULLSCREEN; |
| 28 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_IS_NO_DISPLAY; |
| 29 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_IS_VISIBLE; |
| 30 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_IS_VISIBLE_IGNORING_KEYGUARD; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 31 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_LAUNCH_MODE; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 32 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_LAUNCH; |
| 33 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_VISIBLE; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 34 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_PROCESS_NAME; |
| 35 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_REAL_ACTIVITY; |
| 36 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_RESULT_TO_PKG_NAME; |
| 37 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_RESULT_TO_SHORT_COMPONENT_NAME; |
| 38 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_SHORT_COMPONENT_NAME; |
| 39 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_TARGET_ACTIVITY; |
| 40 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CALLING_PACKAGE_NAME; |
| 41 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CALLING_UID; |
| 42 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CALLING_UID_HAS_ANY_VISIBLE_WINDOW; |
| 43 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CALLING_UID_PROC_STATE; |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 44 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CLASS_NAME; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 45 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_COMING_FROM_PENDING_INTENT; |
Todd Kennedy | 50d946c1 | 2017-03-17 13:55:38 -0700 | [diff] [blame] | 46 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_INSTANT_APP_LAUNCH_TOKEN; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 47 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_INTENT_ACTION; |
| 48 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_CUR_PROC_STATE; |
| 49 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_HAS_CLIENT_ACTIVITIES; |
| 50 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_HAS_FOREGROUND_ACTIVITIES; |
| 51 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_HAS_FOREGROUND_SERVICES; |
| 52 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_HAS_OVERLAY_UI; |
| 53 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_HAS_TOP_UI; |
| 54 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_MILLIS_SINCE_FG_INTERACTION; |
| 55 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_MILLIS_SINCE_LAST_INTERACTION_EVENT; |
| 56 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_MILLIS_SINCE_UNIMPORTANT; |
| 57 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_PENDING_UI_CLEAN; |
| 58 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_PROCESS_RECORD_PROCESS_NAME; |
| 59 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_REAL_CALLING_UID; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 60 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_REAL_CALLING_UID_HAS_ANY_VISIBLE_WINDOW; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 61 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_REAL_CALLING_UID_PROC_STATE; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 62 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_PACKAGE_NAME; |
| 63 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_SHORT_COMPONENT_NAME; |
| 64 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_UID; |
| 65 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_UID_HAS_ANY_VISIBLE_WINDOW; |
| 66 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_UID_PROC_STATE; |
| 67 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_TARGET_WHITELIST_TAG; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 68 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.PACKAGE_OPTIMIZATION_COMPILATION_FILTER; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 69 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.PACKAGE_OPTIMIZATION_COMPILATION_REASON; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 70 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH; |
| 71 | 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] | 72 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE; |
| 73 | 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] | 74 | 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] | 75 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_METRICS; |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 76 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 77 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 78 | import static com.android.server.am.EventLogTags.AM_ACTIVITY_LAUNCH_TIME; |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 79 | import static com.android.server.am.MemoryStatUtil.MemoryStat; |
Rajeev Kumar | bfcd920 | 2018-03-02 22:42:13 +0000 | [diff] [blame] | 80 | import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 81 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_TIMEOUT; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 82 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 83 | import android.content.Context; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 84 | import android.content.Intent; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 85 | import android.content.pm.ApplicationInfo; |
| 86 | import android.content.pm.dex.ArtManagerInternal; |
| 87 | import android.content.pm.dex.PackageOptimizationInfo; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 88 | import android.metrics.LogMaker; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 89 | import android.os.Handler; |
| 90 | import android.os.Looper; |
| 91 | import android.os.Message; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 92 | import android.os.SystemClock; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 93 | import android.os.Trace; |
| 94 | import android.util.EventLog; |
| 95 | import android.util.Log; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 96 | import android.util.Slog; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 97 | import android.util.SparseArray; |
| 98 | import android.util.SparseIntArray; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 99 | import android.util.StatsLog; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 100 | import android.util.TimeUtils; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 101 | |
| 102 | import com.android.internal.logging.MetricsLogger; |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 103 | import com.android.internal.os.BackgroundThread; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 104 | import com.android.internal.os.SomeArgs; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 105 | import com.android.server.LocalServices; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 106 | |
| 107 | /** |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 108 | * Listens to activity launches, transitions, visibility changes and window drawn callbacks to |
| 109 | * determine app launch times and draw delays. Source of truth for activity metrics and provides |
| 110 | * data for Tron, logcat, event logs and {@link android.app.WaitResult}. |
| 111 | * |
| 112 | * Tests: |
Vishnu Nair | f8accc5 | 2018-10-11 10:19:54 -0700 | [diff] [blame] | 113 | * atest CtsActivityManagerDeviceTestCases:ActivityMetricsLoggerTests |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 114 | */ |
| 115 | class ActivityMetricsLogger { |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 116 | |
| 117 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityMetricsLogger" : TAG_AM; |
| 118 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 119 | // Window modes we are interested in logging. If we ever introduce a new type, we need to add |
| 120 | // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array. |
| 121 | private static final int WINDOW_STATE_STANDARD = 0; |
| 122 | private static final int WINDOW_STATE_SIDE_BY_SIDE = 1; |
| 123 | private static final int WINDOW_STATE_FREEFORM = 2; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 124 | private static final int WINDOW_STATE_ASSISTANT = 3; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 125 | private static final int WINDOW_STATE_INVALID = -1; |
| 126 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 127 | private static final long INVALID_START_TIME = -1; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 128 | private static final int INVALID_DELAY = -1; |
| 129 | private static final int INVALID_TRANSITION_TYPE = -1; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 130 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 131 | private static final int MSG_CHECK_VISIBILITY = 0; |
| 132 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 133 | // Preallocated strings we are sending to tron, so we don't have to allocate a new one every |
| 134 | // time we log. |
| 135 | private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 136 | "window_time_0", "window_time_1", "window_time_2", "window_time_3"}; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 137 | |
| 138 | private int mWindowState = WINDOW_STATE_STANDARD; |
| 139 | private long mLastLogTimeSecs; |
| 140 | private final ActivityStackSupervisor mSupervisor; |
| 141 | private final Context mContext; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 142 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 143 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 144 | private long mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 145 | private long mLastTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 146 | |
| 147 | private int mCurrentTransitionDeviceUptime; |
| 148 | private int mCurrentTransitionDelayMs; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 149 | private boolean mLoggedTransitionStarting; |
| 150 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 151 | private final SparseArray<WindowingModeTransitionInfo> mWindowingModeTransitionInfo = |
| 152 | new SparseArray<>(); |
| 153 | private final SparseArray<WindowingModeTransitionInfo> mLastWindowingModeTransitionInfo = |
| 154 | new SparseArray<>(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 155 | private final H mHandler; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 156 | |
| 157 | private ArtManagerInternal mArtManagerInternal; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 158 | private boolean mDrawingTraceActive; |
| 159 | private final StringBuilder mStringBuilder = new StringBuilder(); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 160 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 161 | private final class H extends Handler { |
| 162 | |
| 163 | public H(Looper looper) { |
| 164 | super(looper); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public void handleMessage(Message msg) { |
| 169 | switch (msg.what) { |
| 170 | case MSG_CHECK_VISIBILITY: |
| 171 | final SomeArgs args = (SomeArgs) msg.obj; |
| 172 | checkVisibility((TaskRecord) args.arg1, (ActivityRecord) args.arg2); |
| 173 | break; |
| 174 | } |
| 175 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 176 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 177 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 178 | private final class WindowingModeTransitionInfo { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 179 | private ActivityRecord launchedActivity; |
| 180 | private int startResult; |
| 181 | private boolean currentTransitionProcessRunning; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 182 | /** Elapsed time from when we launch an activity to when its windows are drawn. */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 183 | private int windowsDrawnDelayMs; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 184 | private int startingWindowDelayMs = INVALID_DELAY; |
| 185 | private int bindApplicationDelayMs = INVALID_DELAY; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 186 | private int reason = APP_TRANSITION_TIMEOUT; |
| 187 | private boolean loggedWindowsDrawn; |
| 188 | private boolean loggedStartingWindowDrawn; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 189 | private boolean launchTraceActive; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 192 | final class WindowingModeTransitionInfoSnapshot { |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 193 | final private ApplicationInfo applicationInfo; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 194 | final private WindowProcessController processRecord; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 195 | final String packageName; |
| 196 | final String launchedActivityName; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 197 | final private String launchedActivityLaunchedFromPackage; |
| 198 | final private String launchedActivityLaunchToken; |
| 199 | final private String launchedActivityAppRecordRequiredAbi; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 200 | final String launchedActivityShortComponentName; |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 201 | final private String processName; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 202 | final private int reason; |
| 203 | final private int startingWindowDelayMs; |
| 204 | final private int bindApplicationDelayMs; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 205 | final int windowsDrawnDelayMs; |
| 206 | final int type; |
| 207 | final int userId; |
| 208 | /** |
| 209 | * Elapsed time from when we launch an activity to when the app reported it was |
| 210 | * fully drawn. If this is not reported then the value is set to INVALID_DELAY. |
| 211 | */ |
| 212 | final int windowsFullyDrawnDelayMs; |
| 213 | final int activityRecordIdHashCode; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 214 | |
| 215 | private WindowingModeTransitionInfoSnapshot(WindowingModeTransitionInfo info) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 216 | this(info, info.launchedActivity); |
| 217 | } |
| 218 | |
| 219 | private WindowingModeTransitionInfoSnapshot(WindowingModeTransitionInfo info, |
| 220 | ActivityRecord launchedActivity) { |
| 221 | this(info, launchedActivity, INVALID_DELAY); |
| 222 | } |
| 223 | |
| 224 | private WindowingModeTransitionInfoSnapshot(WindowingModeTransitionInfo info, |
| 225 | ActivityRecord launchedActivity, int windowsFullyDrawnDelayMs) { |
| 226 | applicationInfo = launchedActivity.appInfo; |
| 227 | packageName = launchedActivity.packageName; |
| 228 | launchedActivityName = launchedActivity.info.name; |
| 229 | launchedActivityLaunchedFromPackage = launchedActivity.launchedFromPackage; |
| 230 | launchedActivityLaunchToken = launchedActivity.info.launchToken; |
| 231 | launchedActivityAppRecordRequiredAbi = launchedActivity.app == null |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 232 | ? null |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 233 | : info.launchedActivity.app.getRequiredAbi(); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 234 | reason = info.reason; |
| 235 | startingWindowDelayMs = info.startingWindowDelayMs; |
| 236 | bindApplicationDelayMs = info.bindApplicationDelayMs; |
| 237 | windowsDrawnDelayMs = info.windowsDrawnDelayMs; |
| 238 | type = getTransitionType(info); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 239 | processRecord = findProcessForActivity(info.launchedActivity); |
| 240 | processName = info.launchedActivity.processName; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 241 | userId = launchedActivity.userId; |
| 242 | launchedActivityShortComponentName = launchedActivity.shortComponentName; |
| 243 | activityRecordIdHashCode = System.identityHashCode(launchedActivity); |
| 244 | this.windowsFullyDrawnDelayMs = windowsFullyDrawnDelayMs; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 248 | ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context, Looper looper) { |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 249 | mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000; |
| 250 | mSupervisor = supervisor; |
| 251 | mContext = context; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 252 | mHandler = new H(looper); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void logWindowState() { |
| 256 | final long now = SystemClock.elapsedRealtime() / 1000; |
| 257 | if (mWindowState != WINDOW_STATE_INVALID) { |
| 258 | // We log even if the window state hasn't changed, because the user might remain in |
| 259 | // home/fullscreen move forever and we would like to track this kind of behavior |
| 260 | // too. |
| 261 | MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState], |
| 262 | (int) (now - mLastLogTimeSecs)); |
| 263 | } |
| 264 | mLastLogTimeSecs = now; |
| 265 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 266 | mWindowState = WINDOW_STATE_INVALID; |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 267 | ActivityStack stack = mSupervisor.getTopDisplayFocusedStack(); |
lumark | f6c4a98 | 2018-06-15 15:43:12 +0800 | [diff] [blame] | 268 | if (stack == null) { |
| 269 | return; |
| 270 | } |
| 271 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 272 | if (stack.isActivityTypeAssistant()) { |
| 273 | mWindowState = WINDOW_STATE_ASSISTANT; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 274 | return; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 275 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 276 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 277 | int windowingMode = stack.getWindowingMode(); |
| 278 | if (windowingMode == WINDOWING_MODE_PINNED) { |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 279 | stack = mSupervisor.findStackBehind(stack); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 280 | windowingMode = stack.getWindowingMode(); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 281 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 282 | switch (windowingMode) { |
| 283 | case WINDOWING_MODE_FULLSCREEN: |
| 284 | mWindowState = WINDOW_STATE_STANDARD; |
| 285 | break; |
| 286 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 287 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 288 | mWindowState = WINDOW_STATE_SIDE_BY_SIDE; |
| 289 | break; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 290 | case WINDOWING_MODE_FREEFORM: |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 291 | mWindowState = WINDOW_STATE_FREEFORM; |
| 292 | break; |
| 293 | default: |
| 294 | if (windowingMode != WINDOWING_MODE_UNDEFINED) { |
| 295 | throw new IllegalStateException("Unknown windowing mode for stack=" + stack |
| 296 | + " windowingMode=" + windowingMode); |
| 297 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Notifies the tracker at the earliest possible point when we are starting to launch an |
| 303 | * activity. |
| 304 | */ |
| 305 | void notifyActivityLaunching() { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 306 | if (!isAnyTransitionActive()) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 307 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunching"); |
Alison Cichowlas | b7f67ab | 2017-04-25 18:04:40 -0400 | [diff] [blame] | 308 | mCurrentTransitionStartTime = SystemClock.uptimeMillis(); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 309 | mLastTransitionStartTime = mCurrentTransitionStartTime; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 310 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /** |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 314 | * Notifies the tracker that the activity is actually launching. |
| 315 | * |
| 316 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 317 | * launch |
| 318 | * @param launchedActivity the activity that is being launched |
| 319 | */ |
| 320 | void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 321 | final WindowProcessController processRecord = findProcessForActivity(launchedActivity); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 322 | final boolean processRunning = processRecord != null; |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 323 | |
| 324 | // We consider this a "process switch" if the process of the activity that gets launched |
| 325 | // didn't have an activity that was in started state. In this case, we assume that lot |
| 326 | // of caches might be purged so the time until it produces the first frame is very |
| 327 | // interesting. |
| 328 | final boolean processSwitch = processRecord == null |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 329 | || !processRecord.hasStartedActivity(launchedActivity); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 330 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 331 | notifyActivityLaunched(resultCode, launchedActivity, processRunning, processSwitch); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 334 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 335 | * Notifies the tracker the the activity is actually launching. |
| 336 | * |
| 337 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 338 | * launch |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 339 | * @param launchedActivity the activity being launched |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 340 | * @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] | 341 | * @param processSwitch whether the process that will contain the activity didn't have any |
| 342 | * activity that was stopped, i.e. the started activity is "switching" |
| 343 | * processes |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 344 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 345 | private void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity, |
Jorim Jaggi | be67c90 | 2016-04-12 00:53:16 -0700 | [diff] [blame] | 346 | boolean processRunning, boolean processSwitch) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 347 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 348 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched" |
| 349 | + " resultCode=" + resultCode |
| 350 | + " launchedActivity=" + launchedActivity |
| 351 | + " processRunning=" + processRunning |
| 352 | + " processSwitch=" + processSwitch); |
| 353 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 354 | final int windowingMode = launchedActivity != null |
| 355 | ? launchedActivity.getWindowingMode() |
| 356 | : WINDOWING_MODE_UNDEFINED; |
Vishnu Nair | f8accc5 | 2018-10-11 10:19:54 -0700 | [diff] [blame] | 357 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 358 | if (mCurrentTransitionStartTime == INVALID_START_TIME) { |
Vishnu Nair | f8accc5 | 2018-10-11 10:19:54 -0700 | [diff] [blame] | 359 | // No transition is active ignore this launch. |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 360 | return; |
| 361 | } |
| 362 | |
Vishnu Nair | f8accc5 | 2018-10-11 10:19:54 -0700 | [diff] [blame] | 363 | if (launchedActivity != null && launchedActivity.nowVisible) { |
| 364 | // Launched activity is already visible. We cannot measure windows drawn delay. |
| 365 | reset(true /* abort */, info); |
| 366 | return; |
| 367 | } |
| 368 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 369 | if (launchedActivity != null && info != null) { |
Vishnu Nair | f8accc5 | 2018-10-11 10:19:54 -0700 | [diff] [blame] | 370 | // If we are already in an existing transition, only update the activity name, but not |
| 371 | // the other attributes. |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 372 | info.launchedActivity = launchedActivity; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 376 | final boolean otherWindowModesLaunching = |
| 377 | mWindowingModeTransitionInfo.size() > 0 && info == null; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 378 | if ((!isLoggableResultCode(resultCode) || launchedActivity == null || !processSwitch |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 379 | || windowingMode == WINDOWING_MODE_UNDEFINED) && !otherWindowModesLaunching) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 380 | // Failed to launch or it was not a process switch, so we don't care about the timing. |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 381 | reset(true /* abort */, info); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 382 | return; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 383 | } else if (otherWindowModesLaunching) { |
| 384 | // 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] | 385 | return; |
| 386 | } |
| 387 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 388 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched successful"); |
| 389 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 390 | final WindowingModeTransitionInfo newInfo = new WindowingModeTransitionInfo(); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 391 | newInfo.launchedActivity = launchedActivity; |
| 392 | newInfo.currentTransitionProcessRunning = processRunning; |
| 393 | newInfo.startResult = resultCode; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 394 | mWindowingModeTransitionInfo.put(windowingMode, newInfo); |
| 395 | mLastWindowingModeTransitionInfo.put(windowingMode, newInfo); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 396 | mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 397 | startTraces(newInfo); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 401 | * @return True if we should start logging an event for an activity start that returned |
| 402 | * {@code resultCode} and that we'll indeed get a windows drawn event. |
| 403 | */ |
| 404 | private boolean isLoggableResultCode(int resultCode) { |
| 405 | return resultCode == START_SUCCESS || resultCode == START_TASK_TO_FRONT; |
| 406 | } |
| 407 | |
| 408 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 409 | * Notifies the tracker that all windows of the app have been drawn. |
| 410 | */ |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 411 | WindowingModeTransitionInfoSnapshot notifyWindowsDrawn(int windowingMode, long timestamp) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 412 | if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn windowingMode=" + windowingMode); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 413 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 414 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 415 | if (info == null || info.loggedWindowsDrawn) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 416 | return null; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 417 | } |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 418 | info.windowsDrawnDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 419 | info.loggedWindowsDrawn = true; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 420 | final WindowingModeTransitionInfoSnapshot infoSnapshot = |
| 421 | new WindowingModeTransitionInfoSnapshot(info); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 422 | if (allWindowsDrawn() && mLoggedTransitionStarting) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 423 | reset(false /* abort */, info); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 424 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 425 | return infoSnapshot; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Notifies the tracker that the starting window was drawn. |
| 430 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 431 | void notifyStartingWindowDrawn(int windowingMode, long timestamp) { |
| 432 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 433 | if (info == null || info.loggedStartingWindowDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 434 | return; |
| 435 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 436 | info.loggedStartingWindowDrawn = true; |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 437 | info.startingWindowDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Notifies the tracker that the app transition is starting. |
| 442 | * |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 443 | * @param windowingModeToReason A map from windowing mode to a reason integer, which must be on |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 444 | * of ActivityTaskManagerInternal.APP_TRANSITION_* reasons. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 445 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 446 | void notifyTransitionStarting(SparseIntArray windowingModeToReason, long timestamp) { |
Jorim Jaggi | d8a5777 | 2017-04-14 16:50:42 -0700 | [diff] [blame] | 447 | if (!isAnyTransitionActive() || mLoggedTransitionStarting) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 448 | return; |
| 449 | } |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 450 | if (DEBUG_METRICS) Slog.i(TAG, "notifyTransitionStarting"); |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 451 | mCurrentTransitionDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 452 | mLoggedTransitionStarting = true; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 453 | for (int index = windowingModeToReason.size() - 1; index >= 0; index--) { |
| 454 | final int windowingMode = windowingModeToReason.keyAt(index); |
| 455 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 456 | windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 457 | if (info == null) { |
| 458 | continue; |
| 459 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 460 | info.reason = windowingModeToReason.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 461 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 462 | if (allWindowsDrawn()) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 463 | reset(false /* abort */, null /* WindowingModeTransitionInfo */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 467 | /** |
| 468 | * Notifies the tracker that the visibility of an app is changing. |
| 469 | * |
| 470 | * @param activityRecord the app that is changing its visibility |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 471 | */ |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 472 | void notifyVisibilityChanged(ActivityRecord activityRecord) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 473 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 474 | activityRecord.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 475 | if (info == null) { |
| 476 | return; |
| 477 | } |
| 478 | if (info.launchedActivity != activityRecord) { |
| 479 | return; |
| 480 | } |
| 481 | final TaskRecord t = activityRecord.getTask(); |
| 482 | final SomeArgs args = SomeArgs.obtain(); |
| 483 | args.arg1 = t; |
| 484 | args.arg2 = activityRecord; |
| 485 | mHandler.obtainMessage(MSG_CHECK_VISIBILITY, args).sendToTarget(); |
| 486 | } |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 487 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 488 | private void checkVisibility(TaskRecord t, ActivityRecord r) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 489 | synchronized (mSupervisor.mService.mGlobalLock) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 490 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 491 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 492 | r.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 493 | |
| 494 | // If we have an active transition that's waiting on a certain activity that will be |
| 495 | // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. |
| 496 | if (info != null && !t.isVisible()) { |
| 497 | if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible" |
| 498 | + " activity=" + r); |
| 499 | logAppTransitionCancel(info); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 500 | mWindowingModeTransitionInfo.remove(r.getWindowingMode()); |
| 501 | if (mWindowingModeTransitionInfo.size() == 0) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 502 | reset(true /* abort */, info); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 503 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 504 | stopFullyDrawnTraceIfNeeded(); |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 509 | /** |
| 510 | * Notifies the tracker that we called immediately before we call bindApplication on the client. |
| 511 | * |
| 512 | * @param app The client into which we'll call bindApplication. |
| 513 | */ |
| 514 | void notifyBindApplication(ProcessRecord app) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 515 | for (int i = mWindowingModeTransitionInfo.size() - 1; i >= 0; i--) { |
| 516 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(i); |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 517 | |
| 518 | // App isn't attached to record yet, so match with info. |
| 519 | if (info.launchedActivity.appInfo == app.info) { |
| 520 | info.bindApplicationDelayMs = calculateCurrentDelay(); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 525 | private boolean allWindowsDrawn() { |
| 526 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 527 | if (!mWindowingModeTransitionInfo.valueAt(index).loggedWindowsDrawn) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 528 | return false; |
| 529 | } |
| 530 | } |
| 531 | return true; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 534 | private boolean isAnyTransitionActive() { |
| 535 | return mCurrentTransitionStartTime != INVALID_START_TIME |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 536 | && mWindowingModeTransitionInfo.size() > 0; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 539 | private void reset(boolean abort, WindowingModeTransitionInfo info) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 540 | if (DEBUG_METRICS) Slog.i(TAG, "reset abort=" + abort); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 541 | if (!abort && isAnyTransitionActive()) { |
| 542 | logAppTransitionMultiEvents(); |
| 543 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 544 | stopLaunchTrace(info); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 545 | mCurrentTransitionStartTime = INVALID_START_TIME; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 546 | mCurrentTransitionDelayMs = INVALID_DELAY; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 547 | mLoggedTransitionStarting = false; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 548 | mWindowingModeTransitionInfo.clear(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | private int calculateCurrentDelay() { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 552 | // 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] | 553 | return (int) (SystemClock.uptimeMillis() - mCurrentTransitionStartTime); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 554 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 555 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 556 | private int calculateDelay(long timestamp) { |
| 557 | // Shouldn't take more than 25 days to launch an app, so int is fine here. |
| 558 | return (int) (timestamp - mCurrentTransitionStartTime); |
| 559 | } |
| 560 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 561 | private void logAppTransitionCancel(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 562 | final int type = getTransitionType(info); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 563 | if (type == INVALID_TRANSITION_TYPE) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 564 | return; |
| 565 | } |
| 566 | final LogMaker builder = new LogMaker(APP_TRANSITION_CANCELLED); |
| 567 | builder.setPackageName(info.launchedActivity.packageName); |
| 568 | builder.setType(type); |
| 569 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name); |
| 570 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 571 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 572 | StatsLog.APP_START_CANCELED, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 573 | info.launchedActivity.appInfo.uid, |
| 574 | info.launchedActivity.packageName, |
| 575 | convertAppStartTransitionType(type), |
| 576 | info.launchedActivity.info.name); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 579 | private void logAppTransitionMultiEvents() { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 580 | if (DEBUG_METRICS) Slog.i(TAG, "logging transition events"); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 581 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 582 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 583 | final int type = getTransitionType(info); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 584 | if (type == INVALID_TRANSITION_TYPE) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 585 | return; |
| 586 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 587 | |
| 588 | // Take a snapshot of the transition info before sending it to the handler for logging. |
| 589 | // This will avoid any races with other operations that modify the ActivityRecord. |
| 590 | final WindowingModeTransitionInfoSnapshot infoSnapshot = |
| 591 | new WindowingModeTransitionInfoSnapshot(info); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 592 | final int currentTransitionDeviceUptime = mCurrentTransitionDeviceUptime; |
| 593 | final int currentTransitionDelayMs = mCurrentTransitionDelayMs; |
| 594 | BackgroundThread.getHandler().post(() -> logAppTransition( |
| 595 | currentTransitionDeviceUptime, currentTransitionDelayMs, infoSnapshot)); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 596 | BackgroundThread.getHandler().post(() -> logAppDisplayed(infoSnapshot)); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 597 | |
| 598 | info.launchedActivity.info.launchToken = null; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 602 | // This gets called on a background thread without holding the activity manager lock. |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 603 | private void logAppTransition(int currentTransitionDeviceUptime, int currentTransitionDelayMs, |
| 604 | WindowingModeTransitionInfoSnapshot info) { |
| 605 | final LogMaker builder = new LogMaker(APP_TRANSITION); |
| 606 | builder.setPackageName(info.packageName); |
| 607 | builder.setType(info.type); |
| 608 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivityName); |
| 609 | final boolean isInstantApp = info.applicationInfo.isInstantApp(); |
| 610 | if (info.launchedActivityLaunchedFromPackage != null) { |
| 611 | builder.addTaggedData(APP_TRANSITION_CALLING_PACKAGE_NAME, |
| 612 | info.launchedActivityLaunchedFromPackage); |
| 613 | } |
| 614 | String launchToken = info.launchedActivityLaunchToken; |
| 615 | if (launchToken != null) { |
| 616 | builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN, launchToken); |
| 617 | } |
| 618 | builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0); |
| 619 | builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS, |
| 620 | currentTransitionDeviceUptime); |
| 621 | builder.addTaggedData(APP_TRANSITION_DELAY_MS, currentTransitionDelayMs); |
| 622 | builder.setSubtype(info.reason); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 623 | if (info.startingWindowDelayMs != INVALID_DELAY) { |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 624 | builder.addTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS, |
| 625 | info.startingWindowDelayMs); |
| 626 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 627 | if (info.bindApplicationDelayMs != INVALID_DELAY) { |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 628 | builder.addTaggedData(APP_TRANSITION_BIND_APPLICATION_DELAY_MS, |
| 629 | info.bindApplicationDelayMs); |
| 630 | } |
| 631 | builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs); |
| 632 | final ArtManagerInternal artManagerInternal = getArtManagerInternal(); |
| 633 | final PackageOptimizationInfo packageOptimizationInfo = |
| 634 | (artManagerInternal == null) || (info.launchedActivityAppRecordRequiredAbi == null) |
| 635 | ? PackageOptimizationInfo.createWithNoInfo() |
| 636 | : artManagerInternal.getPackageOptimizationInfo( |
| 637 | info.applicationInfo, |
| 638 | info.launchedActivityAppRecordRequiredAbi); |
| 639 | builder.addTaggedData(PACKAGE_OPTIMIZATION_COMPILATION_REASON, |
| 640 | packageOptimizationInfo.getCompilationReason()); |
| 641 | builder.addTaggedData(PACKAGE_OPTIMIZATION_COMPILATION_FILTER, |
| 642 | packageOptimizationInfo.getCompilationFilter()); |
| 643 | mMetricsLogger.write(builder); |
| 644 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 645 | StatsLog.APP_START_OCCURRED, |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 646 | info.applicationInfo.uid, |
| 647 | info.packageName, |
| 648 | convertAppStartTransitionType(info.type), |
| 649 | info.launchedActivityName, |
| 650 | info.launchedActivityLaunchedFromPackage, |
| 651 | isInstantApp, |
| 652 | currentTransitionDeviceUptime * 1000, |
| 653 | info.reason, |
| 654 | currentTransitionDelayMs, |
| 655 | info.startingWindowDelayMs, |
| 656 | info.bindApplicationDelayMs, |
| 657 | info.windowsDrawnDelayMs, |
| 658 | launchToken, |
| 659 | packageOptimizationInfo.getCompilationReason(), |
| 660 | packageOptimizationInfo.getCompilationFilter()); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 661 | logAppStartMemoryStateCapture(info); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 664 | private void logAppDisplayed(WindowingModeTransitionInfoSnapshot info) { |
| 665 | if (info.type != TYPE_TRANSITION_WARM_LAUNCH && info.type != TYPE_TRANSITION_COLD_LAUNCH) { |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | EventLog.writeEvent(AM_ACTIVITY_LAUNCH_TIME, |
| 670 | info.userId, info.activityRecordIdHashCode, info.launchedActivityShortComponentName, |
| 671 | info.windowsDrawnDelayMs); |
| 672 | |
| 673 | StringBuilder sb = mStringBuilder; |
| 674 | sb.setLength(0); |
| 675 | sb.append("Displayed "); |
| 676 | sb.append(info.launchedActivityShortComponentName); |
| 677 | sb.append(": "); |
| 678 | TimeUtils.formatDuration(info.windowsDrawnDelayMs, sb); |
| 679 | Log.i(TAG, sb.toString()); |
| 680 | } |
| 681 | |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 682 | private int convertAppStartTransitionType(int tronType) { |
| 683 | if (tronType == TYPE_TRANSITION_COLD_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 684 | return StatsLog.APP_START_OCCURRED__TYPE__COLD; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 685 | } |
| 686 | if (tronType == TYPE_TRANSITION_WARM_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 687 | return StatsLog.APP_START_OCCURRED__TYPE__WARM; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 688 | } |
| 689 | if (tronType == TYPE_TRANSITION_HOT_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 690 | return StatsLog.APP_START_OCCURRED__TYPE__HOT; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 691 | } |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 692 | return StatsLog.APP_START_OCCURRED__TYPE__UNKNOWN; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 695 | WindowingModeTransitionInfoSnapshot logAppTransitionReportedDrawn(ActivityRecord r, |
| 696 | boolean restoredFromBundle) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 697 | final WindowingModeTransitionInfo info = mLastWindowingModeTransitionInfo.get( |
| 698 | r.getWindowingMode()); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 699 | if (info == null) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 700 | return null; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 701 | } |
| 702 | final LogMaker builder = new LogMaker(APP_TRANSITION_REPORTED_DRAWN); |
| 703 | builder.setPackageName(r.packageName); |
| 704 | builder.addTaggedData(FIELD_CLASS_NAME, r.info.name); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 705 | long startupTimeMs = SystemClock.uptimeMillis() - mLastTransitionStartTime; |
| 706 | builder.addTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS, startupTimeMs); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 707 | builder.setType(restoredFromBundle |
| 708 | ? TYPE_TRANSITION_REPORTED_DRAWN_WITH_BUNDLE |
| 709 | : TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE); |
| 710 | builder.addTaggedData(APP_TRANSITION_PROCESS_RUNNING, |
| 711 | info.currentTransitionProcessRunning ? 1 : 0); |
| 712 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 713 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 714 | StatsLog.APP_START_FULLY_DRAWN, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 715 | info.launchedActivity.appInfo.uid, |
| 716 | info.launchedActivity.packageName, |
| 717 | restoredFromBundle |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 718 | ? StatsLog.APP_START_FULLY_DRAWN__TYPE__WITH_BUNDLE |
| 719 | : StatsLog.APP_START_FULLY_DRAWN__TYPE__WITHOUT_BUNDLE, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 720 | info.launchedActivity.info.name, |
| 721 | info.currentTransitionProcessRunning, |
| 722 | startupTimeMs); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 723 | stopFullyDrawnTraceIfNeeded(); |
| 724 | final WindowingModeTransitionInfoSnapshot infoSnapshot = |
| 725 | new WindowingModeTransitionInfoSnapshot(info, r, (int) startupTimeMs); |
| 726 | BackgroundThread.getHandler().post(() -> logAppFullyDrawn(infoSnapshot)); |
| 727 | return infoSnapshot; |
| 728 | } |
| 729 | |
| 730 | private void logAppFullyDrawn(WindowingModeTransitionInfoSnapshot info) { |
| 731 | if (info.type != TYPE_TRANSITION_WARM_LAUNCH && info.type != TYPE_TRANSITION_COLD_LAUNCH) { |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | StringBuilder sb = mStringBuilder; |
| 736 | sb.setLength(0); |
| 737 | sb.append("Fully drawn "); |
| 738 | sb.append(info.launchedActivityShortComponentName); |
| 739 | sb.append(": "); |
| 740 | TimeUtils.formatDuration(info.windowsFullyDrawnDelayMs, sb); |
| 741 | Log.i(TAG, sb.toString()); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 744 | void logActivityStart(Intent intent, WindowProcessController callerApp, ActivityRecord r, |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 745 | int callingUid, String callingPackage, int callingUidProcState, |
| 746 | boolean callingUidHasAnyVisibleWindow, |
| 747 | int realCallingUid, int realCallingUidProcState, |
| 748 | boolean realCallingUidHasAnyVisibleWindow, |
| 749 | int targetUid, String targetPackage, int targetUidProcState, |
| 750 | boolean targetUidHasAnyVisibleWindow, String targetWhitelistTag, |
| 751 | boolean comingFromPendingIntent) { |
| 752 | |
| 753 | final long nowElapsed = SystemClock.elapsedRealtime(); |
| 754 | final long nowUptime = SystemClock.uptimeMillis(); |
| 755 | final LogMaker builder = new LogMaker(ACTION_ACTIVITY_START); |
| 756 | builder.setTimestamp(System.currentTimeMillis()); |
| 757 | builder.addTaggedData(FIELD_CALLING_UID, callingUid); |
| 758 | builder.addTaggedData(FIELD_CALLING_PACKAGE_NAME, callingPackage); |
| 759 | builder.addTaggedData(FIELD_CALLING_UID_PROC_STATE, |
| 760 | processStateAmToProto(callingUidProcState)); |
| 761 | builder.addTaggedData(FIELD_CALLING_UID_HAS_ANY_VISIBLE_WINDOW, |
| 762 | callingUidHasAnyVisibleWindow ? 1 : 0); |
| 763 | builder.addTaggedData(FIELD_REAL_CALLING_UID, realCallingUid); |
| 764 | builder.addTaggedData(FIELD_REAL_CALLING_UID_PROC_STATE, |
| 765 | processStateAmToProto(realCallingUidProcState)); |
| 766 | builder.addTaggedData(FIELD_REAL_CALLING_UID_HAS_ANY_VISIBLE_WINDOW, |
| 767 | realCallingUidHasAnyVisibleWindow ? 1 : 0); |
| 768 | builder.addTaggedData(FIELD_TARGET_UID, targetUid); |
| 769 | builder.addTaggedData(FIELD_TARGET_PACKAGE_NAME, targetPackage); |
| 770 | builder.addTaggedData(FIELD_TARGET_UID_PROC_STATE, |
| 771 | processStateAmToProto(targetUidProcState)); |
| 772 | builder.addTaggedData(FIELD_TARGET_UID_HAS_ANY_VISIBLE_WINDOW, |
| 773 | targetUidHasAnyVisibleWindow ? 1 : 0); |
| 774 | builder.addTaggedData(FIELD_TARGET_WHITELIST_TAG, targetWhitelistTag); |
| 775 | builder.addTaggedData(FIELD_TARGET_SHORT_COMPONENT_NAME, r.shortComponentName); |
| 776 | builder.addTaggedData(FIELD_COMING_FROM_PENDING_INTENT, comingFromPendingIntent ? 1 : 0); |
| 777 | builder.addTaggedData(FIELD_INTENT_ACTION, intent.getAction()); |
| 778 | if (callerApp != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 779 | builder.addTaggedData(FIELD_PROCESS_RECORD_PROCESS_NAME, callerApp.mName); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 780 | builder.addTaggedData(FIELD_PROCESS_RECORD_CUR_PROC_STATE, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 781 | processStateAmToProto(callerApp.getCurrentProcState())); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 782 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_CLIENT_ACTIVITIES, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 783 | callerApp.hasClientActivities() ? 1 : 0); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 784 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_FOREGROUND_SERVICES, |
| 785 | callerApp.hasForegroundServices() ? 1 : 0); |
| 786 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_FOREGROUND_ACTIVITIES, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 787 | callerApp.hasForegroundActivities() ? 1 : 0); |
| 788 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_TOP_UI, callerApp.hasTopUi() ? 1 : 0); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 789 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_OVERLAY_UI, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 790 | callerApp.hasOverlayUi() ? 1 : 0); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 791 | builder.addTaggedData(FIELD_PROCESS_RECORD_PENDING_UI_CLEAN, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 792 | callerApp.hasPendingUiClean() ? 1 : 0); |
| 793 | if (callerApp.getInteractionEventTime() != 0) { |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 794 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_LAST_INTERACTION_EVENT, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 795 | (nowElapsed - callerApp.getInteractionEventTime())); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 796 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 797 | if (callerApp.getFgInteractionTime() != 0) { |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 798 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_FG_INTERACTION, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 799 | (nowElapsed - callerApp.getFgInteractionTime())); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 800 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 801 | if (callerApp.getWhenUnimportant() != 0) { |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 802 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_UNIMPORTANT, |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame^] | 803 | (nowUptime - callerApp.getWhenUnimportant())); |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_LAUNCH_MODE, r.info.launchMode); |
| 807 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_TARGET_ACTIVITY, r.info.targetActivity); |
| 808 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_FLAGS, r.info.flags); |
| 809 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_REAL_ACTIVITY, r.realActivity.toShortString()); |
| 810 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_SHORT_COMPONENT_NAME, r.shortComponentName); |
| 811 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_PROCESS_NAME, r.processName); |
| 812 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_FULLSCREEN, r.fullscreen ? 1 : 0); |
| 813 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_NO_DISPLAY, r.noDisplay ? 1 : 0); |
| 814 | if (r.lastVisibleTime != 0) { |
| 815 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_VISIBLE, |
| 816 | (nowUptime - r.lastVisibleTime)); |
| 817 | } |
| 818 | if (r.resultTo != null) { |
| 819 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_RESULT_TO_PKG_NAME, r.resultTo.packageName); |
| 820 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_RESULT_TO_SHORT_COMPONENT_NAME, |
| 821 | r.resultTo.shortComponentName); |
| 822 | } |
| 823 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_VISIBLE, r.visible ? 1 : 0); |
| 824 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_VISIBLE_IGNORING_KEYGUARD, |
| 825 | r.visibleIgnoringKeyguard ? 1 : 0); |
| 826 | if (r.lastLaunchTime != 0) { |
| 827 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_LAUNCH, |
| 828 | (nowUptime - r.lastLaunchTime)); |
| 829 | } |
| 830 | mMetricsLogger.write(builder); |
| 831 | } |
| 832 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 833 | private int getTransitionType(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 834 | if (info.currentTransitionProcessRunning) { |
| 835 | if (info.startResult == START_SUCCESS) { |
| 836 | return TYPE_TRANSITION_WARM_LAUNCH; |
| 837 | } else if (info.startResult == START_TASK_TO_FRONT) { |
| 838 | return TYPE_TRANSITION_HOT_LAUNCH; |
| 839 | } |
| 840 | } else if (info.startResult == START_SUCCESS) { |
| 841 | return TYPE_TRANSITION_COLD_LAUNCH; |
| 842 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 843 | return INVALID_TRANSITION_TYPE; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 844 | } |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 845 | |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 846 | private void logAppStartMemoryStateCapture(WindowingModeTransitionInfoSnapshot info) { |
| 847 | if (info.processRecord == null) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 848 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture processRecord null"); |
| 849 | return; |
| 850 | } |
| 851 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 852 | final int pid = info.processRecord.getPid(); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 853 | final int uid = info.applicationInfo.uid; |
Rajeev Kumar | bfcd920 | 2018-03-02 22:42:13 +0000 | [diff] [blame] | 854 | final MemoryStat memoryStat = readMemoryStatFromFilesystem(uid, pid); |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 855 | if (memoryStat == null) { |
| 856 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture memoryStat null"); |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | StatsLog.write( |
| 861 | StatsLog.APP_START_MEMORY_STATE_CAPTURED, |
| 862 | uid, |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 863 | info.processName, |
| 864 | info.launchedActivityName, |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 865 | memoryStat.pgfault, |
| 866 | memoryStat.pgmajfault, |
| 867 | memoryStat.rssInBytes, |
| 868 | memoryStat.cacheInBytes, |
| 869 | memoryStat.swapInBytes); |
| 870 | } |
| 871 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 872 | private WindowProcessController findProcessForActivity(ActivityRecord launchedActivity) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 873 | return launchedActivity != null |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 874 | ? mSupervisor.mService.mProcessNames.get( |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 875 | launchedActivity.processName, launchedActivity.appInfo.uid) |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 876 | : null; |
| 877 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 878 | |
| 879 | private ArtManagerInternal getArtManagerInternal() { |
| 880 | if (mArtManagerInternal == null) { |
| 881 | // Note that this may be null. |
| 882 | // ArtManagerInternal is registered during PackageManagerService |
| 883 | // initialization which happens after ActivityManagerService. |
| 884 | mArtManagerInternal = LocalServices.getService(ArtManagerInternal.class); |
| 885 | } |
| 886 | return mArtManagerInternal; |
| 887 | } |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 888 | |
| 889 | /** |
| 890 | * Starts traces for app launch and draw times. We stop the fully drawn trace if its already |
| 891 | * active since the app may not have reported fully drawn in the previous launch. |
| 892 | * |
| 893 | * See {@link android.app.Activity#reportFullyDrawn()} |
| 894 | * |
| 895 | * @param info |
| 896 | * */ |
| 897 | private void startTraces(WindowingModeTransitionInfo info) { |
| 898 | if (info == null) { |
| 899 | return; |
| 900 | } |
| 901 | stopFullyDrawnTraceIfNeeded(); |
| 902 | int transitionType = getTransitionType(info); |
| 903 | if (!info.launchTraceActive && transitionType == TYPE_TRANSITION_WARM_LAUNCH |
| 904 | || transitionType == TYPE_TRANSITION_COLD_LAUNCH) { |
| 905 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " |
| 906 | + info.launchedActivity.packageName, 0); |
| 907 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 908 | mDrawingTraceActive = true; |
| 909 | info.launchTraceActive = true; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | private void stopLaunchTrace(WindowingModeTransitionInfo info) { |
| 914 | if (info == null) { |
| 915 | return; |
| 916 | } |
| 917 | if (info.launchTraceActive) { |
| 918 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " |
| 919 | + info.launchedActivity.packageName, 0); |
| 920 | info.launchTraceActive = false; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | void stopFullyDrawnTraceIfNeeded() { |
| 925 | if (mDrawingTraceActive) { |
| 926 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 927 | mDrawingTraceActive = false; |
| 928 | } |
| 929 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 930 | } |