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