Commit Graph

340 Commits

Author SHA1 Message Date
Kweku Adams
df33ae1b0b Removing periodic parole window.
The periodic parole window is the 10 minute window that occurs every
24 hours to let RARE apps run. Now that we have the quota system in
place, there's no need to have the periodic parole window. Alarms and
jobs will still be allowed to run when charging. Network will continue
to be restricted for RARE apps even when charging. JobScheduler requests
an exception for RARE jobs in quota, so they will still be able to run.

Bug: 136184981
Test: atest AppStandbyControllerTests
Test: atest CtsAlarmManagerTestCases
Test: atest NetworkPolicyManagerServiceTest
Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Test: atest com.android.server.AlarmManagerServiceTest
Test: atest com.android.server.AppStateTrackerTest
Test: atest com.android.server.job.controllers.QuotaControllerTest
Test: atest com.android.server.net.ConnOnActivityStartTest
Change-Id: Ide382ad7fb9c7441f0a5232833ad39bf8c3a1e94
2019-10-16 13:04:06 -07:00
Varun Shah
b5ceeaf629 Merge "Allow the supervision app to access certain UsageStats APIs." 2019-10-09 03:24:13 +00:00
Varun Shah
b472b8f281 Allow the supervision app to access certain UsageStats APIs.
Allow the active supervision component to access app usage limit APIs.
This includes #registerAppUsageLimitObserver
and #unregisterAppUsageLimitObserver.

Bug: 138681869
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest#testIsActiveSupervisor
Test: atest AppTimeLimitControllerTests
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: I3daafc14ccdbf27558c1325b965f2bc6d2dab2f6
2019-10-08 11:45:38 -07:00
Makoto Onuki
a72e04fcd9 MoveAppStandbyController to the jobscheduler module
Bug: 137763703
Test: boot
Test: atest AppStandbyControllerTests
Change-Id: I03799c976f6c8b3e775a1a6321885a9cb069a0a0
2019-10-03 15:41:26 -07:00
Varun Shah
535202d9f0 Fix NPE in Usage Stats.
Due to the recent migration to CE, some async calls were being triggered
after the user was removed. Most places were already handled by a
previous CL - this is just another minor fix.

Bug: 141979865
Test: builds and flashes
Change-Id: I059180cb99d04ac266b3e4745f141c285e189314
2019-10-02 13:54:42 -07:00
Varun Shah
77431b8698 Handle async behavior with CE in UsageStats.
With the migration of usage stats data to CE, it's possible for a user
unlock event to be handled after the user has been removed. To prevent
exceptions from being thrown when the user is stopped or removed, when
an exception is thrown, check if the user is unlocked, only then throw
the exception.

Bug: 141307758
Test: atest CtsDevicePolicyManagerTestCases
Change-Id: I70fdb56dd6e87dc911c400554a4b5760785b87a4
2019-09-23 11:26:42 -07:00
Varun Shah
5e1613ef64 Update UsageStats#checkAndGetTimeLocked behavior.
The time change event was happening for every user even if they were not
unlocked, causing UsageStatsService to crash. Since the data is now
located in CE, the #checkAndGetTimeLocked function has been moved to
UserUsageStatsService, tying time change events to each user instead of
UsageStatsService. This gives the guarantee that no usage stats data
will be accessed or modified if the user service is not existent while
keeping the same behavior as earlier.

References to #checkAndGetTimeLocked in UsageStatsService have been
updated to call System.currentTimeMillis() directly.

Bug: 140529704
Test: atest UsageStatsTest
Test: atest UsageStatsDatabaseTest
Change-Id: I746790f3918b927ac8ac76ee860c94cac603e5da
2019-09-05 17:03:36 -07:00
Varun Shah
3a31520250 Move usage stats data to credential encrypted storage.
Move all of the usage stats data from the regular system storage to
the system CE (credential encrypted) storage.

All events being reported while the user is locked will be stored
in memory and will be processed via the handler after the user is
unlocked. All of these events reported will regularly be persisted to
system DE storage to ensure important events are not lost.
Any query requests will be ignored while the user is locked.

Two new usage events have been added: one to indicate the user has been
unlocked and the other to indicate the user has been stopped.

Also updated documentation for APIs in UsageStatsManager to reflect the
new behavior in R when the user is locked.

Bug: 135484470
Test: atest android.app.usage.UsageStatsTest#testDataIsInCe
Test: atest android.app.usage.cts.UsageStatsTest#testUserUnlockedEventExists
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest UsageStatsDatabaseTest
Change-Id: I18da1a9354b6686472972c5f2304e4c19e28307f
2019-08-30 10:44:22 -07:00
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