325 Commits

Author SHA1 Message Date
sqian
22f5749ccc Make getPackagesWithPriviligesForAllActiveSubscriptions system API
Test: build
Bug: 145550382
Change-Id: Ia7efb9e4b22b24f3c87c7cd631548c7254b28926
Merged-In: Ia7efb9e4b22b24f3c87c7cd631548c7254b28926
(cherry picked from commit 6f27c5769d8c5b5c76d143f590a8c4d1c5d8ccee)
2019-12-06 12:07:57 -08: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
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
TreeHugger Robot
89ed22cf08 Merge "Remove temporary UserUsageStatsService logging" into qt-dev 2019-05-10 20:14:54 +00:00
TreeHugger Robot
88f46c6cd6 Merge "Add a dumpsys for UsageStatsDatabase info." into qt-dev 2019-05-10 00:44:34 +00: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
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
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
TreeHugger Robot
1ca78d6198 Merge "Catch IOException when failed to parse new fields." 2018-11-27 01:00:35 +00:00
Hui Yu
746b82aa9d Catch IOException when failed to parse new fields.
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
2018-11-26 22:40:43 +00:00
Hui Yu
7e5bf5c54f Do not update AppStandbyController on foreground service events
Change-Id: I3ce067c9e7aae50aaf9784f1a63618c6cbaea2cc
Fix: 119781710
Test: atest HostsideRestrictBackgroundNetworkTests#testAppIdleMetered_enabled
2018-11-26 11:14:40 -08:00
Esteban Talavera
917a71d4f9 Expand notification generates USER_INTERACTION event
Bug: 118376048
Test: runtest systemui-notification
Change-Id: Idbfac239783aa6371bdef4127125f30c27b74e3d
2018-11-15 10:46:08 +00:00
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