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

Commit b0afc110 authored by Zongheng Wang's avatar Zongheng Wang
Browse files

Remove hidden api dependency of FeatureFlagUtils

Created hearing aid specfic method isHearingAidSettingsEnabled(Context context) to replace isEnabled(Context context, String feature).

Bug: 145230944
Test: Manual
Change-Id: I5fd04c6251ca63eddaa3c71b3d2a69b4202a7952
Merged-In: I2077554cfc6d66e0a2d7682aee11dc9f4364b7d0
parent 87aa31a3
Loading
Loading
Loading
Loading
+29 −3
Original line number Original line Diff line number Diff line
@@ -20,8 +20,9 @@ import android.bluetooth.BluetoothProfile;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings;
import android.util.FeatureFlagUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


import com.android.bluetooth.R;
import com.android.bluetooth.R;
@@ -117,8 +118,7 @@ public class Config {
        for (ProfileConfig config : PROFILE_SERVICES_AND_FLAGS) {
        for (ProfileConfig config : PROFILE_SERVICES_AND_FLAGS) {
            boolean supported = resources.getBoolean(config.mSupported);
            boolean supported = resources.getBoolean(config.mSupported);


            if (!supported && (config.mClass == HearingAidService.class) && FeatureFlagUtils
            if (!supported && (config.mClass == HearingAidService.class) && isHearingAidSettingsEnabled(ctx)) {
                                .isEnabled(ctx, FeatureFlagUtils.HEARING_AID_SETTINGS)) {
                Log.v(TAG, "Feature Flag enables support for HearingAidService");
                Log.v(TAG, "Feature Flag enables support for HearingAidService");
                supported = true;
                supported = true;
            }
            }
@@ -160,4 +160,30 @@ public class Config {


        return (disabledProfilesBitMask & profileMask) != 0;
        return (disabledProfilesBitMask & profileMask) != 0;
    }
    }

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

        // Override precedence:
        // Settings.Global -> sys.fflag.override.* -> static list

        // Step 1: check if hearing aid flag is set in Settings.Global.
        String value;
        if (context != null) {
            value = Settings.Global.getString(context.getContentResolver(), hearingAidSettings);
            if (!TextUtils.isEmpty(value)) {
                return Boolean.parseBoolean(value);
            }
        }

        // Step 2: check if hearing aid flag has any override.
        value = SystemProperties.get(flagOverridePrefix + hearingAidSettings);
        if (!TextUtils.isEmpty(value)) {
            return Boolean.parseBoolean(value);
        }

        // Step 3: return default value.
        return false;
    }
}
}