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). DISABLE_TOPIC_PROTECTOR Bug: 426207912 Test: atest NotificationManagerServiceTest PreferencesHelperTest (cherry picked from commit 236cff68) (cherry picked from commit 8b986fffe8efab8b9ccecabe8dffed3ef49d6834) Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:db461040cf3e0418927291579e697120ce6b9e2d Merged-In: I39c280765ffe26588852ea606dac22ed841d791f Change-Id: I39c280765ffe26588852ea606dac22ed841d791f
Loading
Please register or sign in to comment