diff options
author | Fabian Kozynski <kozynski@google.com> | 2022-08-02 09:54:41 -0400 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-08-12 01:57:06 +0000 |
commit | 6062fccc1247932cd3f126ce6fd19dbdef8745f9 (patch) | |
tree | a57200ff1312356e033c57026405091f2aae33af | |
parent | d8465f805a935660d6c8e8fe2d89a4b8b7097ce8 (diff) | |
download | base-6062fccc1247932cd3f126ce6fd19dbdef8745f9.tar.gz |
Reduce blocking calls to Settings in main thread
In most cases, mTileList contains the same information as the Settings
value, so there's no need to retrieve it before modifying it. Keep track
of that with a dirty flag.
This way, we reduce the number of blocking calls in the main thread (as
that's the thread that processes the tiles).
Test: manual, factory reset
Test: existing QSTileHostTest
Test: performance metrics are back to baseline
Fixes: 240256263
Change-Id: Idebd37d1458c80330b60802729575219b6a7b49a
Merged-In: Idebd37d1458c80330b60802729575219b6a7b49a
(cherry picked from commit 4da071e035b647f498936bdb2b557aa08bd9df0f)
Merged-In: Idebd37d1458c80330b60802729575219b6a7b49a
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java index fcd9e10089bc..bf83ad6bff74 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java @@ -110,6 +110,11 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D private Context mUserContext; private UserTracker mUserTracker; 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 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. saveTilesToSettings(mTileSpecs); } + mTilesListDirty = false; for (int i = 0; i < mCallbacks.size(); i++) { 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 private void saveTilesToSettings(List<String> tileSpecs) { mSecureSettings.putStringForUser(TILES_SETTING, TextUtils.join(",", tileSpecs), @@ -446,9 +453,15 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D @MainThread private void changeTileSpecs(Predicate<List<String>> changeFunction) { - final String setting = mSecureSettings.getStringForUser(TILES_SETTING, mCurrentUser); - final List<String> tileSpecs = loadTileSpecs(mContext, setting); + final List<String> tileSpecs; + if (!mTilesListDirty) { + tileSpecs = new ArrayList<>(mTileSpecs); + } else { + tileSpecs = loadTileSpecs(mContext, + mSecureSettings.getStringForUser(TILES_SETTING, mCurrentUser)); + } if (changeFunction.test(tileSpecs)) { + mTilesListDirty = true; saveTilesToSettings(tileSpecs); } } @@ -508,6 +521,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D } } if (DEBUG) Log.d(TAG, "saveCurrentTiles " + newTiles); + mTilesListDirty = true; saveTilesToSettings(newTiles); } |