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

Commit 10b7b3dd authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes Ief02d1dd,Ic34171d0,Icffca146,Iee2769e9 into main

* changes:
  MediaControlProfile: Move variable to final
  TbsService: Move variable to final
  McpService: Move variable to final
  LeAudioService: Move NativeInterface to final
parents b6f8a51f 6b481688
Loading
Loading
Loading
Loading
+24 −46
Original line number Diff line number Diff line
@@ -165,10 +165,9 @@ public class LeAudioService extends ProfileService {
            leaudioApiSynchronizedBlockFix() ? mGroupReadWriteLock.readLock() : mGroupLock;
    private final Lock mGroupWriteLock =
            leaudioApiSynchronizedBlockFix() ? mGroupReadWriteLock.writeLock() : mGroupLock;
    private final Context mContext;
    ServiceFactory mServiceFactory = new ServiceFactory();

    LeAudioNativeInterface mLeAudioNativeInterface;
    private final LeAudioNativeInterface mNativeInterface;
    boolean mLeAudioNativeIsInitialized = false;
    boolean mLeAudioInbandRingtoneSupportedByPlatform = true;
    boolean mBluetoothEnabled = false;
@@ -218,15 +217,13 @@ public class LeAudioService extends ProfileService {
    ScanCallback mScanCallback;

    public LeAudioService(Context ctx) {
        super(ctx);
        mContext = ctx;
        this(ctx, LeAudioNativeInterface.getInstance());
    }

    @VisibleForTesting
    LeAudioService(Context ctx, LeAudioNativeInterface nativeInterface) {
        super(ctx);
        mLeAudioNativeInterface = nativeInterface;
        mContext = ctx;
        mNativeInterface = Objects.requireNonNull(nativeInterface);
    }

    private class LeAudioGroupDescriptor {
@@ -423,12 +420,6 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(
                        AdapterService.getAdapterService(),
                        "AdapterService cannot be null when LeAudioService starts");
        if (mLeAudioNativeInterface == null) {
            mLeAudioNativeInterface =
                    Objects.requireNonNull(
                            LeAudioNativeInterface.getInstance(),
                            "LeAudioNativeInterface cannot be null when LeAudioService starts");
        }
        mDatabaseManager =
                Objects.requireNonNull(
                        mAdapterService.getDatabase(),
@@ -503,16 +494,10 @@ public class LeAudioService extends ProfileService {
            mTmapStarted = registerTmap();
        }

        LeAudioNativeInterface nativeInterface = mLeAudioNativeInterface;
        if (nativeInterface == null) {
            Log.w(TAG, "the service is stopped. ignore init()");
            return;
        }
        nativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());
        mNativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());

        if (leaudioUseAudioModeListener()) {
            mAudioManager.addOnModeChangedListener(
                    mContext.getMainExecutor(), mAudioModeChangeListener);
            mAudioManager.addOnModeChangedListener(getMainExecutor(), mAudioModeChangeListener);
        }
    }

@@ -594,8 +579,7 @@ public class LeAudioService extends ProfileService {
        }

        // Cleanup native interfaces
        mLeAudioNativeInterface.cleanup();
        mLeAudioNativeInterface = null;
        mNativeInterface.cleanup();
        mLeAudioNativeIsInitialized = false;
        mBluetoothEnabled = false;
        mHfpHandoverDevice = null;
@@ -718,7 +702,7 @@ public class LeAudioService extends ProfileService {
            Log.e(TAG, "setEnabledState, mLeAudioNativeIsInitialized is not initialized");
            return;
        }
        mLeAudioNativeInterface.setEnableState(device, enabled);
        mNativeInterface.setEnableState(device, enabled);
    }

    public boolean connect(BluetoothDevice device) {
@@ -965,7 +949,7 @@ public class LeAudioService extends ProfileService {
            Log.e(TAG, "Le Audio not initialized properly.");
            return false;
        }
        return mLeAudioNativeInterface.groupAddNode(groupId, device);
        return mNativeInterface.groupAddNode(groupId, device);
    }

    /**
@@ -980,7 +964,7 @@ public class LeAudioService extends ProfileService {
            Log.e(TAG, "Le Audio not initialized properly.");
            return false;
        }
        return mLeAudioNativeInterface.groupRemoveNode(groupId, device);
        return mNativeInterface.groupRemoveNode(groupId, device);
    }

    /**
@@ -1108,8 +1092,7 @@ public class LeAudioService extends ProfileService {
                            + " group is deactivated.");
            mCreateBroadcastQueue.add(broadcastSettings);
            if (Flags.leaudioBroadcastAudioHandoverPolicies()) {
                mLeAudioNativeInterface.setUnicastMonitorMode(
                        LeAudioStackEvent.DIRECTION_SINK, true);
                mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SINK, true);
            }
            removeActiveDevice(true);

@@ -1329,7 +1312,7 @@ public class LeAudioService extends ProfileService {

        Log.d(TAG, "destroyBroadcast");
        if (Flags.leaudioBroadcastAudioHandoverPolicies()) {
            mLeAudioNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SINK, false);
            mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SINK, false);
        }
        mLeAudioBroadcasterNativeInterface.destroyBroadcast(broadcastId);
    }
@@ -1409,11 +1392,10 @@ public class LeAudioService extends ProfileService {

        if (active) {
            mIsSourceStreamMonitorModeEnabled = true;
            mLeAudioNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SOURCE, true);
            mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SOURCE, true);
        } else {
            if (mIsSourceStreamMonitorModeEnabled) {
                mLeAudioNativeInterface.setUnicastMonitorMode(
                        LeAudioStackEvent.DIRECTION_SOURCE, false);
                mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SOURCE, false);
            }

            mIsSourceStreamMonitorModeEnabled = false;
@@ -2022,8 +2004,7 @@ public class LeAudioService extends ProfileService {
                    && ((newSupportedAudioDirections & AUDIO_DIRECTION_INPUT_BIT) != 0)) {
                newInDevice = getLeadDeviceForTheGroup(groupId);
            } else if (Flags.leaudioBroadcastAudioHandoverPolicies() && wasSetSinkListeningMode()) {
                mLeAudioNativeInterface.setUnicastMonitorMode(
                        LeAudioStackEvent.DIRECTION_SINK, false);
                mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SINK, false);
            }
        }

@@ -2212,7 +2193,7 @@ public class LeAudioService extends ProfileService {
            }
        }

        mLeAudioNativeInterface.groupSetActive(groupId);
        mNativeInterface.groupSetActive(groupId);
        if (groupId == LE_AUDIO_GROUP_ID_INVALID) {
            /* Native will clear its states and send us group Inactive.
             * However we would like to notify audio framework that LeAudio is not
@@ -2623,8 +2604,7 @@ public class LeAudioService extends ProfileService {
        if (bassClientService == null) {
            Log.e(TAG, "handleSourceStreamStatusChange: BASS Client service is not available");

            mLeAudioNativeInterface.setUnicastMonitorMode(
                    LeAudioStackEvent.DIRECTION_SOURCE, false);
            mNativeInterface.setUnicastMonitorMode(LeAudioStackEvent.DIRECTION_SOURCE, false);
        }

        bassClientService.handleUnicastSourceStreamStatusChange(status);
@@ -2689,8 +2669,7 @@ public class LeAudioService extends ProfileService {

        groupDescriptor.updateAllowedContexts(sinkContextTypes, sourceContextTypes);

        mLeAudioNativeInterface.setGroupAllowedContextMask(
                groupId, sinkContextTypes, sourceContextTypes);
        mNativeInterface.setGroupAllowedContextMask(groupId, sinkContextTypes, sourceContextTypes);
    }

    @VisibleForTesting
@@ -2881,7 +2860,7 @@ public class LeAudioService extends ProfileService {

        if (!leaudioUseAudioModeListener()) {
            if (mQueuedInCallValue.isPresent()) {
                mLeAudioNativeInterface.setInCall(mQueuedInCallValue.get());
                mNativeInterface.setInCall(mQueuedInCallValue.get());
                mQueuedInCallValue = Optional.empty();
            }
        }
@@ -3538,7 +3517,7 @@ public class LeAudioService extends ProfileService {

        sm =
                LeAudioStateMachine.make(
                        device, this, mLeAudioNativeInterface, mStateMachinesThread.getLooper());
                        device, this, mNativeInterface, mStateMachinesThread.getLooper());
        descriptor.mStateMachine = sm;
        return sm;
    }
@@ -3574,7 +3553,7 @@ public class LeAudioService extends ProfileService {

                if (descriptor.mGroupId != LE_AUDIO_GROUP_ID_INVALID) {
                    /* In case device is still in the group, let's remove it */
                    mLeAudioNativeInterface.groupRemoveNode(descriptor.mGroupId, device);
                    mNativeInterface.groupRemoveNode(descriptor.mGroupId, device);
                }

                descriptor.mGroupId = LE_AUDIO_GROUP_ID_INVALID;
@@ -3943,7 +3922,7 @@ public class LeAudioService extends ProfileService {
            }
        }

        mLeAudioNativeInterface.setInCall(inCall);
        mNativeInterface.setInCall(inCall);

        if (!leaudioUseAudioModeListener()) {
            /* For clearing inCall mode */
@@ -3974,7 +3953,7 @@ public class LeAudioService extends ProfileService {
            Log.e(TAG, "Le Audio not initialized properly.");
            return;
        }
        mLeAudioNativeInterface.sendAudioProfilePreferences(
        mNativeInterface.sendAudioProfilePreferences(
                groupId, isOutputPreferenceLeAudio, isDuplexPreferenceLeAudio);
    }

@@ -4184,7 +4163,7 @@ public class LeAudioService extends ProfileService {
            Log.e(TAG, "Le Audio not initialized properly.");
            return;
        }
        mLeAudioNativeInterface.setCcidInformation(ccid, contextType);
        mNativeInterface.setCcidInformation(ccid, contextType);
    }

    /**
@@ -4785,8 +4764,7 @@ public class LeAudioService extends ProfileService {
            return;
        }

        mLeAudioNativeInterface.setCodecConfigPreference(
                groupId, inputCodecConfig, outputCodecConfig);
        mNativeInterface.setCodecConfigPreference(groupId, inputCodecConfig, outputCodecConfig);
    }

    /**
+4 −4
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ public class McpService extends ProfileService {
    @GuardedBy("mLock")
    private MediaControlProfile mGmcs;

    private Map<BluetoothDevice, Integer> mDeviceAuthorizations = new HashMap<>();
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private final Map<BluetoothDevice, Integer> mDeviceAuthorizations = new HashMap<>();
    private final Handler mHandler = new Handler(Looper.getMainLooper());

    public McpService(Context ctx) {
        super(ctx);
@@ -234,7 +234,7 @@ public class McpService extends ProfileService {

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

@@ -245,7 +245,7 @@ public class McpService extends ProfileService {
            return BluetoothDevice.ACCESS_ALLOWED;
        }

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

+11 −14
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.mcp;

import static java.util.Map.entry;
import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.bluetooth.BluetoothAvrcp;
@@ -63,17 +64,20 @@ import java.util.stream.Stream;
 * Implemented according to Media Control Service v1.0 specification.
 */
public class MediaControlProfile implements MediaControlServiceCallbacks {
    private static final String TAG = "MediaControlProfile";
    private final Context mContext;
    private static final String TAG = MediaControlProfile.class.getSimpleName();

    private static final int LOG_NB_EVENTS = 100;
    private final BluetoothEventLogger mEventLogger;

    private final BluetoothEventLogger mEventLogger =
            new BluetoothEventLogger(LOG_NB_EVENTS, TAG + " event log");
    private final Context mContext;
    private final McpService mMcpService;
    private final Map<String, MediaControlGattServiceInterface> mServiceMap = new HashMap<>();

    // Media players data
    private MediaPlayerList mMediaPlayerList;
    private final MediaPlayerList mMediaPlayerList;
    private MediaData mCurrentData;

    private McpService mMcpService;
    // MCP service instance
    private MediaControlGattServiceInterface mGMcsService;

@@ -278,9 +282,8 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
    public MediaControlProfile(@NonNull McpService mcpService) {
        Log.v(TAG, "Creating Generic Media Control Service");

        mMcpService = requireNonNull(mcpService);
        mContext = mcpService;
        mMcpService = mcpService;
        mServiceMap = new HashMap<>();

        if (sMediaPlayerListForTesting != null) {
            mMediaPlayerList = sMediaPlayerListForTesting;
@@ -288,7 +291,6 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
            mMediaPlayerList = new MediaPlayerList(Looper.myLooper(), mContext);
        }

        mEventLogger = new BluetoothEventLogger(LOG_NB_EVENTS, TAG + " event log");
    }

    @Override
@@ -806,10 +808,7 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
    }

    public void cleanup() {
        if (mMediaPlayerList != null) {
        mMediaPlayerList.cleanup();
        }
        mMediaPlayerList = null;

        unregisterServiceInstance(mContext.getPackageName());

@@ -869,8 +868,6 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {
                    | ServiceFeature.MEDIA_CONTROL_POINT_OPCODES_SUPPORTED_NOTIFY
                    | ServiceFeature.CONTENT_CONTROL_ID;

    private final Map<String, MediaControlGattServiceInterface> mServiceMap;

    public void unregisterServiceInstance(String appToken) {
        mEventLogger.logd(TAG, "unregisterServiceInstance");

+5 −18
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class TbsService extends ProfileService {
    private static final String TAG = "TbsService";

    private static TbsService sTbsService;
    private Map<BluetoothDevice, Integer> mDeviceAuthorizations = new HashMap<>();
    private final Map<BluetoothDevice, Integer> mDeviceAuthorizations = new HashMap<>();

    private final TbsGeneric mTbsGeneric = new TbsGeneric();

@@ -65,7 +65,6 @@ public class TbsService extends ProfileService {

    @Override
    public void start() {

        Log.d(TAG, "start()");
        if (sTbsService != null) {
            throw new IllegalStateException("start() called twice");
@@ -88,10 +87,8 @@ public class TbsService extends ProfileService {
        // Mark service as stopped
        setTbsService(null);

        if (mTbsGeneric != null) {
        mTbsGeneric.cleanup();
    }
    }

    @Override
    public void cleanup() {
@@ -156,10 +153,8 @@ public class TbsService extends ProfileService {
                isAuthorized ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED;
        mDeviceAuthorizations.put(device, authorization);

        if (mTbsGeneric != null) {
        mTbsGeneric.onDeviceAuthorizationSet(device);
    }
    }

    /**
     * Returns authorization value for given device.
@@ -187,7 +182,7 @@ public class TbsService extends ProfileService {

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

@@ -198,7 +193,7 @@ public class TbsService extends ProfileService {
            return BluetoothDevice.ACCESS_ALLOWED;
        }

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

@@ -208,10 +203,6 @@ public class TbsService extends ProfileService {
     * @param device device for which inband ringtone has been set
     */
    public void setInbandRingtoneSupport(BluetoothDevice device) {
        if (mTbsGeneric == null) {
            Log.i(TAG, "setInbandRingtoneSupport, mTbsGeneric not available");
            return;
        }
        mTbsGeneric.setInbandRingtoneSupport(device);
    }

@@ -221,10 +212,6 @@ public class TbsService extends ProfileService {
     * @param device device for which inband ringtone has been clear
     */
    public void clearInbandRingtoneSupport(BluetoothDevice device) {
        if (mTbsGeneric == null) {
            Log.i(TAG, "clearInbandRingtoneSupport, mTbsGeneric not available");
            return;
        }
        mTbsGeneric.clearInbandRingtoneSupport(device);
    }