Commit Graph

384 Commits

Author SHA1 Message Date
Sudheer Shanka
77f2a2c3dd Merge "Update BlobStoreMS to augment storage stats with blobs data." 2020-02-21 19:28:09 +00:00
TreeHugger Robot
5025c2ab69 Merge "Disable storage crates functionalities" 2020-02-20 05:00:47 +00:00
Sudheer Shanka
e9232d6d6f Update BlobStoreMS to augment storage stats with blobs data.
- Any pending sessions data is attributed to the apps
  which contributed them.
- Any commited blobs data is attributed to the app which
  has a lease on it. If multiple apps have lease on a blob, don't
  attribute the blob to those apps for now.
- Remove StorageStatsAugmenter.augmentStatsForUser as it
  is not used for anything currently.
- Fix an issue in how we override existing committers and leasees.

Bug: 148694869
Test: atest cts/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
Test: atest tests/tests/os/src/android/os/storage/cts/StorageStatsManagerTest.java
Test: atest hostsidetests/appsecurity/src/android/appsecurity/cts/StorageHostTest.java
Test: manual
Change-Id: Ia4af0a2549c75db66741f2d1979de95d2d150bc8
2020-02-19 14:45:12 -08:00
Sudheer Shanka
b497dd4045 Allow usagestats for multiple pkgs to be dumped.
+ Skip dumping database summaries when dumping data for specific pkgs.

Bug: 145420790
Test: manual
Change-Id: If4ac1008ffc73ad4b3227c0a407323b43547a6b8
2020-02-18 18:59:59 +00:00
Varun Shah
0cbb6b63ee Obfuscate visibility of notification-related events.
UsageStats will return obfuscated NOTIFICATION_SEEN or
NOTIFICATION_INTERRUPTION events to callers of #queryEvents
and #queryEventsForUser if they don't hold the MANAGE_NOTIFICATIONS
permission.

Additionaly, refactor the query API in UsageStats to take in flags as
defined in UsageEvents to make future obfuscation/visibility parameters
cleaner.

Also, add the MANAGE_NOTIFICATIONS permission to shell for CTS test.

Bug: 144724524
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest
Test: atest android.content.pm.cts.shortcutmanager.ShortcutManagerUsageTest
Change-Id: I118de7e589ac8dd5924d3740c70903fa484b79b5
2020-02-13 12:01:13 -08:00
Yuliya Kamatkova
4d5b0be481 Merge "Restrict visibility of LOCUS_ID_SET events." 2020-02-13 01:05:09 +00:00
Yuliya Kamatkova
fea62a512b Restrict visibility of LOCUS_ID_SET events.
UsageStats will not return LOCUS_ID_SET events to callers
of #queryEvents and #queryEventsForUser if they don't have visibility.

Bug: 148821246
Test: manual, atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest
Change-Id: Ic904a97e66775ef63bc8b84e67e8f430b2a4121b
2020-02-12 11:20:22 -08:00
Felka Chang
1980c9a893 Disable storage crates functionalities
The Storage Crates functionalities is disabled by default. In order to
make the android system more secure, the crate function should throw
exception to tell the caller that the crate function is disabled until
it addes more tests such as benchmark and memory regression tests.

Bug: 148179319
Fixes: 149366046
Test: atest \
         CtsOsTestCases:android.os.storage.cts.StorageCrateTest \
         CtsOsTestCases:android.os.storage.cts.StorageStatsManagerTest \
         CtsOsTestCases:android.os.storage.cts.CrateInfoTest
Test: adb root ;\
      adb shell setprop fw.storage_crates 1 ;\
      atest \
        CtsOsTestCases:android.os.storage.cts.StorageCrateTest \
        CtsOsTestCases:android.os.storage.cts.StorageStatsManagerTest \
        CtsOsTestCases:android.os.storage.cts.CrateInfoTest
Change-Id: I7bfbdcbde5a90ecad7ef690a9d9a62e5ed0ad5eb
2020-02-12 17:15:26 +08:00
Varun Shah
96000b20cd Fix UsageStats dump NPEs.
Update the dump method to handle locked users properly.

Fixes: 149019903
Test: manual (adb shell dumpsys usagestats)
Change-Id: I86e7cfe01bb485f2125c84e6f1013e20b5ac9ba4
2020-02-11 11:22:56 -08:00
Danning Chen
001eb8f4d9 Update the method signature for queryEventsForUser()
Change-Id: I9ed16e6164493915dba48366249c61dc49214e5a
Test: atest com.android.server.people.data.DataManagerTest
Bug: 148627336
2020-01-31 09:40:30 -08:00
Varun Shah
01f6f26b54 Restrict visibility of SHORTCUT_INVOCATION events.
UsageStats will not return SHORTCUT_INVOCATION events to callers
of #queryEvents and #queryEventsForUser if they don't have visibility,
as defined by ShortcutService#hasShortcutHostPermission.

Also, add ACCESS_SHORTCUT permission to shell for CTS test and add the
ShortcutManagerUsageTest to postsubmit.

Bug: 145549490
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest android.content.pm.cts.shortcutmanager.ShortcutManagerUsageTest
Change-Id: I2a69f061c35c31035a5d0381ab2f42029ec4fffc
2020-01-29 11:28:22 -08:00
Yuliya Kamatkova
56f7c7f37c Merge "Add Activity#setLocusContext API. Plumb LocusID to the System Server. Add locus update event to the Usage Stats. Test: Build and run on a test device with a test app. Bug: 147594233, 147100454" 2020-01-24 21:10:54 +00:00
Yuliya Kamatkova
48c38076ef Add Activity#setLocusContext API. Plumb LocusID to the System Server.
Add locus update event to the Usage Stats.
Test: Build and run on a test device with a test app.
Bug: 147594233, 147100454

Change-Id: I1e058ac87244d47719606d8dcfaea2df4bff43d2
Signed-off-by: Yuliya Kamatkova <yuliyak@google.com>
2020-01-24 11:19:10 -08:00
Sudheer Shanka
31961ce780 Update references of "DONT_DELETE_DATA" to "DELETE_KEEP_DATA".
The flag PackageManager.DONT_DELETE_DATA was renamed to DELETE_KEEP_DATA
long ago in commit 7767eac.

Bug: 28343859
Test: n/a
Change-Id: I9e4079ec394f92a3e293df7b80b627e2b6130827
2020-01-22 20:56:31 -08:00
Sudheer Shanka
e479c958b5 Merge "Add internal APIs for system services to augment storage stats." 2020-01-16 23:15:58 +00:00
Sudheer Shanka
18d3798328 Add internal APIs for system services to augment storage stats.
Bug: 142808097
Test: n/a (tests will be added along with the client impl)
Change-Id: Iba2330d67a29ccfab95ce65daf85312beff5ecf3
2020-01-16 23:12:30 +00:00
Danning Chen
6a5982f300 Add a new method queryEventsForUser() to UsageStatsManagerInternal for People Service to call
Change-Id: I4baf755a3dc1af421ea755ed2f4cfe3440741290
Test: Build and run on a test device
Bug: 146522621
2020-01-14 16:21:57 -08:00
Kweku Adams
c4ee998be8 Move setAppStandby logic inside AppStandbyController.
Since we've moved AppStandbyController inside the JobScheduler mainline
module boundary, we need to move the logic of setAppStandby over so that
it's consistent for callers and easy to do the right thing.

Bug: 137763703
Bug: 145551233
Test: atest AppIdleHistoryTests
Test: atest AppStandbyControllerTests
Test: atest UsageStatsTest
Change-Id: Ie2ccb0508c3a3887ab3debc47e78427477d2d77b
2020-01-09 12:33:44 -08:00
Felka Chang
71e3efed54 Add query functionalities to query all of crates
Once the application called Context.getCrateDir(), the crates root
directory is also created. The application can mkdir directory under the
crates root. Each child directory in crates root is one crate.

Each crate information is descibed by CrateInfo. CrateInfo contains
the following information.
* Label:
    It is used to display text to the users.
    Default is the folder name.
* Expiration:
    When the system needs more space. The system will clean the files
    in the crates according to the expired or not.
    Default is 0.

Test: atest \
    CtsOsTestCases:android.os.storage.cts.CrateInfoTest \
    CtsOsTestCases:android.os.storage.cts.StorageCrateTest \
    CtsOsTestCases:android.os.storage.cts.StorageStatsManagerTest

Bug: 141660526

Change-Id: Icdc8123c481ef7c5b4fd68ffcfd334ffbfc9d655
2019-12-18 23:04:15 +08:00
TreeHugger Robot
c10004fe32 Merge "Ensure UsageStats data is read correctly." 2019-12-10 19:58:51 +00:00
TreeHugger Robot
a281d69a39 Merge "Better error handling in UsageStats." 2019-12-09 18:00:46 +00:00
Varun Shah
6b993a7408 Ensure UsageStats data is read correctly.
Add documentation that the IntervalStats object passed into the read
methods in UsageStatsDatabase should ideally be used only as a temporary
reading object unless the caller specifically has other use-cases. Also
updated all the internal calls to match this behavior.

Bug: n/a
Test: atest UsageStatsDatabaseTest
Change-Id: Id3aa2575fa29bf5adc6a52ee8e75690aecf50b8e
2019-12-06 17:26:41 -08:00
Varun Shah
55ae881649 Better error handling in UsageStats.
Ensure all types of exceptions are caught and logged/handled within
UsageStats.

Also update how read failures for pending events files are handled -
since the entire System DE directory is deleted on a successful user
unlock, read all the pending events that you can and skip over
potentially corrupted files.

Bug: 145574371
Test: atest UsageStatsDatabaseTest
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: I2e22fb01f9b97961b2160aeebaf7791d6673f8b9
2019-12-06 16:08:04 -08:00
Jeffrey Huang
cb78285b81 Rename writeToProto to be dumpDebug
We want to eventually migrate some of these APIs to be @SystemApi for mainline modules.
The #dumpDebug name is more appropriate than #writeToProto.

Bug: 142279786
Test: Manual
Change-Id: I60793e91cedf6b720d4ecef6a8484f4fed4ff30f
2019-12-05 11:28:11 -08:00
TreeHugger Robot
1403ee3ad5 Merge "Prune UsageStats data belonging to uninstalled packages." 2019-12-05 00:14:43 +00:00
Varun Shah
2c0b9f5d78 Prune UsageStats data belonging to uninstalled packages.
Add a per-user job to prune any usage stats data which belongs to a
recently removed package. This job will be scheduled when a package is
removed and it will be executed when the device is considered to be
idle. The jobs are persisted by job scheduler and they are also removed
when a user is removed since all usage stats data is deleted on user
removal.

When executed, the job reads all of the stats on disk and removes those
that belong to removed packages (packages which don't have a token
mapping). If no data is ommitted on read, a write is not performed. If
the user is in a locked state when the job is executed, the job will
keep getting rescheduled until a sucessful pruning of the data.

Additionally, add logic to prune any obsolete usage stats data on a
database upgrade, pruning all data belonging to packages which have
been uninstalled. This ensures that all data in UsageStats in R belongs
to packages that are currently installed or to packages whose
DONT_DELETE_DATA flag was set when uninstalling.

Also remove the clean-up mappings step on boot. That was added as a
safety measure to ensure the mappings file is always updated. However,
with the logic to prune on upgrade and on package uninstalls, that step
is now unnecessary.

This CL also refactors how the UserUsageStatsService is fetched and
initialized within UsageStatsService. This is to ensure there is no lock
contention when the user service is initialized and it also makes way
for other refactorings in the future related to the user service
initialization.

Bug: 143889121
Test: atest UsageStatsDatabaseTest
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: If475fc018a930d0956b85a64b4e34e2c75b2476f
2019-12-02 17:07:16 -08:00
Kweku Adams
835283f000 Adding temp whitelist methods to PowerWhitelistManager interface.
Migrating temp whitelist APIs to PowerWhitelistManager to allow
telephony to add apps to the temp whitelist.

Bug: 138239060
Bug: 140141678
Bug: 141155196
Bug: 142420609
Bug: 144864180
Test: atest PowerWhitelistTest
Change-Id: Iefd6ecf89aad46de042ef3a1ec0c20d6c35da5a6
2019-11-26 11:07:29 -08:00
Varun Shah
8958d5d0bc Remove UserUsageStatsService#userUnlocked.
UsageStatsDatabase#init was being called twice every time - once when
the usage stats service was initialized and once when the user was
unlocked. However, this was unnecessary and doing duplicate work since
on user unlock, when the service is initialized, the database is also
initialized.

Bug: n/a
Test: atest UsageStatsTest
Change-Id: Ic74ba3ff8a0b68c97340ffe25b19065e1a046731
2019-11-22 16:14:24 -08:00
Varun Shah
ff671494e5 Merge "Fix UsageStats begin and end timestamp bug." 2019-11-05 00:37:47 +00:00
Varun Shah
08d81706b9 Fix UsageStats begin and end timestamp bug.
UsageStatsProtoV2 was not correctly assigning the begin and end
timestamps when reading data from disk. Correctly update the timestamps
when all data has been read from disk.

Bug: 143558600
Bug: 143472799
Test: atest android.app.usage.cts.UsageStatsTest#testPackageUsageStatsIntervals
Test: atest UsageStatsRestoreHostSideTest
Change-Id: Ib436e661744ea82429ee3fb679a16a6e26697050
2019-11-02 11:57:47 -07:00
Hui Yu
a86a36b184 Merge "Add process capability as a new dimension." 2019-10-31 23:11:21 +00:00
Hui Yu
2696932100 Add process capability as a new dimension.
Add new attribute capability to ProcessRecord, it represents what this
process is allowed to do. Capability is a separate dimension for
process state (ProcState).

In OomAdjuster.java, capabilities can be passed from client to service.

Add PROCESS_CAPABILITY_FOREGROUND_LOCATION to represent the capability
that can access location while-in-use.

For permission such as foreground location access, AppOpsService
checks for FOREGROUND_LOCATION capability, also checks if the process
is in one of the foreground process states, if both conditions meet,
the locaton operation is allowed.

Remove PROCESS_STATE_FOREGROUND_SERVICE_LOCATION.

Bug: 136274596
Test: atest CtsAppTestCases:ActivityManagerProcessStateTest
atest CtsAppTestCases:ActivityManagerApi29Test
atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
Change-Id: Ie1c8e670fb0789208b753eb49b7e2fce6a2f211f
2019-10-30 18:23:24 -07:00
TreeHugger Robot
ec2b60ef29 Merge "Add TEST_MAPPING for UsageStats." 2019-10-29 17:49:34 +00:00
Varun Shah
31d134630c Add TEST_MAPPING for UsageStats.
All tests under the packages android.app.usage and
com.android.server.usage (except StorageStatsServiceTest) will now run
in presubmit.
Also added UsageStatsTest CTS to postsubmit.

Bug: 143221092
Test: services/usage/java/com/android/server/usage/ atest
Change-Id: Ibac2b7d5a4f47f354e9190ff6df3aa16002f92f9
2019-10-29 09:34:19 -07:00
Varun Shah
69a85b9733 Merge "Remove XML write functions from UsageStats." 2019-10-28 18:03:52 +00:00
Christopher Tate
b909c4d55a Move UsageStatsManagerInternal to services.jar
UsageStatsManagerInternal is also no longer an API surface for
registration of app idle state change listeners.  AppStandbyInternal has
become a proper LocalService and interested clients can just use that
directly.

Bug: 140833849
Test: boot & run normally
Test: verify system package backup
Change-Id: Ie63f438f129cd8f41169778a3045d131ca7322fb
2019-10-24 18:28:52 +00:00
TreeHugger Robot
341f421e23 Merge "Remove logs related to UsageStats string cache." 2019-10-23 22:18:01 +00:00
Hui Yu
f7ca889268 Better timestamp for shutdown and startup events.
Fix the bug that during android P to Q upgrade, DEVICE_SHUTDOWN
event mistakenly gets a newer timestamp than DEVICE_STARTUP event.

Bug: 139656029
Test: flash the device with android P, then upgrade to android Q,
then "adb shell dumpsys usagestats", observe DEVICE_SHUTDOWN
is before DEVICE_STARTUP.

Change-Id: I5429fe7648529be8379270adefd26bd98a31357c
2019-10-23 17:58:47 +00:00
Varun Shah
690d7798a0 Remove logs related to UsageStats string cache.
Since UsageStatsProto is not being used anymore other than for
backup/restore, there is no string cache (string pool) maintained in
memory. Because of this, there are a bunch of warnings being logged
every time usage stats data is backed up. Remove these logs since they
are simply noise now.

Bug: 143184490
Test: atest UsageStatsDatabase (no warnings seen during backup test)
Change-Id: Ibb0a053e51124087f44231f5fddf3d41f7e345d2
2019-10-22 22:21:28 -07:00
Varun Shah
21c82c3ebd Remove XML write functions from UsageStats.
UsageStats has moved away from XML and is now using protos. This removes
dead XML write functions which should ideally never be triggered. A
warning will be logged when reading XML data and a WTF when some
codepath attempts to write data in XML.

Certain tests are now marked as ignored since the XML write functions are
removed. It was decided to not move those functions into the test context
since the read/write code is so intertwined within the database logic.

Bug: 143187610
Test: atest UsageStatsDatabaseTest
Change-Id: If622b646e0edfe389e49aec9b51accdb9fbf1f45
2019-10-22 21:42:32 -07:00
TreeHugger Robot
5df072b6ae Merge changes from topic "usagestats-obfuscation"
* changes:
  Do not retain UsageStats for uninstalled packages.
  Catch exceptions in UsageStatsService on bad data.
  Obfuscate usage stats data stored on disk.
2019-10-21 17:53:38 +00:00
Varun Shah
23033b0046 Do not retain UsageStats for uninstalled packages.
When packages are removed, remove their associated token mappings in the
packages token data stored in UsageStats. When data is being persisted
to disk, the data for removed packages will not be written to disk.
Additionally, when any of the query APIs are called, data that is read
from disk for which a mapping does not exist will not be returned.

The data deletion uses a lazy techinque to avoid heavy costs of reading
and writing all of the usage stats data on every package removal.

Bug: 135484470
Test: atest IntervalStatsTests
Test: atest UsageStatsDatabaseTest
Change-Id: Ie32d65b47f86071c6a814a8b21e4be060519e598
2019-10-17 18:11:37 -07:00
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
358d500623 Catch exceptions in UsageStatsService on bad data.
Instead of throwing exceptions from UsageStatsService and potentially
crashing the system server, catch exception on reading/writing bad data
and log the exception.

Also ensure proper handling of deobfuscating bad data.

Bug: 140459061
Bug: 135484470
Test: atest IntervalStatsTests
Test: atest UsageStatsDatabaseTest
Change-Id: I17d6ad5e377a2636ff42c9b422fe6ddf1201fc08
2019-10-08 21:24:15 -07:00
Varun Shah
e1ba9cde53 Obfuscate usage stats data stored on disk.
All of the usage stats data stored on disk will now be obfuscated. There
will be a package to tokens mappings file stored on disk which has a
hierarchy of mappings for each string in each package's usage stats
data. A UsageStatsProtoV2 was added to keep the logic clean and separate
from the original usage stats proto parser.

Initial observations show a memory gain of over 60% w.r.t. the usage
stats data size on disk. There is also no performance hit because of this
change - in fact, even with the obfuscation overhead, reads are now over
65% faster and writes are up to 50% faster.

Bug: 135484470
Test: atest UsageStatsTest
Test: atest UsageStatsDatabaseTest
Test: atest UsageStatsDatabasePerfTest
Change-Id: I55ce729033d8b6e4051271802d57c72684053c32
2019-10-08 21:22:13 -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