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