Relocated MOVE_TO_FOREGROUND so that it will get logged for Activity
Paused to Activity Resumed transitions.
Also moved some calls into PackageManager outside of the UsageStats lock
Bug: 159165822
Test: builds and flashes
Change-Id: I8e9e96ae1fc3b77535514df2422ce3b7935d850f
Do not update package mappings for the system user when the user is
first unlocked. Instead, schedule a job to be executed after 24 to 48
hours from when the system user is unlocked. This makes the service
initialization phase for the system user a little quicker since their
data is not likely to be stale. Additionally, this also ensures that
restored data is not pruned by mistake if there is a device restart
before restore is completed. The updating of the mappings occurs
normally for other users, on user service initialization.
Bug: 155209652
Test: manually ensure job is skipped for system user
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: I2c03a1a05246d6b454569c4569813e90bede3693
In the case that the DevicePolicyManagerInternal Local service does not
exist on device, the permission check for
(un)registerAppUsageLimitObserver should not be skipped.
Test: atest android.app.usage.cts.UsageStatsTest (must be on a device
with <unavailable-feature name="android.software.device_admin" /> in
it's features xml)
Fixes: 155360727
Change-Id: I8a88e03a7636956d27f531cf989bda1a32799f07
Currently, we are only using UsageStatsProto for backup and restore
purposes but to ensure it is in sync with UsageStatsProtoV2, adding the
recently added LOCUS_ID event. This enables us to easily fall back to
the earlier proto version if there are issues with V2. This also allows
us to backup all events data if we decide to do that in the future
before updating the B&R restore logic to use V2.
Bug: 155935953
Test: atest UsageStatsDatabaseTest
Change-Id: I792f20a0b44d13f1ed17c4dbebe5555044afa165
This fixes a bug where in-memory usage stats were not being backed up,
potentially causing a loss of up to 20 minutes of data when restoring.
Fixes: 155930164
Test: atest UsageStatsDatabaseTest
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: I454f64e7de3f7a6046c408859998a3e51d5d338d
Over the years we've had several obscure bugs related to how SDK level
comparisons are performed, specifically during the window of time
where we've started distributing the "frankenbuild" to developers.
Consider the case where a framework developer shipping release "R"
wants to only grant a specific behavior to modern apps; they could
write this in two different ways:
1. if (targetSdkVersion > Build.VERSION_CODES.Q) {
2. if (targetSdkVersion >= Build.VERSION_CODES.R) {
The safer of these two options is (2), which will ensure that
developers only get the behavior when *both* the app and the
platform concur on the specific SDK level having shipped.
Consider the breakage that would happen with option (1) if we
started shipping APKs that are based on the final R SDK, but are
then installed on earlier preview releases which still consider R
to be CUR_DEVELOPMENT; they'd risk crashing due to behaviors that
were never part of the official R SDK.
Bug: 64412239
Test: ./build/soong/soong_ui.bash --make-mode services RUN_ERROR_PRONE=true
Exempt-From-Owner-Approval: trivial blueprint changes
Change-Id: Ia20181f8602451ac9a719ea488d148e160708592
When writing UsageStats timestamps to disk in proto, we offset the time
by the begin time to save storage space. However, there was logic which
reset default timestamp values of 0 to begin time for those stats.
This CL standardizes how timestamps are written to disk in proto for
UsageStats and updates the parsers. Since backup and restore use
database version 4, UsageStatsProto is also updated in addition to
UsageStatsProtoV2.
Bug: 155149300
Test: atest UsageStatsDatabaseTest
Test: atest android.app.usage.cts.UsageStatsTest
Change-Id: I624e4d56c91762b56eb1c3be67cd8df033fcac95
UsageStatsManager#isAppInactive provides usage information that is
usually gated by the PACKAGE_USAGE_STATS permission in similar API.
This updates isAppInactive to also check for the PACKAGE_USAGE_STATS
permission.
Test: atest android.app.usage.cts android.app.usage.cts.UsageStatsTest#testIsAppInactive
Fixes: 148991455
Change-Id: I8ff8eb5d2e887bc164095f38d374e3992808fe79
Delete the backup usage stats directory on a successful upgrade to v5.
This was kept as true such that a revert to the previous version would
be possible if needed.
Also indicate that an upgrade was performed such that relevant data is
pruned on dogfood builds.
Bug: 139937606
Test: manual: dir is deleted on migration.
Change-Id: I60285dc812a045bc82dd68a6e7ae87c2d3563adc
Delete legacy usage stats directory on a successful migration to CE.
This was kept as true such that a revert to the legacy would be possible
if needed.
Bug: 138323140
Test: manual: dir is deleted on migration.
Change-Id: I727df5d9139bfa1601cd02d979732f0d912bd29d
- 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
+ Skip dumping database summaries when dumping data for specific pkgs.
Bug: 145420790
Test: manual
Change-Id: If4ac1008ffc73ad4b3227c0a407323b43547a6b8
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
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
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
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
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>
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
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
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
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
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
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
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