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

Commit 3616fd63 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Add multi-user support for AutoTileManager"" into rvc-dev

parents eeff6747 12ea87c8
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.util
package com.android.systemui.controls

import android.os.UserHandle

@@ -23,8 +23,6 @@ import android.os.UserHandle
 * changes.
 */
interface UserAwareController {
    @JvmDefault
    fun changeUser(newUser: UserHandle) {}

    val currentUserId: Int
}
 No newline at end of file
+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.util.UserAwareController
import com.android.systemui.controls.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.util.UserAwareController
import com.android.systemui.controls.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.util.UserAwareController
import com.android.systemui.controls.UserAwareController
import com.android.systemui.statusbar.policy.CallbackController

/**
+11 −53
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ 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;
@@ -31,7 +30,6 @@ 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;
@@ -39,7 +37,7 @@ import java.util.Collections;

import javax.inject.Inject;

public class AutoAddTracker implements UserAwareController {
public class AutoAddTracker {

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

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

    public AutoAddTracker(Context context, int userId) {
    @Inject
    public AutoAddTracker(Context context) {
        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,
                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;
                Secure.getUriFor(Secure.QS_AUTO_ADDED_TILES), false, mObserver);
    }

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

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

    private Collection<String> getAdded() {
        String current = Secure.getStringForUser(mContext.getContentResolver(),
                Secure.QS_AUTO_ADDED_TILES, mUserId);
        String current = Secure.getString(mContext.getContentResolver(), Secure.QS_AUTO_ADDED_TILES);
        if (current == null) {
            return Collections.emptyList();
        }
@@ -124,27 +102,7 @@ public class AutoAddTracker implements UserAwareController {
    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);
        }
    }
}
Loading