Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93629e57 authored by Matías Hernández's avatar Matías Hernández Committed by Android Build Coastguard Worker
Browse files

Prevent accidental creation of PackagePreferences for non-existing packages

This could be caused by (indirectly) invoking PreferencesHelper.getOrCreatePackagePreferences with an INVALID_UID (e.g. as the result of NMS passing along the result of getUidForPackageAndUser for a missing package). This was never intended -- API calls can result in the creation of PackagePreferences (since the structure is lazily initialized) but only for present packages. In most cases this was prevented by other checks (e.g. canNotifyAsPackage, which fails if missing) but specifically for the "fromPrivilegedListener" methods there was no similar enforcement.

Switch the PreferencesHelper usage so that:
* setters (e.g. create/updateChannel, groups) throw if supplied an invalid uid.
* getters that should have PackagePreferences creation as a side effect (e.g. getChannel) early exit if supplied an invalid uid.
* most getters don't actually create PackagePreferences and just return default values (e.g. canShowBadge) if they don't exist yet.

(Also, unify constants for representing a missing package into Process.INVALID_UID, and fix several tests that were impropely set up).

Bug: 426207912
Test: atest NotificationManagerServiceTest PreferencesHelperTest
(cherry picked from commit 236cff68)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:d52aa05738e3fa03ed7fd722c38490399bddf27a
Merged-In: I7d0717aed9fb26490f68801c9220833f2bed8e23
Change-Id: I7d0717aed9fb26490f68801c9220833f2bed8e23
parent b4c67863
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment