Commit Graph

280 Commits

Author SHA1 Message Date
Hui Yu
81f977753a Merge "Add UsageStats events for foreground service start/stop." 2018-11-13 18:16:19 +00:00
TreeHugger Robot
a66a53194c Merge "Add null checks to removing AppTimeLimit observers" 2018-11-13 03:29:21 +00:00
Hui Yu
e361a23bba Add UsageStats events for foreground service start/stop.
1. Send FOREGROUND_SERVICE_START event when foreground service starts.
Send FOREGROUND_SERVICE_STOP event when foreground service stops.
2. One app can multiple foreground services and multiple services can be
started. Because this, in UsageStats, change mLastForegroundEvent to
className to event map, do this for both activity and foreground
service. Change UsageStatsProto and UsageStatsXmlV1 to support this
change.
3. Add more test cases in UsageStatsTest.java.

Test: start music player which is foreground service, observce these
two events when start play and pause play.

Change-Id: I3dc14f5b73cc114a53b8c51f90d3011d9ace35ac
Bug: 112002260
Test: atest UsageStatsTest#testForegroundService
atest frameworks/base/services/tests/servicestests/src/com/android/server/usage/UsageStatsDatabaseTest.java
atest frameworks/base/core/tests/coretests/src/android/app/usage/UsageStatsTest.java
2018-11-12 17:41:03 -08:00
Michael Wachenschwanz
ae9811d44f Add null checks to removing AppTimeLimit observers
Also some minor touch up

Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Change-Id: Ibcecb483bc28ba6b1dcd0158e946137abb0e54e4
Fixes: 119371427
2018-11-12 16:55:34 -08:00
Kweku Adams
1e8947c5da Informing app idle listeners on enabled state changes.
Currently, if AppStandbyController is enabled after some listeners have
already registered, the listeners will be told that the system is in a
state of parole even though AppStandbyController thinks it's not in
parole. This change informs AppIdleStateChangeListeners when
AppStandbyController's enabled state changes as well so that they can be
in the correct state.

I also removed the call to setAppIdleEnabled() in onBootPhase() since
updateSettings() is called right afterwards and that also calls
setAppIdleEnabled().

Bug: 112329453
Test: atest AppStandbyControllerTests
also check logs to confirm that NetworkPolicyManagerService and
JobSchedulerService's listeners switch from ON to OFF when the system is
ready.

Change-Id: I88bc293c70b459f54f75f92126ad306d6ab8d9b7
2018-11-08 13:58:50 -08:00
Risan
5287e1fe48 Merge "isReservedSupported=true when running as container" am: e0076e4145 am: a228f69e07
am: d9231a0984

Change-Id: Id2f4862faa57099d6b15f06567bdb53fd2f33b03
2018-10-31 14:08:54 -07:00
Risan
12adf3a985 isReservedSupported=true when running as container
Test: Remove first_sdk_check from StorageHostTest#testVerify, log
Build.IS_CONTAINER inside isReservedSupported function, run on sailfish.
It shows that Build.IS_CONTAINER=false and the test still passes (i.e.,
isReservedSupported is correctly true).
Also checked that Build.IS_CONTAINER in isReservedSupported is true in
ARC++.
Bug: 111287848

Change-Id: I9af1f6cce5bab75ef941989bf279cf40c52e62b0
2018-10-29 20:43:43 -06:00
Michael Wachenschwanz
0f47284af3 Refactor AppTimeLimitController for Session Observers
Introducing the concept of Usage Session Observers to UsageStats. A
session observer monitors usage within individual "continuous" sessions
(brief gaps of non usage may be allowed in a session and still be
considered continuous)

The new session observer in AppTimeLimitController are both similar and
different enough from the current app usage observer to warrant
refactoring TimeLimitGroup into an OOP friendly abstract base class.

Added some Observer App handling to avoid clash between registered
observers from multiple apps.

Reworded packages to observed and usage entities to accomodate future
changes, where usage may come from more than just app usage.

Reworded moveToForeground/Background to generic usage and allow multiple
usage entities to be active at the same time to accomodate future
changes, where more than just the foreground app can be considered used.

Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Bug: 111465038
Change-Id: I63aebf8b0aa5516111bd6d5e142525d0bee6ef58
2018-10-29 16:21:24 -07:00
Michael Wachenschwanz
0e1ce140a2 Merge changes from topic "UsageStatsDatabaseUpgradeAttempt2"
* changes:
  Add ProtoInputStream and UsageStatsProto to art profiles
  Upgrade UsageStatsDatabase to version 4 (attempt 2)
  Move UsageStatsDatabase upgrade backup to seperate folder
2018-10-24 02:17:00 +00:00
Varun Shah
7609b7535f Prevents uninstalled packages from being added to the DB.
Apps trying to set the standby bucket for a package that was uninstalled
will now be blocked to prevent uninstalled package entries from
appearing in the App Standby DB.

Bug: 116190365
Test: atest com.android.server.usage.AppIdleHistoryTests
Test: atest com.android.server.usage.AppStandbyControllerTests
Test: atest cts/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Test: atest vendor/xts/gts-tests/tests/usagestats/src/com/google/android/usagestats/gts/UsageStatsTests.java
Change-Id: If421c46f3459eced78ae260e88749022ed5cf7a2
2018-10-19 16:48:55 -07:00
Michael Wachenschwanz
d083f6b875 Upgrade UsageStatsDatabase to version 4 (attempt 2)
If version 4 causes any regression, this CL should be reverted.
The other UsageStatsDatabase changes are not safe to revert.

Bug: 111422946
Test: atest UsageStatsDatabase
Change-Id: I8af08a25c596397ec319d457bfa5c51b73beb4df
2018-10-12 14:09:31 -07:00
Michael Wachenschwanz
dc46632382 Move UsageStatsDatabase upgrade backup to seperate folder
During a UsageStatsDatabase version upgrade, move backup files to a
seperate folder to reduce the chance of accidentally picking up the
backup file.

Change-Id: I0052cb25388703c328cd7160f523d8542cf424d7
Fixes: 117224541
Test: atest UsageStatsDatabaseTest
2018-10-12 14:09:31 -07:00
Michael Wachenschwanz
3efa16d29f Revert UsageStatsDatabase to version 3
Change-Id: I650caeaed954ff2d0921b88a000c8f2be37df078
Fixes: 117177943
Bug: 117224541
Test: run google/template/local --template:map test
google/continuous/boot-successive  --no-first-boot --successive-boot
--boot-count 2 --granular-boot-info  -f
SystemServerTiming_StartUsageService    (See go/run-boottest)
2018-10-03 18:52:36 +00:00
Michael Wachenschwanz
c90bc15dc8 Pool Package and Class names when writing UsageStats to disk
Write the package and class names at the top of the proto file and
replace each instance of those strings in the rest of the protobuf with
the index of said string.

Some rough number on the impact of this change plus the previous proto
change:
File size on disk reduces to ~13% of XML file size!!!
File read time reduces to ~32-45% of XML read time!
File write time clock at around ~102-107% of XML write time.

Bug: 111422946
Fixes: 111449191
Test: atest UsageStatsDatabaseTest
Change-Id: I6bcce54a2431a964bda2c03bd3be1f3d4b4156e1
2018-09-28 16:48:35 -07:00
Michael Wachenschwanz
c8c26365a4 Upgrade UsageStatsDatabase from XML to Protobuf
Add the relevant methods to read from ProtoInputStream to
various classes.

Also add some framework to handle version changes in
UsageStatsDatabase. There is some risk of users losing all their current
UsageStats data, if something goes horribly wrong. The debug flag and a
keep backup files flag are temporarily set in UsageStatsDatabase with
this change. They will both be unset in the future before the Q release.

Some rough number on the impact of this change:
Proto file size on disk reduces to ~47% of XML file size :)
Proto file read time reduces to ~55% of XML file read :)
Proto file write time increases ~17% over the XML file write :(

There will be a follow up CL to address the file write time regression

Bug: 111422946
Fixes: 111449927
Test: atest UsageStatsDatabaseTest
Change-Id: I084aea796ed2163c42947d52396a36cc7c5562a2
2018-09-28 16:48:23 -07:00
Andreas Gampe
8ce7ed95a0 Frameworks: Annotate trivial @GuardedBy in services
Add @GuardedBy for simple functions that require locks and have a name in
one of the frameworks naming styles for locks ("^.*(Locked|LPw|LPr|L[a-zA-Z]|UL|AL|NL)$").

Derived by errorprone.

Bug: 73000847
Test: m
Change-Id: If70bb03313388af34d547efca20fb5115de95bf1
2018-09-05 17:02:08 -07:00
Michael Wachenschwanz
ddcac2c78d Set AppStandbyController charging state on init
am: 2795cca1cf

Change-Id: I67b2d6bd5a6f1a5bbc5f8c6e70d6d6516d67a791
2018-08-31 17:22:07 -07:00
Amith Yamasani
8b7725b77a Show the diff instead of current time for last parole time.
So the time shown will be how long ago the last parole happened.
This is easier to read than when the last parole happened, in
time since epoch.

... mChargingStable=false mLastAppIdleParoledTime=+15s666ms


Bug: 112880101
Test: adb shell dumpsys usagestats
Change-Id: Ieddf752e811a95a95e63d621e9cd9f26957b51a8
2018-08-29 21:20:00 +00:00
Michael Wachenschwanz
2795cca1cf Set AppStandbyController charging state on init
Test: manual (restart device and "adb shell dumpsys usagestats | grep
mCharging=")
Test: CtsHostsideNetworkTests
Fixes:80545083

Change-Id: I0592622b83525159eeca611b3cc1021347bc53ca
Merged-In: I0592622b83525159eeca611b3cc1021347bc53ca
(cherry-picked from 13b1e1774c)
(cherry picked from commit 4d5b4b03c8065fc6421456a6135f6d247d2d1dd5)
2018-08-29 15:00:30 +08:00
Jeff Sharkey
5518cf584b No permissions needed for static disk attributes.
Detecting if a storage device has quota or resgid support isn't
sensitive, so we're okay letting anyone ask about it.

Bug: 112175169
Test: atest android.appsecurity.cts.StorageHostTest#testFullDisk
Change-Id: I1e45eeade0d0d8ea242afca274b45a68972e6b57
2018-08-24 17:38:02 -06:00
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