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

Commit c5278424 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Pawlowski
Browse files

mcp: Remove the usage of getMainThreadHandler()

Bug: 150670922
Bug: 197723745
Tag: #feature
Test: atest MediaControlGattServiceTest McpServiceTest
Sponsor: jpawlowski@
Merged-In: Ia34dc1e1a4960774eef8d08c4e2c08a25ffffe51
Change-Id: Ia34dc1e1a4960774eef8d08c4e2c08a25ffffe51
parent d4871e81
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ package com.android.bluetooth.mcp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.IBluetoothMcpServiceManager;
import android.content.AttributionSource;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.android.bluetooth.Utils;
@@ -41,6 +43,7 @@ public class McpService extends ProfileService {

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

    private static synchronized void setMcpService(McpService instance) {
        if (VDBG) {
@@ -95,7 +98,7 @@ public class McpService extends ProfileService {
            // Initialize the Media Control Service Server
            mGmcs = new MediaControlProfile(this);
            // Requires this service to be already started thus we have to make it an async call
            this.getMainThreadHandler().post(() -> mGmcs.init());
            mHandler.post(() -> mGmcs.init());
        }

        return true;
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -126,6 +128,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
    private MediaControlServiceCallbacks mCallbacks;
    private BluetoothGattServerProxy mBluetoothGattServer;
    private BluetoothGattService mGattService = null;
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private Map<Integer, BluetoothGattCharacteristic> mCharacteristics = new HashMap<>();
    private MediaState mCurrentMediaState = MediaState.INACTIVE;
    private Map<BluetoothDevice, List<GattOpContext>> mPendingGattOperations = new HashMap<>();
@@ -843,7 +846,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface
        // Test for RFU bits and currently supported opcodes
        if (!isOpcodeSupported(opcode)) {
            Log.e(TAG, "handleMediaControlPointRequest: opcode or feature not supported");
            mContext.getMainThreadHandler().post(() -> {
            mHandler.post(() -> {
                setMediaControlRequestResult(new Request(opcode, 0),
                        Request.Results.OPCODE_NOT_SUPPORTED);
            });
+3 −5
Original line number Diff line number Diff line
@@ -90,11 +90,9 @@ public class MediaControlProfile implements MediaControlServiceCallbacks {

            mCurrentData = data;

            mContext.getMainThreadHandler().post(() -> {
            onCurrentPlayerStateUpdated(state, metadata);
            if (queue) onCurrentPlayerQueueUpdated();
            processPendingPlayerStateRequest();
            });
        }

        @Override