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

Commit 0798107a authored by Samyak Jain's avatar Samyak Jain Committed by Bruno Martins
Browse files

Revert the change: AudioService: remove dead BT code.

Change-Id: If9902d3d458b6c5ccd474ffe69133d81beb49ca9
CRs-Fixed: 2475616
parent b9f99a20
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -4280,6 +4280,38 @@ public class AudioManager {
        }
    }

     /**
     * Indicate A2DP source or sink active device change and eventually suppress
     * the {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent.
     * This operation is asynchronous but its execution will still be sequentially scheduled
     * relative to calls to {@link #setBluetoothHearingAidDeviceConnectionState(BluetoothDevice,
     * int, boolean, int)} and
     * {@link #handleBluetoothA2dpDeviceConfigChange(BluetoothDevice)}.
     * @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})
     * @param a2dpVolume New volume for the connecting device. Does nothing if
     * disconnecting. Pass value -1 in case you want this field to be ignored
     * @param suppressNoisyIntent if true the
     * {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent will not be sent.
     * @return a delay in ms that the caller should wait before broadcasting
     * BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED intent.
     * {@hide}
     */
    public void handleBluetoothA2dpActiveDeviceChange(
                BluetoothDevice device, int state, int profile,
                boolean suppressNoisyIntent, int a2dpVolume) {
         final IAudioService service = getService();
         try {
             service.handleBluetoothA2dpActiveDeviceChange(device,
                   state, profile, suppressNoisyIntent, a2dpVolume);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
    }

    /** {@hide} */
    public IRingtonePlayer getRingtonePlayer() {
        try {
+3 −0
Original line number Diff line number Diff line
@@ -178,6 +178,9 @@ interface IAudioService {

    void handleBluetoothA2dpDeviceConfigChange(in BluetoothDevice device);

    void handleBluetoothA2dpActiveDeviceChange(in BluetoothDevice device,
            int state, int profile, boolean suppressNoisyIntent, int a2dpVolume);

    @UnsupportedAppUsage
    AudioRoutesInfo startWatchingRoutes(in IAudioRoutesObserver observer);

+29 −1
Original line number Diff line number Diff line
@@ -280,6 +280,15 @@ import com.android.internal.annotations.GuardedBy;
                device);
    }

    /*package*/ void postBluetoothA2dpDeviceConfigChangeExt(
            @NonNull BluetoothDevice device,
            @AudioService.BtProfileConnectionState int state, int profile,
            boolean suppressNoisyIntent, int a2dpVolume) {
         final BtDeviceConnectionInfo info = new BtDeviceConnectionInfo(device, state, profile,
                 suppressNoisyIntent, a2dpVolume);
         sendLMsgNoDelay(MSG_L_A2DP_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, info);
    }

    private static final class HearingAidDeviceConnectionInfo {
        final @NonNull BluetoothDevice mDevice;
        final @AudioService.BtProfileConnectionState int mState;
@@ -879,6 +888,22 @@ import com.android.internal.annotations.GuardedBy;
                                info.mDevice, info.mState, info.mSupprNoisy, info.mMusicDevice);
                    }
                } break;
                case MSG_L_A2DP_ACTIVE_DEVICE_CHANGE_EXT: {
                    final BtDeviceConnectionInfo info = (BtDeviceConnectionInfo) msg.obj;
                    AudioService.sDeviceLogger.log((new AudioEventLogger.StringEvent(
                    "handleBluetoothA2dpActiveDeviceChangeExt "
                           + " state=" + info.mState
                           // only querying address as this is the only readily available
                           // field on the device
                           + " addr=" + info.mDevice.getAddress()
                           + " prof=" + info.mProfile + " supprNoisy=" + info.mSupprNoisy
                           + " vol=" + info.mVolume)).printLog(TAG));
                    synchronized (mDeviceStateLock) {
                        mDeviceInventory.handleBluetoothA2dpActiveDeviceChangeExt(
                                info.mDevice, info.mState, info.mProfile,
                                info.mSupprNoisy, info.mVolume);
                    }
                } break;
                default:
                    Log.wtf(TAG, "Invalid message " + msg.what);
            }
@@ -928,8 +953,10 @@ import com.android.internal.annotations.GuardedBy;
    private static final int MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_DISCONNECTION = 30;
    // process external command to (dis)connect a hearing aid device
    private static final int MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT = 31;
    // process external command to (dis)connect or change active A2DP device
    private static final int MSG_L_A2DP_ACTIVE_DEVICE_CHANGE_EXT = 32;
    // a ScoClient died in BtHelper
    private static final int MSG_L_SCOCLIENT_DIED = 32;
    private static final int MSG_L_SCOCLIENT_DIED = 33;


    private static boolean isMessageHandledUnderWakelock(int msgId) {
@@ -946,6 +973,7 @@ import com.android.internal.annotations.GuardedBy;
            case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_CONNECTION:
            case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT_DISCONNECTION:
            case MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT:
            case MSG_L_A2DP_ACTIVE_DEVICE_CHANGE_EXT:
                return true;
            default:
                return false;
+43 −0
Original line number Diff line number Diff line
@@ -604,6 +604,49 @@ public class AudioDeviceInventory {
        }
    }

    /*package*/ void handleBluetoothA2dpActiveDeviceChangeExt(
            @NonNull BluetoothDevice device,
            @AudioService.BtProfileConnectionState int state, int profile,
            boolean suppressNoisyIntent, int a2dpVolume) {
          if (state == BluetoothProfile.STATE_DISCONNECTED) {
              mDeviceBroker.postBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                             device, state, profile, suppressNoisyIntent, a2dpVolume);
              return;
          }
          // state == BluetoothProfile.STATE_CONNECTED
          synchronized (mConnectedDevices) {
                 final String address = device.getAddress();
                 final int a2dpCodec = mDeviceBroker.getA2dpCodec(device);
                 final String deviceKey = DeviceInfo.makeDeviceListKey(
                                AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address);
                 DeviceInfo deviceInfo = mConnectedDevices.get(deviceKey);
                 if (deviceInfo != null) {
                     // Device config change for matching A2DP device
                     mDeviceBroker.postBluetoothA2dpDeviceConfigChange(device);
                     return;
                 }
                 for (int i = 0; i < mConnectedDevices.size(); i++) {
                      deviceInfo = mConnectedDevices.valueAt(i);
                      if (deviceInfo.mDeviceType != AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP) {
                          continue;
                      }
                      // A2DP device exists, handle active device change
                      final String existingDevicekey = mConnectedDevices.keyAt(i);
                      mConnectedDevices.remove(existingDevicekey);
                      mConnectedDevices.put(deviceKey, new DeviceInfo(
                                 AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, BtHelper.getName(device),
                                 address, a2dpCodec));
                      mDeviceBroker.postA2dpActiveDeviceChange(
                                 new BtHelper.BluetoothA2dpDeviceInfo(
                                     device, a2dpVolume, a2dpCodec));
                      return;
                 }
          }
          // New A2DP device connection
          mDeviceBroker.postBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                             device, state, profile, suppressNoisyIntent, a2dpVolume);
    }

    /*package*/ int setWiredDeviceConnectionState(int type, @AudioService.ConnectionState int state,
                                                  String address, String name, String caller) {
        synchronized (mConnectedDevices) {
+21 −0
Original line number Diff line number Diff line
@@ -4515,6 +4515,27 @@ public class AudioService extends IAudioService.Stub
        mDeviceBroker.postBluetoothA2dpDeviceConfigChange(device);
    }

    /**
     * @see AudioManager#handleBluetoothA2dpActiveDeviceChange(BluetoothDevice, int, int,
     *                                                        boolean, int)
     */
    public void handleBluetoothA2dpActiveDeviceChange(
            BluetoothDevice device, int state, int profile, boolean suppressNoisyIntent,
            int a2dpVolume) {
        if (device == null) {
                throw new IllegalArgumentException("Illegal null device");
        }
        if (profile != BluetoothProfile.A2DP && profile != BluetoothProfile.A2DP_SINK) {
            throw new IllegalArgumentException("invalid profile " + profile);
        }
        if (state != BluetoothProfile.STATE_CONNECTED
                && state != BluetoothProfile.STATE_DISCONNECTED) {
            throw new IllegalArgumentException("Invalid state " + state);
        }
        mDeviceBroker.postBluetoothA2dpDeviceConfigChangeExt(device, state, profile,
                suppressNoisyIntent, a2dpVolume);
    }

    private static final int DEVICE_MEDIA_UNMUTED_ON_PLUG =
            AudioSystem.DEVICE_OUT_WIRED_HEADSET | AudioSystem.DEVICE_OUT_WIRED_HEADPHONE |
            AudioSystem.DEVICE_OUT_LINE |