Skip updating flags for a permission that's not requested.

If a permission isn't requested, there shouldn't be a PermissionState
for it, however updatePermissionFlags() may create such a state and
confuse restorePermissionState() for what is a new implicit
permission. So don't allow adding a new PermissionState for a
permission that's not requested, and make it a no-op because the
caller might just have seen an older package and we shouldn't crash
them. Updating flags for a permission with an existing PermissionState
is still allowed so that a permission state can be erased by revoking
and clearing all its flags.

See also b/159585979#comment7.

Bug: 159585979
Bug: 152580253
Test: atest --rerun-until-failure 100 SplitPermissionTest
Test: The test above fails within 2 or 3 attempts without this fix,
      but passes successfully for 100 times with this fix. Logcat
      shows that the logic in the fix is hit multiple times during the
      test.
Change-Id: I17d252bdc2cfa65485b7950da099dff73c4979a9
1 file changed