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

Commit ce586982 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9325773 from 35e73bbb to tm-qpr2-release

Change-Id: I9c57af9f681e621ddcbb8f7814e61060dc94774b
parents 12864dcb 35e73bbb
Loading
Loading
Loading
Loading
+42 −76
Original line number Diff line number Diff line
@@ -255,27 +255,9 @@ class ActiveDeviceManager {
                            // Lazy active A2DP if it is not being used.
                            // This will prevent the deactivation of LE audio
                            // earlier than the activation of HFP.
                            switch (mAudioManager.getMode()) {
                                case AudioManager.MODE_NORMAL:
                                    break;
                                case AudioManager.MODE_RINGTONE: {
                                    HeadsetService headsetService = mFactory.getHeadsetService();
                                    if (mHfpActiveDevice == null && headsetService != null
                                            && headsetService.isInbandRingingEnabled()) {
                            if (!isMediaMode(mAudioManager.getMode()) && mHfpActiveDevice == null) {
                                mPendingA2dpActiveDevice = device;
                            }
                                    break;
                                }
                                case AudioManager.MODE_IN_CALL:
                                case AudioManager.MODE_IN_COMMUNICATION:
                                case AudioManager.MODE_CALL_SCREENING:
                                case AudioManager.MODE_CALL_REDIRECT:
                                case AudioManager.MODE_COMMUNICATION_REDIRECT: {
                                    if (mHfpActiveDevice == null) {
                                        mPendingA2dpActiveDevice = device;
                                    }
                                }
                            }
                            if (mPendingA2dpActiveDevice == null) {
                                // select the device as active if not lazy active
                                setA2dpActiveDevice(device);
@@ -346,21 +328,9 @@ class ActiveDeviceManager {
                            // Lazy active HFP if it is not being used.
                            // This will prevent the deactivation of LE audio
                            // earlier than the activation of A2DP.
                            switch (mAudioManager.getMode()) {
                                case AudioManager.MODE_NORMAL:
                                    if (mA2dpActiveDevice == null) {
                                        mPendingHfpActiveDevice = device;
                                    }
                                    break;
                                case AudioManager.MODE_RINGTONE: {
                                    HeadsetService headsetService = mFactory.getHeadsetService();
                                    if (headsetService == null
                                            || !headsetService.isInbandRingingEnabled()) {
                            if (isMediaMode(mAudioManager.getMode()) && mA2dpActiveDevice == null) {
                                mPendingHfpActiveDevice = device;
                            }
                                    break;
                                }
                            }
                            if (mPendingHfpActiveDevice == null) {
                                // select the device as active if not lazy active
                                setHfpActiveDevice(device);
@@ -622,34 +592,16 @@ class ActiveDeviceManager {

    private class AudioManagerOnModeChangedListener implements AudioManager.OnModeChangedListener {
        public void onModeChanged(int mode) {
            switch (mode) {
                case AudioManager.MODE_NORMAL: {
            if (isMediaMode(mode)) {
                if (mPendingA2dpActiveDevice != null) {
                    setA2dpActiveDevice(mPendingA2dpActiveDevice);
                    setLeAudioActiveDevice(null, true);
                }
                    break;
                }
                case AudioManager.MODE_RINGTONE: {
                    final HeadsetService headsetService = mFactory.getHeadsetService();
                    if (headsetService != null && headsetService.isInbandRingingEnabled()
                            && mPendingHfpActiveDevice != null) {
                        setHfpActiveDevice(mPendingHfpActiveDevice);
                        setLeAudioActiveDevice(null);
                    }
                    break;
                }
                case AudioManager.MODE_IN_CALL:
                case AudioManager.MODE_IN_COMMUNICATION:
                case AudioManager.MODE_CALL_SCREENING:
                case AudioManager.MODE_CALL_REDIRECT:
                case AudioManager.MODE_COMMUNICATION_REDIRECT:  {
            } else {
                if (mPendingHfpActiveDevice != null) {
                    setHfpActiveDevice(mPendingHfpActiveDevice);
                    setLeAudioActiveDevice(null);
                }
                    break;
                }
            }
        }
    }
@@ -857,6 +809,25 @@ class ActiveDeviceManager {
        }
    }

    private boolean isMediaMode(int mode) {
        switch (mode) {
            case AudioManager.MODE_RINGTONE:
                final HeadsetService headsetService = mFactory.getHeadsetService();
                if (headsetService != null && headsetService.isInbandRingingEnabled()) {
                    return false;
                }
                return true;
            case AudioManager.MODE_IN_CALL:
            case AudioManager.MODE_IN_COMMUNICATION:
            case AudioManager.MODE_CALL_SCREENING:
            case AudioManager.MODE_CALL_REDIRECT:
            case AudioManager.MODE_COMMUNICATION_REDIRECT:
                return false;
            default:
                return true;
        }
    }

    private boolean setFallbackDeviceActive() {
        if (DBG) {
            Log.d(TAG, "setFallbackDeviceActive");
@@ -911,25 +882,20 @@ class ActiveDeviceManager {

        List<BluetoothDevice> connectedDevices = new ArrayList<>();
        connectedDevices.addAll(mLeAudioConnectedDevices);
        switch (mAudioManager.getMode()) {
            case AudioManager.MODE_NORMAL:
        boolean isMediaMode = isMediaMode(mAudioManager.getMode());
        if (isMediaMode) {
            if (a2dpFallbackDevice != null) {
                connectedDevices.add(a2dpFallbackDevice);
            }
                break;
            case AudioManager.MODE_RINGTONE:
                if (headsetFallbackDevice != null && headsetService.isInbandRingingEnabled()) {
                    connectedDevices.add(headsetFallbackDevice);
                }
                break;
            default:
        } else {
            if (headsetFallbackDevice != null) {
                connectedDevices.add(headsetFallbackDevice);
            }
        }

        BluetoothDevice device = dbManager.getMostRecentlyConnectedDevicesInList(connectedDevices);
        if (device != null) {
            if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
            if (isMediaMode) {
                if (Objects.equals(a2dpFallbackDevice, device)) {
                    if (DBG) {
                        Log.d(TAG, "set A2DP device active: " + device);
+72 −36
Original line number Diff line number Diff line
@@ -4388,95 +4388,131 @@ public class AdapterService extends Service {
            return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;
        }

        if (mA2dpService != null && mA2dpService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mA2dpService != null && (mA2dpService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mA2dpService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting A2dp");
            mA2dpService.disconnect(device);
        }
        if (mA2dpSinkService != null && mA2dpSinkService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mA2dpSinkService != null && (mA2dpSinkService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mA2dpSinkService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting A2dp Sink");
            mA2dpSinkService.disconnect(device);
        }
        if (mHeadsetService != null && mHeadsetService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHeadsetService != null && (mHeadsetService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                ||  mHeadsetService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG,
                    "disconnectAllEnabledProfiles: Disconnecting Headset Profile");
            mHeadsetService.disconnect(device);
        }
        if (mHeadsetClientService != null && mHeadsetClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHeadsetClientService != null && (mHeadsetClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mHeadsetClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting HFP");
            mHeadsetClientService.disconnect(device);
        }
        if (mMapClientService != null && mMapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mMapClientService != null && (mMapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mMapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting MAP Client");
            mMapClientService.disconnect(device);
        }
        if (mMapService != null && mMapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mMapService != null && (mMapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mMapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting MAP");
            mMapService.disconnect(device);
        }
        if (mHidDeviceService != null && mHidDeviceService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHidDeviceService != null && (mHidDeviceService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mHidDeviceService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Hid Device Profile");
            mHidDeviceService.disconnect(device);
        }
        if (mHidHostService != null && mHidHostService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHidHostService != null && (mHidHostService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mHidHostService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Hid Host Profile");
            mHidHostService.disconnect(device);
        }
        if (mPanService != null && mPanService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mPanService != null && (mPanService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mPanService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Pan Profile");
            mPanService.disconnect(device);
        }
        if (mPbapClientService != null && mPbapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mPbapClientService != null && (mPbapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mPbapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Pbap Client");
            mPbapClientService.disconnect(device);
        }
        if (mPbapService != null && mPbapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mPbapService != null && (mPbapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mPbapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Pbap Server");
            mPbapService.disconnect(device);
        }
        if (mHearingAidService != null && mHearingAidService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHearingAidService != null && (mHearingAidService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mHearingAidService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Hearing Aid Profile");
            mHearingAidService.disconnect(device);
        }
        if (mHapClientService != null && mHapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mHapClientService != null && (mHapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mHapClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Hearing Access Profile Client");
            mHapClientService.disconnect(device);
        }
        if (mVolumeControlService != null && mVolumeControlService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mVolumeControlService != null && (mVolumeControlService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mVolumeControlService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Volume Control Profile");
            mVolumeControlService.disconnect(device);
        }
        if (mSapService != null && mSapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mSapService != null && (mSapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mSapService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Sap Profile");
            mSapService.disconnect(device);
        }
        if (mCsipSetCoordinatorService != null
                && mCsipSetCoordinatorService.getConnectionState(device)
                        == BluetoothProfile.STATE_CONNECTED) {
                && (mCsipSetCoordinatorService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mCsipSetCoordinatorService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Coordinater Set Profile");
            mCsipSetCoordinatorService.disconnect(device);
        }
        if (mLeAudioService != null && mLeAudioService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mLeAudioService != null && (mLeAudioService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mLeAudioService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting LeAudio profile (BAP)");
            mLeAudioService.disconnect(device);
        }
        if (mBassClientService != null && mBassClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED) {
        if (mBassClientService != null && (mBassClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTED
                || mBassClientService.getConnectionState(device)
                == BluetoothProfile.STATE_CONNECTING)) {
            Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting "
                            + "LE Broadcast Assistant Profile");
            mBassClientService.disconnect(device);
+3 −0
Original line number Diff line number Diff line
@@ -379,6 +379,9 @@ public class LeAudioService extends ProfileService {
            }
        }

        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerAddAudioDeviceCallback);
        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerRemoveAudioDeviceCallback);

        mAdapterService = null;
        mAudioManager = null;
        mVolumeControlService = null;
+10 −0
Original line number Diff line number Diff line
@@ -1235,6 +1235,8 @@ bool LeAudioDeviceGroup::IsConfigurationSupported(
    return false;
  }

  auto required_snk_strategy = GetGroupStrategy();

  /* TODO For now: set ase if matching with first pac.
   * 1) We assume as well that devices will match requirements in order
   *    e.g. 1 Device - 1 Requirement, 2 Device - 2 Requirement etc.
@@ -1259,6 +1261,14 @@ bool LeAudioDeviceGroup::IsConfigurationSupported(
        +required_device_cnt, +ent.ase_cnt, +max_required_ase_per_dev,
        static_cast<int>(strategy));

    if (ent.direction == types::kLeAudioDirectionSink &&
        strategy != required_snk_strategy) {
      LOG_INFO(" Sink strategy mismatch (%d!=%d)",
               static_cast<int>(required_snk_strategy),
               static_cast<int>(strategy));
      return false;
    }

    for (auto* device = GetFirstDeviceWithActiveContext(context_type);
         device != nullptr && required_device_cnt > 0;
         device = GetNextDeviceWithActiveContext(device, context_type)) {
Loading