Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy |
| 6 | * of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations |
| 14 | * under the License. |
| 15 | */ |
| 16 | package android.app.usage; |
| 17 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 18 | import android.annotation.IntDef; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 22 | import android.content.res.Configuration; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 23 | import android.os.Build; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 24 | import android.os.Parcel; |
| 25 | import android.os.Parcelable; |
| 26 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 27 | import java.lang.annotation.Retention; |
| 28 | import java.lang.annotation.RetentionPolicy; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 29 | import java.util.Arrays; |
| 30 | import java.util.List; |
| 31 | |
| 32 | /** |
| 33 | * A result returned from {@link android.app.usage.UsageStatsManager#queryEvents(long, long)} |
| 34 | * from which to read {@link android.app.usage.UsageEvents.Event} objects. |
| 35 | */ |
| 36 | public final class UsageEvents implements Parcelable { |
| 37 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 38 | /** @hide */ |
| 39 | public static final String INSTANT_APP_PACKAGE_NAME = "android.instant_app"; |
| 40 | |
| 41 | /** @hide */ |
| 42 | public static final String INSTANT_APP_CLASS_NAME = "android.instant_class"; |
| 43 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 44 | /** |
| 45 | * An event representing a state change for a component. |
| 46 | */ |
| 47 | public static final class Event { |
| 48 | |
| 49 | /** |
| 50 | * No event type. |
| 51 | */ |
| 52 | public static final int NONE = 0; |
| 53 | |
| 54 | /** |
Hui Yu | e497ad2 | 2019-01-25 15:54:57 -0800 | [diff] [blame] | 55 | * A device level event like {@link #DEVICE_SHUTDOWN} does not have package name, but some |
| 56 | * user code always expect a non-null {@link #mPackage} for every event. Use |
| 57 | * {@link #DEVICE_EVENT_PACKAGE_NAME} as packageName for these device level events. |
| 58 | * @hide |
| 59 | */ |
| 60 | public static final String DEVICE_EVENT_PACKAGE_NAME = "android"; |
| 61 | |
| 62 | /** |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 63 | * @deprecated by {@link #ACTIVITY_RESUMED} |
| 64 | */ |
| 65 | @Deprecated |
| 66 | public static final int MOVE_TO_FOREGROUND = 1; |
| 67 | |
| 68 | /** |
Hui Yu | e361a23 | 2018-10-04 15:05:21 -0700 | [diff] [blame] | 69 | * An event type denoting that an {@link android.app.Activity} moved to the foreground. |
| 70 | * This event has a package name and class name associated with it and can be retrieved |
| 71 | * using {@link #getPackageName()} and {@link #getClassName()}. |
| 72 | * If a package has multiple activities, this event is reported for each activity that moves |
| 73 | * to foreground. |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 74 | * This event is corresponding to {@link android.app.Activity#onResume()} of the |
| 75 | * activity's lifecycle. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 76 | */ |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 77 | public static final int ACTIVITY_RESUMED = MOVE_TO_FOREGROUND; |
| 78 | |
| 79 | /** |
| 80 | * @deprecated by {@link #ACTIVITY_PAUSED} |
| 81 | */ |
| 82 | @Deprecated |
| 83 | public static final int MOVE_TO_BACKGROUND = 2; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Hui Yu | e361a23 | 2018-10-04 15:05:21 -0700 | [diff] [blame] | 86 | * An event type denoting that an {@link android.app.Activity} moved to the background. |
| 87 | * This event has a package name and class name associated with it and can be retrieved |
| 88 | * using {@link #getPackageName()} and {@link #getClassName()}. |
| 89 | * If a package has multiple activities, this event is reported for each activity that moves |
| 90 | * to background. |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 91 | * This event is corresponding to {@link android.app.Activity#onPause()} of the activity's |
| 92 | * lifecycle. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 93 | */ |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 94 | public static final int ACTIVITY_PAUSED = MOVE_TO_BACKGROUND; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * An event type denoting that a component was in the foreground when the stats |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 98 | * rolled-over. This is effectively treated as a {@link #ACTIVITY_PAUSED}. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 99 | * {@hide} |
| 100 | */ |
| 101 | public static final int END_OF_DAY = 3; |
| 102 | |
| 103 | /** |
| 104 | * An event type denoting that a component was in the foreground the previous day. |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 105 | * This is effectively treated as a {@link #ACTIVITY_RESUMED}. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 106 | * {@hide} |
| 107 | */ |
| 108 | public static final int CONTINUE_PREVIOUS_DAY = 4; |
| 109 | |
| 110 | /** |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 111 | * An event type denoting that the device configuration has changed. |
| 112 | */ |
| 113 | public static final int CONFIGURATION_CHANGE = 5; |
| 114 | |
| 115 | /** |
Adam Lesinski | c8e8729 | 2015-06-10 15:33:45 -0700 | [diff] [blame] | 116 | * An event type denoting that a package was interacted with in some way by the system. |
| 117 | * @hide |
Adam Lesinski | 978a1ed | 2015-03-02 11:37:24 -0800 | [diff] [blame] | 118 | */ |
Michael Wachenschwanz | f0acb02 | 2018-03-15 20:17:22 -0700 | [diff] [blame] | 119 | @SystemApi |
Adam Lesinski | c8e8729 | 2015-06-10 15:33:45 -0700 | [diff] [blame] | 120 | public static final int SYSTEM_INTERACTION = 6; |
| 121 | |
| 122 | /** |
| 123 | * An event type denoting that a package was interacted with in some way by the user. |
| 124 | */ |
| 125 | public static final int USER_INTERACTION = 7; |
Adam Lesinski | 978a1ed | 2015-03-02 11:37:24 -0800 | [diff] [blame] | 126 | |
| 127 | /** |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 128 | * An event type denoting that an action equivalent to a ShortcutInfo is taken by the user. |
| 129 | * |
| 130 | * @see android.content.pm.ShortcutManager#reportShortcutUsed(String) |
| 131 | */ |
| 132 | public static final int SHORTCUT_INVOCATION = 8; |
| 133 | |
| 134 | /** |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 135 | * An event type denoting that a package was selected by the user for ChooserActivity. |
| 136 | * @hide |
| 137 | */ |
| 138 | public static final int CHOOSER_ACTION = 9; |
| 139 | |
Amith Yamasani | 803eab69 | 2017-11-09 17:47:04 -0800 | [diff] [blame] | 140 | /** |
| 141 | * An event type denoting that a notification was viewed by the user. |
| 142 | * @hide |
| 143 | */ |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 144 | @SystemApi |
Amith Yamasani | 803eab69 | 2017-11-09 17:47:04 -0800 | [diff] [blame] | 145 | public static final int NOTIFICATION_SEEN = 10; |
| 146 | |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 147 | /** |
Suprabh Shukla | 4e12de8 | 2018-03-08 18:34:15 -0800 | [diff] [blame] | 148 | * An event type denoting a change in App Standby Bucket. The new bucket can be |
Amith Yamasani | ff1575f | 2018-04-08 22:41:38 -0700 | [diff] [blame] | 149 | * retrieved by calling {@link #getAppStandbyBucket()}. |
Suprabh Shukla | 4e12de8 | 2018-03-08 18:34:15 -0800 | [diff] [blame] | 150 | * |
| 151 | * @see UsageStatsManager#getAppStandbyBucket() |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 152 | */ |
| 153 | public static final int STANDBY_BUCKET_CHANGED = 11; |
| 154 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 155 | /** |
| 156 | * An event type denoting that an app posted an interruptive notification. Visual and |
| 157 | * audible interruptions are included. |
| 158 | * @hide |
| 159 | */ |
| 160 | @SystemApi |
| 161 | public static final int NOTIFICATION_INTERRUPTION = 12; |
| 162 | |
Jason Monk | 1918ef7 | 2018-03-14 09:20:39 -0400 | [diff] [blame] | 163 | /** |
| 164 | * A Slice was pinned by the default launcher or the default assistant. |
| 165 | * @hide |
| 166 | */ |
| 167 | @SystemApi |
| 168 | public static final int SLICE_PINNED_PRIV = 13; |
| 169 | |
| 170 | /** |
| 171 | * A Slice was pinned by an app. |
| 172 | * @hide |
| 173 | */ |
| 174 | @SystemApi |
| 175 | public static final int SLICE_PINNED = 14; |
| 176 | |
Dianne Hackborn | ced5439 | 2018-02-26 13:07:42 -0800 | [diff] [blame] | 177 | /** |
| 178 | * An event type denoting that the screen has gone in to an interactive state (turned |
| 179 | * on for full user interaction, not ambient display or other non-interactive state). |
| 180 | */ |
| 181 | public static final int SCREEN_INTERACTIVE = 15; |
| 182 | |
| 183 | /** |
| 184 | * An event type denoting that the screen has gone in to a non-interactive state |
| 185 | * (completely turned off or turned on only in a non-interactive state like ambient |
| 186 | * display). |
| 187 | */ |
| 188 | public static final int SCREEN_NON_INTERACTIVE = 16; |
| 189 | |
Dianne Hackborn | 3378aa9 | 2018-03-30 17:43:49 -0700 | [diff] [blame] | 190 | /** |
| 191 | * An event type denoting that the screen's keyguard has been shown, whether or not |
| 192 | * the screen is off. |
| 193 | */ |
| 194 | public static final int KEYGUARD_SHOWN = 17; |
| 195 | |
| 196 | /** |
| 197 | * An event type denoting that the screen's keyguard has been hidden. This typically |
| 198 | * happens when the user unlocks their phone after turning it on. |
| 199 | */ |
| 200 | public static final int KEYGUARD_HIDDEN = 18; |
| 201 | |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 202 | /** |
Hui Yu | e361a23 | 2018-10-04 15:05:21 -0700 | [diff] [blame] | 203 | * An event type denoting start of a foreground service. |
| 204 | * This event has a package name and class name associated with it and can be retrieved |
| 205 | * using {@link #getPackageName()} and {@link #getClassName()}. |
| 206 | * If a package has multiple foreground services, this event is reported for each service |
| 207 | * that is started. |
| 208 | */ |
| 209 | public static final int FOREGROUND_SERVICE_START = 19; |
| 210 | |
| 211 | /** |
| 212 | * An event type denoting stop of a foreground service. |
| 213 | * This event has a package name and class name associated with it and can be retrieved |
| 214 | * using {@link #getPackageName()} and {@link #getClassName()}. |
| 215 | * If a package has multiple foreground services, this event is reported for each service |
| 216 | * that is stopped. |
| 217 | */ |
| 218 | public static final int FOREGROUND_SERVICE_STOP = 20; |
| 219 | |
| 220 | /** |
| 221 | * An event type denoting that a foreground service is at started state at beginning of a |
| 222 | * time interval. |
| 223 | * This is effectively treated as a {@link #FOREGROUND_SERVICE_START}. |
| 224 | * {@hide} |
| 225 | */ |
| 226 | public static final int CONTINUING_FOREGROUND_SERVICE = 21; |
| 227 | |
| 228 | /** |
| 229 | * An event type denoting that a foreground service is at started state when the stats |
| 230 | * rolled-over at the end of a time interval. |
| 231 | * {@hide} |
| 232 | */ |
| 233 | public static final int ROLLOVER_FOREGROUND_SERVICE = 22; |
| 234 | |
| 235 | /** |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 236 | * An activity becomes invisible on the UI, corresponding to |
| 237 | * {@link android.app.Activity#onStop()} of the activity's lifecycle. |
| 238 | */ |
| 239 | public static final int ACTIVITY_STOPPED = 23; |
| 240 | |
| 241 | /** |
| 242 | * An activity object is destroyed, corresponding to |
| 243 | * {@link android.app.Activity#onDestroy()} of the activity's lifecycle. |
| 244 | * {@hide} |
| 245 | */ |
| 246 | public static final int ACTIVITY_DESTROYED = 24; |
| 247 | |
| 248 | /** |
| 249 | * The event type demoting that a flush of UsageStatsDatabase to file system. Before the |
| 250 | * flush all usage stats need to be updated to latest timestamp to make sure the most |
| 251 | * up to date stats are persisted. |
| 252 | * @hide |
| 253 | */ |
| 254 | public static final int FLUSH_TO_DISK = 25; |
| 255 | |
| 256 | /** |
Hui Yu | 80a8b46 | 2019-03-05 15:22:13 -0800 | [diff] [blame] | 257 | * An event type denoting that the Android runtime underwent a shutdown process. |
Hui Yu | b1d243a | 2018-12-13 12:02:00 -0800 | [diff] [blame] | 258 | * A DEVICE_SHUTDOWN event should be treated as if all started activities and foreground |
| 259 | * services are now stopped and no explicit {@link #ACTIVITY_STOPPED} and |
| 260 | * {@link #FOREGROUND_SERVICE_STOP} events will be generated for them. |
Hui Yu | 80a8b46 | 2019-03-05 15:22:13 -0800 | [diff] [blame] | 261 | * |
| 262 | * <p>The DEVICE_SHUTDOWN timestamp is actually the last time UsageStats database is |
| 263 | * persisted before the actual shutdown. Events (if there are any) between this timestamp |
| 264 | * and the actual shutdown is not persisted in the database. So any open events without |
| 265 | * matching close events between DEVICE_SHUTDOWN and {@link #DEVICE_STARTUP} should be |
| 266 | * ignored because the closing time is unknown.</p> |
Hui Yu | b1d243a | 2018-12-13 12:02:00 -0800 | [diff] [blame] | 267 | */ |
| 268 | public static final int DEVICE_SHUTDOWN = 26; |
| 269 | |
| 270 | /** |
Hui Yu | 80a8b46 | 2019-03-05 15:22:13 -0800 | [diff] [blame] | 271 | * An event type denoting that the Android runtime started up. This could be after a |
| 272 | * shutdown or a runtime restart. Any open events without matching close events between |
| 273 | * {@link #DEVICE_SHUTDOWN} and DEVICE_STARTUP should be ignored because the closing time is |
| 274 | * unknown. |
| 275 | */ |
| 276 | public static final int DEVICE_STARTUP = 27; |
| 277 | |
| 278 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 279 | * Keep in sync with the greatest event type value. |
| 280 | * @hide |
| 281 | */ |
Hui Yu | 80a8b46 | 2019-03-05 15:22:13 -0800 | [diff] [blame] | 282 | public static final int MAX_EVENT_TYPE = 27; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 283 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 284 | /** @hide */ |
| 285 | public static final int FLAG_IS_PACKAGE_INSTANT_APP = 1 << 0; |
| 286 | |
| 287 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 288 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 289 | FLAG_IS_PACKAGE_INSTANT_APP, |
| 290 | }) |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 291 | @Retention(RetentionPolicy.SOURCE) |
| 292 | public @interface EventFlags {} |
| 293 | |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 294 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 295 | * Bitwise OR all valid flag constants to create this constant. |
| 296 | * @hide |
| 297 | */ |
| 298 | public static final int VALID_FLAG_BITS = FLAG_IS_PACKAGE_INSTANT_APP; |
| 299 | |
| 300 | /** |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 301 | * {@hide} |
| 302 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 303 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 304 | public String mPackage; |
| 305 | |
| 306 | /** |
| 307 | * {@hide} |
| 308 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 309 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 310 | public String mClass; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 311 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 312 | /** |
| 313 | * {@hide} |
| 314 | */ |
| 315 | public int mInstanceId; |
| 316 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 317 | /** |
| 318 | * {@hide} |
| 319 | */ |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 320 | public String mTaskRootPackage; |
| 321 | |
| 322 | /** |
| 323 | * {@hide} |
| 324 | */ |
| 325 | public String mTaskRootClass; |
| 326 | |
| 327 | /** |
| 328 | * {@hide} |
| 329 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 330 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 331 | public long mTimeStamp; |
| 332 | |
| 333 | /** |
| 334 | * {@hide} |
| 335 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 336 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 337 | public int mEventType; |
| 338 | |
| 339 | /** |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 340 | * Only present for {@link #CONFIGURATION_CHANGE} event types. |
| 341 | * {@hide} |
| 342 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 343 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 344 | public Configuration mConfiguration; |
| 345 | |
| 346 | /** |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 347 | * ID of the shortcut. |
| 348 | * Only present for {@link #SHORTCUT_INVOCATION} event types. |
| 349 | * {@hide} |
| 350 | */ |
| 351 | public String mShortcutId; |
| 352 | |
| 353 | /** |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 354 | * Action type passed to ChooserActivity |
| 355 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 356 | * {@hide} |
| 357 | */ |
| 358 | public String mAction; |
| 359 | |
| 360 | /** |
| 361 | * Content type passed to ChooserActivity. |
| 362 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 363 | * {@hide} |
| 364 | */ |
| 365 | public String mContentType; |
| 366 | |
| 367 | /** |
| 368 | * Content annotations passed to ChooserActivity. |
| 369 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 370 | * {@hide} |
| 371 | */ |
| 372 | public String[] mContentAnnotations; |
| 373 | |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 374 | /** |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 375 | * The app standby bucket assigned and reason. Bucket is the high order 16 bits, reason |
| 376 | * is the low order 16 bits. |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 377 | * Only present for {@link #STANDBY_BUCKET_CHANGED} event types |
| 378 | * {@hide} |
| 379 | */ |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 380 | public int mBucketAndReason; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 381 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 382 | /** |
| 383 | * The id of the {@link android.app.NotificationChannel} to which an interruptive |
| 384 | * notification was posted. |
| 385 | * Only present for {@link #NOTIFICATION_INTERRUPTION} event types. |
| 386 | * {@hide} |
| 387 | */ |
| 388 | public String mNotificationChannelId; |
| 389 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 390 | /** @hide */ |
| 391 | @EventFlags |
| 392 | public int mFlags; |
| 393 | |
| 394 | public Event() { |
| 395 | } |
| 396 | |
| 397 | /** @hide */ |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 398 | public Event(int type, long timeStamp) { |
| 399 | mEventType = type; |
| 400 | mTimeStamp = timeStamp; |
| 401 | } |
| 402 | |
| 403 | /** @hide */ |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 404 | public Event(Event orig) { |
| 405 | mPackage = orig.mPackage; |
| 406 | mClass = orig.mClass; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 407 | mInstanceId = orig.mInstanceId; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 408 | mTaskRootPackage = orig.mTaskRootPackage; |
| 409 | mTaskRootClass = orig.mTaskRootClass; |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 410 | mTimeStamp = orig.mTimeStamp; |
| 411 | mEventType = orig.mEventType; |
| 412 | mConfiguration = orig.mConfiguration; |
| 413 | mShortcutId = orig.mShortcutId; |
| 414 | mAction = orig.mAction; |
| 415 | mContentType = orig.mContentType; |
| 416 | mContentAnnotations = orig.mContentAnnotations; |
| 417 | mFlags = orig.mFlags; |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 418 | mBucketAndReason = orig.mBucketAndReason; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 419 | mNotificationChannelId = orig.mNotificationChannelId; |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 422 | /** |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 423 | * The package name of the source of this event. |
| 424 | */ |
| 425 | public String getPackageName() { |
| 426 | return mPackage; |
| 427 | } |
| 428 | |
| 429 | /** |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 430 | * Indicates whether it is an instant app. |
| 431 | * STOPSHIP b/111407095: Add GTS tests for the newly added API method. |
| 432 | * @hide |
| 433 | */ |
| 434 | @SystemApi |
| 435 | public boolean isInstantApp() { |
| 436 | return (mFlags & FLAG_IS_PACKAGE_INSTANT_APP) == FLAG_IS_PACKAGE_INSTANT_APP; |
| 437 | } |
| 438 | |
| 439 | /** |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 440 | * The class name of the source of this event. This may be null for |
| 441 | * certain events. |
| 442 | */ |
| 443 | public String getClassName() { |
| 444 | return mClass; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 448 | * An activity can be instantiated multiple times, this is the unique activity instance ID. |
| 449 | * For non-activity class, instance ID is always zero. |
| 450 | * @hide |
| 451 | */ |
| 452 | @SystemApi |
| 453 | public int getInstanceId() { |
| 454 | return mInstanceId; |
| 455 | } |
| 456 | |
| 457 | /** |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 458 | * The package name of the task root when this event was reported. |
| 459 | * Or {@code null} for queries from apps without {@link |
| 460 | * android.Manifest.permission#PACKAGE_USAGE_STATS} |
| 461 | * @hide |
| 462 | */ |
| 463 | @SystemApi |
| 464 | public @Nullable String getTaskRootPackageName() { |
| 465 | return mTaskRootPackage; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * The class name of the task root when this event was reported. |
| 470 | * Or {@code null} for queries from apps without {@link |
| 471 | * android.Manifest.permission#PACKAGE_USAGE_STATS} |
| 472 | * @hide |
| 473 | */ |
| 474 | @SystemApi |
| 475 | public @Nullable String getTaskRootClassName() { |
| 476 | return mTaskRootClass; |
| 477 | } |
| 478 | |
| 479 | /** |
Adam Lesinski | cc562a8 | 2014-08-27 11:52:52 -0700 | [diff] [blame] | 480 | * The time at which this event occurred, measured in milliseconds since the epoch. |
| 481 | * <p/> |
| 482 | * See {@link System#currentTimeMillis()}. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 483 | */ |
| 484 | public long getTimeStamp() { |
| 485 | return mTimeStamp; |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * The event type. |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 490 | * @see #ACTIVITY_PAUSED |
| 491 | * @see #ACTIVITY_RESUMED |
Suprabh Shukla | 4e12de8 | 2018-03-08 18:34:15 -0800 | [diff] [blame] | 492 | * @see #CONFIGURATION_CHANGE |
| 493 | * @see #USER_INTERACTION |
| 494 | * @see #STANDBY_BUCKET_CHANGED |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 495 | * @see #FOREGROUND_SERVICE_START |
| 496 | * @see #FOREGROUND_SERVICE_STOP |
| 497 | * @see #ACTIVITY_STOPPED |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 498 | */ |
| 499 | public int getEventType() { |
| 500 | return mEventType; |
| 501 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * Returns a {@link Configuration} for this event if the event is of type |
| 505 | * {@link #CONFIGURATION_CHANGE}, otherwise it returns null. |
| 506 | */ |
| 507 | public Configuration getConfiguration() { |
| 508 | return mConfiguration; |
| 509 | } |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 510 | |
| 511 | /** |
| 512 | * Returns the ID of a {@link android.content.pm.ShortcutInfo} for this event |
| 513 | * if the event is of type {@link #SHORTCUT_INVOCATION}, otherwise it returns null. |
| 514 | * |
| 515 | * @see android.content.pm.ShortcutManager#reportShortcutUsed(String) |
| 516 | */ |
| 517 | public String getShortcutId() { |
| 518 | return mShortcutId; |
| 519 | } |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 520 | |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 521 | /** |
| 522 | * Returns the standby bucket of the app, if the event is of type |
| 523 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. |
| 524 | * @return the standby bucket associated with the event. |
Amith Yamasani | ff1575f | 2018-04-08 22:41:38 -0700 | [diff] [blame] | 525 | * @hide |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 526 | */ |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 527 | public int getStandbyBucket() { |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 528 | return (mBucketAndReason & 0xFFFF0000) >>> 16; |
| 529 | } |
| 530 | |
| 531 | /** |
Amith Yamasani | ff1575f | 2018-04-08 22:41:38 -0700 | [diff] [blame] | 532 | * Returns the standby bucket of the app, if the event is of type |
| 533 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. |
| 534 | * @return the standby bucket associated with the event. |
| 535 | * |
| 536 | */ |
| 537 | public int getAppStandbyBucket() { |
| 538 | return (mBucketAndReason & 0xFFFF0000) >>> 16; |
| 539 | } |
| 540 | |
| 541 | /** |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 542 | * Returns the reason for the bucketing, if the event is of type |
| 543 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. Reason values include |
| 544 | * the main reason which is one of REASON_MAIN_*, OR'ed with REASON_SUB_*, if there |
| 545 | * are sub-reasons for the main reason, such as REASON_SUB_USAGE_* when the main reason |
| 546 | * is REASON_MAIN_USAGE. |
| 547 | * @hide |
| 548 | */ |
| 549 | public int getStandbyReason() { |
| 550 | return mBucketAndReason & 0x0000FFFF; |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 553 | /** |
| 554 | * Returns the ID of the {@link android.app.NotificationChannel} for this event if the |
| 555 | * event is of type {@link #NOTIFICATION_INTERRUPTION}, otherwise it returns null; |
| 556 | * @hide |
| 557 | */ |
| 558 | @SystemApi |
| 559 | public String getNotificationChannelId() { |
| 560 | return mNotificationChannelId; |
| 561 | } |
| 562 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 563 | /** @hide */ |
| 564 | public Event getObfuscatedIfInstantApp() { |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 565 | if (!isInstantApp()) { |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 566 | return this; |
| 567 | } |
| 568 | final Event ret = new Event(this); |
| 569 | ret.mPackage = INSTANT_APP_PACKAGE_NAME; |
| 570 | ret.mClass = INSTANT_APP_CLASS_NAME; |
| 571 | |
| 572 | // Note there are other string fields too, but they're for app shortcuts and choosers, |
| 573 | // which instant apps can't use anyway, so there's no need to hide them. |
| 574 | return ret; |
| 575 | } |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | // Only used when creating the resulting events. Not used for reading/unparceling. |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 579 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 580 | private List<Event> mEventsToWrite = null; |
| 581 | |
| 582 | // Only used for reading/unparceling events. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 583 | @UnsupportedAppUsage |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 584 | private Parcel mParcel = null; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 585 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 586 | private final int mEventCount; |
| 587 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 588 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 589 | private int mIndex = 0; |
| 590 | |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 591 | // Only used when parceling events. If false, task roots will be omitted from the parcel |
| 592 | private final boolean mIncludeTaskRoots; |
| 593 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 594 | /* |
| 595 | * In order to save space, since ComponentNames will be duplicated everywhere, |
| 596 | * we use a map and index into it. |
| 597 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 598 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 599 | private String[] mStringPool; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * Construct the iterator from a parcel. |
| 603 | * {@hide} |
| 604 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 605 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 606 | public UsageEvents(Parcel in) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 607 | byte[] bytes = in.readBlob(); |
| 608 | Parcel data = Parcel.obtain(); |
| 609 | data.unmarshall(bytes, 0, bytes.length); |
| 610 | data.setDataPosition(0); |
| 611 | mEventCount = data.readInt(); |
| 612 | mIndex = data.readInt(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 613 | if (mEventCount > 0) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 614 | mStringPool = data.createStringArray(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 615 | |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 616 | final int listByteLength = data.readInt(); |
| 617 | final int positionInParcel = data.readInt(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 618 | mParcel = Parcel.obtain(); |
| 619 | mParcel.setDataPosition(0); |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 620 | mParcel.appendFrom(data, data.dataPosition(), listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 621 | mParcel.setDataSize(mParcel.dataPosition()); |
| 622 | mParcel.setDataPosition(positionInParcel); |
| 623 | } |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 624 | mIncludeTaskRoots = true; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /** |
| 628 | * Create an empty iterator. |
| 629 | * {@hide} |
| 630 | */ |
| 631 | UsageEvents() { |
| 632 | mEventCount = 0; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 633 | mIncludeTaskRoots = true; |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Construct the iterator in preparation for writing it to a parcel. |
| 638 | * Defaults to excluding task roots from the parcel. |
| 639 | * {@hide} |
| 640 | */ |
| 641 | public UsageEvents(List<Event> events, String[] stringPool) { |
| 642 | this(events, stringPool, false); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Construct the iterator in preparation for writing it to a parcel. |
| 647 | * {@hide} |
| 648 | */ |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 649 | public UsageEvents(List<Event> events, String[] stringPool, boolean includeTaskRoots) { |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 650 | mStringPool = stringPool; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 651 | mEventCount = events.size(); |
| 652 | mEventsToWrite = events; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 653 | mIncludeTaskRoots = includeTaskRoots; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Returns whether or not there are more events to read using |
| 658 | * {@link #getNextEvent(android.app.usage.UsageEvents.Event)}. |
| 659 | * |
| 660 | * @return true if there are more events, false otherwise. |
| 661 | */ |
| 662 | public boolean hasNextEvent() { |
| 663 | return mIndex < mEventCount; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Retrieve the next {@link android.app.usage.UsageEvents.Event} from the collection and put the |
| 668 | * resulting data into {@code eventOut}. |
| 669 | * |
| 670 | * @param eventOut The {@link android.app.usage.UsageEvents.Event} object that will receive the |
| 671 | * next event data. |
| 672 | * @return true if an event was available, false if there are no more events. |
| 673 | */ |
| 674 | public boolean getNextEvent(Event eventOut) { |
| 675 | if (mIndex >= mEventCount) { |
| 676 | return false; |
| 677 | } |
| 678 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 679 | readEventFromParcel(mParcel, eventOut); |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 680 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 681 | mIndex++; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 682 | if (mIndex >= mEventCount) { |
| 683 | mParcel.recycle(); |
| 684 | mParcel = null; |
| 685 | } |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Resets the collection so that it can be iterated over from the beginning. |
Adam Lesinski | 54e064b | 2014-10-08 12:33:16 -0700 | [diff] [blame] | 691 | * |
| 692 | * @hide When this object is iterated to completion, the parcel is destroyed and |
| 693 | * so resetToStart doesn't work. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 694 | */ |
| 695 | public void resetToStart() { |
| 696 | mIndex = 0; |
| 697 | if (mParcel != null) { |
| 698 | mParcel.setDataPosition(0); |
| 699 | } |
| 700 | } |
| 701 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 702 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 703 | private int findStringIndex(String str) { |
| 704 | final int index = Arrays.binarySearch(mStringPool, str); |
| 705 | if (index < 0) { |
| 706 | throw new IllegalStateException("String '" + str + "' is not in the string pool"); |
| 707 | } |
| 708 | return index; |
| 709 | } |
| 710 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 711 | /** |
| 712 | * Writes a single event to the parcel. Modify this when updating {@link Event}. |
| 713 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 714 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 715 | private void writeEventToParcel(Event event, Parcel p, int flags) { |
| 716 | final int packageIndex; |
| 717 | if (event.mPackage != null) { |
| 718 | packageIndex = findStringIndex(event.mPackage); |
| 719 | } else { |
| 720 | packageIndex = -1; |
| 721 | } |
| 722 | |
| 723 | final int classIndex; |
| 724 | if (event.mClass != null) { |
| 725 | classIndex = findStringIndex(event.mClass); |
| 726 | } else { |
| 727 | classIndex = -1; |
| 728 | } |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 729 | |
| 730 | final int taskRootPackageIndex; |
| 731 | if (mIncludeTaskRoots && event.mTaskRootPackage != null) { |
| 732 | taskRootPackageIndex = findStringIndex(event.mTaskRootPackage); |
| 733 | } else { |
| 734 | taskRootPackageIndex = -1; |
| 735 | } |
| 736 | |
| 737 | final int taskRootClassIndex; |
| 738 | if (mIncludeTaskRoots && event.mTaskRootClass != null) { |
| 739 | taskRootClassIndex = findStringIndex(event.mTaskRootClass); |
| 740 | } else { |
| 741 | taskRootClassIndex = -1; |
| 742 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 743 | p.writeInt(packageIndex); |
| 744 | p.writeInt(classIndex); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 745 | p.writeInt(event.mInstanceId); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 746 | p.writeInt(taskRootPackageIndex); |
| 747 | p.writeInt(taskRootClassIndex); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 748 | p.writeInt(event.mEventType); |
| 749 | p.writeLong(event.mTimeStamp); |
| 750 | |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 751 | switch (event.mEventType) { |
| 752 | case Event.CONFIGURATION_CHANGE: |
| 753 | event.mConfiguration.writeToParcel(p, flags); |
| 754 | break; |
| 755 | case Event.SHORTCUT_INVOCATION: |
| 756 | p.writeString(event.mShortcutId); |
| 757 | break; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 758 | case Event.CHOOSER_ACTION: |
| 759 | p.writeString(event.mAction); |
| 760 | p.writeString(event.mContentType); |
| 761 | p.writeStringArray(event.mContentAnnotations); |
| 762 | break; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 763 | case Event.STANDBY_BUCKET_CHANGED: |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 764 | p.writeInt(event.mBucketAndReason); |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 765 | break; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 766 | case Event.NOTIFICATION_INTERRUPTION: |
| 767 | p.writeString(event.mNotificationChannelId); |
| 768 | break; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 769 | } |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 770 | p.writeInt(event.mFlags); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /** |
| 774 | * Reads a single event from the parcel. Modify this when updating {@link Event}. |
| 775 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 776 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 777 | private void readEventFromParcel(Parcel p, Event eventOut) { |
| 778 | final int packageIndex = p.readInt(); |
| 779 | if (packageIndex >= 0) { |
| 780 | eventOut.mPackage = mStringPool[packageIndex]; |
| 781 | } else { |
| 782 | eventOut.mPackage = null; |
| 783 | } |
| 784 | |
| 785 | final int classIndex = p.readInt(); |
| 786 | if (classIndex >= 0) { |
| 787 | eventOut.mClass = mStringPool[classIndex]; |
| 788 | } else { |
| 789 | eventOut.mClass = null; |
| 790 | } |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 791 | eventOut.mInstanceId = p.readInt(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 792 | |
| 793 | final int taskRootPackageIndex = p.readInt(); |
| 794 | if (taskRootPackageIndex >= 0) { |
| 795 | eventOut.mTaskRootPackage = mStringPool[taskRootPackageIndex]; |
| 796 | } else { |
| 797 | eventOut.mTaskRootPackage = null; |
| 798 | } |
| 799 | |
| 800 | final int taskRootClassIndex = p.readInt(); |
| 801 | if (taskRootClassIndex >= 0) { |
| 802 | eventOut.mTaskRootClass = mStringPool[taskRootClassIndex]; |
| 803 | } else { |
| 804 | eventOut.mTaskRootClass = null; |
| 805 | } |
| 806 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 807 | eventOut.mEventType = p.readInt(); |
| 808 | eventOut.mTimeStamp = p.readLong(); |
| 809 | |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 810 | // Fill out the event-dependant fields. |
| 811 | eventOut.mConfiguration = null; |
| 812 | eventOut.mShortcutId = null; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 813 | eventOut.mAction = null; |
| 814 | eventOut.mContentType = null; |
| 815 | eventOut.mContentAnnotations = null; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 816 | eventOut.mNotificationChannelId = null; |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 817 | |
| 818 | switch (eventOut.mEventType) { |
| 819 | case Event.CONFIGURATION_CHANGE: |
| 820 | // Extract the configuration for configuration change events. |
| 821 | eventOut.mConfiguration = Configuration.CREATOR.createFromParcel(p); |
| 822 | break; |
| 823 | case Event.SHORTCUT_INVOCATION: |
| 824 | eventOut.mShortcutId = p.readString(); |
| 825 | break; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 826 | case Event.CHOOSER_ACTION: |
| 827 | eventOut.mAction = p.readString(); |
| 828 | eventOut.mContentType = p.readString(); |
| 829 | eventOut.mContentAnnotations = p.createStringArray(); |
| 830 | break; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 831 | case Event.STANDBY_BUCKET_CHANGED: |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 832 | eventOut.mBucketAndReason = p.readInt(); |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 833 | break; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 834 | case Event.NOTIFICATION_INTERRUPTION: |
| 835 | eventOut.mNotificationChannelId = p.readString(); |
| 836 | break; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 837 | } |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 838 | eventOut.mFlags = p.readInt(); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | @Override |
| 842 | public int describeContents() { |
| 843 | return 0; |
| 844 | } |
| 845 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 846 | @Override |
| 847 | public void writeToParcel(Parcel dest, int flags) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 848 | Parcel data = Parcel.obtain(); |
| 849 | data.writeInt(mEventCount); |
| 850 | data.writeInt(mIndex); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 851 | if (mEventCount > 0) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 852 | data.writeStringArray(mStringPool); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 853 | |
| 854 | if (mEventsToWrite != null) { |
| 855 | // Write out the events |
| 856 | Parcel p = Parcel.obtain(); |
| 857 | try { |
| 858 | p.setDataPosition(0); |
| 859 | for (int i = 0; i < mEventCount; i++) { |
| 860 | final Event event = mEventsToWrite.get(i); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 861 | writeEventToParcel(event, p, flags); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 862 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 863 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 864 | final int listByteLength = p.dataPosition(); |
| 865 | |
| 866 | // Write the total length of the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 867 | data.writeInt(listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 868 | |
| 869 | // Write our current position into the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 870 | data.writeInt(0); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 871 | |
| 872 | // Write the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 873 | data.appendFrom(p, 0, listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 874 | } finally { |
| 875 | p.recycle(); |
| 876 | } |
| 877 | |
| 878 | } else if (mParcel != null) { |
| 879 | // Write the total length of the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 880 | data.writeInt(mParcel.dataSize()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 881 | |
| 882 | // Write out current position into the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 883 | data.writeInt(mParcel.dataPosition()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 884 | |
| 885 | // Write the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 886 | data.appendFrom(mParcel, 0, mParcel.dataSize()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 887 | } else { |
| 888 | throw new IllegalStateException( |
| 889 | "Either mParcel or mEventsToWrite must not be null"); |
| 890 | } |
| 891 | } |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 892 | // Data can be too large for a transact. Write the data as a Blob, which will be written to |
| 893 | // ashmem if too large. |
| 894 | dest.writeBlob(data.marshall()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 897 | public static final @android.annotation.NonNull Creator<UsageEvents> CREATOR = new Creator<UsageEvents>() { |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 898 | @Override |
| 899 | public UsageEvents createFromParcel(Parcel source) { |
| 900 | return new UsageEvents(source); |
| 901 | } |
| 902 | |
| 903 | @Override |
| 904 | public UsageEvents[] newArray(int size) { |
| 905 | return new UsageEvents[size]; |
| 906 | } |
| 907 | }; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 908 | } |