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