Add usage stats tracking of screen time. There are two new
events, one for when the device is an interactive state, the
other for when it is non-interactive. Also add a whole new
usage stats API for retrieving aggregated data that is associated
with general events, not particular packages. In this case
it allows you to find the time the device spent interactive
and non-interactive and the count of the transitions in to
each of those states.
Bug: 74404949
Test: atest CtsUsageStatsTestCases:UsageStatsTest\#testInteractiveEvents
Change-Id: Ibe6d55e2aecb0c8519b1358644378ec5c7a4250d
Don't keep the app in ACTIVE for too long after an indirect
use of the app. Also don't mark as used, so bucketing algorithm
can override quickly.
Bug: 74340258
Test: atest AppStandbyControllerTests
Change-Id: I3b8014873aaf881de07304b64039da211a63a525
This counts the number of times the app was launched from outside
the app and ignores intra-app activity transitions.
Introduce a new permission for registering to observe app usage.
Fixes a bug where Settings couldn't force the app into another
bucket if it was recently launched.
Bug: 74335821
Fixes: 76100712
Test: Manual test using Settings
Test: UsageStatsTest to verify permission change
Change-Id: Ibd343c1cfa37089a3ac6fc30ba3194e21a9be499
Allow setting groups of apps to control usage time limits on.
Applies only to activity time in the foreground.
Updated UsageStatsTest app to be able to add an observer for
a 30 second timeout across multiple comma separated package
names.
Bug: 74335821
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Install and run frameworks/base/tests/UsageStatsTest
Change-Id: I677c30b4f211f7acf72c9766df3d8c1ac56a4b4e
First pass only logs audibly interruptive notfications; visually
interruptive notifications will be added in a future CL
Test: runtest systemui-notification, cts
Bug: 74318867
Change-Id: I604495bd4af9741ec52c38e4faa17cc87e2a522b
Added an api which apps can query to find out about their own usage
events. This is useful in understanding the apps historical bucket
changes.
Test: atest android.app.usage.cts.UsageStatsTest#testQueryEventsForSelf
Fixes: 71906213
Change-Id: Ie6144cfe515fd0748a317835918a9d8cf1aea007
UsageStats.getAppStandbyBuckets and setAppStandbyBuckets deal with large
maps of packages to buckets which may exceed the IPC transaction size
limit. Using ParceledListSlice to send and receive data across binder.
Test: atest android.app.usage.cts.UsageStatsTest#testGetAppStandbyBuckets
And manually:
adb shell am get-standby-bucket --user 0
adb shell am set-standby-bucket <package1> active <package2> rare ...
Locally, added protectionLevel development to permission
CHANGE_APP_IDLE_STATE and tested setAppStandbyBuckets with a test app.
Bug: 70890569
Change-Id: Ic1fb0465137d1b830d3ad1fbf3ac8698a409c623
On calling dumpsys usagestats, the last 24 hours of events will be
dumped rather than the events since the arbitrary time point
(also increase timestamp granularity to seconds)
Fixes: 73657997
Test: manual (adb shell dumpsys usagestats)
Change-Id: I92f1f17b4119d2023ed9b81e0610c19f62503bf0
Fixes overlapping of predictions, strong usage events
and mild usage events which have forced durations.
Having separate timeouts for ACTIVE and WORKING_SET
and moving between them when necessary prevents
getting stuck in the wrong state (higher) for longer
than necessary.
Bug: 73294677
Test: atest FrameworksServicesTests:AppStandbyControllerTests
Change-Id: I35530e62cffe2c86945b5da64a41704f807708ce
Expose some of the new events as SystemApi.
Make some of the timeouts configurable in AppStandbyController.
Make NOTIFICATION_SEEN event upgrade app to WORKING_SET for
12 hours. This is not perfect though and will require further
tweaking as it may result in the app becoming elevated higher
for much longer than necessary.
Change-Id: I62401cfabddf51b6f80b9bba8a358285b8cf9a51
Fixes: 72741441
Fixes: 72067231
Fixes: 72537465
Fixes: 72536347
Test: atest CtsUsageStatsTestCases:UsageStatsTests
Add @GuardedBy for simple functions that require a single lock
and are named XYZLocked.
Derived by errorprone.
Bug: 73000847
Test: m
Test: m javac-check-framework RUN_ERROR_PRONE=true
Change-Id: Id1d9fbe5018250e3b9d1466fc5f670d5ad902fa3
Relax the permission requirement for UsageStats
API querying inactive state of apps across users.
Bug: 72953020
Fixes: 72942083
Test: Manual -- create a secondary user
Change-Id: I9c5e12f718d9f424c99aa72dd70470c4b083c13f
After an OTA, all system apps were being
pushed into EXEMPTED for 4 hours because
of a race with the boot phase resulting in
it appearing as if app standby was disabled.
Another bug in updating the state out of EXEMPTED
was preventing checkIdleStates() from fixing
the issue soon after.
Bug: 72835804
Test: Manual:
Manually delete /data/system/usagestats/version
Reboot
Verify that correct apps are EXEMPTED
Automated:
atest FrameworksServicesTests:AppStandbyControllerTests
Change-Id: Ib53f0c45e5c2e2456442f6782ad5ca9b9d0c3d72
Push standby bucket changes into UsageStats as events.
Don't use the event for aggregation.
Bug: 63527785
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Change-Id: Icd152b21935e3ef73aaa1a62f09574e51ce921bd
JobScheduler can store the last job run time
for an app and use it later to help with
throttling.
Also, allow reporting a usage for a temporary
period. This will put the app in ACTIVE for a
minimum specified period during which timeouts
and predictions will not be able to reduce the
bucket level.
Bug: 71536897
Test: atest AppIdleHistoryTests
atest AppStandbyControllerTests
Change-Id: I2985f7f3766671f15ea641972346c69875f17946
This is how we tell CTS if the device has reserved blocks set aside
for system critical services.
Test: builds, boots
Bug: 62024591
Change-Id: Ib970554235b49346f9e9df7d3d1646beb168cd92
Mirrors the design of TimeUnit and ChronoUnit which many developers
are already familiar with, making it easy to pick up and use.
Yes, this is an enum.
Bug: 70915728
Test: bit FrameworksCoreTests:android.util.DataUnitTest
Change-Id: Id0cfdac5c81ed89c3c9ece23c964acba4a4f8471
For JobScheduler, DeviceIdle and AppStandby constants, allow
using a more compact format than milliseconds,
which are a PITA to calculate.
So instead of 18640000000... whatever, you can
use PT2H (for 2 hours), or P2D (for 2 days), etc.
Uses Duration.parse() to do the parsing. See Duration
for format.
Test: adb shell settings put global app_standby_constants
screen_thresholds=0/PT2H/PT12H/P2D
Fixes: 71554131
Change-Id: I5141854ec7df6de266725a67f1f3e2a6e0b4c1c1
DUMP OF SERVICE Usagestats was empty in bugreports
because an unexpected -a argument was being passed.
adb shell pm dump <package> had a similar issue with --packages
Change-Id: Ic67c723b8edc74ec7c9c48582b08896ca3430a4a
Fix: 70777338
Test: adb shell pm dump <package> and bugreports now contain usage stats
Disable app standby features if app_standby_enabled
is set to 0. This allows for UI and experiments to
control the feature.
Bug: 70655630
Test: adb shell settings put global app_standby_enabled 0
adb shell dumpsys usagestats
adb shell am get-standby-bucket <packagename>
Change-Id: Id6c62b078e52040767100f2997832cc586bb0806
Don't allow EXEMPT to be overridden
Differentiate between shell and other callers who set
buckets.
Don't allow forced to be modified by bucketeer.
Don't allow bucketeer to modify NEVER bucket.
Fix a locking issue in listeners list. Don't use
the primary lock when calling out to listeners.
Fixes: 70622791
Fixes: 70622338
Test: atest FrameworksServicesTests:AppIdleHistoryTests
atest FrameworksServicesTests:AppStandbyControllerTests
atest CtsAppUsageHostTestCases
Change-Id: I22309478b947d6461235f5a77e08c7be86309e4b
This is different from SDK_INT, which can change due to OTA
software updates.
Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.cts.BuildTest
Bug: 69270887
Change-Id: Ic3f4b22b25dc08f3fbdbdf7622c953323447ea01
SystemApi to pass a map of packagename to bucket mapping.
Reduces the number of IPC calls to be made by bucketing
ML app.
Bug: 63527785
Test: atest CtsAppUsageHostTestCases
Change-Id: I4172fd30cc310092a1f182ae26267de9148009b7
Ignore predicted bucket if it's been too long since the
last update, and use internal timeout logic to set
standby buckets.
Keep track of last predicted time and persist it.
Bug: 70219058
Test: atest FrameworksServicesTests:AppStandbyControllerTests
Change-Id: Ib2992201d204b92fdd4a0a00754d81e7bbfc292f
Instrumentation package should be immediately marked as active so
that the jobs aren't throttled.
Also, make sure special apps' buckets are correctly initialized.
Fixes: 68900608
Fixes: 69799327
Fixes: 69793822
Fixes: 69788489
Test: atest CtsNetSecPolicyUsesCleartextTrafficTrueTestCases
atest FrameworksServicesTests:AppIdleHistoryTests
atest FrameworksServicesTests:AppStandbyControllerTests
atest CtsNetSecPolicyUsesCleartextTrafficUnspecifiedTestCases
atest CtsNetSecConfigDownloadManagerTestCases
atest CtsNetSecPolicyUsesCleartextTrafficFalseTestCases
cts-tradefed run cts-dev -m CtsAppUsageHostTestCases
cts-tradefed run cts-dev -m CtsHostsideNetworkTests
gts-tradefed run gts-dev -m GtsUsageStatsTestCases
Change-Id: Ic880b6f5ed1fdb7912613e882ccf7b2d4e388159
Only check for INTERACT_ACROSS_USERS in getAppStandbyBucket()
Bug: 70126098
Test: gts-tradefed run gts-dev -m GtsUsageStatsTestCases
Change-Id: I6c3f69ff56d8513f84c7d91162567d17c06980c3
Allow apps to query their own standby bucket.
Allow privileged apps with PACKAGE_USAGE_STATS permission to
query apps.
Allow privileged apps with CHANGE_APP_IDLE_STATE to set the
standby state for apps, but not for themselves.
Removed AppStandby class and moved constants into UsageStatsManager.
Bug: 63527785
Test: cts-tradefed run cts-dev -m CtsAppUsageHostTestCases
Change-Id: I3c1c20f6ecb6d54e248233696039286b243d663c