Cache PM data in DPGP

DefaultPermissionGrantPolicy is run on user startup but also in other
cases. On user creation it loads a lot of data from the PackageManager
and applies a lot of permission state.

This change adds an abstraction layer to the
DefaultPermissionGrantPolicy that caches and delays the PackageManager
calls on user creation. As a side-effect it also duplicates the state by
UID as all runtime permission state is by UID.

If this is not for user creation NO_PM_CACHE is used which just forwards
the calls directly to PackageManager.

This carries around the PackageManagerWrapper to all methods which
causes a lot of trivial churn. Other options considered:
- Make it a field in DefaultPermissionGrantPolicy but this would require
  outside code to create multiple DefaultPermissionGrantPolicy for
  different use cases
- Make it a Thread-Local. This is brittle and causes overhead

Also: All app-op setting was removed as this is automatically handled by
PermissonPolicyService

Test: Created user: Before 800 to 1200 ms after ~450 ms spent in
      DefaultPermissionGrantPolicy on sargo-userdebug
Fixes: 150405484
Change-Id: If77214a193a39fec2f311a3aea324ef07c2dfb42
Merged-In: If77214a193a39fec2f311a3aea324ef07c2dfb42
2 files changed