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

Commit cb1ec09a authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

MediaControl: Limit the unauthorized device state reads

Do not disclose the supported opcodes and playback state to the
unauthorized devices. Otherwise they may assume it is ok for them to
control the playback. However any request will be rejected, which may
confuse them.

Bug: 284028276
Test: atest BluetoothInstrumenatationTests
Change-Id: I051cb5d1ab1acae4dbca9ed3f6048d5bd52e4dc3
parent b88ffcbd
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -393,11 +393,12 @@ public class MediaControlGattService implements MediaControlGattServiceInterface

    private void onUnauthorizedCharRead(BluetoothDevice device, GattOpContext op) {
        UUID charUuid = op.mCharacteristic.getUuid();
        boolean allowToReadRealValue = false;
        byte[] buffer = null;

        if (charUuid.equals(UUID_PLAYER_NAME)) {
            allowToReadRealValue = true;
            ByteBuffer bb = ByteBuffer.allocate(0).order(ByteOrder.LITTLE_ENDIAN);
            bb.put("".getBytes());
            buffer = bb.array();

        } else if (charUuid.equals(UUID_PLAYER_ICON_OBJ_ID)) {
            buffer = objId2ByteArray(-1);
@@ -461,13 +462,17 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
            buffer = bb.array();

        } else if (charUuid.equals(UUID_MEDIA_STATE)) {
            allowToReadRealValue = true;
            ByteBuffer bb = ByteBuffer.allocate(1).order(ByteOrder.LITTLE_ENDIAN);
            bb.put((byte) MediaState.INACTIVE.getValue());
            buffer = bb.array();

        } else if (charUuid.equals(UUID_MEDIA_CONTROL_POINT)) {
            // No read is available on this characteristic

        } else if (charUuid.equals(UUID_MEDIA_CONTROL_POINT_OPCODES_SUPPORTED)) {
            allowToReadRealValue = true;
            ByteBuffer bb = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
            bb.putInt((int) Request.SupportedOpcodes.NONE);
            buffer = bb.array();

        } else if (charUuid.equals(UUID_SEARCH_RESULT_OBJ_ID)) {
            buffer = objId2ByteArray(-1);
@@ -476,10 +481,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
            // No read is available on this characteristic

        } else if (charUuid.equals(UUID_CONTENT_CONTROL_ID)) {
            allowToReadRealValue = true;
        }

        if (allowToReadRealValue) {
            // It is ok, to send the real value for CCID
            if (op.mCharacteristic.getValue() != null) {
                buffer =
                        Arrays.copyOfRange(