Fix URI grant persistence bypass

Prevent IOException during XML serialization by checking string lengths
before writing to the grants file. This stops a malicious app from
indefinitely persisting a URI grant after revocation by providing an
overly long URI.

hashtag:b/262884935
Fixes: 262884935
Test: atest UriGrantsManagerServiceTests
Flag: EXEMPT BUGFIX
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:23a398d0f7a171f5f97c5f13052f9ee3bcf7c298
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:89932dbb52489cadcf7a2a10b0d63161a7134dbe
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:e5ba9c7afa4ec0cd21bb78bff820ec0489c9d370
Merged-In: I9f211dbfad84ce23222f256d4a8b18d976624345
Change-Id: I9f211dbfad84ce23222f256d4a8b18d976624345
3 files changed