Commit Graph

234 Commits

Author SHA1 Message Date
Michael Wachenschwanz
b3972f9d23 Merge "Add Stable Charging Threshold for AppStandby" into pi-dev 2018-05-02 00:23:23 +00:00
TreeHugger Robot
10b77a39a2 Merge "Using a list to store usage events" into pi-dev 2018-04-26 22:58:40 +00:00
Michael Wachenschwanz
5ca5cb6c53 Add Stable Charging Threshold for AppStandby
Delay parole when charging to ensure the device has some time to charge
and avoid a spike is activity on plug in.

Change-Id: If85f097249aeed6b64f43a22f4d25ff0a070febb
Fixes: 78040839
Test: atest AppStandbyControllerTests
2018-04-26 15:44:58 -07:00
TreeHugger Robot
4620d9b3a3 Merge "Add ADAPTIVE_BATTERY_MANAGEMENT_ENABLED" into pi-dev 2018-04-25 23:37:43 +00:00
Suprabh Shukla
60aa35b756 Using a list to store usage events
Moving UsageEvent.Event objects to an array list sorted on the event
timestamps as there can be multiple events with the same timestamps.

Test: atest android.app.usage.EventListTest
Existing tests:
atest android.app.usage.cts.UsageStatsTest

Bug: 74406113
Change-Id: Idc7f2a8db6e5a9499b3b0b74efbf014b17fa495f
2018-04-25 16:36:35 -07:00
Lei Yu
4b976ad270 Add ADAPTIVE_BATTERY_MANAGEMENT_ENABLED
APP_STANDBY_ENABLED is controlled by server side to do experiment.
Before this CL, Adaptive Battery is hooked up to this flag, so
even though if user turns it off, it may be turned on by server.

Add a high level ADAPTIVE_BATTERY_MANAGEMENT_ENABLED to control
the feature in settings UI side.

AppStandbyController looks at both flags and enables standby
only if both are true.

Bug: 78153913
Test: Build
      Manually change both flags (through UI and adb)
      Verify dumpsys usagestats shows the correct state
      for mAppIdleEnabled.
Change-Id: I1fb4461f382e1ee87000fdc38962d94a17891c1e
2018-04-19 11:47:38 -07:00
Michael Wachenschwanz
113a0fa35a No AppStandby tracking of non existent packages and add parole window
Disallow attempts to change standby bucket of nonexistent packages.
Also, add a parole window for idle apps. When parole for idle apps is
ready to be set, check that there is network availabilty. If there is
none, wait for network or the end of the parole window before setting
parole.

Change-Id: I7b8786f59b8da76325f2591cc7b1f86753d52d7b
Fixes: b/71857185
Fixes: b/74345840
Test: atest android.app.usage.cts.UsageStatsTest#testIgnoreNonexistentPackage
Test: manual (enable DEBUG and COMPRESS_TIME in AppStandbyController)
2018-04-18 15:21:32 -07:00
Jeff Sharkey
6d63103aa5 Use OS package name when identity cleared.
If we pass through the original calling package name, it obviously
won't match UID 1000.

Bug: 78104140
Test: builds, boots
Change-Id: Id0acf0b038e25a113674fa2f43ff93ba05144c1f
2018-04-16 09:57:31 -06:00
Jeff Sharkey
5a8bcd9031 OP_GET_USAGE_STATS should be noted, not checked.
Per email feedback, we should be using "noteOp" instead of "checkOp"
when testing if caller holds OP_GET_USAGE_STATS, so that we record
that caller used the operation.

Bug: 77662908
Test: builds, boots
Exempt-From-Owner-Approval: keep tests passing
Change-Id: I3a60345d590534fdbc2c1248e0d30dc85a5d6772
2018-04-13 19:32:25 +00:00
Dianne Hackborn
3378aa9f88 Work on issue #74404949: Screen state usage API
Add events for the keyguard being shown and hidden.

Bug: 74404949
Test: atest CtsUsageStatsTestCases:UsageStatsTest\#testInteractiveEvents
Change-Id: I038e03cf4ba80669d7d17c3d66b98ee81050abc8
2018-03-30 17:43:49 -07:00
Makoto Onuki
75ad2496eb AppStandby exemption: sync requested by FG apps
Bug: 72443754
Fix: 72443754

Test: atest ${ANDROID_BUILD_TOP}/frameworks/base/services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java
Test: Manual test with contacts sync:

Precondition: Put the contacts sync in RARE bucket.

adb shell dumpsys deviceidle tempwhitelist -r com.google.android.syncadapters.contacts
adb shell am make-uid-idle com.google.android.syncadapters.contacts
adb shell am set-standby-bucket com.google.android.syncadapters.contacts 40

Test 1: Toggle contacts sync from the Settings -> Account

- Make sure a sync happens.

Test 2: Mutate a contact on the WEB

- Sync is scheduled, but won't run because it has no network access.
- am set-standby-bucket com.google.android.syncadapters.contacts 30
- Sync run runs.

Test 3. adb shell requestsync -n ACCOUNT -t com.google -a com.android.contacts

- Sync is scheduled but won't run.

Test 4. adb shell requestsync -n ACCOUNT -t com.google -a com.android.contacts -f

- Sync is scheduled but it still won't run.

Test 5. adb shell requestsync -n ACCOUNT -t com.google -a com.android.contacts -F

- Sync now runs

Change-Id: I1eb972ed321d2a1a782ae23ccb806671926d3e6b
2018-03-29 14:53:02 -07:00
TreeHugger Robot
50c069e489 Merge "Fallback to ML prediction after short ACTIVE states" into pi-dev 2018-03-29 06:03:17 +00:00
TreeHugger Robot
37594c892d Merge "Add slice pinning to list of reasons for usage" into pi-dev 2018-03-29 05:51:24 +00:00
Amith Yamasani
3154dcf94a Fallback to ML prediction after short ACTIVE states
When an app is temporarily elevated to ACTIVE state for some
reason, keep track of the last predicted bucket and drop back
to that if the ACTIVE state ends.

Also keep track of prediction during a forced ACTIVE state, even
if it's not applied right away.

Bug: 77158823
Test: atest AppStandbyControllerTests
Change-Id: Ic6de6c24bb25c5392ac5b41a2c05889d94f23436
2018-03-28 13:49:21 -07:00
Dianne Hackborn
ced54398cc Work on issue #74404949: Screen state usage API
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
2018-03-27 13:27:20 -07:00
Amith Yamasani
80c4be88e0 Add slice pinning to list of reasons for usage
Bug: 73455786
Test: atest AppStandbyControllerTests
Change-Id: Ia7980a8396a47d88959051329409f0ff39e81977
2018-03-26 15:56:20 -07:00
Amith Yamasani
7f53c7bc97 Shorter bucket elevation for system_interaction and sync_adapter
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
2018-03-25 21:55:50 -07:00
Amith Yamasani
8808edb063 Merge "Provide app launch count in UsageStats" into pi-dev 2018-03-23 19:13:22 +00:00
Amith Yamasani
bc813eb26e Provide app launch count in UsageStats
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
2018-03-22 13:51:57 -07:00
Jason Monk
1918ef7569 UsageEvents for slices pinning
Test: atest frameworks/base/services/tests/servicestests
Bug: 73455786
Change-Id: I6a37f5525c29d3f47aa37e262c8834840309ba44
2018-03-21 10:03:29 -04:00
TreeHugger Robot
a8bb9d255f Merge "App Time Limits API in UsageStats" into pi-dev 2018-03-16 22:40:46 +00:00
Amith Yamasani
62ec27e97f App Time Limits API in UsageStats
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
2018-03-15 17:07:28 -07:00
Julia Reynolds
1fac86e6cd Log interruptive notifications
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
2018-03-12 09:34:48 -04:00
Michael Wachenschwanz
1088cbb770 Add -c option for dumpsys usagestats
Bug: 73657997
Test: manual (adb shel dumpsys usagestats -c)
Change-Id: If37006290b0b8a63e1b51fb9b035ba6a62f7a9b3
2018-03-09 20:12:47 +00:00
Suprabh Shukla
c0fe0626f6 Merge "An api to query usage events for the caller" 2018-03-03 01:32:21 +00:00
Michael Wachenschwanz
78646e58a3 Add null check in usagestats dump
(also adjust the time stamp for easier parsing)

Change-Id: I708c9fe68aa85b4897e95cca6b9d53522eef0d29
Fixes: 73960916
Test: manual
2018-02-27 17:46:26 -08:00
Suprabh Shukla
217ccda8ac An api to query usage events for the caller
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
2018-02-27 15:45:05 -08:00
TreeHugger Robot
2b29889462 Merge "No heavy processing on UID observer thread" 2018-02-26 18:49:54 +00:00
Amith Yamasani
119be9a5fc Improve reporting of bucketing reason
Keep track of main and sub reason for bucket change

Bug: 73178753
Test: atest AppIdleHistoryTests
Change-Id: I4936281ac06046bb5ffed9f3306efa24c7fd47ab
2018-02-23 10:45:39 -08:00
TreeHugger Robot
23ea41c4e7 Merge "Using ParceledListSlice for {get|set}AppStandbyBuckets" 2018-02-23 09:28:33 +00:00
Suprabh Shukla
868bde247c Using ParceledListSlice for {get|set}AppStandbyBuckets
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
2018-02-21 21:23:09 -08:00
Michael Wachenschwanz
06e4940237 Dump last 24 hours of UsageStats events
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
2018-02-21 12:24:15 -08:00
Makoto Onuki
743e0ad61a No heavy processing on UID observer thread
Bug: 73505782
Test: boot and launch several apps.
Change-Id: I7dd5809fac2c4e38c0ff73e6015150a7a0b9a608
2018-02-20 16:01:11 -08:00
Amith Yamasani
bbbad9cc0f Cascading timeouts for App Standby
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
2018-02-14 09:26:46 -08:00
TreeHugger Robot
f9420f4ddd Merge "Track notification clicked events in UsageStats" 2018-02-08 22:16:09 +00:00
Amith Yamasani
7ec8941167 Track notification clicked events in UsageStats
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
2018-02-08 09:09:31 -08:00
Andreas Gampe
bbab23ff97 Frameworks: Annotate trivial @GuardedBy in services/ misc
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
2018-02-08 02:19:42 -08:00
Amith Yamasani
80db94c526 Fix crash in GmsCore due to permission issue
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
2018-02-06 00:29:30 +00:00
Amith Yamasani
777b1537c2 Fix an issue with apps EXEMPTED after OTA
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
2018-02-02 15:46:31 +00:00
Chris Tate
55c84552cc Merge "Let the job scheduler know when the user interacts with an app" 2018-01-26 18:21:04 +00:00
TreeHugger Robot
c7904e1d05 Merge "Keep history of standby bucket changes." 2018-01-24 04:33:46 +00:00
Amith Yamasani
bfc4bf5feb Keep history of standby bucket changes.
Push standby bucket changes into UsageStats as events.
Don't use the event for aggregation.

Bug: 63527785
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Change-Id: Icd152b21935e3ef73aaa1a62f09574e51ce921bd
2018-01-23 18:34:34 -08:00
Sudheer Shanka
c53c47fa3a Load admin data in DPMS asynchronously during boot.
Bug: 71902030
Bug: 71710099
Test: atest services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
Test: Ran boot tests - go/run-boottest
Test: manual
Change-Id: I34970c6f41877c7e3ece4843d47831374d455067
2018-01-19 11:12:44 -08:00
Christopher Tate
d117b293ae Let the job scheduler know when the user interacts with an app
Bug: 70297451
Test: manual
Change-Id: I095d86f17a589d8b6531fb71018cfd4276989ba4
2018-01-16 17:37:04 -08:00
Sudheer Shanka
101c353a7d Update DPMS to push active admins info to UsageStatsService.
Bug: 71710099
Test: atest services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
Test: atest services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
Change-Id: Ia46be9008470b0228978306b9992560fc4f2c586
2018-01-10 17:19:55 -08:00
Amith Yamasani
a0ee7c35e2 Merge "Track last job run time" 2018-01-10 00:05:22 +00:00
Jeff Sharkey
d658207876 Merge "Wire up reserved blocks presence for tests." 2018-01-09 05:40:53 +00:00
TreeHugger Robot
a2fe748e7a Merge "Duration format for tunable settings" 2018-01-09 03:19:03 +00:00
Amith Yamasani
53f06eae61 Track last job run time
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
2018-01-08 17:22:15 -08:00
Jeff Sharkey
55fe0d0686 Wire up reserved blocks presence for tests.
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
2018-01-08 10:41:50 -07:00