Merge changes from topic "race_condition_tm-d1-dev" into tm-d1-dev am: f247c1b1d5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19569654

Change-Id: Ifcd35ae55442f8ea8841fd6f29bd24365cd04f9c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Fabian Kozynski
2022-08-11 16:56:56 +00:00
committed by Automerger Merge Worker

View File

@@ -110,6 +110,11 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
private Context mUserContext; private Context mUserContext;
private UserTracker mUserTracker; private UserTracker mUserTracker;
private SecureSettings mSecureSettings; private SecureSettings mSecureSettings;
// Keep track of whether mTilesList contains the same information as the Settings value.
// This is a performance optimization to reduce the number of blocking calls to Settings from
// main thread.
// This is enforced by only cleaning the flag at the end of a successful run of #onTuningChanged
private boolean mTilesListDirty = true;
private final TileServiceRequestController mTileServiceRequestController; private final TileServiceRequestController mTileServiceRequestController;
private TileLifecycleManager.Factory mTileLifeCycleManagerFactory; private TileLifecycleManager.Factory mTileLifeCycleManagerFactory;
@@ -374,6 +379,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
// the ones that are in the setting, update the Setting. // the ones that are in the setting, update the Setting.
saveTilesToSettings(mTileSpecs); saveTilesToSettings(mTileSpecs);
} }
mTilesListDirty = false;
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {
mCallbacks.get(i).onTilesChanged(); mCallbacks.get(i).onTilesChanged();
} }
@@ -437,6 +443,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
} }
// When calling this, you may want to modify mTilesListDirty accordingly.
@MainThread @MainThread
private void saveTilesToSettings(List<String> tileSpecs) { private void saveTilesToSettings(List<String> tileSpecs) {
mSecureSettings.putStringForUser(TILES_SETTING, TextUtils.join(",", tileSpecs), mSecureSettings.putStringForUser(TILES_SETTING, TextUtils.join(",", tileSpecs),
@@ -446,9 +453,15 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
@MainThread @MainThread
private void changeTileSpecs(Predicate<List<String>> changeFunction) { private void changeTileSpecs(Predicate<List<String>> changeFunction) {
final String setting = mSecureSettings.getStringForUser(TILES_SETTING, mCurrentUser); final List<String> tileSpecs;
final List<String> tileSpecs = loadTileSpecs(mContext, setting); if (!mTilesListDirty) {
tileSpecs = new ArrayList<>(mTileSpecs);
} else {
tileSpecs = loadTileSpecs(mContext,
mSecureSettings.getStringForUser(TILES_SETTING, mCurrentUser));
}
if (changeFunction.test(tileSpecs)) { if (changeFunction.test(tileSpecs)) {
mTilesListDirty = true;
saveTilesToSettings(tileSpecs); saveTilesToSettings(tileSpecs);
} }
} }
@@ -508,6 +521,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
} }
} }
if (DEBUG) Log.d(TAG, "saveCurrentTiles " + newTiles); if (DEBUG) Log.d(TAG, "saveCurrentTiles " + newTiles);
mTilesListDirty = true;
saveTilesToSettings(newTiles); saveTilesToSettings(newTiles);
} }