Loading android/app/src/com/android/bluetooth/Flags.javadeleted 100644 → 0 +0 −35 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth; import android.provider.DeviceConfig; /** * Device config flags for Bluetooth app. * * @hide */ // TODO: Use aconfig flag when available public final class Flags { /** A flag for centralizing audio routing of Bluetooth module. (b/299023147) */ public static boolean audioRoutingCentralization() { return DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_BLUETOOTH, "com.android.bluetooth.audio_routing_centalization", false); } } android/app/src/com/android/bluetooth/a2dp/A2dpService.java +7 −3 Original line number Diff line number Diff line Loading @@ -59,13 +59,14 @@ import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Flags; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.ServiceFactory; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetService; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; Loading @@ -89,6 +90,7 @@ public class A2dpService extends ProfileService { private static A2dpService sA2dpService; private final FeatureFlags mFeatureFlags; private AdapterService mAdapterService; private DatabaseManager mDatabaseManager; private HandlerThread mStateMachinesThread; Loading Loading @@ -128,12 +130,14 @@ public class A2dpService extends ProfileService { A2dpService() { mNativeInterface = requireNonNull(A2dpNativeInterface.getInstance()); mFeatureFlags = new FeatureFlagsImpl(); } @VisibleForTesting A2dpService(Context ctx, A2dpNativeInterface nativeInterface) { A2dpService(Context ctx, A2dpNativeInterface nativeInterface, FeatureFlags featureFlags) { attachBaseContext(ctx); mNativeInterface = requireNonNull(nativeInterface); mFeatureFlags = featureFlags; onCreate(); } Loading Loading @@ -1344,7 +1348,7 @@ public class A2dpService extends ProfileService { if (toState == BluetoothProfile.STATE_CONNECTED) { MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP); } if (!Flags.audioRoutingCentralization()) { if (!mFeatureFlags.audioRoutingCentralization()) { // Set the active device if only one connected device is supported and it was connected if (toState == BluetoothProfile.STATE_CONNECTED && (mMaxConnectedAudioDevices == 1)) { setActiveDevice(device); Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +1 −2 Original line number Diff line number Diff line Loading @@ -108,7 +108,6 @@ import android.util.SparseArray; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Flags; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dp.A2dpService; Loading Loading @@ -695,7 +694,7 @@ public class AdapterService extends Service { Log.i(TAG, "Phone policy disabled"); } if (Flags.audioRoutingCentralization()) { if (featureFlags.audioRoutingCentralization()) { mActiveDeviceManager = new AudioRoutingManager(this, new ServiceFactory()); } else { mActiveDeviceManager = new ActiveDeviceManager(this, new ServiceFactory()); Loading android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ import com.android.bluetooth.btservice.ActiveDeviceManager; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.SilenceDeviceManager; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.flags.FakeFeatureFlagsImpl; import com.android.bluetooth.flags.Flags; import org.junit.After; import org.junit.Assert; Loading Loading @@ -77,6 +79,7 @@ public class A2dpServiceTest { private final BlockingQueue<Intent> mCodecConfigChangedQueue = new LinkedBlockingQueue<>(); private final BlockingQueue<Intent> mActiveDeviceQueue = new LinkedBlockingQueue<>(); private FakeFeatureFlagsImpl mFakeFlagsImpl; @Mock private AdapterService mAdapterService; @Mock private ActiveDeviceManager mActiveDeviceManager; @Mock private A2dpNativeInterface mMockNativeInterface; Loading Loading @@ -104,9 +107,10 @@ public class A2dpServiceTest { doReturn(mActiveDeviceManager).when(mAdapterService).getActiveDeviceManager(); doReturn(mSilenceDeviceManager).when(mAdapterService).getSilenceDeviceManager(); mFakeFlagsImpl = new FakeFeatureFlagsImpl(); mFakeFlagsImpl.setFlag(Flags.FLAG_AUDIO_ROUTING_CENTRALIZATION, false); mAdapter = BluetoothAdapter.getDefaultAdapter(); mA2dpService = new A2dpService(mTargetContext, mMockNativeInterface); mA2dpService = new A2dpService(mTargetContext, mMockNativeInterface, mFakeFlagsImpl); mA2dpService.doStart(); // Override the timeout value to speed up the test Loading flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ aconfig_declarations { name: "bluetooth_aconfig_flags", package: "com.android.bluetooth.flags", srcs: [ "audio_routing.aconfig", "gatt.aconfig", "hap.aconfig", "hfp.aconfig", Loading Loading
android/app/src/com/android/bluetooth/Flags.javadeleted 100644 → 0 +0 −35 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth; import android.provider.DeviceConfig; /** * Device config flags for Bluetooth app. * * @hide */ // TODO: Use aconfig flag when available public final class Flags { /** A flag for centralizing audio routing of Bluetooth module. (b/299023147) */ public static boolean audioRoutingCentralization() { return DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_BLUETOOTH, "com.android.bluetooth.audio_routing_centalization", false); } }
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +7 −3 Original line number Diff line number Diff line Loading @@ -59,13 +59,14 @@ import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Flags; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.ServiceFactory; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.flags.FeatureFlags; import com.android.bluetooth.flags.FeatureFlagsImpl; import com.android.bluetooth.hfp.HeadsetService; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; Loading @@ -89,6 +90,7 @@ public class A2dpService extends ProfileService { private static A2dpService sA2dpService; private final FeatureFlags mFeatureFlags; private AdapterService mAdapterService; private DatabaseManager mDatabaseManager; private HandlerThread mStateMachinesThread; Loading Loading @@ -128,12 +130,14 @@ public class A2dpService extends ProfileService { A2dpService() { mNativeInterface = requireNonNull(A2dpNativeInterface.getInstance()); mFeatureFlags = new FeatureFlagsImpl(); } @VisibleForTesting A2dpService(Context ctx, A2dpNativeInterface nativeInterface) { A2dpService(Context ctx, A2dpNativeInterface nativeInterface, FeatureFlags featureFlags) { attachBaseContext(ctx); mNativeInterface = requireNonNull(nativeInterface); mFeatureFlags = featureFlags; onCreate(); } Loading Loading @@ -1344,7 +1348,7 @@ public class A2dpService extends ProfileService { if (toState == BluetoothProfile.STATE_CONNECTED) { MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP); } if (!Flags.audioRoutingCentralization()) { if (!mFeatureFlags.audioRoutingCentralization()) { // Set the active device if only one connected device is supported and it was connected if (toState == BluetoothProfile.STATE_CONNECTED && (mMaxConnectedAudioDevices == 1)) { setActiveDevice(device); Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +1 −2 Original line number Diff line number Diff line Loading @@ -108,7 +108,6 @@ import android.util.SparseArray; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Flags; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dp.A2dpService; Loading Loading @@ -695,7 +694,7 @@ public class AdapterService extends Service { Log.i(TAG, "Phone policy disabled"); } if (Flags.audioRoutingCentralization()) { if (featureFlags.audioRoutingCentralization()) { mActiveDeviceManager = new AudioRoutingManager(this, new ServiceFactory()); } else { mActiveDeviceManager = new ActiveDeviceManager(this, new ServiceFactory()); Loading
android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +6 −2 Original line number Diff line number Diff line Loading @@ -44,6 +44,8 @@ import com.android.bluetooth.btservice.ActiveDeviceManager; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.SilenceDeviceManager; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.flags.FakeFeatureFlagsImpl; import com.android.bluetooth.flags.Flags; import org.junit.After; import org.junit.Assert; Loading Loading @@ -77,6 +79,7 @@ public class A2dpServiceTest { private final BlockingQueue<Intent> mCodecConfigChangedQueue = new LinkedBlockingQueue<>(); private final BlockingQueue<Intent> mActiveDeviceQueue = new LinkedBlockingQueue<>(); private FakeFeatureFlagsImpl mFakeFlagsImpl; @Mock private AdapterService mAdapterService; @Mock private ActiveDeviceManager mActiveDeviceManager; @Mock private A2dpNativeInterface mMockNativeInterface; Loading Loading @@ -104,9 +107,10 @@ public class A2dpServiceTest { doReturn(mActiveDeviceManager).when(mAdapterService).getActiveDeviceManager(); doReturn(mSilenceDeviceManager).when(mAdapterService).getSilenceDeviceManager(); mFakeFlagsImpl = new FakeFeatureFlagsImpl(); mFakeFlagsImpl.setFlag(Flags.FLAG_AUDIO_ROUTING_CENTRALIZATION, false); mAdapter = BluetoothAdapter.getDefaultAdapter(); mA2dpService = new A2dpService(mTargetContext, mMockNativeInterface); mA2dpService = new A2dpService(mTargetContext, mMockNativeInterface, mFakeFlagsImpl); mA2dpService.doStart(); // Override the timeout value to speed up the test Loading
flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ aconfig_declarations { name: "bluetooth_aconfig_flags", package: "com.android.bluetooth.flags", srcs: [ "audio_routing.aconfig", "gatt.aconfig", "hap.aconfig", "hfp.aconfig", Loading