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

Commit e28baefa authored by Aaron Liu's avatar Aaron Liu
Browse files

[Fix settings] Multi user for settings wrapper

Audit and fix SettingsProxy usages to account for multiple users.

Note that this does not fix any Settings usages that does not use
SettingsProxy. There maybe be outstanding files to change, but from a
glance, most of the usages seem to be user aware.

Bug: 226391543
Test: Manual and fixed unit tests

Change-Id: Ia8ff59fe55049cc79ac73237087d3aaca2cbb3b3
parent f86c86cd
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.keyguard.KeyguardClockSwitch.SMALL;
import android.app.WallpaperManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
@@ -264,10 +265,11 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
            mKeyguardUnlockAnimationController.setLockscreenSmartspace(mSmartspaceView);
        }

        mSecureSettings.registerContentObserver(
        mSecureSettings.registerContentObserverForUser(
                Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK),
                false, /* notifyForDescendants */
                mDoubleLineClockObserver
                mDoubleLineClockObserver,
                UserHandle.USER_ALL
        );

        updateDoubleLineClock();
@@ -476,8 +478,9 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    }

    private void updateDoubleLineClock() {
        mCanShowDoubleLineClock = mSecureSettings.getInt(
            Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, 1) != 0;
        mCanShowDoubleLineClock = mSecureSettings.getIntForUser(
            Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK, 1,
                UserHandle.USER_CURRENT) != 0;

        if (!mCanShowDoubleLineClock) {
            mUiExecutor.execute(() -> displayClock(KeyguardClockSwitch.SMALL, /* animate */ true));
+6 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.controls.dagger
import android.content.ContentResolver
import android.content.Context
import android.database.ContentObserver
import android.os.UserHandle
import android.provider.Settings
import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.management.ControlsListingController
@@ -73,10 +74,11 @@ class ControlsComponent @Inject constructor(

    init {
        if (featureEnabled) {
            secureSettings.registerContentObserver(
            secureSettings.registerContentObserverForUser(
                Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS),
                false, /* notifyForDescendants */
                showWhileLockedObserver
                showWhileLockedObserver,
                UserHandle.USER_ALL
            )
            updateShowWhileLocked()
        }
@@ -123,8 +125,8 @@ class ControlsComponent @Inject constructor(
    }

    private fun updateShowWhileLocked() {
        canShowWhileLockedSetting = secureSettings.getInt(
            Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 0) != 0
        canShowWhileLockedSetting = secureSettings.getIntForUser(
            Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 0, UserHandle.USER_CURRENT) != 0
    }

    enum class Visibility {
+20 −14
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.ResolveInfo
import android.database.ContentObserver
import android.net.Uri
import android.os.Handler
import android.os.UserHandle
import android.os.VibrationEffect
import android.provider.Settings.Secure
import android.service.controls.Control
@@ -74,10 +75,10 @@ class ControlActionCoordinatorImpl @Inject constructor(
    private var actionsInProgress = mutableSetOf<String>()
    private val isLocked: Boolean
        get() = !keyguardStateController.isUnlocked()
    private var mAllowTrivialControls: Boolean = secureSettings.getInt(
            Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 0) != 0
    private var mShowDeviceControlsInLockscreen: Boolean = secureSettings.getInt(
            Secure.LOCKSCREEN_SHOW_CONTROLS, 0) != 0
    private var mAllowTrivialControls: Boolean = secureSettings.getIntForUser(
            Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 0, UserHandle.USER_CURRENT) != 0
    private var mShowDeviceControlsInLockscreen: Boolean = secureSettings.getIntForUser(
            Secure.LOCKSCREEN_SHOW_CONTROLS, 0, UserHandle.USER_CURRENT) != 0
    override lateinit var activityContext: Context

    companion object {
@@ -95,23 +96,25 @@ class ControlActionCoordinatorImpl @Inject constructor(
                super.onChange(selfChange, uri)
                when (uri) {
                    lockScreenShowControlsUri -> {
                        mAllowTrivialControls = secureSettings.getInt(
                                Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 0) != 0
                        mAllowTrivialControls = secureSettings.getIntForUser(
                                Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
                                0, UserHandle.USER_CURRENT) != 0
                    }
                    showControlsUri -> {
                        mShowDeviceControlsInLockscreen = secureSettings
                                .getInt(Secure.LOCKSCREEN_SHOW_CONTROLS, 0) != 0
                                .getIntForUser(Secure.LOCKSCREEN_SHOW_CONTROLS,
                                        0, UserHandle.USER_CURRENT) != 0
                    }
                }
            }
        }
        secureSettings.registerContentObserver(
        secureSettings.registerContentObserverForUser(
            lockScreenShowControlsUri,
            false /* notifyForDescendants */, controlsContentObserver
            false /* notifyForDescendants */, controlsContentObserver, UserHandle.USER_ALL
        )
        secureSettings.registerContentObserver(
        secureSettings.registerContentObserverForUser(
            showControlsUri,
            false /* notifyForDescendants */, controlsContentObserver
            false /* notifyForDescendants */, controlsContentObserver, UserHandle.USER_ALL
        )
    }

@@ -311,7 +314,8 @@ class ControlActionCoordinatorImpl @Inject constructor(
                                    MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
                                    .commit()
                        }
                        secureSettings.putInt(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 1)
                        secureSettings.putIntForUser(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 1,
                                UserHandle.USER_CURRENT)
                        true
                    }
                    .create()
@@ -325,8 +329,10 @@ class ControlActionCoordinatorImpl @Inject constructor(
                                    MAX_NUMBER_ATTEMPTS_CONTROLS_DIALOG)
                                    .commit()
                        }
                        secureSettings.putInt(Secure.LOCKSCREEN_SHOW_CONTROLS, 1)
                        secureSettings.putInt(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS, 1)
                        secureSettings.putIntForUser(Secure.LOCKSCREEN_SHOW_CONTROLS,
                                1, UserHandle.USER_CURRENT)
                        secureSettings.putIntForUser(Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS,
                                1, UserHandle.USER_CURRENT)
                        true
                    }
                    .create()
+5 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -210,7 +211,8 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
            Log.w(TAG, "Failed to set id " + id + " to " + value);
            return;
        }
        mSecureSettings.putString(mFlagManager.idToSettingsKey(id), data);
        mSecureSettings.putStringForUser(mFlagManager.idToSettingsKey(id), data,
                UserHandle.USER_CURRENT);
        Log.i(TAG, "Set id " + id + " to " + value);
        removeFromCache(id);
        mFlagManager.dispatchListenersAndMaybeRestart(id, this::restartSystemUI);
@@ -238,7 +240,8 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
    /** Works just like {@link #eraseFlag(int)} except that it doesn't restart SystemUI. */
    private void eraseInternal(int id) {
        // We can't actually "erase" things from sysprops, but we can set them to empty!
        mSecureSettings.putString(mFlagManager.idToSettingsKey(id), "");
        mSecureSettings.putStringForUser(mFlagManager.idToSettingsKey(id), "",
                UserHandle.USER_CURRENT);
        Log.i(TAG, "Erase id " + id);
    }

+5 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.hdmi;

import android.os.UserHandle;
import android.provider.Settings;

import com.android.internal.app.LocalePicker;
@@ -50,8 +51,8 @@ public class HdmiCecSetMenuLanguageHelper {
            SecureSettings secureSettings) {
        mBackgroundExecutor = executor;
        mSecureSettings = secureSettings;
        String denylist = mSecureSettings.getString(
                Settings.Secure.HDMI_CEC_SET_MENU_LANGUAGE_DENYLIST);
        String denylist = mSecureSettings.getStringForUser(
                Settings.Secure.HDMI_CEC_SET_MENU_LANGUAGE_DENYLIST, UserHandle.USER_CURRENT);
        mDenylist = new HashSet<>(denylist == null
                ? Collections.EMPTY_SET
                : Arrays.asList(denylist.split(SEPARATOR)));
@@ -91,7 +92,7 @@ public class HdmiCecSetMenuLanguageHelper {
     */
    public void declineLocale() {
        mDenylist.add(mLocale.toLanguageTag());
        mSecureSettings.putString(Settings.Secure.HDMI_CEC_SET_MENU_LANGUAGE_DENYLIST,
                String.join(SEPARATOR, mDenylist));
        mSecureSettings.putStringForUser(Settings.Secure.HDMI_CEC_SET_MENU_LANGUAGE_DENYLIST,
                String.join(SEPARATOR, mDenylist), UserHandle.USER_CURRENT);
    }
}
Loading