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