The Usage Reporting Api allows apps to report usage within the app to
platform. Apps with the the OBSERVE_APP_USAGE permission may register
observers that use the reported in-app usage.
Test: manual (using the included Usage Reporter App)
Test: atest CtsUsageStatsTestCases:UsageReportingTest
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Bug: 112486938
Change-Id: Iddd6f0993bbbf68a2032b34d473ef8d67da7747a
When parsing newly added fields from Xml database, must catch
the IOException because the new fields do not exist in old Xml database.
This is not really an error. Change Log.e to Log.i, do not print the
full stack.
Change-Id: I5ba86790f7c8eadf4f5dd20d28f9348a23201f87
Fix: 121085733
Test: atest UsageStatsDatabaseTest.java
1. Add UsageStats Event types:
ACTIVITY_RESUMED is synonym to existing MOVE_TO_FOREGROUND.
ACTIVITY_PAUSED is synonym to existing MOVE_TO_BACKGROUND.
ACTIVITY_STOPPED when an activity becomes invisible on the UI.
2. In UsageStats.java, add API getLastTimeVisible() to report last time the
app is visible (ACTIVITY_RESUMED or ACTIVITY_PAUSED), add API getTotalTimeVisible()
to report total time the app is visible.
The existing API getLastTimeUsed() can report last time the app is in
foreground (AKA have focus).
The existing API getTotalTimeInForeground() can report total time the
app is in foreground (AKA have focus).
3. UsageStats.getTotalTimeVisible() can report screen usage for
split-screen mode and picture-in-picture mode.
4. Because in the same package, activity can be instantiated multiple times,
In UsageEvents.Event class, add a member mInstaceId for activity's
instance ID, add interface getInstanceId() to retrieve the instance ID.
Bug: 112002260
Test: frameworks/base/services/tests/servicestests/src/com/android/server/usage/UsageStatsDatabaseTest.java
atest frameworks/base/core/tests/coretests/src/android/app/usage/UsageStatsTest.java
Change-Id: Ibcef2488e9620804c9f9220b027f976e8fa0c98b
When parsing from a XML file written by previous code, the new fields
will get an IOException, catch the IOException and let the new fields
to have default value.
Change-Id: I2b2a494bf17aaf1383a6cc469d9c2addd6cac9c3
Fix: 119822293
Test: test com.google.android.gts.backup.UsageStatsRestoreHostSideTest#testUsageStatsRestore
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
Also some minor touch up
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Change-Id: Ibcecb483bc28ba6b1dcd0158e946137abb0e54e4
Fixes: 119371427
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
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
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
* changes:
Add ProtoInputStream and UsageStatsProto to art profiles
Upgrade UsageStatsDatabase to version 4 (attempt 2)
Move UsageStatsDatabase upgrade backup to seperate folder
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
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
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
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
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
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
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
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
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
- 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
In UsageStatsService, the calling uid is considered
from the system regardeless of the curret user id
Change-Id: I5c33db37c585ac918a09ad9014bb819b1e24d7f8
Fixes: 110527624
Test: manual
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
Caught by test UsageStatsTest due to stricter checks for
MATCH_ANY_USER.
Change-Id: Ie884c7007a8588a222773fba8d7967bcdf2a528a
Fixes: 109700742
Test: atest CtsUsageStatsTestCases:UsageStatsTest
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
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
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