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 | b1d243a | 2018-12-13 12:02:00 -0800 | [diff] [blame] | 257 | * An event type denoting that the device underwent a shutdown process. |
| 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. |
| 261 | */ |
| 262 | public static final int DEVICE_SHUTDOWN = 26; |
| 263 | |
| 264 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 265 | * Keep in sync with the greatest event type value. |
| 266 | * @hide |
| 267 | */ |
Hui Yu | b1d243a | 2018-12-13 12:02:00 -0800 | [diff] [blame] | 268 | public static final int MAX_EVENT_TYPE = 26; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 269 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 270 | /** @hide */ |
| 271 | public static final int FLAG_IS_PACKAGE_INSTANT_APP = 1 << 0; |
| 272 | |
| 273 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 274 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 275 | FLAG_IS_PACKAGE_INSTANT_APP, |
| 276 | }) |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 277 | @Retention(RetentionPolicy.SOURCE) |
| 278 | public @interface EventFlags {} |
| 279 | |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 280 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 281 | * Bitwise OR all valid flag constants to create this constant. |
| 282 | * @hide |
| 283 | */ |
| 284 | public static final int VALID_FLAG_BITS = FLAG_IS_PACKAGE_INSTANT_APP; |
| 285 | |
| 286 | /** |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 287 | * {@hide} |
| 288 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 289 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 290 | public String mPackage; |
| 291 | |
| 292 | /** |
| 293 | * {@hide} |
| 294 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 295 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 296 | public String mClass; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 297 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 298 | /** |
| 299 | * {@hide} |
| 300 | */ |
| 301 | public int mInstanceId; |
| 302 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 303 | /** |
| 304 | * {@hide} |
| 305 | */ |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 306 | public String mTaskRootPackage; |
| 307 | |
| 308 | /** |
| 309 | * {@hide} |
| 310 | */ |
| 311 | public String mTaskRootClass; |
| 312 | |
| 313 | /** |
| 314 | * {@hide} |
| 315 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 316 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 317 | public long mTimeStamp; |
| 318 | |
| 319 | /** |
| 320 | * {@hide} |
| 321 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 322 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 323 | public int mEventType; |
| 324 | |
| 325 | /** |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 326 | * Only present for {@link #CONFIGURATION_CHANGE} event types. |
| 327 | * {@hide} |
| 328 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 329 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 330 | public Configuration mConfiguration; |
| 331 | |
| 332 | /** |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 333 | * ID of the shortcut. |
| 334 | * Only present for {@link #SHORTCUT_INVOCATION} event types. |
| 335 | * {@hide} |
| 336 | */ |
| 337 | public String mShortcutId; |
| 338 | |
| 339 | /** |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 340 | * Action type passed to ChooserActivity |
| 341 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 342 | * {@hide} |
| 343 | */ |
| 344 | public String mAction; |
| 345 | |
| 346 | /** |
| 347 | * Content type passed to ChooserActivity. |
| 348 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 349 | * {@hide} |
| 350 | */ |
| 351 | public String mContentType; |
| 352 | |
| 353 | /** |
| 354 | * Content annotations passed to ChooserActivity. |
| 355 | * Only present for {@link #CHOOSER_ACTION} event types. |
| 356 | * {@hide} |
| 357 | */ |
| 358 | public String[] mContentAnnotations; |
| 359 | |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 360 | /** |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 361 | * The app standby bucket assigned and reason. Bucket is the high order 16 bits, reason |
| 362 | * is the low order 16 bits. |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 363 | * Only present for {@link #STANDBY_BUCKET_CHANGED} event types |
| 364 | * {@hide} |
| 365 | */ |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 366 | public int mBucketAndReason; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 367 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 368 | /** |
| 369 | * The id of the {@link android.app.NotificationChannel} to which an interruptive |
| 370 | * notification was posted. |
| 371 | * Only present for {@link #NOTIFICATION_INTERRUPTION} event types. |
| 372 | * {@hide} |
| 373 | */ |
| 374 | public String mNotificationChannelId; |
| 375 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 376 | /** @hide */ |
| 377 | @EventFlags |
| 378 | public int mFlags; |
| 379 | |
| 380 | public Event() { |
| 381 | } |
| 382 | |
| 383 | /** @hide */ |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 384 | public Event(int type, long timeStamp) { |
| 385 | mEventType = type; |
| 386 | mTimeStamp = timeStamp; |
| 387 | } |
| 388 | |
| 389 | /** @hide */ |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 390 | public Event(Event orig) { |
| 391 | mPackage = orig.mPackage; |
| 392 | mClass = orig.mClass; |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 393 | mInstanceId = orig.mInstanceId; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 394 | mTaskRootPackage = orig.mTaskRootPackage; |
| 395 | mTaskRootClass = orig.mTaskRootClass; |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 396 | mTimeStamp = orig.mTimeStamp; |
| 397 | mEventType = orig.mEventType; |
| 398 | mConfiguration = orig.mConfiguration; |
| 399 | mShortcutId = orig.mShortcutId; |
| 400 | mAction = orig.mAction; |
| 401 | mContentType = orig.mContentType; |
| 402 | mContentAnnotations = orig.mContentAnnotations; |
| 403 | mFlags = orig.mFlags; |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 404 | mBucketAndReason = orig.mBucketAndReason; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 405 | mNotificationChannelId = orig.mNotificationChannelId; |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 408 | /** |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 409 | * The package name of the source of this event. |
| 410 | */ |
| 411 | public String getPackageName() { |
| 412 | return mPackage; |
| 413 | } |
| 414 | |
| 415 | /** |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 416 | * Indicates whether it is an instant app. |
| 417 | * STOPSHIP b/111407095: Add GTS tests for the newly added API method. |
| 418 | * @hide |
| 419 | */ |
| 420 | @SystemApi |
| 421 | public boolean isInstantApp() { |
| 422 | return (mFlags & FLAG_IS_PACKAGE_INSTANT_APP) == FLAG_IS_PACKAGE_INSTANT_APP; |
| 423 | } |
| 424 | |
| 425 | /** |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 426 | * The class name of the source of this event. This may be null for |
| 427 | * certain events. |
| 428 | */ |
| 429 | public String getClassName() { |
| 430 | return mClass; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /** |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 434 | * An activity can be instantiated multiple times, this is the unique activity instance ID. |
| 435 | * For non-activity class, instance ID is always zero. |
| 436 | * @hide |
| 437 | */ |
| 438 | @SystemApi |
| 439 | public int getInstanceId() { |
| 440 | return mInstanceId; |
| 441 | } |
| 442 | |
| 443 | /** |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 444 | * The package name of the task root when this event was reported. |
| 445 | * Or {@code null} for queries from apps without {@link |
| 446 | * android.Manifest.permission#PACKAGE_USAGE_STATS} |
| 447 | * @hide |
| 448 | */ |
| 449 | @SystemApi |
| 450 | public @Nullable String getTaskRootPackageName() { |
| 451 | return mTaskRootPackage; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * The class name of the task root when this event was reported. |
| 456 | * Or {@code null} for queries from apps without {@link |
| 457 | * android.Manifest.permission#PACKAGE_USAGE_STATS} |
| 458 | * @hide |
| 459 | */ |
| 460 | @SystemApi |
| 461 | public @Nullable String getTaskRootClassName() { |
| 462 | return mTaskRootClass; |
| 463 | } |
| 464 | |
| 465 | /** |
Adam Lesinski | cc562a8 | 2014-08-27 11:52:52 -0700 | [diff] [blame] | 466 | * The time at which this event occurred, measured in milliseconds since the epoch. |
| 467 | * <p/> |
| 468 | * See {@link System#currentTimeMillis()}. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 469 | */ |
| 470 | public long getTimeStamp() { |
| 471 | return mTimeStamp; |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * The event type. |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 476 | * @see #ACTIVITY_PAUSED |
| 477 | * @see #ACTIVITY_RESUMED |
Suprabh Shukla | 4e12de8 | 2018-03-08 18:34:15 -0800 | [diff] [blame] | 478 | * @see #CONFIGURATION_CHANGE |
| 479 | * @see #USER_INTERACTION |
| 480 | * @see #STANDBY_BUCKET_CHANGED |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 481 | * @see #FOREGROUND_SERVICE_START |
| 482 | * @see #FOREGROUND_SERVICE_STOP |
| 483 | * @see #ACTIVITY_STOPPED |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 484 | */ |
| 485 | public int getEventType() { |
| 486 | return mEventType; |
| 487 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * Returns a {@link Configuration} for this event if the event is of type |
| 491 | * {@link #CONFIGURATION_CHANGE}, otherwise it returns null. |
| 492 | */ |
| 493 | public Configuration getConfiguration() { |
| 494 | return mConfiguration; |
| 495 | } |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * Returns the ID of a {@link android.content.pm.ShortcutInfo} for this event |
| 499 | * if the event is of type {@link #SHORTCUT_INVOCATION}, otherwise it returns null. |
| 500 | * |
| 501 | * @see android.content.pm.ShortcutManager#reportShortcutUsed(String) |
| 502 | */ |
| 503 | public String getShortcutId() { |
| 504 | return mShortcutId; |
| 505 | } |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 506 | |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 507 | /** |
| 508 | * Returns the standby bucket of the app, if the event is of type |
| 509 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. |
| 510 | * @return the standby bucket associated with the event. |
Amith Yamasani | ff1575f | 2018-04-08 22:41:38 -0700 | [diff] [blame] | 511 | * @hide |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 512 | */ |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 513 | public int getStandbyBucket() { |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 514 | return (mBucketAndReason & 0xFFFF0000) >>> 16; |
| 515 | } |
| 516 | |
| 517 | /** |
Amith Yamasani | ff1575f | 2018-04-08 22:41:38 -0700 | [diff] [blame] | 518 | * Returns the standby bucket of the app, if the event is of type |
| 519 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. |
| 520 | * @return the standby bucket associated with the event. |
| 521 | * |
| 522 | */ |
| 523 | public int getAppStandbyBucket() { |
| 524 | return (mBucketAndReason & 0xFFFF0000) >>> 16; |
| 525 | } |
| 526 | |
| 527 | /** |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 528 | * Returns the reason for the bucketing, if the event is of type |
| 529 | * {@link #STANDBY_BUCKET_CHANGED}, otherwise returns 0. Reason values include |
| 530 | * the main reason which is one of REASON_MAIN_*, OR'ed with REASON_SUB_*, if there |
| 531 | * are sub-reasons for the main reason, such as REASON_SUB_USAGE_* when the main reason |
| 532 | * is REASON_MAIN_USAGE. |
| 533 | * @hide |
| 534 | */ |
| 535 | public int getStandbyReason() { |
| 536 | return mBucketAndReason & 0x0000FFFF; |
Amith Yamasani | 7ec8941 | 2018-02-07 08:48:49 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 539 | /** |
| 540 | * Returns the ID of the {@link android.app.NotificationChannel} for this event if the |
| 541 | * event is of type {@link #NOTIFICATION_INTERRUPTION}, otherwise it returns null; |
| 542 | * @hide |
| 543 | */ |
| 544 | @SystemApi |
| 545 | public String getNotificationChannelId() { |
| 546 | return mNotificationChannelId; |
| 547 | } |
| 548 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 549 | /** @hide */ |
| 550 | public Event getObfuscatedIfInstantApp() { |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 551 | if (!isInstantApp()) { |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 552 | return this; |
| 553 | } |
| 554 | final Event ret = new Event(this); |
| 555 | ret.mPackage = INSTANT_APP_PACKAGE_NAME; |
| 556 | ret.mClass = INSTANT_APP_CLASS_NAME; |
| 557 | |
| 558 | // Note there are other string fields too, but they're for app shortcuts and choosers, |
| 559 | // which instant apps can't use anyway, so there's no need to hide them. |
| 560 | return ret; |
| 561 | } |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // Only used when creating the resulting events. Not used for reading/unparceling. |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 565 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 566 | private List<Event> mEventsToWrite = null; |
| 567 | |
| 568 | // Only used for reading/unparceling events. |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 569 | @UnsupportedAppUsage |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 570 | private Parcel mParcel = null; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 571 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 572 | private final int mEventCount; |
| 573 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 574 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 575 | private int mIndex = 0; |
| 576 | |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 577 | // Only used when parceling events. If false, task roots will be omitted from the parcel |
| 578 | private final boolean mIncludeTaskRoots; |
| 579 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 580 | /* |
| 581 | * In order to save space, since ComponentNames will be duplicated everywhere, |
| 582 | * we use a map and index into it. |
| 583 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 584 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 585 | private String[] mStringPool; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 586 | |
| 587 | /** |
| 588 | * Construct the iterator from a parcel. |
| 589 | * {@hide} |
| 590 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 591 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 592 | public UsageEvents(Parcel in) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 593 | byte[] bytes = in.readBlob(); |
| 594 | Parcel data = Parcel.obtain(); |
| 595 | data.unmarshall(bytes, 0, bytes.length); |
| 596 | data.setDataPosition(0); |
| 597 | mEventCount = data.readInt(); |
| 598 | mIndex = data.readInt(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 599 | if (mEventCount > 0) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 600 | mStringPool = data.createStringArray(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 601 | |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 602 | final int listByteLength = data.readInt(); |
| 603 | final int positionInParcel = data.readInt(); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 604 | mParcel = Parcel.obtain(); |
| 605 | mParcel.setDataPosition(0); |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 606 | mParcel.appendFrom(data, data.dataPosition(), listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 607 | mParcel.setDataSize(mParcel.dataPosition()); |
| 608 | mParcel.setDataPosition(positionInParcel); |
| 609 | } |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 610 | mIncludeTaskRoots = true; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Create an empty iterator. |
| 615 | * {@hide} |
| 616 | */ |
| 617 | UsageEvents() { |
| 618 | mEventCount = 0; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 619 | mIncludeTaskRoots = true; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * Construct the iterator in preparation for writing it to a parcel. |
| 624 | * Defaults to excluding task roots from the parcel. |
| 625 | * {@hide} |
| 626 | */ |
| 627 | public UsageEvents(List<Event> events, String[] stringPool) { |
| 628 | this(events, stringPool, false); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Construct the iterator in preparation for writing it to a parcel. |
| 633 | * {@hide} |
| 634 | */ |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 635 | public UsageEvents(List<Event> events, String[] stringPool, boolean includeTaskRoots) { |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 636 | mStringPool = stringPool; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 637 | mEventCount = events.size(); |
| 638 | mEventsToWrite = events; |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 639 | mIncludeTaskRoots = includeTaskRoots; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Returns whether or not there are more events to read using |
| 644 | * {@link #getNextEvent(android.app.usage.UsageEvents.Event)}. |
| 645 | * |
| 646 | * @return true if there are more events, false otherwise. |
| 647 | */ |
| 648 | public boolean hasNextEvent() { |
| 649 | return mIndex < mEventCount; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Retrieve the next {@link android.app.usage.UsageEvents.Event} from the collection and put the |
| 654 | * resulting data into {@code eventOut}. |
| 655 | * |
| 656 | * @param eventOut The {@link android.app.usage.UsageEvents.Event} object that will receive the |
| 657 | * next event data. |
| 658 | * @return true if an event was available, false if there are no more events. |
| 659 | */ |
| 660 | public boolean getNextEvent(Event eventOut) { |
| 661 | if (mIndex >= mEventCount) { |
| 662 | return false; |
| 663 | } |
| 664 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 665 | readEventFromParcel(mParcel, eventOut); |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 666 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 667 | mIndex++; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 668 | if (mIndex >= mEventCount) { |
| 669 | mParcel.recycle(); |
| 670 | mParcel = null; |
| 671 | } |
| 672 | return true; |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * 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] | 677 | * |
| 678 | * @hide When this object is iterated to completion, the parcel is destroyed and |
| 679 | * so resetToStart doesn't work. |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 680 | */ |
| 681 | public void resetToStart() { |
| 682 | mIndex = 0; |
| 683 | if (mParcel != null) { |
| 684 | mParcel.setDataPosition(0); |
| 685 | } |
| 686 | } |
| 687 | |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 688 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 9d96075 | 2014-08-25 14:48:12 -0700 | [diff] [blame] | 689 | private int findStringIndex(String str) { |
| 690 | final int index = Arrays.binarySearch(mStringPool, str); |
| 691 | if (index < 0) { |
| 692 | throw new IllegalStateException("String '" + str + "' is not in the string pool"); |
| 693 | } |
| 694 | return index; |
| 695 | } |
| 696 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 697 | /** |
| 698 | * Writes a single event to the parcel. Modify this when updating {@link Event}. |
| 699 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 700 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 701 | private void writeEventToParcel(Event event, Parcel p, int flags) { |
| 702 | final int packageIndex; |
| 703 | if (event.mPackage != null) { |
| 704 | packageIndex = findStringIndex(event.mPackage); |
| 705 | } else { |
| 706 | packageIndex = -1; |
| 707 | } |
| 708 | |
| 709 | final int classIndex; |
| 710 | if (event.mClass != null) { |
| 711 | classIndex = findStringIndex(event.mClass); |
| 712 | } else { |
| 713 | classIndex = -1; |
| 714 | } |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 715 | |
| 716 | final int taskRootPackageIndex; |
| 717 | if (mIncludeTaskRoots && event.mTaskRootPackage != null) { |
| 718 | taskRootPackageIndex = findStringIndex(event.mTaskRootPackage); |
| 719 | } else { |
| 720 | taskRootPackageIndex = -1; |
| 721 | } |
| 722 | |
| 723 | final int taskRootClassIndex; |
| 724 | if (mIncludeTaskRoots && event.mTaskRootClass != null) { |
| 725 | taskRootClassIndex = findStringIndex(event.mTaskRootClass); |
| 726 | } else { |
| 727 | taskRootClassIndex = -1; |
| 728 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 729 | p.writeInt(packageIndex); |
| 730 | p.writeInt(classIndex); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 731 | p.writeInt(event.mInstanceId); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 732 | p.writeInt(taskRootPackageIndex); |
| 733 | p.writeInt(taskRootClassIndex); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 734 | p.writeInt(event.mEventType); |
| 735 | p.writeLong(event.mTimeStamp); |
| 736 | |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 737 | switch (event.mEventType) { |
| 738 | case Event.CONFIGURATION_CHANGE: |
| 739 | event.mConfiguration.writeToParcel(p, flags); |
| 740 | break; |
| 741 | case Event.SHORTCUT_INVOCATION: |
| 742 | p.writeString(event.mShortcutId); |
| 743 | break; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 744 | case Event.CHOOSER_ACTION: |
| 745 | p.writeString(event.mAction); |
| 746 | p.writeString(event.mContentType); |
| 747 | p.writeStringArray(event.mContentAnnotations); |
| 748 | break; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 749 | case Event.STANDBY_BUCKET_CHANGED: |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 750 | p.writeInt(event.mBucketAndReason); |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 751 | break; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 752 | case Event.NOTIFICATION_INTERRUPTION: |
| 753 | p.writeString(event.mNotificationChannelId); |
| 754 | break; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 755 | } |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 756 | p.writeInt(event.mFlags); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /** |
| 760 | * Reads a single event from the parcel. Modify this when updating {@link Event}. |
| 761 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 762 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 763 | private void readEventFromParcel(Parcel p, Event eventOut) { |
| 764 | final int packageIndex = p.readInt(); |
| 765 | if (packageIndex >= 0) { |
| 766 | eventOut.mPackage = mStringPool[packageIndex]; |
| 767 | } else { |
| 768 | eventOut.mPackage = null; |
| 769 | } |
| 770 | |
| 771 | final int classIndex = p.readInt(); |
| 772 | if (classIndex >= 0) { |
| 773 | eventOut.mClass = mStringPool[classIndex]; |
| 774 | } else { |
| 775 | eventOut.mClass = null; |
| 776 | } |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 777 | eventOut.mInstanceId = p.readInt(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 778 | |
| 779 | final int taskRootPackageIndex = p.readInt(); |
| 780 | if (taskRootPackageIndex >= 0) { |
| 781 | eventOut.mTaskRootPackage = mStringPool[taskRootPackageIndex]; |
| 782 | } else { |
| 783 | eventOut.mTaskRootPackage = null; |
| 784 | } |
| 785 | |
| 786 | final int taskRootClassIndex = p.readInt(); |
| 787 | if (taskRootClassIndex >= 0) { |
| 788 | eventOut.mTaskRootClass = mStringPool[taskRootClassIndex]; |
| 789 | } else { |
| 790 | eventOut.mTaskRootClass = null; |
| 791 | } |
| 792 | |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 793 | eventOut.mEventType = p.readInt(); |
| 794 | eventOut.mTimeStamp = p.readLong(); |
| 795 | |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 796 | // Fill out the event-dependant fields. |
| 797 | eventOut.mConfiguration = null; |
| 798 | eventOut.mShortcutId = null; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 799 | eventOut.mAction = null; |
| 800 | eventOut.mContentType = null; |
| 801 | eventOut.mContentAnnotations = null; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 802 | eventOut.mNotificationChannelId = null; |
Makoto Onuki | ac04250 | 2016-05-20 16:39:42 -0700 | [diff] [blame] | 803 | |
| 804 | switch (eventOut.mEventType) { |
| 805 | case Event.CONFIGURATION_CHANGE: |
| 806 | // Extract the configuration for configuration change events. |
| 807 | eventOut.mConfiguration = Configuration.CREATOR.createFromParcel(p); |
| 808 | break; |
| 809 | case Event.SHORTCUT_INVOCATION: |
| 810 | eventOut.mShortcutId = p.readString(); |
| 811 | break; |
Kang Li | 53b4314 | 2016-11-14 14:38:25 -0800 | [diff] [blame] | 812 | case Event.CHOOSER_ACTION: |
| 813 | eventOut.mAction = p.readString(); |
| 814 | eventOut.mContentType = p.readString(); |
| 815 | eventOut.mContentAnnotations = p.createStringArray(); |
| 816 | break; |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 817 | case Event.STANDBY_BUCKET_CHANGED: |
Amith Yamasani | 119be9a | 2018-02-18 22:23:00 -0800 | [diff] [blame] | 818 | eventOut.mBucketAndReason = p.readInt(); |
Amith Yamasani | bfc4bf5 | 2018-01-19 06:55:08 -0800 | [diff] [blame] | 819 | break; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 820 | case Event.NOTIFICATION_INTERRUPTION: |
| 821 | eventOut.mNotificationChannelId = p.readString(); |
| 822 | break; |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 823 | } |
Dimuthu Gamage | 88ebac4 | 2019-01-14 08:28:13 -0800 | [diff] [blame] | 824 | eventOut.mFlags = p.readInt(); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | @Override |
| 828 | public int describeContents() { |
| 829 | return 0; |
| 830 | } |
| 831 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 832 | @Override |
| 833 | public void writeToParcel(Parcel dest, int flags) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 834 | Parcel data = Parcel.obtain(); |
| 835 | data.writeInt(mEventCount); |
| 836 | data.writeInt(mIndex); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 837 | if (mEventCount > 0) { |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 838 | data.writeStringArray(mStringPool); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 839 | |
| 840 | if (mEventsToWrite != null) { |
| 841 | // Write out the events |
| 842 | Parcel p = Parcel.obtain(); |
| 843 | try { |
| 844 | p.setDataPosition(0); |
| 845 | for (int i = 0; i < mEventCount; i++) { |
| 846 | final Event event = mEventsToWrite.get(i); |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 847 | writeEventToParcel(event, p, flags); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 848 | } |
Adam Lesinski | 7f61e96 | 2014-09-02 16:43:52 -0700 | [diff] [blame] | 849 | |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 850 | final int listByteLength = p.dataPosition(); |
| 851 | |
| 852 | // Write the total length of the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 853 | data.writeInt(listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 854 | |
| 855 | // Write our current position into the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 856 | data.writeInt(0); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 857 | |
| 858 | // Write the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 859 | data.appendFrom(p, 0, listByteLength); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 860 | } finally { |
| 861 | p.recycle(); |
| 862 | } |
| 863 | |
| 864 | } else if (mParcel != null) { |
| 865 | // Write the total length of the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 866 | data.writeInt(mParcel.dataSize()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 867 | |
| 868 | // Write out current position into the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 869 | data.writeInt(mParcel.dataPosition()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 870 | |
| 871 | // Write the data. |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 872 | data.appendFrom(mParcel, 0, mParcel.dataSize()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 873 | } else { |
| 874 | throw new IllegalStateException( |
| 875 | "Either mParcel or mEventsToWrite must not be null"); |
| 876 | } |
| 877 | } |
Michael Wachenschwanz | 76d03fc | 2018-05-24 17:21:02 +0000 | [diff] [blame] | 878 | // Data can be too large for a transact. Write the data as a Blob, which will be written to |
| 879 | // ashmem if too large. |
| 880 | dest.writeBlob(data.marshall()); |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | public static final Creator<UsageEvents> CREATOR = new Creator<UsageEvents>() { |
| 884 | @Override |
| 885 | public UsageEvents createFromParcel(Parcel source) { |
| 886 | return new UsageEvents(source); |
| 887 | } |
| 888 | |
| 889 | @Override |
| 890 | public UsageEvents[] newArray(int size) { |
| 891 | return new UsageEvents[size]; |
| 892 | } |
| 893 | }; |
Adam Lesinski | 3516800 | 2014-07-21 15:25:30 -0700 | [diff] [blame] | 894 | } |