Synchronize increment of resource cache generations
Test: manual/presubmits Fixes: 287691671 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c137aac4d8bbe2c7f36f2b5b60dc3bfa86bc0457) Merged-In: I6189813291d3581fc401fd29801ae46c6eeab58c Change-Id: I6189813291d3581fc401fd29801ae46c6eeab58c
This commit is contained in:
committed by
Cherrypicker Worker
parent
b91edcc660
commit
d58dcf5514
@@ -137,8 +137,10 @@ abstract class ThemedResourceCache<T> {
|
|||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public void onConfigurationChange(@Config int configChanges) {
|
public void onConfigurationChange(@Config int configChanges) {
|
||||||
prune(configChanges);
|
synchronized (this) {
|
||||||
mGeneration++;
|
pruneLocked(configChanges);
|
||||||
|
mGeneration++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,22 +216,20 @@ abstract class ThemedResourceCache<T> {
|
|||||||
* simply prune missing weak references
|
* simply prune missing weak references
|
||||||
* @return {@code true} if the cache is completely empty after pruning
|
* @return {@code true} if the cache is completely empty after pruning
|
||||||
*/
|
*/
|
||||||
private boolean prune(@Config int configChanges) {
|
private boolean pruneLocked(@Config int configChanges) {
|
||||||
synchronized (this) {
|
if (mThemedEntries != null) {
|
||||||
if (mThemedEntries != null) {
|
for (int i = mThemedEntries.size() - 1; i >= 0; i--) {
|
||||||
for (int i = mThemedEntries.size() - 1; i >= 0; i--) {
|
if (pruneEntriesLocked(mThemedEntries.valueAt(i), configChanges)) {
|
||||||
if (pruneEntriesLocked(mThemedEntries.valueAt(i), configChanges)) {
|
mThemedEntries.removeAt(i);
|
||||||
mThemedEntries.removeAt(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pruneEntriesLocked(mNullThemedEntries, configChanges);
|
|
||||||
pruneEntriesLocked(mUnthemedEntries, configChanges);
|
|
||||||
|
|
||||||
return mThemedEntries == null && mNullThemedEntries == null
|
|
||||||
&& mUnthemedEntries == null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pruneEntriesLocked(mNullThemedEntries, configChanges);
|
||||||
|
pruneEntriesLocked(mUnthemedEntries, configChanges);
|
||||||
|
|
||||||
|
return mThemedEntries == null && mNullThemedEntries == null
|
||||||
|
&& mUnthemedEntries == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean pruneEntriesLocked(@Nullable LongSparseArray<WeakReference<T>> entries,
|
private boolean pruneEntriesLocked(@Nullable LongSparseArray<WeakReference<T>> entries,
|
||||||
|
|||||||
Reference in New Issue
Block a user