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

Commit 43991ab2 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Automerger Merge Worker
Browse files

Merge "Add multi-user support for AutoTileManager" into rvc-dev am: d73e5df1

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

Change-Id: I6ceb4fb189151217e2e13f01a9795f1373750187
parents 7a5ddb24 d73e5df1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.content.ComponentName
import android.service.controls.Control
import android.service.controls.ControlsProviderService
import android.service.controls.actions.ControlAction
import com.android.systemui.controls.UserAwareController
import com.android.systemui.util.UserAwareController
import java.util.function.Consumer

/**
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.service.controls.Control
import android.service.controls.ControlsProviderService
import android.service.controls.actions.ControlAction
import com.android.systemui.controls.ControlStatus
import com.android.systemui.controls.UserAwareController
import com.android.systemui.util.UserAwareController
import com.android.systemui.controls.management.ControlsFavoritingActivity
import com.android.systemui.controls.ui.ControlsUiController
import java.util.function.Consumer
+2 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.systemui.controls.management

import android.content.ComponentName
import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.controls.UserAwareController
import com.android.systemui.util.UserAwareController
import com.android.systemui.statusbar.policy.CallbackController

/**
+53 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.systemui.statusbar.phone.AutoTileManager.WORK;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings.Secure;
import android.text.TextUtils;
import android.util.ArraySet;
@@ -30,6 +31,7 @@ import android.util.ArraySet;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Prefs;
import com.android.systemui.Prefs.Key;
import com.android.systemui.util.UserAwareController;

import java.util.Arrays;
import java.util.Collection;
@@ -37,7 +39,7 @@ import java.util.Collections;

import javax.inject.Inject;

public class AutoAddTracker {
public class AutoAddTracker implements UserAwareController {

    private static final String[][] CONVERT_PREFS = {
            {Key.QS_HOTSPOT_ADDED, HOTSPOT},
@@ -49,20 +51,39 @@ public class AutoAddTracker {

    private final ArraySet<String> mAutoAdded;
    private final Context mContext;
    private int mUserId;

    @Inject
    public AutoAddTracker(Context context) {
    public AutoAddTracker(Context context, int userId) {
        mContext = context;
        mUserId = userId;
        mAutoAdded = new ArraySet<>(getAdded());
        // TODO: remove migration code and shared preferences keys after P release
        if (mUserId == UserHandle.USER_SYSTEM) {
            for (String[] convertPref : CONVERT_PREFS) {
                if (Prefs.getBoolean(context, convertPref[0], false)) {
                    setTileAdded(convertPref[1]);
                    Prefs.remove(context, convertPref[0]);
                }
            }
        }
        mContext.getContentResolver().registerContentObserver(
                Secure.getUriFor(Secure.QS_AUTO_ADDED_TILES), false, mObserver);
                Secure.getUriFor(Secure.QS_AUTO_ADDED_TILES), false, mObserver,
                UserHandle.USER_ALL);
    }

    @Override
    public void changeUser(UserHandle newUser) {
        if (newUser.getIdentifier() == mUserId) {
            return;
        }
        mUserId = newUser.getIdentifier();
        mAutoAdded.clear();
        mAutoAdded.addAll(getAdded());
    }

    @Override
    public int getCurrentUserId() {
        return mUserId;
    }

    public boolean isAdded(String tile) {
@@ -86,12 +107,13 @@ public class AutoAddTracker {
    }

    private void saveTiles() {
        Secure.putString(mContext.getContentResolver(), Secure.QS_AUTO_ADDED_TILES,
                TextUtils.join(",", mAutoAdded));
        Secure.putStringForUser(mContext.getContentResolver(), Secure.QS_AUTO_ADDED_TILES,
                TextUtils.join(",", mAutoAdded), mUserId);
    }

    private Collection<String> getAdded() {
        String current = Secure.getString(mContext.getContentResolver(), Secure.QS_AUTO_ADDED_TILES);
        String current = Secure.getStringForUser(mContext.getContentResolver(),
                Secure.QS_AUTO_ADDED_TILES, mUserId);
        if (current == null) {
            return Collections.emptyList();
        }
@@ -102,7 +124,27 @@ public class AutoAddTracker {
    protected final ContentObserver mObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            mAutoAdded.clear();
            mAutoAdded.addAll(getAdded());
        }
    };

    public static class Builder {
        private final Context mContext;
        private int mUserId;

        @Inject
        public Builder(Context context) {
            mContext = context;
        }

        public Builder setUserId(int userId) {
            mUserId = userId;
            return this;
        }

        public AutoAddTracker build() {
            return new AutoAddTracker(mContext, mUserId);
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -255,6 +255,9 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory>, D
        int currentUser = ActivityManager.getCurrentUser();
        if (currentUser != mCurrentUser) {
            mUserContext = mContext.createContextAsUser(UserHandle.of(currentUser), 0);
            if (mAutoTiles != null) {
                mAutoTiles.changeUser(UserHandle.of(currentUser));
            }
        }
        if (tileSpecs.equals(mTileSpecs) && currentUser == mCurrentUser) return;
        mTiles.entrySet().stream().filter(tile -> !tileSpecs.contains(tile.getKey())).forEach(
Loading