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

Commit 55cfff04 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

McpService: Allow to read MCP service by devices supporting LeAudio

Current authorication mechanism is done in the way, that remote device
needs to have connected LeAudio service in order to be authorize to
operate on MCP.

This might cause issue, when LeAudio service connects after remote
device tries to read MCP service.

This patch, looks into supported services by remote device, and if
LeAudio is supported, authorization is granded.

Bug: 249164851
Test: atest BluetoothInstrumentationTests
Tag: #feature

Merged-In: I12ba3010c324ce784a1bc1ab2f422575490761a1
Change-Id: I12ba3010c324ce784a1bc1ab2f422575490761a1
(cherry picked from commit 2d1c749b)
parent 46fbeecd
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package com.android.bluetooth.mcp;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothMcpServiceManager;
import android.content.AttributionSource;
import android.os.Handler;
@@ -27,6 +28,7 @@ import android.util.Log;

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

@@ -199,10 +201,34 @@ public class McpService extends ProfileService {
    }

    public int getDeviceAuthorization(BluetoothDevice device) {
        // TODO: For now just reject authorization for other than LeAudio device already authorized
        // except for PTS. Consider intent based authorization mechanism for non-LeAudio devices.
        return mDeviceAuthorizations.getOrDefault(device, Utils.isPtsTestMode()
                ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_UNKNOWN);
        /* Media control is allowed for
         * 1. in PTS mode
         * 2. authorized devices
         * 3. Any LeAudio devices which are allowed to connect
         */
        if (mDeviceAuthorizations.getOrDefault(device, Utils.isPtsTestMode()
                ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_UNKNOWN)
                        == BluetoothDevice.ACCESS_ALLOWED) {
            return BluetoothDevice.ACCESS_ALLOWED;
        }

        LeAudioService leAudioService = LeAudioService.getLeAudioService();
        if (leAudioService == null) {
            Log.e(TAG, "MCS access not permited. LeAudioService not available");
            return BluetoothDevice.ACCESS_UNKNOWN;
        }

        if (leAudioService.getConnectionPolicy(device)
                > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            if (DBG) {
                Log.d(TAG, "MCS authorization allowed based on supported LeAudio service");
            }
            setDeviceAuthorized(device, true);
            return BluetoothDevice.ACCESS_ALLOWED;
        }

        Log.e(TAG, "MCS access not permited");
        return BluetoothDevice.ACCESS_UNKNOWN;
    }

    @GuardedBy("mLock")