Refresh legacy permission state right before writing.

This was done for writing all the package settings, but not when
writing runtime permissions only, so we need to do the same thing
before we eventually migrate to new persistence.

This is a resubmission of ag/12960409, and this time we are only
refreshing the state before the actual disk write, instead of whenever
a write is (asynchronously) scheduled.

Bug: 171755668
Bug: 172297495
Test: manual
Test: atest MultiUserPerfTests
Change-Id: I0c69b6a28ea795c6682e28a26be4cac5b644c70b
2 files changed