OSDN Git Service

Ensure local settings caches are not stale
authorSvet Ganov <svetoslavganov@google.com>
Wed, 20 Apr 2016 02:38:00 +0000 (19:38 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Tue, 26 Apr 2016 18:31:55 +0000 (11:31 -0700)
commit53a441ca8eda5a3e6209a952b1bbd32a39e19a1c
treea2ba745db7de9a74135bb7fd9fa971dff6f33f6b
parent5a91b615232374084a45752d7c09c25265e263ed
Ensure local settings caches are not stale

We used the system proterties as a shared memory mechanism
to propagate information to local settings caches when the
content has changed and the cache should be cleared. The
system properties are unfortunately updated asynchronously
leading to cases where clients may read stale data.

This change adds a simple int array data structure backed
by shared memory which guarantees individual values are
atomically read and updated without memory tear. Multi-
index opearations are not synchronized between each other.

The settings provider is using the new data structure to
propagate the settings generation which drives when caches
are purged.

We have a single memory array keeping the generation for
different settings tables per user. Since memory array is
not a compact data structure and the user space exceeds
the memory array size we use an in-memory map from keys
to indices in the memory array where the generation id of
a key is stored. A key is derived by the setting type in
the 4 most significant bits and the user id in the 28 least
significant bits.

The mapping from a key to an index is cleared if the user is
removed and the corresponding index in the memory arry is
reset to make it available for other users. The size of the
memory array is derived from the max user count that can be
created at the same time.

bug:18826179

Change-Id: I64009cc5105309ef9aa83aba90b82afc8ad8c659
15 files changed:
Android.mk
api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/provider/Settings.java
core/java/android/util/MemoryIntArray.aidl [new file with mode: 0644]
core/java/android/util/MemoryIntArray.java [new file with mode: 0644]
core/jni/Android.mk
core/jni/AndroidRuntime.cpp
core/jni/android_util_MemoryIntArray.cpp [new file with mode: 0644]
core/tests/utiltests/src/android/util/MemoryIntArrayTest.java [new file with mode: 0644]
packages/SettingsProvider/src/com/android/providers/settings/GenerationRegistry.java [new file with mode: 0644]
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
services/core/java/com/android/server/pm/UserRestrictionsUtils.java