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

Commit a062beb9 authored by Amin Shaikh's avatar Amin Shaikh
Browse files

Ensure removal of stock tiles doesn't clear tiles.

Only update settings when a tile spec was actually removed from the set.

Change-Id: I7f2e467e79dbd48d376719e6b2adc6944b8ab73a
Fixes: 110917612
Test: manual
parent cf8c8523
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Predicate;

/** Platform implementation of the quick settings tile host **/
public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory> {
@@ -226,24 +227,23 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory> {
    }

    @Override
    public void removeTile(String tileSpec) {
        ArrayList<String> specs = new ArrayList<>(mTileSpecs);
        specs.remove(tileSpec);
        Settings.Secure.putStringForUser(mContext.getContentResolver(), TILES_SETTING,
                TextUtils.join(",", specs), ActivityManager.getCurrentUser());
    public void removeTile(String spec) {
        changeTileSpecs(tileSpecs-> tileSpecs.remove(spec));
    }

    public void addTile(String spec) {
        changeTileSpecs(tileSpecs-> tileSpecs.add(spec));
    }

    private void changeTileSpecs(Predicate<List<String>> changeFunction) {
        final String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
            TILES_SETTING, ActivityManager.getCurrentUser());
        final List<String> tileSpecs = loadTileSpecs(mContext, setting);
        if (tileSpecs.contains(spec)) {
            return;
        }
        tileSpecs.add(spec);
        if (changeFunction.test(tileSpecs)) {
            Settings.Secure.putStringForUser(mContext.getContentResolver(), TILES_SETTING,
                TextUtils.join(",", tileSpecs), ActivityManager.getCurrentUser());
        }
    }

    public void addTile(ComponentName tile) {
        List<String> newSpecs = new ArrayList<>(mTileSpecs);
@@ -300,7 +300,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory> {
        throw new RuntimeException("Default factory didn't create view for " + tile.getTileSpec());
    }

    protected List<String> loadTileSpecs(Context context, String tileList) {
    protected static List<String> loadTileSpecs(Context context, String tileList) {
        final Resources res = context.getResources();
        final String defaultTileList = res.getString(R.string.quick_settings_tiles_default);
        if (tileList == null) {