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

Commit 06887c38 authored by Mingbo Zhang's avatar Mingbo Zhang Committed by Bruno Martins
Browse files

Add callback onA2dpCodecConfigChanged

Add callback onA2dpCodecConfigChanged for
intent BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED.

Change-Id: I4d19f0427c2f68dfd01a241eb631c6782d948395
CRs-Fixed: 2735935
parent 9c88a61b
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settingslib.bluetooth;

import android.bluetooth.BluetoothCodecStatus;

/**
 * BluetoothCallback provides a callback interface for the settings
@@ -140,4 +141,15 @@ public interface BluetoothCallback {
     */
    default void onAclConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
    }

    /**
     * Called when a2dp codec config is changed. It listens to
     * {@link android.bluetooth.BluetoothA2dp#ACTION_CODEC_CONFIG_CHANGED}.
     *
     * @param cachedDevice Bluetooth device that changed
     * @param codecStatus  the current codec status of the a2dp profile
     */
    default void onA2dpCodecConfigChanged(CachedBluetoothDevice cachedDevice,
            BluetoothCodecStatus codecStatus) {
    }
}
+33 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settingslib.bluetooth;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
@@ -127,6 +128,7 @@ public class BluetoothEventManager {
        // ACL connection changed broadcasts
        addHandler(BluetoothDevice.ACTION_ACL_CONNECTED, new AclStateChangedHandler());
        addHandler(BluetoothDevice.ACTION_ACL_DISCONNECTED, new AclStateChangedHandler());
        addHandler(BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED, new A2dpCodecConfigChangedHandler());

        registerAdapterIntentReceiver();
    }
@@ -241,6 +243,13 @@ public class BluetoothEventManager {
        }
    }

    private void dispatchA2dpCodecConfigChanged(CachedBluetoothDevice cachedDevice,
            BluetoothCodecStatus codecStatus) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onA2dpCodecConfigChanged(cachedDevice, codecStatus);
        }
    }

    @VisibleForTesting
    void addHandler(String action, Handler handler) {
        mHandlerMap.put(action, handler);
@@ -520,4 +529,28 @@ public class BluetoothEventManager {
            dispatchAudioModeChanged();
        }
    }

    private class A2dpCodecConfigChangedHandler implements Handler {

        @Override
        public void onReceive(Context context, Intent intent, BluetoothDevice device) {
            final String action = intent.getAction();
            if (action == null) {
                Log.w(TAG, "A2dpCodecConfigChangedHandler: action is null");
                return;
            }

            CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
            if (cachedDevice == null) {
                Log.w(TAG, "A2dpCodecConfigChangedHandler: device is null");
                return;
            }

            BluetoothCodecStatus codecStatus = intent.getParcelableExtra(
                    BluetoothCodecStatus.EXTRA_CODEC_STATUS);
            Log.d(TAG, "A2dpCodecConfigChangedHandler: device=" + device +
                    ", codecStatus=" + codecStatus);
            dispatchA2dpCodecConfigChanged(cachedDevice, codecStatus);
        }
    }
}