Added a new AppUsageLimit group observer which follows the same pattern as
other UsageGroups. This specific observer allows the launcher to query
for the AppUsageLimit, available via the new LauncherApps API below. The
observer can be registered and unregistered via the respective new APIs in
UsageStats.
LauncherApps has a new API which allows it to get the AppUsageLimit for
a specified package and user, initally set via the API in UsageStats.
This new API allows the launcher to query specifics about the limit such
as how much usage time the limit has, and how much total usage time is
remaining.
Bug: 117409586
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Test: atest android.app.usage.cts.UsageStatsTest#testObserveUsagePermissionForRegisterObserver
Test: atest android.app.usage.cts.UsageStatsTest#testObserveUsagePermissionForUnregisterObserver
Test: manual (mmma frameworks/base/tests/UsageStatsTest/)
Change-Id: Ifaffab629409e9191e40404a949c8df70bd3f7cb
DEVICE_SHUTDOWN event is used to close all open usage events that do
not have matching closing event when device is shut down. For example,
ACTIVITY_RESUMED or FOREGROUND_SERVICE_START are open events, the
DEVICE_SHUTDOWN event will close the usage session of the open events.
At orderly shutdown like selecting Power Off or Restart after pressing
power button, a DEVICE_SHUTDOWN event is sent to UsageStats.
UsageStats persists UsageStatsDatabase to disk immediately.
When power button is pressed for 3.5 seconds (configured by
config_veryLongPressTimeout in config.xml). A DEVICE_SHUTDOWN
event is sent to UsageStats. UsageStats persists UsageStatsDatabase
to disk immediately.
This is the mechanism that we do not lose UsageStats data when the
device is shut down.
When the device boots up, if the last event is not
DEVICE_SHUTDOWN, we add a DEVICE_SHUTDOWN with timestamp set to be the last
time database file is persisted. This is to handle the case device
shutdown abruptly due to power drained or cold temperature.
Bug: 111464278
Test: atest UsageStatsTest.java
Change-Id: I1e88063ba71d09042d02c6deb9f07d8581a15c30
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