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