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

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

Snap for 9121707 from f3100d2f to tm-qpr1-release

Change-Id: Ie591bf68237235f08b215bb70b34f5714debdb4a
parents e53a6f16 f3100d2f
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -71,6 +71,9 @@ public class A2dpService extends ProfileService {
    private static final boolean DBG = true;
    private static final String TAG = "A2dpService";

    // TODO(b/240635097): remove in U
    private static final int SOURCE_CODEC_TYPE_OPUS = 6;

    private static A2dpService sA2dpService;

    private AdapterService mAdapterService;
@@ -600,6 +603,7 @@ public class A2dpService extends ProfileService {
            // This needs to happen before we inform the audio manager that the device
            // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why.
            updateAndBroadcastActiveDevice(device);
            updateLowLatencyAudioSupport(device);

            BluetoothDevice newActiveDevice = null;
            synchronized (mStateMachines) {
@@ -819,6 +823,7 @@ public class A2dpService extends ProfileService {
            Log.e(TAG, "enableOptionalCodecs: Codec status is null");
            return;
        }
        updateLowLatencyAudioSupport(device);
        mA2dpCodecConfig.enableOptionalCodecs(device, codecStatus.getCodecConfig());
    }

@@ -849,6 +854,7 @@ public class A2dpService extends ProfileService {
            Log.e(TAG, "disableOptionalCodecs: Codec status is null");
            return;
        }
        updateLowLatencyAudioSupport(device);
        mA2dpCodecConfig.disableOptionalCodecs(device, codecStatus.getCodecConfig());
    }

@@ -1208,6 +1214,34 @@ public class A2dpService extends ProfileService {
        }
    }

    /**
     *  Check for low-latency codec support and inform AdapterService
     *
     *  @param device device whose audio low latency will be allowed or disallowed
     */
    @VisibleForTesting
    public void updateLowLatencyAudioSupport(BluetoothDevice device) {
        synchronized (mStateMachines) {
            A2dpStateMachine sm = mStateMachines.get(device);
            if (sm == null) {
                return;
            }
            BluetoothCodecStatus codecStatus = sm.getCodecStatus();
            boolean lowLatencyAudioAllow = false;
            BluetoothCodecConfig lowLatencyCodec = new BluetoothCodecConfig.Builder()
                    .setCodecType(SOURCE_CODEC_TYPE_OPUS) // remove in U
                    .build();

            if (codecStatus != null
                    && codecStatus.isCodecConfigSelectable(lowLatencyCodec)
                    && getOptionalCodecsEnabled(device)
                            == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
                lowLatencyAudioAllow = true;
            }
            mAdapterService.allowLowLatencyAudio(lowLatencyAudioAllow, device);
        }
    }

    private void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
        if ((device == null) || (fromState == toState)) {
            return;
+2 −0
Original line number Diff line number Diff line
@@ -483,6 +483,7 @@ final class A2dpStateMachine extends StateMachine {
            // codecs (perhaps it's had a firmware update, etc.) and save that state if
            // it differs from what we had saved before.
            mA2dpService.updateOptionalCodecsSupport(mDevice);
            mA2dpService.updateLowLatencyAudioSupport(mDevice);
            broadcastConnectionState(mConnectionState, mLastConnectionState);
            // Upon connected, the audio starts out as stopped
            broadcastAudioState(BluetoothA2dp.STATE_NOT_PLAYING,
@@ -655,6 +656,7 @@ final class A2dpStateMachine extends StateMachine {
            // for this codec change event.
            mA2dpService.updateOptionalCodecsSupport(mDevice);
        }
        mA2dpService.updateLowLatencyAudioSupport(mDevice);
        if (mA2dpOffloadEnabled) {
            boolean update = false;
            BluetoothCodecConfig newCodecConfig = mCodecStatus.getCodecConfig();
+15 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ public class A2dpStateMachineTest {
        // Selected codec = SBC, selectable codec = SBC
        mA2dpStateMachine.processCodecConfigEvent(codecStatusSbcAndSbc);
        verify(mA2dpService).codecConfigUpdated(mTestDevice, codecStatusSbcAndSbc, false);
        verify(mA2dpService, times(1)).updateLowLatencyAudioSupport(mTestDevice);

        // Inject an event to change state machine to connected state
        A2dpStackEvent connStCh =
@@ -379,6 +380,7 @@ public class A2dpStateMachineTest {

        // Verify that state machine update optional codec when enter connected state
        verify(mA2dpService, times(1)).updateOptionalCodecsSupport(mTestDevice);
        verify(mA2dpService, times(2)).updateLowLatencyAudioSupport(mTestDevice);

        // Change codec status when device connected.
        // Selected codec = SBC, selectable codec = SBC+AAC
@@ -387,12 +389,14 @@ public class A2dpStateMachineTest {
            verify(mA2dpService).codecConfigUpdated(mTestDevice, codecStatusSbcAndSbcAac, true);
        }
        verify(mA2dpService, times(2)).updateOptionalCodecsSupport(mTestDevice);
        verify(mA2dpService, times(3)).updateLowLatencyAudioSupport(mTestDevice);

        // Update selected codec with selectable codec unchanged.
        // Selected codec = AAC, selectable codec = SBC+AAC
        mA2dpStateMachine.processCodecConfigEvent(codecStatusAacAndSbcAac);
        verify(mA2dpService).codecConfigUpdated(mTestDevice, codecStatusAacAndSbcAac, false);
        verify(mA2dpService, times(2)).updateOptionalCodecsSupport(mTestDevice);
        verify(mA2dpService, times(4)).updateLowLatencyAudioSupport(mTestDevice);

        // Update selected codec
        // Selected codec = OPUS, selectable codec = SBC+AAC+OPUS
@@ -401,5 +405,16 @@ public class A2dpStateMachineTest {
            verify(mA2dpService).codecConfigUpdated(mTestDevice, codecStatusOpusAndSbcAacOpus, true);
        }
        verify(mA2dpService, times(3)).updateOptionalCodecsSupport(mTestDevice);
        // Check if low latency audio been updated.
        verify(mA2dpService, times(5)).updateLowLatencyAudioSupport(mTestDevice);

        // Update selected codec with selectable codec changed.
        // Selected codec = SBC, selectable codec = SBC+AAC
        mA2dpStateMachine.processCodecConfigEvent(codecStatusSbcAndSbcAac);
        if (!offloadEnabled) {
            verify(mA2dpService).codecConfigUpdated(mTestDevice, codecStatusSbcAndSbcAac, true);
        }
        // Check if low latency audio been update.
        verify(mA2dpService, times(6)).updateLowLatencyAudioSupport(mTestDevice);
    }
}
+21 −6
Original line number Diff line number Diff line
@@ -1566,6 +1566,14 @@ class LeAudioClientImpl : public LeAudioClient {
  void RegisterKnownNotifications(LeAudioDevice* leAudioDevice) {
    LOG(INFO) << __func__ << " device: " << leAudioDevice->address_;

    if (leAudioDevice->ctp_hdls_.val_hdl == 0) {
      LOG_ERROR(
          "Control point characteristic is mandatory - disconnecting device %s",
          leAudioDevice->address_.ToString().c_str());
      DisconnectDevice(leAudioDevice);
      return;
    }

    /* GATTC will ommit not registered previously handles */
    for (auto pac_tuple : leAudioDevice->snk_pacs_) {
      subscribe_for_notification(leAudioDevice->conn_id_,
@@ -1597,14 +1605,12 @@ class LeAudioClientImpl : public LeAudioClient {
                                 leAudioDevice->address_,
                                 leAudioDevice->audio_supp_cont_hdls_);

    if (leAudioDevice->ctp_hdls_.val_hdl != 0)
      subscribe_for_notification(leAudioDevice->conn_id_,
                                 leAudioDevice->address_,
                                 leAudioDevice->ctp_hdls_);

    for (struct ase& ase : leAudioDevice->ases_)
      subscribe_for_notification(leAudioDevice->conn_id_,
                                 leAudioDevice->address_, ase.hdls);

    subscribe_for_notification(leAudioDevice->conn_id_, leAudioDevice->address_,
                               leAudioDevice->ctp_hdls_);
  }

  void changeMtuIfPossible(LeAudioDevice* leAudioDevice) {
@@ -1653,7 +1659,7 @@ class LeAudioClientImpl : public LeAudioClient {
     * just notify connected  */
    if (leAudioDevice->known_service_handles_ &&
        !leAudioDevice->notify_connected_after_read_) {
      connectionReady(leAudioDevice);
      LOG_INFO("Wait for CCC registration and MTU change request");
      return;
    }

@@ -2155,6 +2161,15 @@ class LeAudioClientImpl : public LeAudioClient {
    if (status == GATT_SUCCESS) {
      LOG(INFO) << __func__
                << ", successfully registered on ccc: " << loghex(hdl);

      if (leAudioDevice->ctp_hdls_.ccc_hdl == hdl &&
          leAudioDevice->known_service_handles_ &&
          !leAudioDevice->notify_connected_after_read_) {
        /* Reconnection case. Control point is the last CCC LeAudio is
         * registering for on reconnection */
        connectionReady(leAudioDevice);
      }

      return;
    }

+9 −5
Original line number Diff line number Diff line
@@ -200,18 +200,22 @@ void LeAudioDeviceGroup::SetCigState(le_audio::types::CigState state) {
}

bool LeAudioDeviceGroup::Activate(LeAudioContextType context_type) {
  bool is_activate = false;
  for (auto leAudioDevice : leAudioDevices_) {
    if (leAudioDevice.expired()) continue;

    bool activated = leAudioDevice.lock()->ActivateConfiguredAses(context_type);
    LOG_INFO("Device %s is activated now: ",
             leAudioDevice.lock().get()->address_.ToString().c_str());
    LOG_INFO("Device %s is %s",
             leAudioDevice.lock().get()->address_.ToString().c_str(),
             activated ? "activated" : " not activated");
    if (activated) {
      if (!CigAssignCisIds(leAudioDevice.lock().get())) return false;
      if (!CigAssignCisIds(leAudioDevice.lock().get())) {
        return false;
      }
      is_activate = true;
    }

  return true;
  }
  return is_activate;
}

LeAudioDevice* LeAudioDeviceGroup::GetFirstDevice(void) {
Loading