Commit Graph

514 Commits

Author SHA1 Message Date
TreeHugger Robot
bd58f61bc1 Merge "Update standby buckets for restored apps." into tm-qpr-dev am: 8d296990a6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18916003

Change-Id: I6d3c7052c5a73da2df9520f146580ab3a9fa7dd4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-28 01:51:46 +00:00
Varun Shah
dfd04f3547 Update standby buckets for restored apps.
When apps are restored, set their standby bucket to RARE if
they have been used within the past 90 days, based on the
restored UsageStats data.

Bug: 214580000
Test: atest UsageStatsDatabaseTest
Change-Id: I9d63032ef84fef97734b51323f41b797caa4f554
(cherry picked from commit 89f69113ad)
2022-06-15 21:07:38 +00:00
Sudheer Shanka
ca9fc6535a Merge "Allow exemption of roles/permissions from broadcast response events." into tm-dev am: d79cb12422
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18639261

Change-Id: Idfb26d0855b6ee4f98172a60e97a334741f97446
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 19:43:24 +00:00
Eric Biggers
a7f6aedc36 Merge "UsageStatsService: ignore removed users in persistPendingEventsLocked()" am: f523bbcddc am: 27938f3b4e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2109435

Change-Id: Iaa8b46044139a69a51915e26f76a148b7029b0c7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 18:55:15 +00:00
Eric Biggers
407bc2617e UsageStatsService: ignore removed users in persistPendingEventsLocked()
If a pre-created user is removed before it becomes a full user, the
ACTION_USER_REMOVED intent is never sent, so UsageStatsService is never
notified that the user's pending events should be discarded.  It will
eventually try to persist the events.  As the first step, it tries to
create /data/system_de/$userId/usagestats and the parent directory
/data/system_de/$userId if it doesn't already exist.

However, due to https://r.android.com/2078213 the SELinux policy no
longer allows system_server to create /data/system_de/$userId.  The
failure to create this directory is causing UsageStatsService to throw
an IllegalStateException which crashes system_server.

(Before the sepolicy change, system_server could create
/data/system_de/$userId, so the crash wouldn't have happened.  But
problems still might have occurred if the user ID was reused.)

The underlying user state tracking bug still needs to be fixed.  For
now, just avoid crashing system_server unnecessarily, and avoid an
SELinux denial by using mkdir() instead of mkdirs().

Test: pm create-user --pre-create-only
      pm remove-user 10
      # Wait 20 minutes and check logcat.

Bug: 234059731
Change-Id: Ic5efc19cda6b820a2c07f77b4f316d501acb9e80
2022-06-01 06:24:04 +00:00
Sudheer Shanka
8da64cacf3 Allow exemption of roles/permissions from broadcast response events.
Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/BroadcastResponseStatsTest.java
Change-Id: Iaae9775491caeae95ff04f4fd0fcb83b064a0f56
2022-05-31 12:21:13 -07:00
Sudheer Shanka
1d224ef830 Merge "Update TEST_MAPPING to include broadcast response related tests." into tm-dev am: c5229086de
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18378786

Change-Id: Ic0eeaeab84dca8746d8169a0b2f73cb83998592d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-20 18:14:04 +00:00
Sudheer Shanka
8aa21b257c Merge "Group broadcasts occurred within a certain duration into sessions." into tm-dev am: 0a790c6419
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18360308

Change-Id: If54c45ff15790df72f8be4ed0db55f2175d8a2c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 20:27:35 +00:00
Sudheer Shanka
afba0fb8b1 Merge "Don't consider PACKAGE_USAGE_STATS permission." into tm-dev am: 4bc2075b9f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18188884

Change-Id: Icad37137d2637d6e62247e2336fae9618e7cb006
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 20:27:14 +00:00
Sudheer Shanka
eb94b580ae Update TEST_MAPPING to include broadcast response related tests.
Bug: 206518114
Test: n/a
Change-Id: Id9b8b5862e7346638562da441ebd305b700ff29b
2022-05-17 00:19:48 -07:00
Sudheer Shanka
0a790c6419 Merge "Group broadcasts occurred within a certain duration into sessions." into tm-dev 2022-05-16 21:26:01 +00:00
Sudheer Shanka
e15884c96f Group broadcasts occurred within a certain duration into sessions.
For the purposes of tracking whether there is a response event
from an app after receiving a broadcast, treat all broadcasts
received by the app immediately after each other into a single
session and when there is a response event, then treat as if
the app received only one broadcast and there is one response
event corresponding to that.

Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I4c495d07026a4d6ab445ce463bd1b07e9a89bd06
2022-05-13 10:29:55 -07:00
Sudheer Shanka
33c832e34b Don't consider PACKAGE_USAGE_STATS permission.
When we added the new ACCESS_BROADCAST_RESPONSE_STATS
permission, we updated the new broadcast response
related APIs to check both PACKAGE_USAGE_STATS and
ACCESS_BROADCAST_RESPONSE_STATS permissions until clients
are udpated to use the new permission. We can now remove
the logic for checking PACKAGE_USAGE_STATS permission and
only consider ACCESS_BROADCAST_RESPONSE_STATS.

Bug: 225039700
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I5b8e8565b936b26463110ce1f0368122c322e632
2022-05-03 17:26:44 -07:00
Treehugger Robot
a92dd9f9c4 Merge "UsageStatsService: don't create stuff directly in /data/system_de" am: d24351d56e am: 7613c6d580
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2080465

Change-Id: I9cc1df675278651ff65f350dae043d9cc6c9c29f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-03 05:51:23 +00:00
Eric Biggers
e25b77c1db UsageStatsService: don't create stuff directly in /data/system_de
/data/system_de is only for per-user data; it *must* only contain
per-user encrypted directories.  Only vold should ever create anything
directly in this directory.  In preparation for removing system_server's
write access to this directory (https://r.android.com/2078213), make
UsageStatsService store its globalcomponentusage file at
/data/system/usagestats/globalcomponentusage instead of
/data/system_de/usagestats/globalcomponentusage.

Migration happens lazily, except that the old file and directory aren't
ever deleted since the SELinux policy will no longer allow system_server
to do that; the old file just stops being used.  vold will need to
handle the cleanup instead, or we could just leave the file around.

Note that before Android 11, UsageStatsService stored per-user stats in
/data/system/usagestats/$userId.  These per-user stats are *not* the
same thing as globalcomponentusage, which was added in Android 12.
UsageStatsService contains code to migrate the per-user stats to
/data/system_ce/$userId/usagestats.  This is fine, and is the right
thing to do, since the per-user stats are potentially sensitive per-user
data.  This does mean that UsageStatsService now implements two types of
migrations, and that the source directory for one migration is the
target directory for the other, which is a bit unfortunate.  However,
since different files are involved in each one, it all works out.

Bug: 156305599
Change-Id: I53c16640e8ed8b7eac111990f1cdb3f59579e051
2022-05-02 20:58:00 +00:00
Kweku Adams
173bdbd330 Merge "Cache earliest event results." into tm-dev 2022-04-08 18:02:14 +00:00
Kweku Adams
09c0ede3bf Consolidate launch time change notifications.
Track pending estimated launch time changes in a single Set so that we
avoid sending repeat notifications for a single package.

Bug: 227796747
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Test: atest FrameworksCoreTests:android.util.SparseSetArrayTest
Test: atest FrameworksMockingServicesTests:PrefetchControllerTest
Test: atest FrameworksMockingServicesTests:UserUsageStatsServiceTest
Change-Id: I671c97e4e4110d0a1c76a8f6400dfe8c1e5055dc
2022-04-06 15:24:34 +00:00
Kweku Adams
3356cc7be8 Cache earliest event results.
Cache the results from getEarliestEventsForPackage() so we don't have to
go down to the raw database as often.

Bug: 227796747
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Test: atest FrameworksMockingServicesTests:PrefetchControllerTest
Test: atest FrameworksMockingServicesTests:UserUsageStatsServiceTest
Change-Id: I2e3cf6650ed36b4915e4fcab16e9519cc8800f65
2022-04-01 23:12:33 +00:00
Austin Borger
45081ab6a0 Merge changes from topics "b124224342", "change_procstate_flag" into tm-dev
* changes:
  Add new onUidProcAdjChanged callback to be consumed by the camera service.
  Modify UidRecord.CHANGE_PROCSTATE such that it behaves like a bit mask.
2022-03-29 21:52:36 +00:00
Austin Borger
db9165baf2 Add new onUidProcAdjChanged callback to be consumed by the camera
service.

The camera service needs to know when individual process oom adj scores
are changed in order to address bug #124224342. When two separate
processes are displayed in split screen and focus is switched between
them, both proc states will remain the same while their oom scores
change. This is a problem if both have access to the camera - we want
only one owner of the camera stream at any given time and for the app
in focus to be the one to own it.

This patch adds a new IUidObserver registration level for individual
process oom score changes. In addition a new callback has been added to
IUidObserver to track these changes.

Change-Id: I68d964f474d20f819f54b614a4e314ce00aac8fb
Bug: 124224342
Test: -- ActivityManagerServiceTest
      -- ActivityManagerProcessStateTest
      -- ActivityManagerFgsBgStartTest
      -- UidObserverControllerTest
      -- NetworkPolicyManagerServiceTest
      -- ShortcutManagerTest2
      -- HintManagerServiceTest
      -- VibrationSettingsTest
      -- CameraEvictionTest#testCamera2AccessCallbackInSplitMode (x100)
2022-03-28 19:46:45 -07:00
Sudheer Shanka
9ef2c906e8 Add "clear-last-used-timestamps" command to usagestats service.
Bug: 206518483
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ieeedb17182ea93e162e2d7fb2d53169f2cc70e3a
2022-03-23 18:46:50 +00:00
Sudheer Shanka
4b61ecc716 Merge "Add ACCESS_BROADCAST_RESPONSE_STATS permission." into tm-dev 2022-03-19 05:14:21 +00:00
Sudheer Shanka
be82be6e88 Add ACCESS_BROADCAST_RESPONSE_STATS permission.
Instead of re-using PACKAGE_USAGE_STATS permission,
we are creating a new permission to guard access to
broadcast response stats.

For now, we check both permissions until the clients
migrate to using the new permission.

Bug: 225039700
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I65965b647da5994f434167693df999bc939807e2
2022-03-16 18:05:04 -07:00
Sudheer Shanka
4bf375b8dc Add a hidden API to query appstandby constants.
This will allow the tests to query the value for
appstandby constants that are last known to
the AppStandbyController.

Bug: 221176951
Test: atest ./tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I8175c9f0acbc44b25606b477c6db8b0edf85991d
2022-03-09 14:31:06 -08:00
Kweku Adams
386362eb1b Merge "Let settings query an app's minimum bucket." into tm-dev 2022-03-02 17:55:45 +00:00
Kweku Adams
9d999938df Let settings query an app's minimum bucket.
Bug: 156509848
Test: manual
Change-Id: Ife3869524f93b3341fa6eb1379619142ede5ca73
2022-02-28 20:47:47 +00:00
Sudheer Shanka
1ce3e3fa31 Add some recent broadcast and notification events to the dumpsys.
Bug: 197654954
Test: manual
Change-Id: I5a67894c38253711d1eac98ee7bdb32545f5908c
2022-02-25 17:57:40 -08:00
Sudheer Shanka
d807ffe41f Add an API to bulk query broadcast response stats for all pkgs.
Bug: 217567456
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I12853fdfb8a7b70eac935cf6aab23a388d2b7005
2022-02-15 15:45:17 -08:00
Sudheer Shanka
768522945d Add a missing return statement.
Bug: 206518114
Test: manual
Change-Id: Iadb13f6b64e19fef84310aeefd39c5e4d71d1882
2022-02-02 14:03:47 -08:00
Sudheer Shanka
918d724386 Make broadcast response fg threshold state configurable.
Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ic28b25393b8ff7d50164535722567d1a4e34f102
2022-01-31 10:40:16 -08:00
Sudheer Shanka
d1e5fabaa9 Track broadcast dispatched event only when the app is in the bg.
Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ic017fff35d800a1ea9b4288421e021859f443b30
2022-01-28 16:27:57 -08:00
Sudheer Shanka
cc59c25bd1 Make broadcast response window duration configurable.
Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ifc6792e969304967af7019483fdd1ec242bd2a83
2022-01-28 07:22:30 +00:00
Sudheer Shanka
ea2378808e Add some debug logging to UsageStatsService.
Bug: 197654954
Test: manual
Change-Id: If693714280998c7d057b1649f6d99c57c664b1ce
2022-01-27 19:24:21 +00:00
Sudheer Shanka
7ce974c2b2 Add APIs for querying broadcast response stats.
Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
CTS-Coverage-Bug: 206518114
Change-Id: Idcefc143215a372a7bd786fcb2208a7c26f2f7e2
2022-01-26 08:10:56 +00:00
Sudheer Shanka
5373a2e698 Merge changes Idde09e4c,I0337b400
* changes:
  Inform UsageStatsManager about notification related events.
  Allow reporting certain events to UsageStatsManager.
2022-01-24 22:13:30 +00:00
Sudheer Shanka
4e50889197 Allow reporting certain events to UsageStatsManager.
Add methods to allow reporting broadcast-dispatched,
notification-posted, notification-updated,
notification-removed events to UsageStatsManager.

Bug: 206518114
Test: atest --test-mapping apex/jobscheduler/service/java/com/android/server/usage/TEST_MAPPING
Change-Id: I0337b4004505930d21f4ef669e79ba4512b9792b
2022-01-24 09:22:43 -08:00
Neharika Jali
f29cf7bbb5 Makes constants related to cache configurable via DeviceConfig API
Bug: 214343564
Test: atest installd_cache_test, atest StorageManagerBaseTest, atest
StorageManagerTest#testComputeStorageCacheBytes

Change-Id: Ie977b8798e7169471c407621535ca1ca8feb6fec
2022-01-20 10:42:36 +00:00
Neharika Jali
967094148d Merge "In low storage, recalculate cache quotas if 2% change in total space" 2021-12-16 08:14:52 +00:00
Neharika Jali
d5af2ead56 In low storage, recalculate cache quotas if 2% change in total space
Bug: 203651230
Test: manual
Change-Id: Ie5df873f41e0bd0beca430b8e8ec51d5305bb844
2021-12-08 05:33:39 +00:00
Kweku Adams
e566f33a82 Add SystemApi to change app launch time estimates.
An SystemApis that allow a prediction app to update app launch time
estimates.

Bug: 194532703
Test: atest CtsPermissionTestCases:AppIdleStatePermissionTest
Test: atest CtsPermission2TestCases
Change-Id: I0fde220fa038f7f1f4d543a8906e92ca625bf097
2021-12-01 12:40:40 -08:00
Varun Shah
a70c46b8a5 Update deletion conditions for a package's UsageStats.
If a profile owner is defined for a specific user, do not delete usage
stats for a package on package deletion.

Bug: 197399948
Test: atest UserUsageStatsServiceTest
Test: atest UsageStatsTest [all]
Change-Id: I94a8e3dfca8ef4c7616f77944d61726e06043b85
Merged-In: I94a8e3dfca8ef4c7616f77944d61726e06043b85
(cherry picked from commit 157fbcfbe4)
Merged-In:I94a8e3dfca8ef4c7616f77944d61726e06043b85
2021-11-24 23:22:06 +00:00
Varun Shah
c755331c56 Merge "Update deletion conditions for a package's UsageStats." 2021-11-10 16:51:41 +00:00
Neharika Jali
044731c451 recalculate cache quotas when an app is uninstalled
Bug: 203651114
Test: manual
Change-Id: I81081a1efc6272b41babc64288592765c55ff9ac
2021-11-10 12:32:44 +00:00
Varun Shah
9af940970d Update deletion conditions for a package's UsageStats.
If a profile owner is defined for a specific user, do not delete usage
stats for a package on package deletion.

Bug: 197399948
Test: atest UserUsageStatsServiceTest
Test: atest UsageStatsTest [all]
Change-Id: I94a8e3dfca8ef4c7616f77944d61726e06043b85
2021-11-08 17:55:31 -08:00
Neharika Jali
eb406946e4 Merge "Recalculating cache quotas every 10 hours" 2021-11-08 12:10:28 +00:00
Neharika Jali
945ec1e647 Recalculating cache quotas every 10 hours
Bug: 203651640
Test: manual
Change-Id: I7d8065fcfa619b66d89e70f71f3ea726032f1995
2021-11-07 12:55:36 +00:00
Kweku Adams
4d0d1dd6e8 Revert "Revert "Add basic launch time prediction.""
This reverts commit 3785977ca6.

Reason for revert: Fixing

Change-Id: I31425d8086e3f1d1d806b84e9339d0acd3f420d4
2021-11-04 21:07:05 +00:00
Jakub Pawlowski
3785977ca6 Revert "Add basic launch time prediction."
This reverts commit cc590ac913.

Reason for revert: breakage of errorprone build

Change-Id: I0a896a2637521b36df2a132b8209f4fab23946ad
2021-11-04 16:02:21 +00:00
Kweku Adams
cc590ac913 Add basic launch time prediction.
We estimate the next app launch time by looking at the past 7 days of
usage history and assuming that the user opens the app like clockwork.
If there is at least 24 hours of usage events, then we take the earliest
ACTIVITY_RESUMED event and estimate that the app will be launched
exactly 7 days after that event. If there is less than 24 hours of
history (which would be the case for a new app), then we take the
earliest ACTIVITY_RESUMED and add 24 hours. If we don't see any launch
event in the past 7 days, then we just say the app should be launched
within a year. If we have a long estimate for an app and it is launched,
then we re-evaluate our estimate because we can now estimate a launch
within the next 7 days.

Bug: 194532703
Test: atest FrameworksMockingServicesTests:PrefetchControllerTest
Test: manually launch apps and check dumpsys for expected launch time changes
Change-Id: I9ef5fc3e3df3c2d029243b1fb8949a4bf21900db
2021-11-02 16:18:14 -07:00
Kweku Adams
72754e5847 Address small inefficiencies.
1. Don't hold the lock for validation checks that don't need it.
2. Put early returns ahead of other work when possible.

Bug: 203811598
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/usage
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/usage
Change-Id: Ic923db1534e27e0932e594b8259fe482772b8a6a
2021-10-21 14:09:07 -07:00