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

Commit 6217df19 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

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

Merge "McpService: Allow to read MCP service by devices supporting LeAudio" into tm-qpr-dev am: 8299d71f

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



Change-Id: I36478c88278bc0296df95c5118a6fc5f58064e2c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents de703a28 8299d71f
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")