Commit Graph

208 Commits

Author SHA1 Message Date
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
Jeff Sharkey
9f2dc0527e Add DataUnit to clarify SI-vs-IEC units.
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
2018-01-07 19:06:01 -07:00
Amith Yamasani
761d3ff06c Duration format for tunable settings
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
2018-01-04 09:37:13 -08:00
Esteban Talavera
e51ffaa6ac Merge "Fix usagestats DUMP OF SERVICE" 2017-12-19 17:46:06 +00:00
Esteban Talavera
838ea24493 Fix usagestats DUMP OF SERVICE
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
2017-12-19 15:23:43 +00:00
Amith Yamasani
172612c891 Global app standby flag
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
2017-12-16 07:13:53 -08:00
Amith Yamasani
9388519d5e Don't allow certain bucket overrides
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
2017-12-14 20:21:32 +00:00
Jeff Sharkey
6cff5c2840 Merge "API that reports first SDK level of the device." 2017-12-13 16:53:55 +00:00
Jeff Sharkey
28c660f11a API that reports first SDK level of the device.
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
2017-12-12 14:11:14 -07:00
Amith Yamasani
e878931414 Allow multiple standby buckets to be set in one IPC
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
2017-12-10 18:52:20 -08:00
TreeHugger Robot
e2fa77ab4d Merge "Timeout app predictions after 12 hours" 2017-12-08 23:27:11 +00:00
Amith Yamasani
bd7b302f91 Timeout app predictions after 12 hours
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
2017-12-08 13:46:17 -08:00
TreeHugger Robot
1b09d2ff8b Merge "Increase history of UsageEvents" 2017-12-08 13:16:43 +00:00
Amith Yamasani
5a8cc72386 Fix CTS tests failing due to job throttling
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
2017-12-06 10:26:10 -08:00
Amith Yamasani
22af6c7e98 Allow privileged apps to query standby state
Only check for INTERACT_ACROSS_USERS in getAppStandbyBucket()

Bug: 70126098
Test: gts-tradefed run gts-dev -m GtsUsageStatsTestCases
Change-Id: I6c3f69ff56d8513f84c7d91162567d17c06980c3
2017-12-03 20:16:15 -08:00
Amith Yamasani
afbccb7d37 Expose App Standby APIs for apps and system
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
2017-12-01 14:00:37 -08:00
Esteban Talavera
bb6b748ea3 Increase history of UsageEvents
We need over 8 days of UsageEvents in order to capture weekly
patterns in our app usage models

Change-Id: I8e1149b82cfbaedae4d19bbbfaeffa989bfd54e7
Fix: 69244223
Test: It builds
2017-12-01 13:11:34 +00:00
Christopher Tate
a732f014c5 The job scheduler now backs off jobs based on standby bucketing
The default parameters here translate to roughly this rate limiting:

  ACTIVE:   run jobs whenever
  WORKING:  ~ hourly
  FREQUENT: ~ every 6 hours
  RARE:     ~ daily

Bug: 63527785
Test: cts & manual (WIP)
      atest CtsJobSchedulerTestCases
Change-Id: I58f8e53e5bdf40601823e5a10a9f2383a6f67ae5
2017-11-22 22:07:06 +00:00
Amith Yamasani
a0ef1ca2b2 Cleanup old idle variables
Switch to using the new bucket thresholds and
remove the previous idle thresholds.

Bug: 63527785
Test: atest AppStandbyControllerTests
      atest AppIdleHistoryTests

Change-Id: Ica3fd10fe172faa5b4e712b08273b77357fdae14
2017-11-20 09:43:56 -08:00
Amith Yamasani
301e94a9ef Shorter thresholds for app standby
Start off with slightly more aggressive timeouts to
switch between buckets. 12Hrs, 24Hrs and 48Hrs.

Bug: 63527785
Test: atest AppStandbyControllerTests
Change-Id: I4aa0cc38ef91538192eda0f48dd3840217aa49c4
2017-11-17 16:35:44 -08:00
Amith Yamasani
803eab6906 Add a new usage event type for seen notification
On a notification becoming visible, NOTIFICATION_SEEN event is
dispatched. This will only bump up the app's bucket to WORKING_SET and
no higher. Same goes for sync adapters associated with a content
provider. Only move them to WORKING_SET.

Updated NotificationManagerService to report event to usagestats on
visibility changes.

Bug: 63527785
Test: runtest -x
frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
atest NotificationManagerServiceTest
Change-Id: I5b132e1fc1f70e2126473b43b9b1979fbc523b85
2017-11-16 09:15:03 -08:00
Amith Yamasani
84cd7b7a9e Allow standby timeouts to occur after usage
And inform listeners when the bucket changes, not just when
going in and out of RARE bucket.
Avoid redundant callbacks when informing listeners.

Bug: 63527785
Test: runtest -x
frameworks/base/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
Change-Id: Icd98d59f597147fbf8ea4bf44edf4b3b3d5c8e14
2017-11-08 15:06:10 -08:00
Dianne Hackborn
c81983a0c3 Start removing remaining pm code to package manager
Everything is now moved out of the pm command except for
the various install commands.  I am going to hold of on
those since they require doing some resolution with the
current implementations in the package manager to make
sure they match and behave identically to the implementations
currently in the pm command.  But other than that, everything
in pm is now just redirecting over to "cmd package".

Also fix up some of the dumpsys output of a few other sevices
when asking to print the data for a particular package, so
the "pm dump" command gives a little more sane result.

Test: manual

Change-Id: I139e06e560203b72243d7eea9543c2240db0f8f8
2017-10-25 12:19:26 -07:00
Amith Yamasani
17fffee490 App Bucketing for Standby
Manage the standby bucket in AppStandbyController

Default implementation of bucketing based on simple timeout:
 ACTIVE, if recently used
 12 hrs to move to WORKING_SET
 2 days to move to FREQUENT
 7 days to move to RARE
 (subject to change)

RARE bucket equates to the old "idle" or "inactive" state for
an app.

Bug: 63527785
Test: AppStandbyControllerTests.java
Change-Id: I970d7afcdf47c31a9413da8fd4852066a13676a2
2017-10-24 19:24:15 -07:00
Amith Yamasani
7e528f3fda Refactor App Standby code
Move the App Standby code out of UsageStatsService into
an AppStandbyController class. This doesn't change any
behavior. Also, it doesn't change the entry points, which
are still in UsageStatsManager. The binder APIs are still
in UsageStatsService and are forwarded to
AppStandbyController.

This change is in preparation for switching to app standby
buckets instead of a boolean state.

Bug: 63527785
Test: adb shell dumpsys usagestats
      adb shell am set-inactive <packagename> true
      // Ensure state changes are persisted

Change-Id: Ic94357bdc891d1defae37bb29d533b6153a09967
2017-10-05 17:30:37 -07:00