1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.media;
18 
19 import android.annotation.StringDef;
20 import android.provider.DeviceConfig;
21 
22 import java.lang.annotation.ElementType;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 import java.lang.annotation.Target;
26 
27 /* package */ class MediaFeatureFlagManager {
28 
29     /**
30      * Namespace for media better together features.
31      */
32     private static final String NAMESPACE_MEDIA_BETTER_TOGETHER = "media_better_together";
33 
34     @StringDef(prefix = "FEATURE_", value = {
35             FEATURE_AUDIO_STRATEGIES_IS_USING_LEGACY_CONTROLLER
36     })
37     @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
38     @Retention(RetentionPolicy.SOURCE)
39     /* package */ @interface MediaFeatureFlag {}
40 
41     /**
42      * Whether to use old legacy implementation of BluetoothRouteController or new
43      * 'Audio Strategies'-aware controller.
44      */
45     /* package */ static final @MediaFeatureFlag String
46             FEATURE_AUDIO_STRATEGIES_IS_USING_LEGACY_CONTROLLER =
47             "BluetoothRouteController__enable_legacy_bluetooth_routes_controller";
48 
49     private static final MediaFeatureFlagManager sInstance = new MediaFeatureFlagManager();
50 
MediaFeatureFlagManager()51     private MediaFeatureFlagManager() {
52         // Empty to prevent instantiation.
53     }
54 
getInstance()55     /* package */ static MediaFeatureFlagManager getInstance() {
56         return sInstance;
57     }
58 
59     /**
60      * Returns a boolean value from {@link DeviceConfig} from the system_time namespace, or
61      * {@code defaultValue} if there is no explicit value set.
62      */
getBoolean(@ediaFeatureFlag String key, boolean defaultValue)63     public boolean getBoolean(@MediaFeatureFlag String key, boolean defaultValue) {
64         return DeviceConfig.getBoolean(NAMESPACE_MEDIA_BETTER_TOGETHER, key, defaultValue);
65     }
66 }
67