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