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

Commit 4487d4a7 authored by John Du's avatar John Du
Browse files

Adding support for Absolute Volume

Change-Id: I7bbc6f9296221ca219a50a5e377ebac9dcf5a407
parent 1f0c3da6
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -387,6 +387,66 @@ public final class BluetoothA2dp implements BluetoothProfile {
        return BluetoothProfile.PRIORITY_OFF;
    }

    /**
     * Checks if Avrcp device supports the absolute volume feature.
     *
     * @return true if device supports absolute volume
     * @hide
     */
    public boolean isAvrcpAbsoluteVolumeSupported() {
        if (DBG) Log.d(TAG, "isAvrcpAbsoluteVolumeSupported");
        if (mService != null && isEnabled()) {
            try {
                return mService.isAvrcpAbsoluteVolumeSupported();
            } catch (RemoteException e) {
                Log.e(TAG, "Error talking to BT service in isAvrcpAbsoluteVolumeSupported()", e);
                return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    }

    /**
     * Tells remote device to adjust volume. Only if absolute volume is supported.
     *
     * @param direction 1 to increase volume, or -1 to decrease volume
     * @hide
     */
    public void adjustAvrcpAbsoluteVolume(int direction) {
        if (DBG) Log.d(TAG, "adjustAvrcpAbsoluteVolume");
        if (mService != null && isEnabled()) {
            try {
                mService.adjustAvrcpAbsoluteVolume(direction);
                return;
            } catch (RemoteException e) {
                Log.e(TAG, "Error talking to BT service in adjustAvrcpAbsoluteVolume()", e);
                return;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
    }

    /**
     * Tells remote device to set an absolute volume. Only if absolute volume is supported
     *
     * @param volume Absolute volume to be set on AVRCP side
     * @hide
     */
    public void setAvrcpAbsoluteVolume(int volume) {
        if (DBG) Log.d(TAG, "setAvrcpAbsoluteVolume");
        if (mService != null && isEnabled()) {
            try {
                mService.setAvrcpAbsoluteVolume(volume);
                return;
            } catch (RemoteException e) {
                Log.e(TAG, "Error talking to BT service in setAvrcpAbsoluteVolume()", e);
                return;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
    }

    /**
     * Check if A2DP profile is streaming music.
     *
+3 −0
Original line number Diff line number Diff line
@@ -32,5 +32,8 @@ interface IBluetoothA2dp {
    int getConnectionState(in BluetoothDevice device);
    boolean setPriority(in BluetoothDevice device, int priority);
    int getPriority(in BluetoothDevice device);
    boolean isAvrcpAbsoluteVolumeSupported();
    oneway void adjustAvrcpAbsoluteVolume(int direction);
    oneway void setAvrcpAbsoluteVolume(int volume);
    boolean isA2dpPlaying(in BluetoothDevice device);
}