Refresh in-memory SharedPreferences instances after restore

Existing instances don't know that the file has changed out from
under them, so they continue to return stale values from reads, and
risk overwriting restored data with stale content if writes are
performed.  We now tell the backing cache system to induce a
reload after restore (i.e. after we might have written a relevant
file out from under it).

Along the way we shook out an irregularity in the way we were
setting up the context topology of non-lifecycle instances of
the metadata-handling BackupAgent subclass, so that's fixed
now too.

Bug 12061817
Test: cts-tradefed run cts -m CtsBackupHostTestCases

Change-Id: I401fe9297235b55d8a8f041e430d122dc6e24129
This commit is contained in:
Christopher Tate
2017-05-17 15:42:35 -07:00
parent 1bd58ef4b1
commit fe2368c38c
6 changed files with 71 additions and 7 deletions

View File

@@ -149,6 +149,12 @@ public class MockContext extends Context {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public void reloadSharedPreferences() {
throw new UnsupportedOperationException();
}
@Override
public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
throw new UnsupportedOperationException();