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

Commit 12852ffc authored by Nick Chameyev's avatar Nick Chameyev Committed by Automerger Merge Worker
Browse files

Merge "Add DeviceConfig feature flag type to SystemUI" into tm-qpr-dev am: 1e09b6db

parents 4ad8a03c 1e09b6db
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,12 @@ interface ResourceFlag<T> : Flag<T> {
    val resourceId: Int
    val resourceId: Int
}
}


interface DeviceConfigFlag<T> : Flag<T> {
    val name: String
    val namespace: String
    val default: T
}

interface SysPropFlag<T> : Flag<T> {
interface SysPropFlag<T> : Flag<T> {
    val name: String
    val name: String
    val default: T
    val default: T
@@ -74,6 +80,14 @@ data class ResourceBooleanFlag @JvmOverloads constructor(
    override val teamfood: Boolean = false
    override val teamfood: Boolean = false
) : ResourceFlag<Boolean>
) : ResourceFlag<Boolean>


data class DeviceConfigBooleanFlag @JvmOverloads constructor(
    override val id: Int,
    override val name: String,
    override val namespace: String,
    override val default: Boolean = false,
    override val teamfood: Boolean = false
) : DeviceConfigFlag<Boolean>

data class SysPropBooleanFlag @JvmOverloads constructor(
data class SysPropBooleanFlag @JvmOverloads constructor(
    override val id: Int,
    override val id: Int,
    override val name: String,
    override val name: String,
+3 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,9 @@ interface FeatureFlags : FlagListenable {
    /** Returns a boolean value for the given flag.  */
    /** Returns a boolean value for the given flag.  */
    fun isEnabled(flag: ResourceBooleanFlag): Boolean
    fun isEnabled(flag: ResourceBooleanFlag): Boolean


    /** Returns a boolean value for the given flag.  */
    fun isEnabled(flag: DeviceConfigBooleanFlag): Boolean

    /** Returns a boolean value for the given flag.  */
    /** Returns a boolean value for the given flag.  */
    fun isEnabled(flag: SysPropBooleanFlag): Boolean
    fun isEnabled(flag: SysPropBooleanFlag): Boolean


+23 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.util.Log;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
@@ -44,6 +45,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.statusbar.commandline.Command;
import com.android.systemui.statusbar.commandline.Command;
import com.android.systemui.statusbar.commandline.CommandRegistry;
import com.android.systemui.statusbar.commandline.CommandRegistry;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.settings.SecureSettings;


import java.io.PrintWriter;
import java.io.PrintWriter;
@@ -81,6 +83,7 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
    private final SecureSettings mSecureSettings;
    private final SecureSettings mSecureSettings;
    private final Resources mResources;
    private final Resources mResources;
    private final SystemPropertiesHelper mSystemProperties;
    private final SystemPropertiesHelper mSystemProperties;
    private final DeviceConfigProxy mDeviceConfigProxy;
    private final Map<Integer, Flag<?>> mAllFlags;
    private final Map<Integer, Flag<?>> mAllFlags;
    private final Map<Integer, Boolean> mBooleanFlagCache = new TreeMap<>();
    private final Map<Integer, Boolean> mBooleanFlagCache = new TreeMap<>();
    private final Map<Integer, String> mStringFlagCache = new TreeMap<>();
    private final Map<Integer, String> mStringFlagCache = new TreeMap<>();
@@ -94,6 +97,7 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
            SystemPropertiesHelper systemProperties,
            SystemPropertiesHelper systemProperties,
            @Main Resources resources,
            @Main Resources resources,
            DumpManager dumpManager,
            DumpManager dumpManager,
            DeviceConfigProxy deviceConfigProxy,
            @Named(ALL_FLAGS) Map<Integer, Flag<?>> allFlags,
            @Named(ALL_FLAGS) Map<Integer, Flag<?>> allFlags,
            CommandRegistry commandRegistry,
            CommandRegistry commandRegistry,
            IStatusBarService barService) {
            IStatusBarService barService) {
@@ -101,6 +105,7 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
        mSecureSettings = secureSettings;
        mSecureSettings = secureSettings;
        mResources = resources;
        mResources = resources;
        mSystemProperties = systemProperties;
        mSystemProperties = systemProperties;
        mDeviceConfigProxy = deviceConfigProxy;
        mAllFlags = allFlags;
        mAllFlags = allFlags;
        mBarService = barService;
        mBarService = barService;


@@ -137,6 +142,18 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
        return mBooleanFlagCache.get(id);
        return mBooleanFlagCache.get(id);
    }
    }


    @Override
    public boolean isEnabled(@NonNull DeviceConfigBooleanFlag flag) {
        int id = flag.getId();
        if (!mBooleanFlagCache.containsKey(id)) {
            boolean deviceConfigValue = mDeviceConfigProxy.getBoolean(flag.getNamespace(),
                    flag.getName(), flag.getDefault());
            mBooleanFlagCache.put(id, readFlagValue(id, deviceConfigValue));
        }

        return mBooleanFlagCache.get(id);
    }

    @Override
    @Override
    public boolean isEnabled(@NonNull SysPropBooleanFlag flag) {
    public boolean isEnabled(@NonNull SysPropBooleanFlag flag) {
        int id = flag.getId();
        int id = flag.getId();
@@ -293,6 +310,8 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
            setFlagValue(flag.getId(), value, BooleanFlagSerializer.INSTANCE);
            setFlagValue(flag.getId(), value, BooleanFlagSerializer.INSTANCE);
        } else if (flag instanceof ResourceBooleanFlag) {
        } else if (flag instanceof ResourceBooleanFlag) {
            setFlagValue(flag.getId(), value, BooleanFlagSerializer.INSTANCE);
            setFlagValue(flag.getId(), value, BooleanFlagSerializer.INSTANCE);
        } else if (flag instanceof DeviceConfigBooleanFlag) {
            setFlagValue(flag.getId(), value, BooleanFlagSerializer.INSTANCE);
        } else if (flag instanceof SysPropBooleanFlag) {
        } else if (flag instanceof SysPropBooleanFlag) {
            // Store SysProp flags in SystemProperties where they can read by outside parties.
            // Store SysProp flags in SystemProperties where they can read by outside parties.
            mSystemProperties.setBoolean(((SysPropBooleanFlag) flag).getName(), value);
            mSystemProperties.setBoolean(((SysPropBooleanFlag) flag).getName(), value);
@@ -394,6 +413,10 @@ public class FeatureFlagsDebug implements FeatureFlags, Dumpable {
                return new BooleanFlag(
                return new BooleanFlag(
                        f.getId(), isEnabled((ResourceBooleanFlag) f), f.getTeamfood());
                        f.getId(), isEnabled((ResourceBooleanFlag) f), f.getTeamfood());
            }
            }
            if (f instanceof DeviceConfigBooleanFlag) {
                return new BooleanFlag(
                        f.getId(), isEnabled((DeviceConfigBooleanFlag) f), f.getTeamfood());
            }
            if (f instanceof SysPropBooleanFlag) {
            if (f instanceof SysPropBooleanFlag) {
                // TODO(b/223379190): Teamfood not supported for sysprop flags yet.
                // TODO(b/223379190): Teamfood not supported for sysprop flags yet.
                return new BooleanFlag(
                return new BooleanFlag(
+17 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.flags;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;


import android.content.res.Resources;
import android.content.res.Resources;
import android.provider.DeviceConfig;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseBooleanArray;


@@ -28,6 +29,7 @@ import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.util.DeviceConfigProxy;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map;
@@ -44,6 +46,7 @@ import javax.inject.Inject;
public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
    private final Resources mResources;
    private final Resources mResources;
    private final SystemPropertiesHelper mSystemProperties;
    private final SystemPropertiesHelper mSystemProperties;
    private final DeviceConfigProxy mDeviceConfigProxy;
    SparseBooleanArray mBooleanCache = new SparseBooleanArray();
    SparseBooleanArray mBooleanCache = new SparseBooleanArray();
    SparseArray<String> mStringCache = new SparseArray<>();
    SparseArray<String> mStringCache = new SparseArray<>();


@@ -51,9 +54,11 @@ public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
    public FeatureFlagsRelease(
    public FeatureFlagsRelease(
            @Main Resources resources,
            @Main Resources resources,
            SystemPropertiesHelper systemProperties,
            SystemPropertiesHelper systemProperties,
            DeviceConfigProxy deviceConfigProxy,
            DumpManager dumpManager) {
            DumpManager dumpManager) {
        mResources = resources;
        mResources = resources;
        mSystemProperties = systemProperties;
        mSystemProperties = systemProperties;
        mDeviceConfigProxy = deviceConfigProxy;
        dumpManager.registerDumpable("SysUIFlags", this);
        dumpManager.registerDumpable("SysUIFlags", this);
    }
    }


@@ -78,6 +83,18 @@ public class FeatureFlagsRelease implements FeatureFlags, Dumpable {
        return mBooleanCache.valueAt(cacheIndex);
        return mBooleanCache.valueAt(cacheIndex);
    }
    }


    @Override
    public boolean isEnabled(@NonNull DeviceConfigBooleanFlag flag) {
        int cacheIndex = mBooleanCache.indexOfKey(flag.getId());
        if (cacheIndex < 0) {
            boolean deviceConfigValue = mDeviceConfigProxy.getBoolean(flag.getNamespace(),
                    flag.getName(), flag.getDefault());
            return isEnabled(flag.getId(), deviceConfigValue);
        }

        return mBooleanCache.valueAt(cacheIndex);
    }

    @Override
    @Override
    public boolean isEnabled(SysPropBooleanFlag flag) {
    public boolean isEnabled(SysPropBooleanFlag flag) {
        int cacheIndex = mBooleanCache.indexOfKey(flag.getId());
        int cacheIndex = mBooleanCache.indexOfKey(flag.getId());
+7 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.systemui.flags;
package com.android.systemui.flags;


import static android.provider.DeviceConfig.NAMESPACE_WINDOW_MANAGER;

import com.android.internal.annotations.Keep;
import com.android.internal.annotations.Keep;
import com.android.systemui.R;
import com.android.systemui.R;


@@ -173,6 +175,11 @@ public class Flags {
    public static final SysPropBooleanFlag BUBBLES_HOME_GESTURE =
    public static final SysPropBooleanFlag BUBBLES_HOME_GESTURE =
            new SysPropBooleanFlag(1101, "persist.wm.debug.bubbles_home_gesture", true);
            new SysPropBooleanFlag(1101, "persist.wm.debug.bubbles_home_gesture", true);


    @Keep
    public static final DeviceConfigBooleanFlag WM_ENABLE_PARTIAL_SCREEN_SHARING =
            new DeviceConfigBooleanFlag(1102, "record_task_content",
                    NAMESPACE_WINDOW_MANAGER, false, true);

    // 1200 - predictive back
    // 1200 - predictive back
    @Keep
    @Keep
    public static final SysPropBooleanFlag WM_ENABLE_PREDICTIVE_BACK = new SysPropBooleanFlag(
    public static final SysPropBooleanFlag WM_ENABLE_PREDICTIVE_BACK = new SysPropBooleanFlag(
Loading