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 (this is flag-controlled). * 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: 430250142 Test: atest NotificationManagerServiceTest PreferencesHelperTest Flag: com.android.server.notification.preferences_throws_on_invalid_uid Change-Id: I7d0717aed9fb26490f68801c9220833f2bed8e23
Loading