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

Commit 8cee9c1e authored by William Escande's avatar William Escande
Browse files

A2dpService: use local adapterservice

Do not rely on AdapterService.getAdapterService in binder constructor

Bug: 311772251
Test: atest A2dpServiceBinderTest
Flag: Exempt, mechanical no-op change
Change-Id: I5b52e4f8b7eb4fda64f85a355f0568effc4d8648
parent 962e32c4
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -141,10 +141,13 @@ public class A2dpService extends ProfileService {
        return BluetoothProperties.isProfileA2dpSourceEnabled().orElse(false);
    }

    ActiveDeviceManager getActiveDeviceManager() {
        return mAdapterService.getActiveDeviceManager();
    }

    @Override
    protected IProfileServiceBinder initBinder() {
        return new BluetoothA2dpBinder(
                this, AdapterService.getAdapterService().getActiveDeviceManager());
        return new BluetoothA2dpBinder(this);
    }

    @Override
@@ -1372,7 +1375,6 @@ public class A2dpService extends ProfileService {
    static class BluetoothA2dpBinder extends IBluetoothA2dp.Stub
            implements IProfileServiceBinder {
        private A2dpService mService;
        private ActiveDeviceManager mActiveDeviceManager;

        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private A2dpService getService(AttributionSource source) {
@@ -1387,9 +1389,8 @@ public class A2dpService extends ProfileService {
            return mService;
        }

        BluetoothA2dpBinder(A2dpService svc, ActiveDeviceManager activeDeviceManager) {
        BluetoothA2dpBinder(A2dpService svc) {
            mService = svc;
            mActiveDeviceManager = activeDeviceManager;
        }

        @Override
@@ -1479,7 +1480,7 @@ public class A2dpService extends ProfileService {
                A2dpService service = getService(source);
                if (service != null) {
                    if (Flags.audioRoutingCentralization()) {
                        ((AudioRoutingManager) mActiveDeviceManager)
                        ((AudioRoutingManager) service.getActiveDeviceManager())
                                .activateDeviceProfile(device, BluetoothProfile.A2DP, receiver);
                    } else {
                        boolean result;
+2 −2
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ public class A2dpServiceBinderTest {
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock private A2dpService mA2dpService;
    @Mock private A2dpNativeInterface mNativeInterface;
    @Mock private AudioRoutingManager mAudioRoutingManager;
    @Mock private PackageManager mPackageManager;

@@ -66,12 +65,13 @@ public class A2dpServiceBinderTest {
    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        doReturn(mAudioRoutingManager).when(mA2dpService).getActiveDeviceManager();
        doReturn(mPackageManager).when(mA2dpService).getPackageManager();
        ApplicationInfo appInfo = new ApplicationInfo();
        appInfo.targetSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
        doReturn(appInfo).when(mPackageManager).getApplicationInfo(any(), anyInt());

        mBinder = new A2dpService.BluetoothA2dpBinder(mA2dpService, mAudioRoutingManager);
        mBinder = new A2dpService.BluetoothA2dpBinder(mA2dpService);
    }

    @After