Commit Graph

260 Commits

Author SHA1 Message Date
TreeHugger Robot
06ea043275 Merge "Add missing app standby parameters to controller dump" 2018-08-08 23:50:42 +00:00
TreeHugger Robot
8c8a9a1e33 Merge "Add null check for LastEvent in UserUsageStatsService" 2018-07-20 05:50:28 +00:00
Michael Wachenschwanz
bc9abc6589 Add null check for LastEvent in UserUsageStatsService
Change-Id: Ie57233ccb23f1399234b1dbb6ae490de9595e71f
Fixes: 111630625
Test: manual
2018-07-19 12:02:19 -07:00
TreeHugger Robot
766d24e06c Merge "Log Wtf when UsageStats missing over a day of events" 2018-07-17 02:45:52 +00:00
Michael Wachenschwanz
e4c818f440 Log Wtf when UsageStats missing over a day of events
Bug: 110930764
Test: manual (hardcode future time in printLast24HrEvents)
Change-Id: Ia254f7512bfa549966dda3674140772504dbbffd
2018-07-16 16:26:32 -07:00
Amith Yamasani
a4dd6efdc1 Merge "Fix crash on calling getAppStandbyBucket()" into pi-dev am: 632c036d8c
am: 9d629c85fd

Change-Id: I9760ced42479a795c03ecefd24ed6b7597294421
2018-07-16 14:00:20 -07:00
Amith Yamasani
99e1424e0a Fix crash on calling getAppStandbyBucket()
MATCH_ANY_USER, which was locked down recently, is not
really needed in this context, so removed it.

Bug: 111145886
Test: cts CtsAppUsageHostTestCases
Change-Id: I1bb9df0c7370015365bea414599b2b83084a1846
2018-07-11 10:44:17 -07:00
Makoto Onuki
3ab7781d1f Clean up sync manager and fix the lock screen blocked sync issue.
- Fix the issue where when a sync starts when the user is locked, the sync
is enqueued and waits for the 10 minute timeout, which drains the battery.

Now, in this case, we finished the job right away, and if it's a non-periodic
sync, we ask the job scheduler to reschedule.

- Clean up all the mess and unnecessary code.

Fixes: 79433653
Test: manual: Add an account, remove it, make sure all the sync operations are
gone from dumpsys content.
Test: manual: Use the requestsync command while the user is locked and
make sure the sync won't stuck.

Change-Id: I8cfd6a80715336ebea3793b2ed10b59d90cd8e52
2018-07-10 14:11:34 -07:00
Esteban Talavera
5b79bfa763 Add missing app standby parameters to controller dump
Test: adb shell dumpsys usagestats

Change-Id: Iacbbbab8608ebd871ab9fcf56b20be51dc847d52
2018-07-05 15:15:44 +01:00
TreeHugger Robot
565aa50952 Merge "Initial UsageStatsDatabase Perf tests" 2018-07-03 21:15:15 +00:00
Beverly
f7cc6b28c1 Ignore user portion when checking for system uid
In UsageStatsService, the calling uid is considered
from the system regardeless of the curret user id

Change-Id: I5c33db37c585ac918a09ad9014bb819b1e24d7f8
Fixes: 110527624
Test: manual
2018-06-28 19:41:11 +00:00
Michael Wachenschwanz
e717e0cb4e Initial UsageStatsDatabase Perf tests
A suite of simple performance test for UsageStatsDatabase. They measure
the time it take to write and read UsageEvents to and from a file.

Bug: 110428559
Test: atest UsageStatsPerfTests
Change-Id: If1558515e1da9e22fb56bc13f8e89c10c51a1625
2018-06-21 15:59:49 -07:00
Julia Reynolds
5dc1edfe16 Fix notification interruption stats
- Write channelid to xml
- Fix issue querying packages by user

Test: manual
Bug: 79607096
Change-Id: I77b1a532d364fcf97a4dba9d83ce97b93650a88c
2018-06-14 11:16:30 -04:00
TreeHugger Robot
0ebb10d596 Merge "Set AppStandbyController charging state on init" 2018-06-08 02:27:26 +00:00
Michael Wachenschwanz
13b1e1774c Set AppStandbyController charging state on init
Test: manual (restart device and "adb shell dumpsys usagestats | grep
mCharging=")
Test: CtsHostsideNetworkTests
Fixes:80545083

Change-Id: I0592622b83525159eeca611b3cc1021347bc53ca
2018-06-07 18:33:22 +00:00
Amith Yamasani
82d3041f30 DO NOT MERGE Fix security exception due to incorrect flags
Caught by test UsageStatsTest due to stricter checks for
MATCH_ANY_USER.

Change-Id: Ie884c7007a8588a222773fba8d7967bcdf2a528a
Fixes: 109700742
Test: atest CtsUsageStatsTestCases:UsageStatsTest
2018-06-06 19:51:24 +00:00
Julia Reynolds
1b61d018ec Allow cross user usage event queries
For multipackage requests, caller must be system uid or hold
interact_across_users if not requesting fate for the same user.

For single package requests, caller must be system uid or the
same package and hold interact_across_users if not requesting data
for the current user.

In both cases the caller must have the usagestats permission.

Test: couldn't find automated tests for this file; manual
Bug: 79142791
Change-Id: I8d650f8e875e0e4578cb48c9ba42e821342852a0
2018-06-06 14:26:49 -04:00
Makoto Onuki
da4db58021 Merge "Tweak exemption for sync requests made by FG apps" into pi-dev am: 621fd20f55
am: d8cf91c5f8

Change-Id: Icac177c8d404ce20d5e894d85df2b72a001d6d9a
2018-05-24 22:14:27 -07:00
Makoto Onuki
621fd20f55 Merge "Tweak exemption for sync requests made by FG apps" into pi-dev 2018-05-24 23:22:09 +00:00
Makoto Onuki
d5f25d2cd8 Tweak exemption for sync requests made by FG apps
Exemption given to a sync request made by a foreground app (including
PROCESS_STATE_IMPORTANT_FOREGROUND).
At the schedule time, we promote the sync adapter app for a higher bucket:
- If the device is not dozing (so the sync will start right away)
  promote to ACTIVE for 1 hour.
- If the device is dozing (so the sync *won't* start right away),
promote to WORKING_SET for 4 hours, so it'll get a higher chance to be started once the
device comes out of doze.
- When the sync actually starts, we promote the sync adapter app to ACTIVE for 10 minutes,
so it can schedule and start more syncs without getting throttled, even when the first
operation was canceled and now we're retrying.

Test: atest cts/tests/tests/syncmanager/
Test: Manual test with "requestsync -f" and "am set-standby-bucket", while checking
"dumpsys usagestats"
Test: settings put global app_idle_constants \
  exempted_sync_scheduled_nd_duration=1,exempted_sync_scheduled_d_duration=2,exempted_sync_start_duration=3
  and check "dumpsys usagestats" and make sure the constants are properly updated.
Fixes: 72443754

Change-Id: I233d8e4be85769150830bac798abc04810f4cc7b
2018-05-23 14:50:05 -07:00
TreeHugger Robot
452936192f Merge "DO NOT MERGE Allow cross user usage event queries" into pi-dev 2018-05-23 21:49:56 +00:00
Makoto Onuki
a0058b47e3 Make "am set-standby-bucket" reset active/working left time
This is needed for manual testing the fix for b/72443754.

Test: atest cts/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Test: atest cts/tests/tests/batterysaving
Bug: 72443754
Change-Id: I13ac03917c0a5a08859c44930406e7a82ebf1a07
2018-05-23 08:14:50 -07:00
Julia Reynolds
20e682910d DO NOT MERGE Allow cross user usage event queries
For multipackage requests, caller must be system uid or hold
interact_across_users if not requesting fate for the same user.

For single package requests, caller must be system uid or the
same package and hold interact_across_users if not requesting data
for the current user.

In both cases the caller must have the usagestats permission.

Test: couldn't find automated tests for this file; manual
Bug: 79142791
Change-Id: I8d650f8e875e0e4578cb48c9ba42e821342852a0
2018-05-23 09:51:13 -04:00
Suprabh Shukla
d8611ecd36 Added a command to return app_standby_enabled
The only way to know the runtime state was check dumpsys usagestats, and
parse through a lot of output.
This makes it easier to retreive the state.

Test: adb shell settings put global app_standby_enabled 0
adb shell dumpsys usagestats is-app-standby-enabled

Bug: 74336662
Change-Id: Ibe80d27bdf940682b9e4c3c14f93b4871f9f1746
2018-05-16 16:53:58 -07:00
Amith Yamasani
98fd4fa0f4 Merge "Add limits to App Usage Observer Api" into pi-dev 2018-05-11 19:03:11 +00:00
Michael Wachenschwanz
c870309921 Add limits to App Usage Observer Api
Added a minimum time limit for App Time Limit Observers and a maximum
number of observers an app can register to AppTimeLimitController

Also fix small bug with mDpmInternal initialization

Change-Id: I8c0861d79711149f3ecd92ba4660f7b207e9b921
Fixes: 78890515
Fixes: 79230583
Test: atest AppTimeLimitController
Test: atest cts/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ProfileOwnerTest.java#testAppUsageObserver
2018-05-04 14:43:04 -07:00
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