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

Commit 1f62a1be authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Automerger Merge Worker
Browse files

[DO NOT MERGE] Cleans up Config.java am: c8b3567a

parents 76313b8a c8b3567a
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Config {
    private static final String TAG = "AdapterServiceConfig";
@@ -67,6 +68,14 @@ public class Config {
    private static final String FEATURE_HEARING_AID = "settings_bluetooth_hearing_aid";
    private static final String FEATURE_BATTERY = "settings_bluetooth_battery";

    private static final String FFLAG_OVERRIDE_PREFIX = "sys.fflag.override.";
    private static final String PERSIST_PREFIX = "persist." + FFLAG_OVERRIDE_PREFIX;

    private static final Set<String> PERSISTENT_FLAGS = Set.of(
            FEATURE_HEARING_AID,
            FEATURE_BATTERY
    );

    private static class ProfileConfig {
        Class mClass;
        int mSupported;
@@ -255,17 +264,9 @@ public class Config {
        return (disabledProfilesBitMask & profileMask) != 0;
    }

    private static boolean isHearingAidSettingsEnabled(Context context) {
        final String flagOverridePrefix = "sys.fflag.override.";
        final String hearingAidSettings = "settings_bluetooth_hearing_aid";

        return isFeatureEnabled(context, hearingAidSettings, /*defaultValue=*/false);
    }

    private static boolean isFeatureEnabled(Context context, String feature, boolean defaultValue) {
        final String flagOverridePrefix = "sys.fflag.override.";
        // Override precedence:
        // Settings.Global -> sys.fflag.override.* -> static list
        // Settings.Global -> [persist.]sys.fflag.override.* -> static list

        // Step 1: check if feature flag is set in Settings.Global.
        String value;
@@ -277,8 +278,8 @@ public class Config {
        }

        // Step 2: check if feature flag has any override.
        // Flag name: sys.fflag.override.<feature>
        value = SystemProperties.get(flagOverridePrefix + feature);
        // Flag name: [persist.]sys.fflag.override.<feature>
        value = SystemProperties.get(getSystemPropertyPrefix(feature) + feature);
        if (!TextUtils.isEmpty(value)) {
            return Boolean.parseBoolean(value);
        }
@@ -286,6 +287,10 @@ public class Config {
        return defaultValue;
    }

    private static String getSystemPropertyPrefix(String feature) {
        return PERSISTENT_FLAGS.contains(feature) ? PERSIST_PREFIX : FFLAG_OVERRIDE_PREFIX;
    }

    private static List<String> getSystemConfigEnabledProfilesForPackage(Context ctx) {
        SystemConfigManager systemConfigManager = ctx.getSystemService(SystemConfigManager.class);
        if (systemConfigManager == null) {