Skip to content
Commit e3a3105c authored by Hai Zhang's avatar Hai Zhang
Browse files

Further refactor UidPermissionState and GIDs.

The GIDs returned by the original permission state implementation in R
actually was never unique, but simply all GIDs from granted permission
concatenated together, and PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED
was returned when the length of the GIDs changed. This is equivalent
to simply checking whether the permission whose grant state changed
has GIDs or not, and can greatly simplify the
logic. PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED was only used in two
places anyway.

The original permission actually would never return
PERMISSION_OPERATION_FAILURE as well because it checks hasPermission()
beforehand and returns PERMISSION_OPERATION_SUCCESS if there's nothing
to change in grant/revokePermission(). The name
PERMISSION_OPERATION_FAILURE isn't a great name for unchanged anyway,
so grant/revokePermission() is now changed to simply return a boolean
for whether the permission state is changed.

The cache for isPermissionReviewRequired() is removed because it's
broken in subtle cases and iterating over an ArrayMap isn't a terrible
trade-off anyway, in exchange for simpler code and correct behavior.

Made removePermissionState() public so that code that actually wants
to erase the state permission doesn't need to perform a revocation
followed by updating all flags to 0.

Non-null arrays are preferred in APIs, the same as non-null
collections, so the GIDs-related APIs are updated to return non-null
int arrays as well. EmptyArray.INT is used instead of null so there
shouldn't be any performance penalty. Also ensured that the APIs are
returning copies instead of the original array to guard against
accidental mutation.

Bug: 158736025
Test: presubmit
Change-Id: I606210e18e5f8f87b8f8408fe476a72c2b7ed1c1
parent f579dd52
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment