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

Commit 5885037c authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioDeviceBroker in audio service

New AudioDeviceBroker class running in audio service.
Has dedicated message loop for handling audio device
   connections and disconnections.
New helper classes for AudioDeviceBroker:
 - BtHelper for Bluetooth
 - AudioDeviceInventory to manage list of devices

Bug: 112863932
Test: media CTS + audio CTS Verifier
Change-Id: I3e8f662a9d82fa7245695888e14fac7f4fc6e728
parent a28407a4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -434,7 +434,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * {@inheritDoc}
     */
    @Override
    public int getConnectionState(BluetoothDevice device) {
    public @BtProfileState int getConnectionState(BluetoothDevice device) {
        if (VDBG) log("getState(" + device + ")");
        try {
            mServiceLock.readLock().lock();
@@ -689,7 +689,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @hide
     */
    @UnsupportedAppUsage
    public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
    public @Nullable BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
        try {
            mServiceLock.readLock().lock();
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.bluetooth;

import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
@@ -42,7 +43,7 @@ public final class BluetoothCodecStatus implements Parcelable {
    public static final String EXTRA_CODEC_STATUS =
            "android.bluetooth.codec.extra.CODEC_STATUS";

    private final BluetoothCodecConfig mCodecConfig;
    private final @Nullable BluetoothCodecConfig mCodecConfig;
    private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
    private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;

@@ -140,7 +141,7 @@ public final class BluetoothCodecStatus implements Parcelable {
     * @return the current codec configuration
     */
    @UnsupportedAppUsage
    public BluetoothCodecConfig getCodecConfig() {
    public @Nullable BluetoothCodecConfig getCodecConfig() {
        return mCodecConfig;
    }

+13 −0
Original line number Diff line number Diff line
@@ -18,11 +18,14 @@
package android.bluetooth;

import android.Manifest;
import android.annotation.IntDef;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.os.Build;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
@@ -60,6 +63,16 @@ public interface BluetoothProfile {
    /** The profile is in disconnecting state */
    int STATE_DISCONNECTING = 3;

    /** @hide */
    @IntDef({
            STATE_DISCONNECTED,
            STATE_CONNECTING,
            STATE_CONNECTED,
            STATE_DISCONNECTING,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BtProfileState {}

    /**
     * Headset and Handsfree profile
     */
+5 −26
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -3988,34 +3989,12 @@ public class AudioManager {
        return delay;
    }

     /**
     * Indicate A2DP source or sink connection state change.
     * @param device Bluetooth device connected/disconnected
     * @param state  new connection state (BluetoothProfile.STATE_xxx)
     * @param profile profile for the A2DP device
     * (either {@link android.bluetooth.BluetoothProfile.A2DP} or
     * {@link android.bluetooth.BluetoothProfile.A2DP_SINK})
     * @return a delay in ms that the caller should wait before broadcasting
     * BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED intent.
     * {@hide}
     */
    public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state,
            int profile) {
        final IAudioService service = getService();
        int delay = 0;
        try {
            delay = service.setBluetoothA2dpDeviceConnectionState(device, state, profile);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return delay;
    }

     /**
     * Indicate A2DP source or sink connection state change and eventually suppress
     * the {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent.
     * @param device Bluetooth device connected/disconnected
     * @param state  new connection state (BluetoothProfile.STATE_xxx)
     * @param state  new connection state, {@link BluetoothProfile#STATE_CONNECTED}
     *     or {@link BluetoothProfile#STATE_DISCONNECTED}
     * @param profile profile for the A2DP device
     * @param a2dpVolume New volume for the connecting device. Does nothing if disconnecting.
     * (either {@link android.bluetooth.BluetoothProfile.A2DP} or
@@ -4027,8 +4006,8 @@ public class AudioManager {
     * {@hide}
     */
    public int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                BluetoothDevice device, int state, int profile,
                boolean suppressNoisyIntent, int a2dpVolume) {
            BluetoothDevice device, int state,
            int profile, boolean suppressNoisyIntent, int a2dpVolume) {
        final IAudioService service = getService();
        int delay = 0;
        try {
+12 −1
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import java.util.Map;
 */
public class AudioSystem
{
    private static final boolean DEBUG_VOLUME = true;

    private static final String TAG = "AudioSystem";
    /* These values must be kept in sync with system/audio.h */
    /*
@@ -879,6 +881,15 @@ public class AudioSystem
        }
    }

    /** Wrapper for native methods called from AudioService */
    public static int setStreamVolumeIndexAS(int stream, int index, int device) {
        if (DEBUG_VOLUME) {
            Log.i(TAG, "setStreamVolumeIndex: " + STREAM_NAMES[stream]
                    + " dev=" + Integer.toHexString(device) + " idx=" + index);
        }
        return setStreamVolumeIndex(stream, index, device);
    }

    // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t
    public static final int SYNC_EVENT_NONE = 0;
    public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1;
@@ -906,7 +917,7 @@ public class AudioSystem
    @UnsupportedAppUsage
    public static native int initStreamVolume(int stream, int indexMin, int indexMax);
    @UnsupportedAppUsage
    public static native int setStreamVolumeIndex(int stream, int index, int device);
    private static native int setStreamVolumeIndex(int stream, int index, int device);
    public static native int getStreamVolumeIndex(int stream, int device);
    public static native int setMasterVolume(float value);
    public static native float getMasterVolume();
Loading