Optimize check for requested permissions.

Added requestedPackageStates in evalutePermissionState() so that
requested permissions is only checked for one time.

any/forEachRequestingPackageInAppId() is removed in favor of
any/forEachPackageInAppId() - other usages outside of
evaluatePermissionState() can manually check for requested permissions
if needed, and this also benefits performance a bit in that other faster
checks can be done before checking requested permissions.

Also changed revokePermissionsOnPackageUpdate() to check for all packages
in the app ID, because storage isolation always applies to the entire
UID regardless of whether they requested a certain permission, and
this is also more consistent with the old subsystem.

The added reduce*() extension functions are hard coded to work with
Int instead of using generics, because generics will compile into
boxed Integer in bytecode despite that the functions are inlined.

Bug: 278913322
Test: presubmit
Change-Id: I6cbace38b5ea7d1782da3b1c1ee68683073080ba
3 files changed