Commit Graph

192 Commits

Author SHA1 Message Date
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
Rhed Jao
f727d0dc3c Move logics of suspending packages out of package manager service
Bug: 201334238
Test: atest com.android.server.pm.SuspendPackagesTest
Test: atest CtsSuspendAppsTestCases
Test: atest CtsSuspendAppsPermissionTestCases
Test: atest SuspendPackageHelperTest
Change-Id: I88940b68b07ea0acdac4fcce6649431e4bb1e4b8
2022-01-19 22:29:22 +08:00
Winson
efbb319630 Move package parsing to services.jar
This facilitates exposing the Parsed_ classes as
@SystemApi(client = SYSTEM_SERVER) while keeping everything inside
services.jar rather than having it split across both jars.

This reverts getPackageArchiveInfo to use legacy PackageParser, since
framework.jar can no longer access the moved classes.

Bug: 214038417

Test: presubmit, no logic changes

Change-Id: I152d70fb4f643d32efb012cfb20b0fbc5f88f2d8
2022-01-18 12:47:45 -08:00
Winson
c82b3c669e Introduce package state mutation APIs
Adds APIs to record a state at some time and use that state to commit
changes to package state. Which allows reconcilation and retry of
competing changes without needing to take the data model lock unless
absolutely necessary.

Also copies over data model/settings changes to make it compile.

Split from actual usage to make review easier.

Bug: 202291547

Test: presubmit, no usages yet

Change-Id: I6738829185022efef4add1805b5a52b3de3d173a
2021-12-30 13:42:18 -08:00
Songchun Fan
5e303008b4 Merge "[pm] new APIs for ApplictaionInfo/PackageInfo/ComponentInfo/ResolveInfo flags" 2021-12-10 16:08:09 +00:00
Songchun Fan
e801d3e48c [pm] better annotation for storage flags
+ Use explicit flag types in PackageManager.
+ Distinguish AllocationFlags from StorageFlags.

BUG: 207030431
Test: Builds
Change-Id: I641c76859d3a16f70acad17507695ddd161f339a
2021-12-06 22:14:38 +00:00
Songchun Fan
cf3f673b48 [pm] new APIs for ApplictaionInfo/PackageInfo/ComponentInfo/ResolveInfo flags
We are running out of int flags for public API methods such as
PackageManager.getPackageInfo(String packageName, int flags). As a
solution, we will change the flags param to Flags objects. At the
same time, we deprecate the old methods that directly use int flags.

The new flags classes are: ApplicationInfoFlags, PackageInfoFlags,
ComponentInfoFlags and ResolveInfoFlags. Because there are already
annotations of the same names, we renamed the annotations to *FlagsBits.

Old API usage example:
getPackageInfo(pkgName, MATCH_UNINSTALLED_PACKAGES)

New API usage example:
getPackageInfo(pkgName, PackageInfoFlags.of(MATCH_UNINSTALLED_PACKAGES))

See b/204433742 for discussions.

CTS-Coverage-Bug: 206147270
BUG: 204432643
BUG: 204433659
Test: manual
Change-Id: I8ab2adad6907670c5879c043d170c950afefe46c
2021-12-02 15:35:51 -08:00
Songchun Fan
5fab45ef67 [pm] change internal flags to long
Changes IPackageManager.aidl methods to use long flags instead of int.
Public API change to be followed.

BUG: 204432643
BUG: 204433659
Test: manual
Change-Id: Ib5c42fef998f0116e312c71d620e1a15329e26e0
2021-11-24 06:58:50 -08:00
Winson
190819a32a Remove some read only usages of PackageManagerService mLock
In most non-install, non-mutate areas, migrates away from locking
PackageManagerService directly in favor of the Computer snapshot.

This will relieve more lock contention and allow scoping
PackageSetting to mutate-only scenarios, such as install.

Bug: 202291449

Change-Id: Ie92ebfeacdc4a00484373f11739fdfe3c3897a7f
2021-11-12 18:32:12 -08:00
Winson Chiu
d63ec17204 Merge "Migrate PackageSetting usages to PackageStateInternal" 2021-11-04 21:43:44 +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
Winson
b049d95ef8 Migrate PackageSetting usages to PackageStateInternal
Moves to a read-only interface inside Computer and all of its
dependencies. This is the next step towards true data model
immutability and mutation time snapshots.

Bug: 202291449

Test: atest PackageManagerServiceUnitTests \
        PackageManagerSettingsTests \
        PackageUserStateTest \
        PackageParserTest \
        PackageManagerTest \
        ScanTests \
        PackageInfoUserFieldsTest \
        DexoptUtilsTest \
        PackageManagerComponentLabelIconOverrideTest

Change-Id: If5afb44e20b50a15b2b99057b0797c9b88e6e60b
2021-11-04 00:42:38 -07: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
Treehugger Robot
1de79d89a4 Merge "Consolidating PM owner definition and adding new owners." am: 75e0091067 am: e32f384ce7 am: db319657ed am: 3af00e82f8 am: 904b1d5f79
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1863214

Change-Id: I779688092591bcd316849225aa64592a4c72ec04
2021-10-26 20:31:11 +00:00
Patrick Baumann
8255f5f4c0 Consolidating PM owner definition and adding new owners.
Change-Id: If4b080755701452c53d55f26380e887dc3944dbf
2021-10-19 21:06:56 +00:00
Songchun Fan
cb7b88fc8b [pm] app data helper
A separate class for handling app data directory setup and reconciling
apps data duing boot.

Notice that I moved some related booting sequence into the new class.

BUG: 199428170
Test: manual
Change-Id: I0d2e0f70b815f0f8e340de9ee876d6ac5c8a6ee9
2021-10-06 22:12:26 +00:00
Jackal Guo
9674823bf3 Apply visibility to get session info APIs
Callers need to either declare <queries> element with the specific
package name in the app's manifest, be the owner of the session, or
has appropriate permission to get the session infos.

Bug: 187176203
Bug: 187176993
Bug: 194694069
Bug: 194694094
Test: atest AppEnumerationTests
Test: manually using the PoC in the buganizer to ensure the symptom
      no longer exists.
Change-Id: I51e84e9560ebff3c5fcde1639542efd04a77557b
2021-09-27 14:23:16 +08:00
John Wu
40d77b9e85 Migrate permissions when leaving sharedUserId
- Retrieve the previous uid permission state and create a copy of it as
  the new app's uid state.
- Remove the app from the original shared user group. Other apps in the
  shared user group will perceive as if the original app is uninstalled.
- The new permission state is updated in updatePermissions() just like
  a normal package upgrade.

Test: atest CtsSharedUserMigrationTestCases
Bug: 179284822
Change-Id: I9d7c3b16959dd4b2c2684ddaf8bd223fb32c3c41
2021-09-23 11:15:07 -07:00
Felka Chang
8a9a7af6b3 Add system server pm to trigger CTS PackageInstaller tests
When the developers change any code in
frameworks/base/service/core/java/com/android/server/pm,
frameworks/base/service/core/java/android/content/pm, and
frameworks/base/packages/PackageInstaller, it should invoke all of
the tests under cts/tests/tests/packageinstaller.

service/core/java/com/android/server/pm/TEST_MAPPING already imports
core/java/android/content/pm/TEST_MAPPING which imports
cts/tests/tests/packageinstaller/TEST_MAPPING.  Adding
service/core/java/android/content/pm/TEST_MAPPING to import
core/java/android/content/pm/TEST_MAPPING is just like
service/core/java/com/android/server/pm/TEST_MAPPING.

This patch also removes invoking CtsAtomicInstallTestCases with the
file patterns because invoking CtsAtomicInstallTestCases with file
patterns is redundant. It has been imported in
cts/tests/tests/packageinstaller/TEST_MAPPING. And,
cts/tests/tests/packageinstaller/TEST_MAPPING is imported in
core/java/android/content/pm/TEST_MAPPING that is imported in
service/core/java/com/android/server/pm/TEST_MAPPING.

Test: atest --collect-test-only -p \
      frameworks/base/services/core/java/com/android/server/pm
Test: atest --collect-test-only -p \
      frameworks/base/services/core/java/android/content/pm

Bug: 180650365
Change-Id: If24e4b2308891775965cb7b2659cb7e25f255436
2021-09-11 09:49:28 +08:00
Winson Chiu
d7adbb01ba Revert "Revert "Open up AndroidPackage as @SystemApi""
This reverts commit 750ce30b84.

Reason for revert: b/199246839 fixed, re-introduce change

Change-Id: I48f3fd20ac14c823c85de55f667d1860dade1f97
2021-09-10 16:50:01 +00:00
Winson Chiu
750ce30b84 Revert "Open up AndroidPackage as @SystemApi"
This reverts commit b013a475eb.

Reason for revert: b/199246839, breaks some builds

Change-Id: If71cb271c6f4bb32f3cc9b31822fa0b9dbab7c37
2021-09-09 21:01:38 +00:00
Winson
b013a475eb Open up AndroidPackage as @SystemApi
Moves all the PackageInfo/ApplicationInfo values into core SDK side
interfaces which represent all the mirrored functionality.

Creates AndroidPackageApi, PackageState, and a new PackageUserState
interface that act as the actual exposed interfaces for consumers like
mainline.

To avoid taking the PackageManagerService lock, and to avoid mutability
issues, PackageSettings are shallowly copied into PackageState objects.
And class PackageUserState objects into interface PackageUserState.

Eventually PackageSetting/class PackageUserState should be migrated to
the corresponding interfaces.

Miscellaneous additional changes:
 - Removes PackageSetting#uidError, was never used
 - Removes PackageUserState#categoryHint, was a package level field
   without per-user difference, use PackageSetting#categoryHint instead
 - Add locking to class PackageUserState overlay paths so they can be
   copied for the new interface.

Bug: 173455397

Test: atest com.android.server.pm.ScanTests

Change-Id: Ib98c66a9b4d78d09151724eaf14c16074c3621c9
2021-09-02 10:39:04 -07:00
Jackal Guo
0a35f11ba7 Fix visibility was gone after updating
System grants implicit visibility when the Uri permission is granted.
But, all the visibility rules would be cleared when package updating.
Since the implict visibility doesn't come from manifest, we cannot
restore it via recompuating visibility. This solution is similar to
how UriGrantsManagerService handles the granted Uri permissions when
packagea updated. We keep them unchanged instead of clearing them.

Bug: 161912313
Test: atest AppsFilterTest
Test: atest AppEnumerationTests
Test: atest UriGrantsManagerServiceTest
Test: manually use test APKs on buganizer to verify
Change-Id: I3026e06574f78c15dbf60c74db126679c677adb1
2021-08-20 10:41:14 +08:00
John Wu
f41ff188a0 Enforce intents to match intent filters.
When an app registers an exported component in its manifest and adds an <intent-filter>, the component can be started by any intent - even those that do not match the intent filter. This has proven to be something that many developers find counterintuitive. Without checking the intent when the component is started, in some circumstances this can allow 3P apps to trigger internal-only functionality.

Bug: 161252188
Test: atest CtsContentTestCases:PackageManagerTest
Change-Id: I19e8ee0a529314b3417435471c6e68988a2ab897
2021-08-03 22:24:48 +00:00
Rhed Jao
c7f6ac5ae5 Merge "Migrates to the new resolveContentProvider api" 2021-07-27 02:48:11 +00:00
Rhed Jao
80573612b2 Migrates to the new resolveContentProvider api
The original resolveContentProvider api gets the caller's uid using
the Binder#getCallingUid. That may cause the package information
disclosure issue if the caller has cleared the calling identify.
This cl migrates the callers of resolveContentProvider to use the
new one with a calling uid parameter. The caller could pass the
correct caller's uid to use the api.

Bug: 192354703
Test: atest UriGrantsManagerServiceTest
Test: atest UriPermissionTest
Test: atest ContextTest
Change-Id: I153df4e77642f0622c7f0f5804639795e90ded21
2021-07-23 14:58:04 +08:00
TreeHugger Robot
2b2435925a Merge "[pm] small refactor to hide PackageManagerService.getPackageSetting" 2021-07-23 01:22:36 +00:00
Songchun Fan
77719392d7 [pm] small refactor to hide PackageManagerService.getPackageSetting
Use PackageManagerInternal methods instead.

+ Also removes PackageManagerService.getPackages which is only used by
OtaDexoptService

Test: builds
BUG: 194319951
Change-Id: Ibadbb5996e4589ef321c41d7d00fe4aa5b59b805
2021-07-22 11:43:16 -07:00
Jackal Guo
39747538c6 Apply package visibility to PACKAGE_DATA_CLEARED
Intent ACTION_PACKAGE_DATA_CLEARED is sent without the allowlist so
it may potentially leakage the package information.

Bug: 191291133
Test: atest AppEnumerationTests
Change-Id: Ica10615db22c0bc0eb4fba550bc069031f18c9a9
2021-07-20 13:18:23 +08:00
Rhed Jao
c02e59a12a Merge "Enforce package visibility to the api checkUriPermission" 2021-07-20 02:15:37 +00:00
Kweku Adams
76f52ec93c Merge "Prevent app check via content provider." into sc-dev am: 10239a0c9c am: cc90b23749
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15018027

Change-Id: I519eeaf05d3ffedc2f53e9c096ba29b408782b72
2021-07-07 16:47:04 +00:00
Rhed Jao
6d90858f6d Enforce package visibility to the api checkUriPermission
App can query which applications are installed on the device via
api grantUriPermission and checkUriPermission. This cl enforces
package visibility filter to the api checkUriPermission to fix
the security issue.

Bug: 180019130
Test: atest AppEnumerationTests
Test: atest CtsProviderTestCases
Test: atest UriGrantsManagerServiceTest
Test: atest UriPermissionTest
Test: atest ContentProviderTest
Test: atest ContentResolverTest
Test: atest DownloadManagerTest
Test: atest MediaProviderTest
Test: atest ManagedProfileCrossProfileTest
Change-Id: Ic19caef7f3f221b9c35afe2805336e50d838cf26
2021-07-07 13:35:49 +08:00
Kweku Adams
ddca60058e Prevent app check via content provider.
Pass in the calling UID when asking PackageManager to resolve the
content provider. This makes sure PM is resolving the provider based on
the calling UID's permissions and not the system server's permissions.

Bug: 189122544
Bug: 189122545
Test: atest CtsContentTestCases
Test: atest CtsJobSchedulerTestCases
Test: atest FrameworksServicesTests:UriGrantsManagerServiceTest
Change-Id: Iaa421e982fca1e29828eda43f0762893199b5ce1
2021-07-01 10:20:44 -07:00
Zhen Zhang
eb419e0c45 Merge "Log storage savings info with the GlobalHibernatedApps atom" into sc-dev am: b70b810af4 am: 7f906bc0be
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15025828

Change-Id: I874fdbec43b706c53160cbcf93a638cd8632d337
2021-06-23 18:52:21 +00:00
Zhen Zhang
5e0446a263 Log storage savings info with the GlobalHibernatedApps atom
Retrieve the number of freed bytes from PM and store it in
GlobalLevelState when a package is globally hibernated. Reset the value
when it gets unhibernated and write it to disk to persist across device
reboot.

Bug: 188819665
Test: atest AppHibernationServiceTest
Change-Id: I187ec803776cc76c77a660e1ba2f72c2e77765f9
2021-06-21 17:56:32 -07:00
TreeHugger Robot
ce3d3f0733 Merge "Extend set user protected packages for multi-user" into sc-dev am: cf5b205e9a am: 96dbff6fb2 am: 87f411576a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14344090

Change-Id: I2dfea79b29149d1d9998a3d731afb9dbca757b9d
2021-05-20 02:06:56 +00:00
Salud Lemus
46a1dcefb0 Extend set user protected packages for multi-user
The current implementation does not work when the multi-user feature is
enabled because it clears the "globally" protected packages set by the
device owner whenever a new user is created.

Bug: 178500150
Test: atest FrameworksServicesTests:com.android.server.devicepolicy.OwnersTest
Test: atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest
Test: Ran the CTS tests that were added

Change-Id: Id04cb9b5b2357b0a0b5090442a39d97405287dbe
2021-05-13 12:02:22 -07:00
Alex Buynytskyy
3e43b9f2ff Merge "Customer API feedback." into sc-dev am: 915f8bdaba
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14377096

Change-Id: I923a79acf57ef760bdd2172c8d2ebdb2326dc7b3
2021-05-04 18:38:43 +00:00
Alex Buynytskyy
1e5cf8f1ff Customer API feedback.
Use two separate interfaces for flags and single value. This produces
correct API documentation.

Bug: 160605420
Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest PackageManagerServiceTest ChecksumsTest
Change-Id: I9a7eaf86af558d8dcfd1636a4baf6a28e2ee79b1
2021-05-04 15:24:02 +00:00
Winson Chiu
9863b99f7b Merge changes Ie90dc390,Ia9513817 into sc-dev am: 627cac02ad
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14116366

Change-Id: Icc54b54a406babf1c4c3fac6ec53375ce4681093
2021-04-30 21:43:09 +00:00
Winson
a74c1f3c69 Move withPackageSettingsSnapshot methods into PackageManagerInternal
For consumers who don't care about blocking package data updates and
only need data at a specific snapshot in time, these methods would
avoid locking PMS during the iteration process.

Bug: 183643808

Test: atest com.android.server.pm.test.verify.domain

Change-Id: Ia951381798d75f77c4ad5fc010a469b69992f074
2021-04-30 10:46:32 -07:00
Guliz Tuncay
9550d2f640 Merge "Migrate |documenter to |role" 2021-04-28 16:30:28 +00:00
TreeHugger Robot
301bec1c37 Merge "[pm] remove incremental startable/unstartable code" into sc-dev am: 18ecd98109
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14185076

Change-Id: I6b3a69cca804cd1e73c507168b3d4dc5bac0910e
2021-04-20 22:12:53 +00:00
TreeHugger Robot
18ecd98109 Merge "[pm] remove incremental startable/unstartable code" into sc-dev 2021-04-20 22:03:22 +00:00
Rhed Jao
4b56a300df Merge "Apply package visibility to the LauncherApps#isActivityEnabled" into sc-dev am: b8a482b0f1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14150475

Change-Id: Ic7557d59fe96f183e4487b68f206fc40d8a6fc97
2021-04-19 06:18:41 +00:00
Songchun Fan
5ada1508c2 [pm] remove incremental startable/unstartable code
Also remove streaming health status reporting which could cause
startable state change because it is also not needed any more.

BUG: 171920377
Test: builds
Change-Id: I7284e7a63df79da7dbf3d16ff64302b3d1ce1348
2021-04-16 02:29:24 +00:00
Rhed Jao
9ac5f83a72 Apply package visibility to the LauncherApps#isActivityEnabled
Bug: 180417374
Test: atest AppEnumerationTests
Change-Id: I23ad6515ca7a8235290809c390f2527bd0b3c987
2021-04-14 15:40:08 +08:00
Güliz Seray Tuncay
11c21eb23b Migrate |documenter to |role
Migrate the |documenter permission flag to the role infrastructure

Bug: 158878560
Test: atest CtsPermission2TestCases:PermissionPolicyTest
Change-Id: Iad1ad168064688b2efbb964a1eae9110a4cac231
2021-04-09 00:44:15 +00:00
Jackal Guo
18119e69cd Merge "Refactor PackageParser (6/n)" 2021-04-08 09:28:21 +00:00