Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c7114f9 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Reduce blocking calls to Settings in main thread" into tm-qpr-dev am:...

Merge "Reduce blocking calls to Settings in main thread" into tm-qpr-dev am: bf928790 am: d9e0f169

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



Change-Id: I457ac6ffe8ed06e5f05a6d8edbb07dea38728dd2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 21e626ea d9e0f169
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -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();
            }
@@ -436,6 +442,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),
@@ -445,9 +452,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);
        }
    }
@@ -507,6 +520,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
            }
        }
        if (DEBUG) Log.d(TAG, "saveCurrentTiles " + newTiles);
        mTilesListDirty = true;
        saveTilesToSettings(newTiles);
    }