Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 1 | package com.android.server.am; |
| 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; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6 | import static com.android.server.wm.ActivityTaskManagerInternal.APP_TRANSITION_TIMEOUT; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 7 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 8 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 9 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 10 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 11 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 12 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
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; |
| 31 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_LAUNCH; |
| 32 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_VISIBLE; |
| 33 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_ACTIVITY_RECORD_LAUNCH_MODE; |
| 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; |
| 60 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_REAL_CALLING_UID_PROC_STATE; |
| 61 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_REAL_CALLING_UID_HAS_ANY_VISIBLE_WINDOW; |
| 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_REASON; |
| 69 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.PACKAGE_OPTIMIZATION_COMPILATION_FILTER; |
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; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 75 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_METRICS; |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 76 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 77 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 78 | import static com.android.server.am.MemoryStatUtil.MemoryStat; |
Rajeev Kumar | bfcd920 | 2018-03-02 22:42:13 +0000 | [diff] [blame] | 79 | import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 80 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 81 | import android.content.Context; |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 82 | import android.content.Intent; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 83 | import android.content.pm.ApplicationInfo; |
| 84 | import android.content.pm.dex.ArtManagerInternal; |
| 85 | import android.content.pm.dex.PackageOptimizationInfo; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 86 | import android.metrics.LogMaker; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 87 | import android.os.Handler; |
| 88 | import android.os.Looper; |
| 89 | import android.os.Message; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 90 | import android.os.SystemClock; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 91 | import android.util.Slog; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 92 | import android.util.SparseArray; |
| 93 | import android.util.SparseIntArray; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 94 | import android.util.StatsLog; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 95 | |
| 96 | import com.android.internal.logging.MetricsLogger; |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 97 | import com.android.internal.os.BackgroundThread; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 98 | import com.android.internal.os.SomeArgs; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 99 | import com.android.server.LocalServices; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 100 | |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 101 | import java.util.ArrayList; |
| 102 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 103 | /** |
| 104 | * Handles logging into Tron. |
| 105 | */ |
| 106 | class ActivityMetricsLogger { |
Jorim Jaggi | f970410 | 2016-05-05 19:14:22 -0700 | [diff] [blame] | 107 | |
| 108 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityMetricsLogger" : TAG_AM; |
| 109 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 110 | // Window modes we are interested in logging. If we ever introduce a new type, we need to add |
| 111 | // a value here and increase the {@link #TRON_WINDOW_STATE_VARZ_STRINGS} array. |
| 112 | private static final int WINDOW_STATE_STANDARD = 0; |
| 113 | private static final int WINDOW_STATE_SIDE_BY_SIDE = 1; |
| 114 | private static final int WINDOW_STATE_FREEFORM = 2; |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 115 | private static final int WINDOW_STATE_ASSISTANT = 3; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 116 | private static final int WINDOW_STATE_INVALID = -1; |
| 117 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 118 | private static final long INVALID_START_TIME = -1; |
| 119 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 120 | private static final int MSG_CHECK_VISIBILITY = 0; |
| 121 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 122 | // Preallocated strings we are sending to tron, so we don't have to allocate a new one every |
| 123 | // time we log. |
| 124 | private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 125 | "window_time_0", "window_time_1", "window_time_2", "window_time_3"}; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 126 | |
| 127 | private int mWindowState = WINDOW_STATE_STANDARD; |
| 128 | private long mLastLogTimeSecs; |
| 129 | private final ActivityStackSupervisor mSupervisor; |
| 130 | private final Context mContext; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 131 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 132 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 133 | private long mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 134 | private long mLastTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 135 | |
| 136 | private int mCurrentTransitionDeviceUptime; |
| 137 | private int mCurrentTransitionDelayMs; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 138 | private boolean mLoggedTransitionStarting; |
| 139 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 140 | private final SparseArray<WindowingModeTransitionInfo> mWindowingModeTransitionInfo = |
| 141 | new SparseArray<>(); |
| 142 | private final SparseArray<WindowingModeTransitionInfo> mLastWindowingModeTransitionInfo = |
| 143 | new SparseArray<>(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 144 | private final H mHandler; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 145 | |
| 146 | private ArtManagerInternal mArtManagerInternal; |
| 147 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 148 | private final class H extends Handler { |
| 149 | |
| 150 | public H(Looper looper) { |
| 151 | super(looper); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void handleMessage(Message msg) { |
| 156 | switch (msg.what) { |
| 157 | case MSG_CHECK_VISIBILITY: |
| 158 | final SomeArgs args = (SomeArgs) msg.obj; |
| 159 | checkVisibility((TaskRecord) args.arg1, (ActivityRecord) args.arg2); |
| 160 | break; |
| 161 | } |
| 162 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 163 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 164 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 165 | private final class WindowingModeTransitionInfo { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 166 | private ActivityRecord launchedActivity; |
| 167 | private int startResult; |
| 168 | private boolean currentTransitionProcessRunning; |
| 169 | private int windowsDrawnDelayMs; |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 170 | private int startingWindowDelayMs = -1; |
| 171 | private int bindApplicationDelayMs = -1; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 172 | private int reason = APP_TRANSITION_TIMEOUT; |
| 173 | private boolean loggedWindowsDrawn; |
| 174 | private boolean loggedStartingWindowDrawn; |
| 175 | } |
| 176 | |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 177 | private final class WindowingModeTransitionInfoSnapshot { |
| 178 | final private ApplicationInfo applicationInfo; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 179 | final private WindowProcessController processRecord; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 180 | final private String packageName; |
| 181 | final private String launchedActivityName; |
| 182 | final private String launchedActivityLaunchedFromPackage; |
| 183 | final private String launchedActivityLaunchToken; |
| 184 | final private String launchedActivityAppRecordRequiredAbi; |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 185 | final private String processName; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 186 | final private int reason; |
| 187 | final private int startingWindowDelayMs; |
| 188 | final private int bindApplicationDelayMs; |
| 189 | final private int windowsDrawnDelayMs; |
| 190 | final private int type; |
| 191 | |
| 192 | private WindowingModeTransitionInfoSnapshot(WindowingModeTransitionInfo info) { |
| 193 | applicationInfo = info.launchedActivity.appInfo; |
| 194 | packageName = info.launchedActivity.packageName; |
| 195 | launchedActivityName = info.launchedActivity.info.name; |
| 196 | launchedActivityLaunchedFromPackage = info.launchedActivity.launchedFromPackage; |
| 197 | launchedActivityLaunchToken = info.launchedActivity.info.launchToken; |
| 198 | launchedActivityAppRecordRequiredAbi = info.launchedActivity.app == null |
| 199 | ? null |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 200 | : info.launchedActivity.app.getRequiredAbi(); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 201 | reason = info.reason; |
| 202 | startingWindowDelayMs = info.startingWindowDelayMs; |
| 203 | bindApplicationDelayMs = info.bindApplicationDelayMs; |
| 204 | windowsDrawnDelayMs = info.windowsDrawnDelayMs; |
| 205 | type = getTransitionType(info); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 206 | processRecord = findProcessForActivity(info.launchedActivity); |
| 207 | processName = info.launchedActivity.processName; |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 211 | ActivityMetricsLogger(ActivityStackSupervisor supervisor, Context context, Looper looper) { |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 212 | mLastLogTimeSecs = SystemClock.elapsedRealtime() / 1000; |
| 213 | mSupervisor = supervisor; |
| 214 | mContext = context; |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 215 | mHandler = new H(looper); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void logWindowState() { |
| 219 | final long now = SystemClock.elapsedRealtime() / 1000; |
| 220 | if (mWindowState != WINDOW_STATE_INVALID) { |
| 221 | // We log even if the window state hasn't changed, because the user might remain in |
| 222 | // home/fullscreen move forever and we would like to track this kind of behavior |
| 223 | // too. |
| 224 | MetricsLogger.count(mContext, TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState], |
| 225 | (int) (now - mLastLogTimeSecs)); |
| 226 | } |
| 227 | mLastLogTimeSecs = now; |
| 228 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 229 | mWindowState = WINDOW_STATE_INVALID; |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 230 | ActivityStack stack = mSupervisor.getTopDisplayFocusedStack(); |
lumark | f6c4a98 | 2018-06-15 15:43:12 +0800 | [diff] [blame] | 231 | if (stack == null) { |
| 232 | return; |
| 233 | } |
| 234 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 235 | if (stack.isActivityTypeAssistant()) { |
| 236 | mWindowState = WINDOW_STATE_ASSISTANT; |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 237 | return; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 238 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 239 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 240 | int windowingMode = stack.getWindowingMode(); |
| 241 | if (windowingMode == WINDOWING_MODE_PINNED) { |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 242 | stack = mSupervisor.findStackBehind(stack); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 243 | windowingMode = stack.getWindowingMode(); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 244 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 245 | switch (windowingMode) { |
| 246 | case WINDOWING_MODE_FULLSCREEN: |
| 247 | mWindowState = WINDOW_STATE_STANDARD; |
| 248 | break; |
| 249 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 250 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 251 | mWindowState = WINDOW_STATE_SIDE_BY_SIDE; |
| 252 | break; |
Bryce Lee | 6c60509 | 2017-10-12 11:14:49 -0700 | [diff] [blame] | 253 | case WINDOWING_MODE_FREEFORM: |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 254 | mWindowState = WINDOW_STATE_FREEFORM; |
| 255 | break; |
| 256 | default: |
| 257 | if (windowingMode != WINDOWING_MODE_UNDEFINED) { |
| 258 | throw new IllegalStateException("Unknown windowing mode for stack=" + stack |
| 259 | + " windowingMode=" + windowingMode); |
| 260 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 263 | |
| 264 | /** |
| 265 | * Notifies the tracker at the earliest possible point when we are starting to launch an |
| 266 | * activity. |
| 267 | */ |
| 268 | void notifyActivityLaunching() { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 269 | if (!isAnyTransitionActive()) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 270 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunching"); |
Alison Cichowlas | b7f67ab | 2017-04-25 18:04:40 -0400 | [diff] [blame] | 271 | mCurrentTransitionStartTime = SystemClock.uptimeMillis(); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 272 | mLastTransitionStartTime = mCurrentTransitionStartTime; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 273 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /** |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 277 | * Notifies the tracker that the activity is actually launching. |
| 278 | * |
| 279 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 280 | * launch |
| 281 | * @param launchedActivity the activity that is being launched |
| 282 | */ |
| 283 | void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 284 | final WindowProcessController processRecord = findProcessForActivity(launchedActivity); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 285 | final boolean processRunning = processRecord != null; |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 286 | |
| 287 | // We consider this a "process switch" if the process of the activity that gets launched |
| 288 | // didn't have an activity that was in started state. In this case, we assume that lot |
| 289 | // of caches might be purged so the time until it produces the first frame is very |
| 290 | // interesting. |
| 291 | final boolean processSwitch = processRecord == null |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 292 | || !processRecord.hasStartedActivity(launchedActivity); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 293 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 294 | notifyActivityLaunched(resultCode, launchedActivity, processRunning, processSwitch); |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jorim Jaggi | 1e630c0 | 2016-05-16 12:13:13 -0700 | [diff] [blame] | 297 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 298 | * Notifies the tracker the the activity is actually launching. |
| 299 | * |
| 300 | * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the |
| 301 | * launch |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 302 | * @param launchedActivity the activity being launched |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 303 | * @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] | 304 | * @param processSwitch whether the process that will contain the activity didn't have any |
| 305 | * activity that was stopped, i.e. the started activity is "switching" |
| 306 | * processes |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 307 | */ |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 308 | private void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity, |
Jorim Jaggi | be67c90 | 2016-04-12 00:53:16 -0700 | [diff] [blame] | 309 | boolean processRunning, boolean processSwitch) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 310 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 311 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched" |
| 312 | + " resultCode=" + resultCode |
| 313 | + " launchedActivity=" + launchedActivity |
| 314 | + " processRunning=" + processRunning |
| 315 | + " processSwitch=" + processSwitch); |
| 316 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 317 | // If we are already in an existing transition, only update the activity name, but not the |
| 318 | // other attributes. |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 319 | final int windowingMode = launchedActivity != null |
| 320 | ? launchedActivity.getWindowingMode() |
| 321 | : WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 322 | |
| 323 | if (mCurrentTransitionStartTime == INVALID_START_TIME) { |
| 324 | return; |
| 325 | } |
| 326 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 327 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 328 | if (launchedActivity != null && info != null) { |
| 329 | info.launchedActivity = launchedActivity; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 330 | return; |
| 331 | } |
| 332 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 333 | final boolean otherWindowModesLaunching = |
| 334 | mWindowingModeTransitionInfo.size() > 0 && info == null; |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 335 | if ((!isLoggableResultCode(resultCode) || launchedActivity == null || !processSwitch |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 336 | || windowingMode == WINDOWING_MODE_UNDEFINED) && !otherWindowModesLaunching) { |
Alison Cichowlas | 803054d | 2016-12-13 14:38:01 -0500 | [diff] [blame] | 337 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 338 | // Failed to launch or it was not a process switch, so we don't care about the timing. |
| 339 | reset(true /* abort */); |
| 340 | return; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 341 | } else if (otherWindowModesLaunching) { |
| 342 | // 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] | 343 | return; |
| 344 | } |
| 345 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 346 | if (DEBUG_METRICS) Slog.i(TAG, "notifyActivityLaunched successful"); |
| 347 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 348 | final WindowingModeTransitionInfo newInfo = new WindowingModeTransitionInfo(); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 349 | newInfo.launchedActivity = launchedActivity; |
| 350 | newInfo.currentTransitionProcessRunning = processRunning; |
| 351 | newInfo.startResult = resultCode; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 352 | mWindowingModeTransitionInfo.put(windowingMode, newInfo); |
| 353 | mLastWindowingModeTransitionInfo.put(windowingMode, newInfo); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 354 | mCurrentTransitionDeviceUptime = (int) (SystemClock.uptimeMillis() / 1000); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
Jorim Jaggi | 54cff64 | 2018-03-15 15:51:32 +0100 | [diff] [blame] | 358 | * @return True if we should start logging an event for an activity start that returned |
| 359 | * {@code resultCode} and that we'll indeed get a windows drawn event. |
| 360 | */ |
| 361 | private boolean isLoggableResultCode(int resultCode) { |
| 362 | return resultCode == START_SUCCESS || resultCode == START_TASK_TO_FRONT; |
| 363 | } |
| 364 | |
| 365 | /** |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 366 | * Notifies the tracker that all windows of the app have been drawn. |
| 367 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 368 | void notifyWindowsDrawn(int windowingMode, long timestamp) { |
| 369 | if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn windowingMode=" + windowingMode); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 370 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 371 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 372 | if (info == null || info.loggedWindowsDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 373 | return; |
| 374 | } |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 375 | info.windowsDrawnDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 376 | info.loggedWindowsDrawn = true; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 377 | if (allWindowsDrawn() && mLoggedTransitionStarting) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 378 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Notifies the tracker that the starting window was drawn. |
| 384 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 385 | void notifyStartingWindowDrawn(int windowingMode, long timestamp) { |
| 386 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get(windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 387 | if (info == null || info.loggedStartingWindowDrawn) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 388 | return; |
| 389 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 390 | info.loggedStartingWindowDrawn = true; |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 391 | info.startingWindowDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Notifies the tracker that the app transition is starting. |
| 396 | * |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 397 | * @param windowingModeToReason A map from windowing mode to a reason integer, which must be on |
| 398 | * of ActivityManagerInternal.APP_TRANSITION_* reasons. |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 399 | */ |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 400 | void notifyTransitionStarting(SparseIntArray windowingModeToReason, long timestamp) { |
Jorim Jaggi | d8a5777 | 2017-04-14 16:50:42 -0700 | [diff] [blame] | 401 | if (!isAnyTransitionActive() || mLoggedTransitionStarting) { |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 402 | return; |
| 403 | } |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 404 | if (DEBUG_METRICS) Slog.i(TAG, "notifyTransitionStarting"); |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 405 | mCurrentTransitionDelayMs = calculateDelay(timestamp); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 406 | mLoggedTransitionStarting = true; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 407 | for (int index = windowingModeToReason.size() - 1; index >= 0; index--) { |
| 408 | final int windowingMode = windowingModeToReason.keyAt(index); |
| 409 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 410 | windowingMode); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 411 | if (info == null) { |
| 412 | continue; |
| 413 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 414 | info.reason = windowingModeToReason.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 415 | } |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 416 | if (allWindowsDrawn()) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 417 | reset(false /* abort */); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 421 | /** |
| 422 | * Notifies the tracker that the visibility of an app is changing. |
| 423 | * |
| 424 | * @param activityRecord the app that is changing its visibility |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 425 | */ |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 426 | void notifyVisibilityChanged(ActivityRecord activityRecord) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 427 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 428 | activityRecord.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 429 | if (info == null) { |
| 430 | return; |
| 431 | } |
| 432 | if (info.launchedActivity != activityRecord) { |
| 433 | return; |
| 434 | } |
| 435 | final TaskRecord t = activityRecord.getTask(); |
| 436 | final SomeArgs args = SomeArgs.obtain(); |
| 437 | args.arg1 = t; |
| 438 | args.arg2 = activityRecord; |
| 439 | mHandler.obtainMessage(MSG_CHECK_VISIBILITY, args).sendToTarget(); |
| 440 | } |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 441 | |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 442 | private void checkVisibility(TaskRecord t, ActivityRecord r) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 443 | synchronized (mSupervisor.mService.mGlobalLock) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 444 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 445 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( |
| 446 | r.getWindowingMode()); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 447 | |
| 448 | // If we have an active transition that's waiting on a certain activity that will be |
| 449 | // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. |
| 450 | if (info != null && !t.isVisible()) { |
| 451 | if (DEBUG_METRICS) Slog.i(TAG, "notifyVisibilityChanged to invisible" |
| 452 | + " activity=" + r); |
| 453 | logAppTransitionCancel(info); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 454 | mWindowingModeTransitionInfo.remove(r.getWindowingMode()); |
| 455 | if (mWindowingModeTransitionInfo.size() == 0) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 456 | reset(true /* abort */); |
| 457 | } |
Jorim Jaggi | cdfc04e | 2017-04-28 19:06:24 +0200 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 462 | /** |
| 463 | * Notifies the tracker that we called immediately before we call bindApplication on the client. |
| 464 | * |
| 465 | * @param app The client into which we'll call bindApplication. |
| 466 | */ |
| 467 | void notifyBindApplication(ProcessRecord app) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 468 | for (int i = mWindowingModeTransitionInfo.size() - 1; i >= 0; i--) { |
| 469 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(i); |
Jorim Jaggi | 515dd68 | 2017-05-05 15:05:07 +0200 | [diff] [blame] | 470 | |
| 471 | // App isn't attached to record yet, so match with info. |
| 472 | if (info.launchedActivity.appInfo == app.info) { |
| 473 | info.bindApplicationDelayMs = calculateCurrentDelay(); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 478 | private boolean allWindowsDrawn() { |
| 479 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 480 | if (!mWindowingModeTransitionInfo.valueAt(index).loggedWindowsDrawn) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | } |
| 484 | return true; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 485 | } |
| 486 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 487 | private boolean isAnyTransitionActive() { |
| 488 | return mCurrentTransitionStartTime != INVALID_START_TIME |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 489 | && mWindowingModeTransitionInfo.size() > 0; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | private void reset(boolean abort) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 493 | if (DEBUG_METRICS) Slog.i(TAG, "reset abort=" + abort); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 494 | if (!abort && isAnyTransitionActive()) { |
| 495 | logAppTransitionMultiEvents(); |
| 496 | } |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 497 | mCurrentTransitionStartTime = INVALID_START_TIME; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 498 | mCurrentTransitionDelayMs = -1; |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 499 | mLoggedTransitionStarting = false; |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 500 | mWindowingModeTransitionInfo.clear(); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | private int calculateCurrentDelay() { |
| 504 | |
| 505 | // 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] | 506 | return (int) (SystemClock.uptimeMillis() - mCurrentTransitionStartTime); |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 507 | } |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 508 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 509 | private int calculateDelay(long timestamp) { |
| 510 | // Shouldn't take more than 25 days to launch an app, so int is fine here. |
| 511 | return (int) (timestamp - mCurrentTransitionStartTime); |
| 512 | } |
| 513 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 514 | private void logAppTransitionCancel(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 515 | final int type = getTransitionType(info); |
| 516 | if (type == -1) { |
| 517 | return; |
| 518 | } |
| 519 | final LogMaker builder = new LogMaker(APP_TRANSITION_CANCELLED); |
| 520 | builder.setPackageName(info.launchedActivity.packageName); |
| 521 | builder.setType(type); |
| 522 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name); |
| 523 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 524 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 525 | StatsLog.APP_START_CANCELED, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 526 | info.launchedActivity.appInfo.uid, |
| 527 | info.launchedActivity.packageName, |
| 528 | convertAppStartTransitionType(type), |
| 529 | info.launchedActivity.info.name); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 532 | private void logAppTransitionMultiEvents() { |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 533 | if (DEBUG_METRICS) Slog.i(TAG, "logging transition events"); |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 534 | for (int index = mWindowingModeTransitionInfo.size() - 1; index >= 0; index--) { |
| 535 | final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.valueAt(index); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 536 | final int type = getTransitionType(info); |
| 537 | if (type == -1) { |
| 538 | return; |
| 539 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 540 | |
| 541 | // Take a snapshot of the transition info before sending it to the handler for logging. |
| 542 | // This will avoid any races with other operations that modify the ActivityRecord. |
| 543 | final WindowingModeTransitionInfoSnapshot infoSnapshot = |
| 544 | new WindowingModeTransitionInfoSnapshot(info); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 545 | final int currentTransitionDeviceUptime = mCurrentTransitionDeviceUptime; |
| 546 | final int currentTransitionDelayMs = mCurrentTransitionDelayMs; |
| 547 | BackgroundThread.getHandler().post(() -> logAppTransition( |
| 548 | currentTransitionDeviceUptime, currentTransitionDelayMs, infoSnapshot)); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 549 | |
| 550 | info.launchedActivity.info.launchToken = null; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 554 | // 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] | 555 | private void logAppTransition(int currentTransitionDeviceUptime, int currentTransitionDelayMs, |
| 556 | WindowingModeTransitionInfoSnapshot info) { |
| 557 | final LogMaker builder = new LogMaker(APP_TRANSITION); |
| 558 | builder.setPackageName(info.packageName); |
| 559 | builder.setType(info.type); |
| 560 | builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivityName); |
| 561 | final boolean isInstantApp = info.applicationInfo.isInstantApp(); |
| 562 | if (info.launchedActivityLaunchedFromPackage != null) { |
| 563 | builder.addTaggedData(APP_TRANSITION_CALLING_PACKAGE_NAME, |
| 564 | info.launchedActivityLaunchedFromPackage); |
| 565 | } |
| 566 | String launchToken = info.launchedActivityLaunchToken; |
| 567 | if (launchToken != null) { |
| 568 | builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN, launchToken); |
| 569 | } |
| 570 | builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0); |
| 571 | builder.addTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS, |
| 572 | currentTransitionDeviceUptime); |
| 573 | builder.addTaggedData(APP_TRANSITION_DELAY_MS, currentTransitionDelayMs); |
| 574 | builder.setSubtype(info.reason); |
| 575 | if (info.startingWindowDelayMs != -1) { |
| 576 | builder.addTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS, |
| 577 | info.startingWindowDelayMs); |
| 578 | } |
| 579 | if (info.bindApplicationDelayMs != -1) { |
| 580 | builder.addTaggedData(APP_TRANSITION_BIND_APPLICATION_DELAY_MS, |
| 581 | info.bindApplicationDelayMs); |
| 582 | } |
| 583 | builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs); |
| 584 | final ArtManagerInternal artManagerInternal = getArtManagerInternal(); |
| 585 | final PackageOptimizationInfo packageOptimizationInfo = |
| 586 | (artManagerInternal == null) || (info.launchedActivityAppRecordRequiredAbi == null) |
| 587 | ? PackageOptimizationInfo.createWithNoInfo() |
| 588 | : artManagerInternal.getPackageOptimizationInfo( |
| 589 | info.applicationInfo, |
| 590 | info.launchedActivityAppRecordRequiredAbi); |
| 591 | builder.addTaggedData(PACKAGE_OPTIMIZATION_COMPILATION_REASON, |
| 592 | packageOptimizationInfo.getCompilationReason()); |
| 593 | builder.addTaggedData(PACKAGE_OPTIMIZATION_COMPILATION_FILTER, |
| 594 | packageOptimizationInfo.getCompilationFilter()); |
| 595 | mMetricsLogger.write(builder); |
| 596 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 597 | StatsLog.APP_START_OCCURRED, |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 598 | info.applicationInfo.uid, |
| 599 | info.packageName, |
| 600 | convertAppStartTransitionType(info.type), |
| 601 | info.launchedActivityName, |
| 602 | info.launchedActivityLaunchedFromPackage, |
| 603 | isInstantApp, |
| 604 | currentTransitionDeviceUptime * 1000, |
| 605 | info.reason, |
| 606 | currentTransitionDelayMs, |
| 607 | info.startingWindowDelayMs, |
| 608 | info.bindApplicationDelayMs, |
| 609 | info.windowsDrawnDelayMs, |
| 610 | launchToken, |
| 611 | packageOptimizationInfo.getCompilationReason(), |
| 612 | packageOptimizationInfo.getCompilationFilter()); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 613 | logAppStartMemoryStateCapture(info); |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 616 | private int convertAppStartTransitionType(int tronType) { |
| 617 | if (tronType == TYPE_TRANSITION_COLD_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 618 | return StatsLog.APP_START_OCCURRED__TYPE__COLD; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 619 | } |
| 620 | if (tronType == TYPE_TRANSITION_WARM_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 621 | return StatsLog.APP_START_OCCURRED__TYPE__WARM; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 622 | } |
| 623 | if (tronType == TYPE_TRANSITION_HOT_LAUNCH) { |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 624 | return StatsLog.APP_START_OCCURRED__TYPE__HOT; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 625 | } |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 626 | return StatsLog.APP_START_OCCURRED__TYPE__UNKNOWN; |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 629 | void logAppTransitionReportedDrawn(ActivityRecord r, boolean restoredFromBundle) { |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 630 | final WindowingModeTransitionInfo info = mLastWindowingModeTransitionInfo.get( |
| 631 | r.getWindowingMode()); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 632 | if (info == null) { |
| 633 | return; |
| 634 | } |
| 635 | final LogMaker builder = new LogMaker(APP_TRANSITION_REPORTED_DRAWN); |
| 636 | builder.setPackageName(r.packageName); |
| 637 | builder.addTaggedData(FIELD_CLASS_NAME, r.info.name); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 638 | long startupTimeMs = SystemClock.uptimeMillis() - mLastTransitionStartTime; |
| 639 | builder.addTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS, startupTimeMs); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 640 | builder.setType(restoredFromBundle |
| 641 | ? TYPE_TRANSITION_REPORTED_DRAWN_WITH_BUNDLE |
| 642 | : TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE); |
| 643 | builder.addTaggedData(APP_TRANSITION_PROCESS_RUNNING, |
| 644 | info.currentTransitionProcessRunning ? 1 : 0); |
| 645 | mMetricsLogger.write(builder); |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 646 | StatsLog.write( |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 647 | StatsLog.APP_START_FULLY_DRAWN, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 648 | info.launchedActivity.appInfo.uid, |
| 649 | info.launchedActivity.packageName, |
| 650 | restoredFromBundle |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 651 | ? StatsLog.APP_START_FULLY_DRAWN__TYPE__WITH_BUNDLE |
| 652 | : StatsLog.APP_START_FULLY_DRAWN__TYPE__WITHOUT_BUNDLE, |
Olivier Gaillard | aed7f12 | 2017-12-12 14:26:22 +0000 | [diff] [blame] | 653 | info.launchedActivity.info.name, |
| 654 | info.currentTransitionProcessRunning, |
| 655 | startupTimeMs); |
Jorim Jaggi | 4d27b84 | 2017-08-17 17:22:26 +0200 | [diff] [blame] | 656 | } |
| 657 | |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 658 | void logActivityStart(Intent intent, ProcessRecord callerApp, ActivityRecord r, |
| 659 | int callingUid, String callingPackage, int callingUidProcState, |
| 660 | boolean callingUidHasAnyVisibleWindow, |
| 661 | int realCallingUid, int realCallingUidProcState, |
| 662 | boolean realCallingUidHasAnyVisibleWindow, |
| 663 | int targetUid, String targetPackage, int targetUidProcState, |
| 664 | boolean targetUidHasAnyVisibleWindow, String targetWhitelistTag, |
| 665 | boolean comingFromPendingIntent) { |
| 666 | |
| 667 | final long nowElapsed = SystemClock.elapsedRealtime(); |
| 668 | final long nowUptime = SystemClock.uptimeMillis(); |
| 669 | final LogMaker builder = new LogMaker(ACTION_ACTIVITY_START); |
| 670 | builder.setTimestamp(System.currentTimeMillis()); |
| 671 | builder.addTaggedData(FIELD_CALLING_UID, callingUid); |
| 672 | builder.addTaggedData(FIELD_CALLING_PACKAGE_NAME, callingPackage); |
| 673 | builder.addTaggedData(FIELD_CALLING_UID_PROC_STATE, |
| 674 | processStateAmToProto(callingUidProcState)); |
| 675 | builder.addTaggedData(FIELD_CALLING_UID_HAS_ANY_VISIBLE_WINDOW, |
| 676 | callingUidHasAnyVisibleWindow ? 1 : 0); |
| 677 | builder.addTaggedData(FIELD_REAL_CALLING_UID, realCallingUid); |
| 678 | builder.addTaggedData(FIELD_REAL_CALLING_UID_PROC_STATE, |
| 679 | processStateAmToProto(realCallingUidProcState)); |
| 680 | builder.addTaggedData(FIELD_REAL_CALLING_UID_HAS_ANY_VISIBLE_WINDOW, |
| 681 | realCallingUidHasAnyVisibleWindow ? 1 : 0); |
| 682 | builder.addTaggedData(FIELD_TARGET_UID, targetUid); |
| 683 | builder.addTaggedData(FIELD_TARGET_PACKAGE_NAME, targetPackage); |
| 684 | builder.addTaggedData(FIELD_TARGET_UID_PROC_STATE, |
| 685 | processStateAmToProto(targetUidProcState)); |
| 686 | builder.addTaggedData(FIELD_TARGET_UID_HAS_ANY_VISIBLE_WINDOW, |
| 687 | targetUidHasAnyVisibleWindow ? 1 : 0); |
| 688 | builder.addTaggedData(FIELD_TARGET_WHITELIST_TAG, targetWhitelistTag); |
| 689 | builder.addTaggedData(FIELD_TARGET_SHORT_COMPONENT_NAME, r.shortComponentName); |
| 690 | builder.addTaggedData(FIELD_COMING_FROM_PENDING_INTENT, comingFromPendingIntent ? 1 : 0); |
| 691 | builder.addTaggedData(FIELD_INTENT_ACTION, intent.getAction()); |
| 692 | if (callerApp != null) { |
| 693 | builder.addTaggedData(FIELD_PROCESS_RECORD_PROCESS_NAME, callerApp.processName); |
| 694 | builder.addTaggedData(FIELD_PROCESS_RECORD_CUR_PROC_STATE, |
| 695 | processStateAmToProto(callerApp.curProcState)); |
| 696 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_CLIENT_ACTIVITIES, |
| 697 | callerApp.hasClientActivities ? 1 : 0); |
| 698 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_FOREGROUND_SERVICES, |
| 699 | callerApp.hasForegroundServices() ? 1 : 0); |
| 700 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_FOREGROUND_ACTIVITIES, |
| 701 | callerApp.foregroundActivities ? 1 : 0); |
| 702 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_TOP_UI, callerApp.hasTopUi ? 1 : 0); |
| 703 | builder.addTaggedData(FIELD_PROCESS_RECORD_HAS_OVERLAY_UI, |
| 704 | callerApp.hasOverlayUi ? 1 : 0); |
| 705 | builder.addTaggedData(FIELD_PROCESS_RECORD_PENDING_UI_CLEAN, |
| 706 | callerApp.pendingUiClean ? 1 : 0); |
| 707 | if (callerApp.interactionEventTime != 0) { |
| 708 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_LAST_INTERACTION_EVENT, |
| 709 | (nowElapsed - callerApp.interactionEventTime)); |
| 710 | } |
| 711 | if (callerApp.fgInteractionTime != 0) { |
| 712 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_FG_INTERACTION, |
| 713 | (nowElapsed - callerApp.fgInteractionTime)); |
| 714 | } |
| 715 | if (callerApp.whenUnimportant != 0) { |
| 716 | builder.addTaggedData(FIELD_PROCESS_RECORD_MILLIS_SINCE_UNIMPORTANT, |
| 717 | (nowUptime - callerApp.whenUnimportant)); |
| 718 | } |
| 719 | } |
| 720 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_LAUNCH_MODE, r.info.launchMode); |
| 721 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_TARGET_ACTIVITY, r.info.targetActivity); |
| 722 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_FLAGS, r.info.flags); |
| 723 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_REAL_ACTIVITY, r.realActivity.toShortString()); |
| 724 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_SHORT_COMPONENT_NAME, r.shortComponentName); |
| 725 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_PROCESS_NAME, r.processName); |
| 726 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_FULLSCREEN, r.fullscreen ? 1 : 0); |
| 727 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_NO_DISPLAY, r.noDisplay ? 1 : 0); |
| 728 | if (r.lastVisibleTime != 0) { |
| 729 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_VISIBLE, |
| 730 | (nowUptime - r.lastVisibleTime)); |
| 731 | } |
| 732 | if (r.resultTo != null) { |
| 733 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_RESULT_TO_PKG_NAME, r.resultTo.packageName); |
| 734 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_RESULT_TO_SHORT_COMPONENT_NAME, |
| 735 | r.resultTo.shortComponentName); |
| 736 | } |
| 737 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_VISIBLE, r.visible ? 1 : 0); |
| 738 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_IS_VISIBLE_IGNORING_KEYGUARD, |
| 739 | r.visibleIgnoringKeyguard ? 1 : 0); |
| 740 | if (r.lastLaunchTime != 0) { |
| 741 | builder.addTaggedData(FIELD_ACTIVITY_RECORD_MILLIS_SINCE_LAST_LAUNCH, |
| 742 | (nowUptime - r.lastLaunchTime)); |
| 743 | } |
| 744 | mMetricsLogger.write(builder); |
| 745 | } |
| 746 | |
Jorim Jaggi | 9b58f2d | 2018-02-19 17:48:44 +0100 | [diff] [blame] | 747 | private int getTransitionType(WindowingModeTransitionInfo info) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 748 | if (info.currentTransitionProcessRunning) { |
| 749 | if (info.startResult == START_SUCCESS) { |
| 750 | return TYPE_TRANSITION_WARM_LAUNCH; |
| 751 | } else if (info.startResult == START_TASK_TO_FRONT) { |
| 752 | return TYPE_TRANSITION_HOT_LAUNCH; |
| 753 | } |
| 754 | } else if (info.startResult == START_SUCCESS) { |
| 755 | return TYPE_TRANSITION_COLD_LAUNCH; |
| 756 | } |
| 757 | return -1; |
| 758 | } |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 759 | |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 760 | private void logAppStartMemoryStateCapture(WindowingModeTransitionInfoSnapshot info) { |
| 761 | if (info.processRecord == null) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 762 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture processRecord null"); |
| 763 | return; |
| 764 | } |
| 765 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 766 | final int pid = info.processRecord.getPid(); |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 767 | final int uid = info.applicationInfo.uid; |
Rajeev Kumar | bfcd920 | 2018-03-02 22:42:13 +0000 | [diff] [blame] | 768 | final MemoryStat memoryStat = readMemoryStatFromFilesystem(uid, pid); |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 769 | if (memoryStat == null) { |
| 770 | if (DEBUG_METRICS) Slog.i(TAG, "logAppStartMemoryStateCapture memoryStat null"); |
| 771 | return; |
| 772 | } |
| 773 | |
| 774 | StatsLog.write( |
| 775 | StatsLog.APP_START_MEMORY_STATE_CAPTURED, |
| 776 | uid, |
Ng Zhi An | 8347354 | 2018-02-20 09:02:14 -0800 | [diff] [blame] | 777 | info.processName, |
| 778 | info.launchedActivityName, |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 779 | memoryStat.pgfault, |
| 780 | memoryStat.pgmajfault, |
| 781 | memoryStat.rssInBytes, |
| 782 | memoryStat.cacheInBytes, |
| 783 | memoryStat.swapInBytes); |
| 784 | } |
| 785 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 786 | private WindowProcessController findProcessForActivity(ActivityRecord launchedActivity) { |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 787 | return launchedActivity != null |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 788 | ? mSupervisor.mService.mProcessNames.get( |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 789 | launchedActivity.processName, launchedActivity.appInfo.uid) |
Ng Zhi An | bbefdec | 2018-01-30 17:12:39 -0800 | [diff] [blame] | 790 | : null; |
| 791 | } |
Calin Juravle | 759fbda | 2018-02-20 19:52:30 +0000 | [diff] [blame] | 792 | |
| 793 | private ArtManagerInternal getArtManagerInternal() { |
| 794 | if (mArtManagerInternal == null) { |
| 795 | // Note that this may be null. |
| 796 | // ArtManagerInternal is registered during PackageManagerService |
| 797 | // initialization which happens after ActivityManagerService. |
| 798 | mArtManagerInternal = LocalServices.getService(ArtManagerInternal.class); |
| 799 | } |
| 800 | return mArtManagerInternal; |
| 801 | } |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 802 | } |