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