Commit Graph

561 Commits

Author SHA1 Message Date
mattgilbride
d84a0bd79d UsageStatsService - call PermissionEnforcer helper on methods annotated with @EnforcePermission
Migrates all existing java methods annotated with @EnforcePermission
such that they call the super.<methodName>_enforcePermission
method provided by PermissionEnforcer.

This required by the @EnforcePermission annotation, but is currently a
no-op, and will be switched on with ag/20325484.

Bug: 234083358
Test: TH
Change-Id: I44f229a9f9b3483e638d2fe7ce49d7093f1fa5db
2022-11-10 17:09:56 +00:00
Suprabh Shukla
c6dcd3e42e Refactoring and tweaking TimeSparseArray
Tweaking the returned result from the boundary condition in
closestIndexOnOrAfter to be conceptually similar to
closestIndexOnOrBefore. This should also make it simpler to use by
callers.

Also exposing the class more broadly by moving it to android.util

Test: atest FrameworksCoreTests:TimeSparseArrayTest

Bug: 195684213
Change-Id: I44a06db8792d590be0eea4de39bc81387f2baac8
2022-10-05 14:37:42 -07:00
Kweku Adams
0288bcb415 Handle object in thread-safe manner.
Make sure mUsageEventListeners is always accessed while holding an
appropriate lock.

Bug: 247635314
Test: Android builds
Change-Id: Ia649f1724836f09020ae438bbdcfbe45c71b6784
2022-09-19 23:39:08 +00:00
Cole Faust
9acf46f66f [conflict] Merge "Fix array-related errorprone warnings" am: a1eb8cf128 am: 44f8576073 am: 91d6c5b564 am: 6a79ae2567 am: 9b3a5fc03b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2186016

Change-Id: I5e59b8549df348c181cd3b72311798a5d7602a67
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-30 21:03:54 +00:00
Cole Faust
9b3a5fc03b Merge "Fix array-related errorprone warnings" am: a1eb8cf128 am: 44f8576073 am: 91d6c5b564 am: 6a79ae2567
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2186016

Change-Id: I7052a1f7391ed6701fe0e1036c27368609032e35
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-30 20:44:00 +00:00
Cole Faust
584140c83a Fix array-related errorprone warnings
The ArrayEquals, ArrayHashCode, ArrayToString, and
ArraysAsListPrimitiveArray errorprone findings were
demoted from errors to warnings. Fix existing
occurrences of them so they can be made errors again.

Bug: 242630963
Test: RUN_ERROR_PRONE=true m javac-check
Change-Id: Ia6f216cc36ad0a5758f39fd9b34962cd4adf9d8e
2022-08-25 10:57:12 -07:00
TreeHugger Robot
a7d85cabf3 Merge "Support test skipping when power save modes aren't enabled." 2022-08-02 20:20:14 +00:00
Kweku Adams
ba3b5d7e53 Support test skipping when power save modes aren't enabled.
Some classes of devices will not have auto power save modes enabled. On
those devices, we should skip tests that require the modes be enabled.

Bug: 240108412
Bug: 240630396
Test: Manually go through CTS-V "Ignore Battery Optimizations Test"
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Change-Id: Icc64fbe75213386a1f41fae258e50c4032920b0a
2022-08-02 14:57:16 +00:00
Jackal Guo
6d5eb8dc25 Fix getAppStandbyBucket(s)
An instant app should be able to get its own standby bucket.

Fix: 237446222
Test: atest CtsUsageStatsTestCases
Test: atest CtsUsageStatsTestCases --module-parameter instant_app
Change-Id: I00ec091f3d6d51283d3a230f3bcfe2185763ac9d
2022-07-27 11:24:00 +08:00
mattgilbride
5bdb1218cc @EnforcePermission migrations - other services
Immediate calls to Context.enforceCallingPermission.  Fixes
applied by Android Lint (ag/18432857).

Bug: 232058525
Test: N/A
Change-Id: I7e488596ad4438506b68e5148bc69a8172c1eb5e
2022-07-14 16:06:21 +00:00
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
TreeHugger Robot
8e5f3fb3f4 Merge "Update standby buckets for restored apps." 2022-06-15 21:00:16 +00:00
Varun Shah
89f69113ad 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
2022-06-06 14:46:36 -07:00
Eric Biggers
04b3e85e46 Merge "UsageStatsService: ignore removed users in persistPendingEventsLocked()" am: f523bbcddc am: 27938f3b4e am: a7f6aedc36 am: 731a725635 am: cdbffdc561
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2109435

Change-Id: I3e21c33c141c852d4c3515949a7e5854e43025c4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 20:10:02 +00:00
Sudheer Shanka
77fb68dbd3 Merge "Allow exemption of roles/permissions from broadcast response events." into tm-dev am: d79cb12422 am: 002676b223
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18639261

Change-Id: I894807ff9b424e38714c782fc950fa23172677e2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-01 20:09:23 +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
6e66541dc6 Merge "Update TEST_MAPPING to include broadcast response related tests." into tm-dev am: c5229086de am: 1d224ef830 am: 4b8bf9d132 am: 01032eac33
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18378786

Change-Id: I8546e3fab78b36ccc4f7e3721b415d782dbca67c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-20 19:34:45 +00: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
96a9797844 Merge "Update OWNERS for broadcast response related classes." into tm-dev am: 9af0eed1de am: d0fa6d117b am: 0fe7ac75f9 am: 9fab7ac7ed
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18377776

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

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

Change-Id: If34fa3d33850e0f327ad163a4b18cd979860793d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 21:26:49 +00:00
Sudheer Shanka
d0fa6d117b Merge "Update OWNERS for broadcast response related classes." into tm-dev am: 9af0eed1de
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18377776

Change-Id: I46f4949332f6958ba780e973db80e22bf409b167
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 20:27:58 +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
9af0eed1de Merge "Update OWNERS for broadcast response related classes." into tm-dev 2022-05-16 21:26:19 +00: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
caf0790d49 Update OWNERS for broadcast response related classes.
Bug: 206518114
Test: n/a
Change-Id: I88e4bb13f536b732ca839d20111bd503a017885e
2022-05-13 10:37:38 -07: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
0f4ebc4410 Merge "UsageStatsService: don't create stuff directly in /data/system_de" am: d24351d56e am: 7613c6d580 am: a92dd9f9c4 am: eb8e0771a6 am: 9b7ac10cfb
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2080465

Change-Id: I97cfaa872d62c9b212a7855219308e4b0f6660b3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-03 07:34:13 +00: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
Jackal Guo
45a0da00fe Filter instant app from standby bucket
Since we restrict access to instant app data in usage stats (by
replacing instant app's package name with a placeholder name), we
should also filter out this data when getting standby bucket with
a given package name. This gives the callers a way to tell if the
instant app exists or not.

Bug: 217561828
Bug: 217740016
Test: atest CtsUsageStatsTestCases
Test: manually using the PoC in the buganizer to ensure the symptom
      no longer exists.
Change-Id: I091e65c01d184b9df02fda29c64ac61787077fdb
2022-04-26 11:41:18 +08: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