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

Commit de02e49c authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I7ff39026,Ifcadb97d,I6626418a,I8e9fd570 into main

* changes:
  24Q4: Removal of override_context_to_specify_device_id
  24Q4: Removal of leaudio_call_start_scan_directly
  24Q4: Removal of leaudio_synchronize_start
  24Q4: Removal of respect_ble_scan_setting
parents ca277aeb 6468b975
Loading
Loading
Loading
Loading
+39 −100
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.bluetooth.avrcpcontroller.AvrcpControllerService;
import com.android.bluetooth.bas.BatteryService;
import com.android.bluetooth.bass_client.BassClientService;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.hap.HapClientService;
import com.android.bluetooth.hearingaid.HearingAidService;
@@ -86,11 +85,7 @@ public class Config {
    };

    /** List of profile services with the profile-supported resource flag and bit mask. */
    private static final ProfileConfig[] PROFILE_SERVICES_AND_FLAGS;

    static {
        if (Flags.leaudioSynchronizeStart()) {
            PROFILE_SERVICES_AND_FLAGS =
    private static final ProfileConfig[] PROFILE_SERVICES_AND_FLAGS =
            new ProfileConfig[] {
                // Prioritize GattService startup by making it the first Profile to
                // boot. This resolves dependency issues for some Profiles.
@@ -99,8 +94,7 @@ public class Config {
                new ProfileConfig(A2dpSinkService.isEnabled(), BluetoothProfile.A2DP_SINK),
                new ProfileConfig(AvrcpTargetService.isEnabled(), BluetoothProfile.AVRCP),
                new ProfileConfig(
                                AvrcpControllerService.isEnabled(),
                                BluetoothProfile.AVRCP_CONTROLLER),
                        AvrcpControllerService.isEnabled(), BluetoothProfile.AVRCP_CONTROLLER),
                new ProfileConfig(
                        BassClientService.isEnabled(),
                        BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT),
@@ -108,83 +102,28 @@ public class Config {
                new ProfileConfig(
                        CsipSetCoordinatorService.isEnabled(),
                        BluetoothProfile.CSIP_SET_COORDINATOR),
                        new ProfileConfig(
                                HapClientService.isEnabled(), BluetoothProfile.HAP_CLIENT),
                new ProfileConfig(HapClientService.isEnabled(), BluetoothProfile.HAP_CLIENT),
                new ProfileConfig(HeadsetService.isEnabled(), BluetoothProfile.HEADSET),
                new ProfileConfig(
                        HeadsetClientService.isEnabled(), BluetoothProfile.HEADSET_CLIENT),
                        new ProfileConfig(
                                HearingAidService.isEnabled(), BluetoothProfile.HEARING_AID),
                        new ProfileConfig(
                                HidDeviceService.isEnabled(), BluetoothProfile.HID_DEVICE),
                new ProfileConfig(HearingAidService.isEnabled(), BluetoothProfile.HEARING_AID),
                new ProfileConfig(HidDeviceService.isEnabled(), BluetoothProfile.HID_DEVICE),
                new ProfileConfig(HidHostService.isEnabled(), BluetoothProfile.HID_HOST),
                new ProfileConfig(TbsService.isEnabled(), BluetoothProfile.LE_CALL_CONTROL),
                new ProfileConfig(BluetoothMapService.isEnabled(), BluetoothProfile.MAP),
                        new ProfileConfig(
                                MapClientService.isEnabled(), BluetoothProfile.MAP_CLIENT),
                new ProfileConfig(MapClientService.isEnabled(), BluetoothProfile.MAP_CLIENT),
                new ProfileConfig(McpService.isEnabled(), BluetoothProfile.MCP_SERVER),
                new ProfileConfig(BluetoothOppService.isEnabled(), BluetoothProfile.OPP),
                new ProfileConfig(PanService.isEnabled(), BluetoothProfile.PAN),
                new ProfileConfig(BluetoothPbapService.isEnabled(), BluetoothProfile.PBAP),
                        new ProfileConfig(
                                PbapClientService.isEnabled(), BluetoothProfile.PBAP_CLIENT),
                new ProfileConfig(PbapClientService.isEnabled(), BluetoothProfile.PBAP_CLIENT),
                new ProfileConfig(SapService.isEnabled(), BluetoothProfile.SAP),
                new ProfileConfig(
                        VolumeControlService.isEnabled(), BluetoothProfile.VOLUME_CONTROL),
                new ProfileConfig(LeAudioService.isEnabled(), BluetoothProfile.LE_AUDIO),
                new ProfileConfig(
                                LeAudioService.isBroadcastEnabled(),
                                BluetoothProfile.LE_AUDIO_BROADCAST),
                    };
        } else {
            PROFILE_SERVICES_AND_FLAGS =
                    new ProfileConfig[] {
                        // Prioritize GattService startup by making it the first Profile to
                        // boot. This resolves dependency issues for some Profiles.
                        new ProfileConfig(GattService.isEnabled(), BluetoothProfile.GATT),
                        new ProfileConfig(A2dpService.isEnabled(), BluetoothProfile.A2DP),
                        new ProfileConfig(A2dpSinkService.isEnabled(), BluetoothProfile.A2DP_SINK),
                        new ProfileConfig(AvrcpTargetService.isEnabled(), BluetoothProfile.AVRCP),
                        new ProfileConfig(
                                AvrcpControllerService.isEnabled(),
                                BluetoothProfile.AVRCP_CONTROLLER),
                        new ProfileConfig(
                                BassClientService.isEnabled(),
                                BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT),
                        new ProfileConfig(BatteryService.isEnabled(), BluetoothProfile.BATTERY),
                        new ProfileConfig(
                                CsipSetCoordinatorService.isEnabled(),
                                BluetoothProfile.CSIP_SET_COORDINATOR),
                        new ProfileConfig(
                                HapClientService.isEnabled(), BluetoothProfile.HAP_CLIENT),
                        new ProfileConfig(HeadsetService.isEnabled(), BluetoothProfile.HEADSET),
                        new ProfileConfig(
                                HeadsetClientService.isEnabled(), BluetoothProfile.HEADSET_CLIENT),
                        new ProfileConfig(
                                HearingAidService.isEnabled(), BluetoothProfile.HEARING_AID),
                        new ProfileConfig(
                                HidDeviceService.isEnabled(), BluetoothProfile.HID_DEVICE),
                        new ProfileConfig(HidHostService.isEnabled(), BluetoothProfile.HID_HOST),
                        new ProfileConfig(LeAudioService.isEnabled(), BluetoothProfile.LE_AUDIO),
                        new ProfileConfig(
                                LeAudioService.isBroadcastEnabled(),
                                BluetoothProfile.LE_AUDIO_BROADCAST),
                        new ProfileConfig(TbsService.isEnabled(), BluetoothProfile.LE_CALL_CONTROL),
                        new ProfileConfig(BluetoothMapService.isEnabled(), BluetoothProfile.MAP),
                        new ProfileConfig(
                                MapClientService.isEnabled(), BluetoothProfile.MAP_CLIENT),
                        new ProfileConfig(McpService.isEnabled(), BluetoothProfile.MCP_SERVER),
                        new ProfileConfig(BluetoothOppService.isEnabled(), BluetoothProfile.OPP),
                        new ProfileConfig(PanService.isEnabled(), BluetoothProfile.PAN),
                        new ProfileConfig(BluetoothPbapService.isEnabled(), BluetoothProfile.PBAP),
                        new ProfileConfig(
                                PbapClientService.isEnabled(), BluetoothProfile.PBAP_CLIENT),
                        new ProfileConfig(SapService.isEnabled(), BluetoothProfile.SAP),
                        new ProfileConfig(
                                VolumeControlService.isEnabled(), BluetoothProfile.VOLUME_CONTROL),
                        LeAudioService.isBroadcastEnabled(), BluetoothProfile.LE_AUDIO_BROADCAST),
            };
        }
    }

    /** A test function to allow for dynamic enabled */
    @VisibleForTesting
+16 −158
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import android.bluetooth.IBluetoothLeBroadcastCallback;
import android.bluetooth.IBluetoothVolumeControl;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.IScannerCallback;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
@@ -222,10 +221,8 @@ public class LeAudioService extends ProfileService {
            new RemoteCallbackList<>();

    BluetoothLeScanner mAudioServersScanner;
    /* When mScanCallback is not null, it means scan is started. */
    ScanCallback mScanCallback;

    private final AudioServerScanCallback2 mScanCallback2 = new AudioServerScanCallback2();
    private final AudioServerScanCallback mScanCallback = new AudioServerScanCallback();

    public LeAudioService(Context ctx) {
        this(ctx, LeAudioNativeInterface.getInstance());
@@ -604,30 +601,6 @@ public class LeAudioService extends ProfileService {

        // Setup codec config
        mLeAudioCodecConfig = new LeAudioCodecConfig(this);
        if (!Flags.leaudioSynchronizeStart()) {
            // Delay the call to init by posting it. This ensures TBS and MCS are fully initialized
            // before we start accepting connections
            mHandler.post(this::init);
            return;
        }
        mNativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());

        if (leaudioUseAudioModeListener()) {
            mAudioManager.addOnModeChangedListener(getMainExecutor(), mAudioModeChangeListener);
        }
    }

    // TODO: b/341385684 -- Delete the init method as it has been inlined in start
    private void init() {
        if (!isAvailable()) {
            Log.e(TAG, " Service disabled before init");
            return;
        }

        if (!mTmapStarted) {
            mTmapStarted = registerTmap();
        }

        mNativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());

        if (leaudioUseAudioModeListener()) {
@@ -656,9 +629,6 @@ public class LeAudioService extends ProfileService {

        clearCreateBroadcastTimeoutCallback();

        if (!Flags.leaudioSynchronizeStart()) {
            mHandler.removeCallbacks(this::init);
        }
        removeActiveDevice(false);

        if (mTmapGattServer == null) {
@@ -669,7 +639,7 @@ public class LeAudioService extends ProfileService {
            mTmapStarted = false;
        }

        stopAudioServersBackgroundScan();
        mScanCallback.stopBackgroundScan();
        mAudioServersScanner = null;

        // Don't wait for async call with INACTIVE group status, clean active
@@ -1984,7 +1954,7 @@ public class LeAudioService extends ProfileService {
        return true;
    }

    private class AudioServerScanCallback2 extends IScannerCallback.Stub {
    private class AudioServerScanCallback extends IScannerCallback.Stub {
        // See BluetoothLeScanner.BleScanCallbackWrapper.mScannerId
        int mScannerId = 0;

@@ -2083,44 +2053,6 @@ public class LeAudioService extends ProfileService {
        public void onScanManagerErrorCallback(int errorCode) {}
    }

    private class AudioServerScanCallback extends ScanCallback {
        int mMaxScanRetries = 10;
        int mScanRetries = 0;

        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            /* Filter is set in the way, that there will be no results found.
             * We just need a scanner to be running for the APCF filtering defined in native
             */
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            /* Filter is set in the way, that there will be no results found.
             * We just need a scanner to be running for the APCF filtering defined in native
             */
        }

        @Override
        public void onScanFailed(int errorCode) {
            Log.w(TAG, "Scan failed err: " + errorCode + " scan retries: " + mScanRetries);
            switch (errorCode) {
                case SCAN_FAILED_INTERNAL_ERROR:
                case SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
                    if (mScanRetries < mMaxScanRetries) {
                        mScanRetries++;
                        Log.w(TAG, "Failed to start. Let's retry");
                        mHandler.post(() -> startAudioServersBackgroundScan(/* retry= */ true));
                    }
                    break;
                default:
                    /* Indicate scan is no running */
                    mScanCallback = null;
                    break;
            }
        }
    }

    @VisibleForTesting
    boolean handleAudioDeviceAdded(
            BluetoothDevice device, int type, boolean isSink, boolean isSource) {
@@ -3129,87 +3061,6 @@ public class LeAudioService extends ProfileService {
        }
    }

    @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/348562830 - Remove with flag
    void stopAudioServersBackgroundScan() {
        Log.d(TAG, "stopAudioServersBackgroundScan");

        if (Flags.leaudioCallStartScanDirectly()) {
            mScanCallback2.stopBackgroundScan();
            return;
        }

        if (mAudioServersScanner == null || mScanCallback == null) {
            Log.d(TAG, "stopAudioServersBackgroundScan: already stopped");
            return;
        }

        try {
            mAudioServersScanner.stopScan(mScanCallback);
        } catch (IllegalStateException e) {
            Log.e(TAG, "Fail to stop scanner, consider it stopped", e);
        }

        /* Callback is the indicator for scanning being enabled */
        mScanCallback = null;
    }

    @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/348562830 - Remove with flag
    void startAudioServersBackgroundScan(boolean retry) {
        Log.d(TAG, "startAudioServersBackgroundScan, retry: " + retry);

        if (!isScannerNeeded()) {
            return;
        }

        if (Flags.leaudioCallStartScanDirectly()) {
            mScanCallback2.startBackgroundScan();
            return;
        }

        if (mAudioServersScanner == null) {
            mAudioServersScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
            if (mAudioServersScanner == null) {
                Log.e(TAG, "startAudioServersBackgroundScan: Could not get scanner");
                return;
            }
        }

        if (!retry) {
            if (mScanCallback != null) {
                Log.d(TAG, "startAudioServersBackgroundScan: Scanning already enabled");
                return;
            }
            mScanCallback = new AudioServerScanCallback();
        }

        /* Filter we are building here will not match to anything.
         * Eventually we should be able to start scan from native when
         * b/276350722 is done
         */
        byte[] serviceData = new byte[] {0x11};

        ArrayList filterList = new ArrayList<ScanFilter>();
        ScanFilter filter =
                new ScanFilter.Builder()
                        .setServiceData(BluetoothUuid.LE_AUDIO, serviceData)
                        .build();
        filterList.add(filter);

        ScanSettings settings =
                new ScanSettings.Builder()
                        .setLegacy(false)
                        .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
                        .setPhy(BluetoothDevice.PHY_LE_1M)
                        .build();

        try {
            mAudioServersScanner.startScan(filterList, settings, mScanCallback);
        } catch (IllegalStateException e) {
            Log.e(TAG, "Fail to start scanner, consider it stopped", e);
            mScanCallback = null;
        }
    }

    void transitionFromBroadcastToUnicast() {
        if (mUnicastGroupIdDeactivatedForBroadcastTransition == LE_AUDIO_GROUP_ID_INVALID) {
            Log.d(TAG, "No deactivated group due for broadcast transmission");
@@ -3439,7 +3290,10 @@ public class LeAudioService extends ProfileService {
                        case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTING:
                        case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                            deviceDescriptor.mAclConnected = false;
                            startAudioServersBackgroundScan(/* retry= */ false);

                            if (isScannerNeeded()) {
                                mScanCallback.startBackgroundScan();
                            }

                            boolean disconnectDueToUnbond =
                                    (BluetoothDevice.BOND_NONE
@@ -4171,7 +4025,7 @@ public class LeAudioService extends ProfileService {
            }
            mDeviceDescriptors.remove(device);
            if (!isScannerNeeded()) {
                stopAudioServersBackgroundScan();
                mScanCallback.stopBackgroundScan();
            }
        } finally {
            mGroupWriteLock.unlock();
@@ -4213,7 +4067,7 @@ public class LeAudioService extends ProfileService {
        }

        if (!isScannerNeeded()) {
            stopAudioServersBackgroundScan();
            mScanCallback.stopBackgroundScan();
        }

        /* Set by default earliest connected device */
@@ -4249,7 +4103,7 @@ public class LeAudioService extends ProfileService {
        }

        if (!isScannerNeeded()) {
            stopAudioServersBackgroundScan();
            mScanCallback.stopBackgroundScan();
        }

        mGroupReadLock.lock();
@@ -4782,7 +4636,9 @@ public class LeAudioService extends ProfileService {
            mGroupReadLock.unlock();
        }

        startAudioServersBackgroundScan(/* retry= */ false);
        if (isScannerNeeded()) {
            mScanCallback.startBackgroundScan();
        }
    }

    @VisibleForTesting
@@ -4894,7 +4750,9 @@ public class LeAudioService extends ProfileService {

        if (mBluetoothEnabled) {
            setAuthorizationForRelatedProfiles(device, true);
            startAudioServersBackgroundScan(/* retry= */ false);
            if (isScannerNeeded()) {
                mScanCallback.startBackgroundScan();
            }
        }
    }

+1 −14
Original line number Diff line number Diff line
@@ -24,15 +24,12 @@ import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothMcpServiceManager;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelUuid;
import android.sysprop.BluetoothProperties;
import android.util.Log;

import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.internal.annotations.VisibleForTesting;

@@ -48,7 +45,6 @@ public class McpService extends ProfileService {

    private final MediaControlProfile mGmcs;
    private final Map<BluetoothDevice, Integer> mDeviceAuthorizations = new HashMap<>();
    private final Handler mHandler = new Handler(Looper.getMainLooper());

    public McpService(Context ctx) {
        this(ctx, null);
@@ -102,16 +98,7 @@ public class McpService extends ProfileService {
        // Mark service as started
        setMcpService(this);

        if (Flags.leaudioSynchronizeStart()) {
        mGmcs.init();
            return;
        }
        mHandler.post(
                () -> {
                    if (isAvailable()) {
                        mGmcs.init();
                    }
                });
    }

    @Override
+0 −10
Original line number Diff line number Diff line
package: "com.android.bluetooth.flags"
container: "com.android.btservices"

flag {
    name: "override_context_to_specify_device_id"
    namespace: "bluetooth"
    description: "In Bluetooth Manager, override the context with createDeviceContext to pin a specific DeviceId"
    bug: "349657939"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "support_metadata_device_types_apis"
    is_exported: true
+0 −20
Original line number Diff line number Diff line
@@ -203,16 +203,6 @@ flag {
    }
}

flag {
    name: "leaudio_call_start_scan_directly"
    namespace: "bluetooth"
    description: "Calling the framework is working only when we are expecting IPC. This will call the underlying implementation directly"
    bug: "348562830"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "leaudio_no_context_validate_streaming_request"
    namespace: "bluetooth"
@@ -223,16 +213,6 @@ flag {
    }
}

flag {
    name: "leaudio_synchronize_start"
    namespace: "bluetooth"
    description: "Do not post on main looper when starting le_audio"
    bug: "341385684"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "headtracker_codec_capability"
    namespace: "bluetooth"
Loading