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

Commit 7eb69f8e authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Gerrit Code Review
Browse files

Merge "Use aconfig instead of device configs" into main

parents f10da57c 86448f29
Loading
Loading
Loading
Loading
+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);
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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();
    }

@@ -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);
+1 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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());
+6 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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