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

Commit d97b9a48 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge "Use VolumeControlService instead of proxy" am: be936601

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1916438

Change-Id: I40c901bf6d68733bc7cf999a8ea4a80dc81d7111
parents 05d3b7e3 be936601
Loading
Loading
Loading
Loading
+3 −69
Original line number Diff line number Diff line
@@ -133,36 +133,6 @@ public class LeAudioService extends ProfileService {
    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mConnectionStateChangedReceiver;

    private volatile IBluetoothVolumeControl mVolumeControlProxy;
    VolumeControlService mVolumeControlService = null;
    private final ServiceConnection mVolumeControlProxyConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            if (DBG) {
                Log.d(TAG, "mVolumeControlProxyConnection connected");
            }
            synchronized (LeAudioService.this) {

                mVolumeControlProxy = IBluetoothVolumeControl.Stub.asInterface(service);
                mVolumeControlService =
                    VolumeControlService.getVolumeControlService();
                if (mVolumeControlService == null) {
                    Log.e(TAG, "VolumeControlService is null when LeAudioService starts");
                }
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            if (DBG) {
                Log.d(TAG, "mVolumeControlProxy disconnected");
            }
            synchronized (LeAudioService.this) {
                mVolumeControlProxy = null;
            }
        }
    };

    @Override
    protected IProfileServiceBinder initBinder() {
        return new BluetoothLeAudioBinder(this);
@@ -209,10 +179,6 @@ public class LeAudioService extends ProfileService {
        mConnectionStateChangedReceiver = new ConnectionStateChangedReceiver();
        registerReceiver(mConnectionStateChangedReceiver, filter);


        /* Bind Volume control service */
        bindVolumeControlService();

        // Mark service as started
        setLeAudioService(this);

@@ -280,7 +246,6 @@ public class LeAudioService extends ProfileService {
        mAdapterService = null;
        mAudioManager = null;

        unbindVolumeControlService();
        return true;
    }

@@ -308,30 +273,6 @@ public class LeAudioService extends ProfileService {
        sLeAudioService = instance;
    }

    private void bindVolumeControlService() {
        synchronized (mVolumeControlProxyConnection) {
            Intent intent = new Intent(IBluetoothVolumeControl.class.getName());
            ComponentName comp = intent.resolveSystemService(getPackageManager(), 0);
            intent.setComponent(comp);
            if (comp == null || !bindService(intent, mVolumeControlProxyConnection, 0)) {
                Log.wtf(TAG, "Could not bind to IBluetoothVolumeControl Service with " +
                        intent);
            }
        }
    }
    private void unbindVolumeControlService() {
        synchronized (mVolumeControlProxyConnection) {
            if (mVolumeControlProxy != null) {
                if (DBG) {
                    Log.d(TAG, "Unbinding mVolumeControlProxyConnection");
                }
                mVolumeControlProxy = null;
                // Synchronization should make sure unbind can be successful
                unbindService(mVolumeControlProxyConnection);
            }
        }
    }

    public boolean connect(BluetoothDevice device) {
        if (DBG) {
            Log.d(TAG, "connect(): " + device);
@@ -1278,16 +1219,9 @@ public class LeAudioService extends ProfileService {
            return;
        }

        if (mVolumeControlService == null) {
            Log.e(TAG, "VolumeControl no available ");
            return;
        }

        try {
            mVolumeControlProxy.setVolumeGroup(mActiveDeviceGroupId, volume,
                                               this.getAttributionSource());
        } catch (RemoteException e) {
            Log.e(TAG, "Set Volume failed: " + e);
        VolumeControlService service = mServiceFactory.getVolumeControlService();
        if (service != null) {
            service.setVolumeGroup(mActiveDeviceGroupId, volume);
        }
    }

+4 −1
Original line number Diff line number Diff line
@@ -413,7 +413,10 @@ public class VolumeControlService extends ProfileService {
        mVolumeControlNativeInterface.setVolume(device, volume);
    }

    void setVolumeGroup(int groupId, int volume) {
    /**
     * {@hide}
     */
    public void setVolumeGroup(int groupId, int volume) {
        mVolumeControlNativeInterface.setVolumeGroup(groupId, volume);
    }