Commit Graph

332 Commits

Author SHA1 Message Date
Sudheer Shanka
62022dc7cc Add usagestats dump option to get appstandby settings state.
Test: adb shell dumpsys usagestats appstandby
Change-Id: I60f65a9421c4eb3eefbbef22a5534cf85b739ab5
2019-08-02 18:06:39 -07:00
Kweku Adams
6acbca3a9a Rename ProtoInputStream.isNextField to nextField.
ProtoInputStream.isNextField() skips over the current field to read the
next tag. This side effect means that calling isNextField prevents the
caller from reading the field it was just on. The "is" prefix makes it
easy to assume that the method has no side effects. Renaming to
nextField(long) with a parameter should help make it clear that the call
is as dangerous as calling nextField().

Fixes: 137294060
Test: atest android.app.usage.UsageStatsTest
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest com.android.server.usage.UsageStatsDatabaseTest
Test: atest ProtoInputStreamTests
Change-Id: Ibfb8ef741f27a211f076dc0b715b64acbfc0696a
2019-07-12 17:10:39 -07:00
Jeff Sharkey
f7f23bfd8e Merge "Explicitly request clearing of external storage." into qt-dev am: 9637326ea8
am: b7be677e24

Change-Id: Ia4c56d1879f3a4159031f82ff82ce7258b8edf5f
2019-05-14 19:47:20 -07:00
Jeff Sharkey
3f704637b4 Explicitly request clearing of external storage.
Similar to how we target DE and CE storage areas, callers need to
specifically ask to work with EXTERNAL storage.  This is because
external storage often lives on a separate device from where internal
DE and CE data lives.

As one specific example, if we're moving an app between two
"internal" storage devices, we don't want to clean up the data
for that package on external storage, since it's not being moved.

This change also expands to all mounted external storage devices,
not just the storage backed by the incoming UUID.

Bug: 113277754
Test: atest android.appsecurity.cts.StorageHostTest
Test: atest android.appsecurity.cts.ExternalStorageHostTest
Test: atest --test-mapping frameworks/base/services/core/java/com/android/server/pm/
Change-Id: Ie125303726dd757ee45bd373f53addb35569c2f7
2019-05-14 14:55:15 -06:00
Chen Xu
1872260bfb Merge "checkCarrierPrivilegesForPackage by subId rather than default" into qt-dev am: 856fe0fefc
am: 5811135e2a

Change-Id: I999ef3ea7ce65452f8503696f89cbb5f91632cbc
2019-05-13 18:54:58 -07:00
Chen Xu
856fe0fefc Merge "checkCarrierPrivilegesForPackage by subId rather than default" into qt-dev 2019-05-14 01:06:05 +00:00
chen xu
28fe1359ee checkCarrierPrivilegesForPackage by subId rather than default
1. checkCarrierPrivilegesForPackages by subId
2. getPackagesWithCarrierPrivileges by subId
3. new hidden API getPackagesWithCarrierPrivilegesForAllPhones which
returns packages for all subs.

Bug: 132078279
Test: Manual
Change-Id: Ic666218f0c290d1b428530982b689af110f74c69
2019-05-13 16:30:37 -07:00
Michael Wachenschwanz
9dbd816399 Merge "Remove temporary UserUsageStatsService logging" into qt-dev am: 89ed22cf08
am: f587419057

Change-Id: I1336c4cc1df39fa81599487a3b0626aaa2bffd8f
2019-05-10 22:35:30 -07:00
TreeHugger Robot
89ed22cf08 Merge "Remove temporary UserUsageStatsService logging" into qt-dev 2019-05-10 20:14:54 +00:00
Varun Shah
33a3a401f8 Merge "Add a dumpsys for UsageStatsDatabase info." into qt-dev am: 88f46c6cd6
am: b16ab3b9e1

Change-Id: I6097f30aa4ffd19065392cd59b7a99aab2fcf115
2019-05-10 04:31:30 -07:00
TreeHugger Robot
88f46c6cd6 Merge "Add a dumpsys for UsageStatsDatabase info." into qt-dev 2019-05-10 00:44:34 +00:00
Varun Shah
b5997f8e8b Merge "Remove sanity check in UsageStatsDatabase." into qt-dev am: 973ec50c27
am: eedf868716

Change-Id: I95d0e7f30a9c90bfd495bbfe6a55ba8ef89c2dd9
2019-05-09 15:10:32 -07:00
Michael Wachenschwanz
f9cbd67a7d Remove temporary UserUsageStatsService logging
Fixes: 115998347
Test: builds and flashes
Change-Id: I538480fb7ce00195138b772c56a90cef9ec5f73e
2019-05-09 14:34:37 -07:00
Varun Shah
dbdee14bba Remove sanity check in UsageStatsDatabase.
Also update debug variables to default ones.

Bug: 115429334
Bug: 111422946
Test: builds and flashes
Change-Id: I10d53b3960eb579d61388791488290354ba446d5
2019-05-08 19:14:55 -07:00
Varun Shah
5bef1bedf2 Add a dumpsys for UsageStatsDatabase info.
'dumpsys usagestats file [user] [interval] [filename]' added.
When all options are specified, this command dumps all usage stats
information stored in the specified filename.
If the filename is not specified, information of all files for the
specified interval is dumped.
If the interval is not specified, information of all files in all of the
intervals for the specified user is dumped.
If the user is not specified, information for all users is dumped.

Also added 'dumpsys usagestats database-info [user]'. This simply
connects the existing dump in UsageStatsDatabase.
If the user is not specified, information for all users is dumped.

Bug: 131923219
Test: various combinations of the dumpsys command added
Change-Id: Id2c2b20e07f9ab0e1a577e45fba199d565532b7b
2019-05-08 15:51:12 -07:00
Michael Wachenschwanz
6d2d509c6e Merge "Elevate standby bucket on first foreground service start" into qt-dev am: 8189440785
am: 9ddd631f9a

Change-Id: I8e81ee304dc0b2f6a49cb6add77874174a247c6a
2019-05-02 18:37:06 -07:00
Michael Wachenschwanz
6ced0ee15a Elevate standby bucket on first foreground service start
If an app is in the NEVER standby bucket, a foreground service start
will bring the app up to the ACTIVE bucket for 30 min (by default).
Foreground service starts in other circumstances will not affect the
standby bucket

Bug: 111578623
Test: atest AppStandbyControllerTests#testInitialForegroundServiceTimeout

Change-Id: Ia9d5fd7a04d2378a5525457d465da7ed463fe8fc
2019-04-16 14:00:37 -07:00
Hui Yu
cf268275fc Merge "Do not print exception and stack trace." 2019-04-04 18:34:54 +00:00
Hui Yu
6849f9a691 Do not print exception and stack trace.
When upgrading a device from P build to Q build, since mInstanceId,
majorVersion, minorVersion are newly added fields in Q build, P version
XML file does not have this fields and Q build will get
java.net.ProtocolException and these newly fields are assigned default
value. This is normal during upgrade process. There is no need to
printout the exception and stack trace because that would confuse
people.

Bug: 127451110
Test: NA.
Change-Id: I0fb38a68d7f049b7f417c9ca444db61c4e5c3657
2019-04-03 15:10:25 -07:00
TreeHugger Robot
005984015c Merge "Minor fixes to IntervalStats" 2019-03-27 19:41:11 +00:00
Michael Wachenschwanz
bfbe71e104 Minor fixes to IntervalStats
Close hole in IntervalStats time tracking.
Fix EventTracker commitTime math
Also make eventList final

Fixes: 124850206
Test: builds and runs

Change-Id: I967cd4b3f5ccea0f7f8fd7e8729f258a5f8f1981
2019-03-19 03:00:28 +00:00
Varun Shah
4f76a1e091 Update #registerAppUsageLimitObserver to take time used.
Update the time remaining parameter of #registerAppUsageLimitObserver to
time used to avoid confusion between time limit and time remaining.

Bug: 128414428
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: Ied8e4ca0b8636bb9efc4d85dcae46ac6cf1ef5f7
2019-03-12 11:46:10 -07:00
Hui Yu
041b3ebe56 Merge "Add new UsageStats event DEVICE_STARTUP" 2019-03-11 17:37:59 +00:00
Hui Yu
80a8b4678d Add new UsageStats event DEVICE_STARTUP
As a counterpart to DEVICE_SHUTDOWN event, DEVICE_STARTUP records the
device startup event and timestamp.

Bug: 126529272
Test: adb shell dumpsys usagestats | grep DEVICE
Change-Id: Ia977658f9a1f701ad802dc943e9eff71171e9957
2019-03-07 15:00:43 -08:00
Michael Wachenschwanz
08a517e2a9 Merge "Persist Standby Buckets after System defaults set" 2019-03-07 02:07:33 +00:00
TreeHugger Robot
5ee812a499 Merge "Update #registerAppUsageLimitObserver to accept time remaining." 2019-03-04 23:00:22 +00:00
Varun Shah
9f58b7c007 Update #registerAppUsageLimitObserver to accept time remaining.
UsageStatsManager#registerAppUsageLimitObserver now accepts the time
remaining in addition to the total time limit.

The API now also uses java.time.Duration instead of long+TimeUnit for
the total time and remaining time.

Bug: 124272203
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: I6f85ca9295cad46e10a30035b67e6210ae5c1886
2019-03-04 19:06:32 +00:00
TreeHugger Robot
19373c1600 Merge "Usagestats dumpsys print list of usagestats database files." 2019-03-02 02:27:38 +00:00
Michael Wachenschwanz
d1d8aa66b3 Persist Standby Buckets after System defaults set
Also repair defaults if persisted file is missing on boot.

Fixes: 123206562
Test: manual ("adb shell reboot" within 20 min of a fresh wipe
              "adb shell dumpsys usagestats"
	      System apps bucket levels equal 10)

Change-Id: I0403099c899d181ef6206cc9f5516c25213edc9c
2019-02-28 16:45:42 -08:00
Michael Wachenschwanz
17c7c791f5 Merge "Promote apps in the NEVER bucket on sync scheduled" 2019-02-28 22:52:02 +00:00
Hui Yu
0818df080a Usagestats dumpsys print list of usagestats database files.
Print total number and list of daily/weekly/monthly/yearly files, so
we can tell if excessive number of files are created.

Bug: 125426689
Test: "adb shell dumpsys usagestats" and search for UsageStatsDatabase
Change-Id: Id5c6028151d4c21e019820f7b6070712283f4983
2019-02-26 11:06:49 -08:00
Michael Wachenschwanz
c329520a99 Promote apps in the NEVER bucket on sync scheduled
Fixes: 124510195
Test: atest CtsSyncManagerTest
Change-Id: Ia6f3a60f7073c646a900799d8e5cda144654fa83
2019-02-22 22:49:54 -08:00
Hui Yu
f6118b3d17 Remove extra null-check on IntervalStats.events.
Now IntervalStats.events field is initialized at construction of
IntervalStats object, we can remove the extra null-check on
IntervalStats.events, make code more clean and readable.

Test: atest UsageStatsDatabaseTest.java
Change-Id: I2580509f41593c1fdf380ba56ebc7a5b6c6f0c5f
2019-02-20 18:10:29 -08:00
TreeHugger Robot
ff5d286d09 Merge "UsageStats creates too many daily/weekly/monthly/yearly files." 2019-02-21 01:45:37 +00:00
Hui Yu
b21d59f283 UsageStats creates too many daily/weekly/monthly/yearly files.
A wrong condition causes new sets of daily/weekly/monthly/yearly files
been created before it reaches the rollover time.

Currently database files are pruned by timestamp, it allows 3 years
yearly files, 6 months monthly files, 4 weeks weekly files, 10 days
daily files. Because the bug there could be unlimited number of files
are created as long as files' timestamp falls in these allowed time
spans.

Add a logic to prune files by number of files. Only allow up to 10 yearly
files, 12 monthly files, 50 weekly files, 100 daily files.

Change-Id: Iac42f70ae19edb48885a123dfd9988021de6c88d
Fix: b/122725555
Test: NA.
2019-02-20 21:15:39 +00:00
Michael Wachenschwanz
08be74fa54 Populate null UsageStats event task root fields with known data
It is possible for an activity's task root to be reported as null to
UsageStats during a destry. Use past known data to populate the fields.

Change-Id: Id20c809580e854ca9075444957bd10a338087e3d
Fixes: 123404490
Test: atest cts/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java#testSuddenDestroy
2019-02-15 14:44:48 -08:00
TreeHugger Robot
e3e704846f Merge "Allow registration of AppUsageLimitObservers with 0 time limit." 2019-02-11 20:28:52 +00:00
Varun Shah
54f7f7f903 Allow registration of AppUsageLimitObservers with 0 time limit.
A wellbeing app can now register AppUsageLimit observers with a time
limit of 0 seconds. There will be no callback intent fired in this case.

Bug: 123899673
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests#testAppUsageLimitObserver_ZeroTimeLimitIsAllowed
Test: atest android.content.pm.cts.LauncherAppsTest#testGetAppUsageLimit_allowsZeroLimit
Change-Id: I9cdff21bcfa72f202699cea288e703f35a4f158f
2019-02-08 11:42:45 -08:00
Michael Wachenschwanz
b541f3c5d3 Merge "Only start tracking usage on first activity resume" 2019-02-06 23:47:15 +00:00
TreeHugger Robot
729bf1cf17 Merge "Create a default package name for device level events." 2019-02-04 22:20:19 +00:00
Varun Shah
9c6f72bae3 Removed AppUsageLimit#isGroupLimit API.
Bug: 123354775
Test: atest FrameworksServicesTests:AppTimeLimitControllerTests
Change-Id: I7082aaac0071be8d5bc444c6f8521576bf513cff
2019-01-25 21:13:56 -08:00
Hui Yu
e497ad26c8 Create a default package name for device level events.
Device level event like DEVICE_SHUTDOWN does not have package name,
but some user code always expect a non-null packageName for every event.
Create a default packageName for these device level events.

Change-Id: Iee49794bdc6f5cb7b30d50f7421ac0de2a33c858
Fix: b/123429960
Test: NA.
2019-01-25 15:54:57 -08:00
Varun Shah
2546cef56c Added APIs for App Usage Limits.
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
2019-01-23 20:30:25 -08:00
Michael Wachenschwanz
c790a29689 Only start tracking usage on first activity resume
Fixes: 122937104
Test: manual (open two apps in splitscreen and bring each into focus
multiple times, close both apps, check "adb shell dumpsys usagestats
apptimelimit")

Change-Id: I3ea30d55291d37d156cb3573074ada7f9ed18171
2019-01-23 18:02:12 +00:00
Michael Wachenschwanz
0b4ab1f171 Add Task Root package info to UsageEvent
Bug: 113094946
Test: manual (use "adb shell dumpsys usagestats apptimelimit" to verify
apps at the root of tasks are considered active)
Test: atest cts/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java#testTaskRootEventField
Test: atest cts/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java#testUsageSourceAttribution
Test: atest UsageStatsDatabaseTest

Change-Id: I40f86743d33c13892de0e59ae02c9ebddb606ee7
2019-01-22 22:19:21 -08:00
Hui Yu
b1d243a51b UsageStats DEVICE_SHUTDOWN event.
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
2019-01-16 11:13:58 -08:00
Michael Wachenschwanz
266dd3bfd7 Merge "Add Usage Reporting Api to UsageStatsManager" 2019-01-08 06:50:24 +00:00
Michael Wachenschwanz
36778525ba Add Usage Reporting Api to UsageStatsManager
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
2019-01-07 14:56:06 -08:00
Hui Yu
63c0ad4dbb Reduce UsageStatsXmlV1 log messages.
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
2018-12-17 10:13:17 -08:00
Hui Yu
03d1240ef3 UsageStats tracking of screen usage.
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
2018-12-12 10:07:14 -08:00