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

Commit f7c8a9b0 authored by Mark Punzalan's avatar Mark Punzalan
Browse files

Reduce logging in AconfigFlags.java

By default, the only logging that should be generated is when an element
is skipped due to an disabled or enabled feature flag. The more verbose
logging needs to be enabled by setting `DEBUG = true`.

Also cleaned up some unused code and refactored constants.

Bug: 369907949
Test: Full build
Flag: EXEMPT flagging support change
Change-Id: Ie61bff7e39fa3136e95f773afb359a03c90eef1a
parent 49a44426
Loading
Loading
Loading
Loading
+28 −41
Original line number Diff line number Diff line
@@ -53,19 +53,18 @@ import java.util.Map;
 * @hide
 */
public class AconfigFlags {
    private static final boolean DEBUG = false;
    private static final String LOG_TAG = "AconfigFlags";

    public enum Permission {
        READ_WRITE,
        READ_ONLY
    }
    private static final String OVERRIDE_PREFIX = "device_config_overrides/";
    private static final String STAGED_PREFIX = "staged/";

    private final ArrayMap<String, Boolean> mFlagValues = new ArrayMap<>();
    private final ArrayMap<String, Permission> mFlagPermissions = new ArrayMap<>();

    public AconfigFlags() {
        if (!Flags.manifestFlagging()) {
            if (DEBUG) {
                Slog.v(LOG_TAG, "Feature disabled, skipped all loading");
            }
            return;
        }
        final var defaultFlagProtoFiles =
@@ -130,19 +129,17 @@ public class AconfigFlags {
                    if (!"false".equalsIgnoreCase(value) && !"true".equalsIgnoreCase(value)) {
                        continue;
                    }
                    final var overridePrefix = "device_config_overrides/";
                    final var stagedPrefix = "staged/";
                    String separator = "/";
                    String prefix = "default";
                    int priority = 0;
                    if (name.startsWith(overridePrefix)) {
                        prefix = overridePrefix;
                        name = name.substring(overridePrefix.length());
                    if (name.startsWith(OVERRIDE_PREFIX)) {
                        prefix = OVERRIDE_PREFIX;
                        name = name.substring(OVERRIDE_PREFIX.length());
                        separator = ":";
                        priority = 20;
                    } else if (name.startsWith(stagedPrefix)) {
                        prefix = stagedPrefix;
                        name = name.substring(stagedPrefix.length());
                    } else if (name.startsWith(STAGED_PREFIX)) {
                        prefix = STAGED_PREFIX;
                        name = name.substring(STAGED_PREFIX.length());
                        separator = "*";
                        priority = 10;
                    }
@@ -155,12 +152,19 @@ public class AconfigFlags {
                    if (!mFlagValues.containsKey(flagPackageAndName)) {
                        continue;
                    }
                    if (DEBUG) {
                        Slog.d(LOG_TAG, "Found " + prefix
                            + " Aconfig flag value for " + flagPackageAndName + " = " + value);
                                + " Aconfig flag value in settings for " + flagPackageAndName
                                + " = " + value);
                    }
                    final Integer currentPriority = flagPriority.get(flagPackageAndName);
                    if (currentPriority != null && currentPriority >= priority) {
                        Slog.i(LOG_TAG, "Skipping " + prefix + " flag " + flagPackageAndName
                                + " because of the existing one with priority " + currentPriority);
                        if (DEBUG) {
                            Slog.d(LOG_TAG, "Skipping " + prefix + " flag "
                                    + flagPackageAndName
                                    + " in settings because of existing one with priority "
                                    + currentPriority);
                        }
                        continue;
                    }
                    flagPriority.put(flagPackageAndName, priority);
@@ -185,15 +189,7 @@ public class AconfigFlags {
        for (parsed_flag flag : parsedFlags.parsedFlag) {
            String flagPackageAndName = flag.package_ + "." + flag.name;
            boolean flagValue = (flag.state == Aconfig.ENABLED);
            Slog.v(LOG_TAG, "Read Aconfig default flag value "
                    + flagPackageAndName + " = " + flagValue);
            mFlagValues.put(flagPackageAndName, flagValue);

            Permission permission = flag.permission == Aconfig.READ_ONLY
                    ? Permission.READ_ONLY
                    : Permission.READ_WRITE;

            mFlagPermissions.put(flagPackageAndName, permission);
        }
    }

@@ -203,21 +199,12 @@ public class AconfigFlags {
     * @return the current value of the given Aconfig flag, or null if there is no such flag
     */
    @Nullable
    public Boolean getFlagValue(@NonNull String flagPackageAndName) {
    private Boolean getFlagValue(@NonNull String flagPackageAndName) {
        Boolean value = mFlagValues.get(flagPackageAndName);
        Slog.d(LOG_TAG, "Aconfig flag value for " + flagPackageAndName + " = " + value);
        return value;
        if (DEBUG) {
            Slog.v(LOG_TAG, "Aconfig flag value for " + flagPackageAndName + " = " + value);
        }

    /**
     * Get the flag permission, or null if the flag doesn't exist.
     * @param flagPackageAndName Full flag name formatted as 'package.flag'
     * @return the current permission of the given Aconfig flag, or null if there is no such flag
     */
    @Nullable
    public Permission getFlagPermission(@NonNull String flagPackageAndName) {
        Permission permission = mFlagPermissions.get(flagPackageAndName);
        return permission;
        return value;
    }

    /**
@@ -247,7 +234,7 @@ public class AconfigFlags {
        }
        // Skip if flag==false && attr=="flag" OR flag==true && attr=="!flag" (negated)
        if (flagValue == negated) {
            Slog.v(LOG_TAG, "Skipping element " + parser.getName()
            Slog.i(LOG_TAG, "Skipping element " + parser.getName()
                    + " behind feature flag " + featureFlag + " = " + flagValue);
            return true;
        }