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

Commit f8675ea2 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge "McpService: Allow to read MCP service by devices supporting LeAudio"

parents 792bc3a9 2d1c749b
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")