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

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

Snap for 8543353 from f999f3b3 to tm-qpr1-release

Change-Id: I3e2a010a35d0bd4eb49af622ba506cee3b2df533
parents 43b583b8 f999f3b3
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.bluetooth.bass_client;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcastMetadata;
@@ -672,8 +675,12 @@ public class BassClientService extends ProfileService {
                filters = new ArrayList<ScanFilter>();
            }
            if (!BassUtils.containUuid(filters, BassConstants.BAAS_UUID)) {
                byte[] serviceData = {0x00, 0x00 ,0x00}; // Broadcast_ID
                byte[] serviceDataMask = {0x00, 0x00, 0x00};

                filters.add(new ScanFilter.Builder()
                        .setServiceUuid(BassConstants.BAAS_UUID).build());
                        .setServiceData(BassConstants.BAAS_UUID,
                                serviceData, serviceDataMask).build());
            }
            scanner.startScan(filters, settings, mSearchScanCallback);
            mCallbacks.notifySearchStarted(BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);
@@ -1119,6 +1126,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return false;
                }
                mService.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                return service.setConnectionPolicy(device, connectionPolicy);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1134,6 +1142,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
                }
                mService.enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
                return service.getConnectionPolicy(device);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1149,6 +1158,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.registerCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1163,6 +1173,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.unregisterCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1177,6 +1188,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.startSearchingForSources(filters);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1191,6 +1203,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.stopSearchingForSources();
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1205,6 +1218,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return false;
                }
                enforceBluetoothPrivilegedPermission(service);
                return service.isSearchInProgress();
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1222,6 +1236,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.addSource(sink, sourceMetadata, isGroupOp);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1237,6 +1252,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.modifySource(sink, sourceId, updatedMetadata);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1251,6 +1267,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return;
                }
                enforceBluetoothPrivilegedPermission(service);
                service.removeSource(sink, sourceId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1265,6 +1282,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return Collections.emptyList();
                }
                enforceBluetoothPrivilegedPermission(service);
                return service.getAllSources(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
@@ -1280,6 +1298,7 @@ public class BassClientService extends ProfileService {
                    Log.e(TAG, "Service is null");
                    return 0;
                }
                enforceBluetoothPrivilegedPermission(service);
                return service.getMaximumSourceCapacity(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Exception happened", e);
+3 −1
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@

package com.android.bluetooth.gatt;

import android.os.Build;

/**
 * GattService configuration.
 */
/*package*/ class GattServiceConfig {
    public static final boolean DBG = false;
    public static final boolean DBG = Build.TYPE.equals("userdebug") || Build.TYPE.equals("eng");
    public static final boolean VDBG = false;
    public static final String TAG_PREFIX = "BtGatt.";
    public static final boolean DEBUG_ADMIN = false;
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class HfpClientDeviceBlockTest {
    private static final String TEST_DEVICE_ADDRESS = "00:11:22:33:44:55";
    private static final String TEST_NUMBER = "000-111-2222";
    private static final String KEY_SCO_STATE = "com.android.bluetooth.hfpclient.SCO_STATE";
    private static final String TEST_PACKAGE = "test";

    @Mock
    private HeadsetClientService mHeadsetClientService;
@@ -76,6 +77,7 @@ public class HfpClientDeviceBlockTest {
                        .hfp_client_connection_service_support_emergency_call)).thenReturn(true);
        when(mApplicationContext.getResources()).thenReturn(mResources);
        when(mConnServ.getApplicationContext()).thenReturn(mApplicationContext);
        when(mConnServ.getPackageName()).thenReturn(TEST_PACKAGE);

        when(mConnServ.getSystemService(Context.TELECOM_SERVICE)).thenReturn(mTelecomManager);
        when(mConnServ.getSystemServiceName(TelecomManager.class))
+86 −66
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <unordered_set>

#include "common/bind.h"
#include "common/init_flags.h"
#include "crypto_toolbox/crypto_toolbox.h"
#include "hci/acl_manager/assembler.h"
#include "hci/acl_manager/le_connection_management_callbacks.h"
@@ -272,9 +273,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    auto connecting_addr_with_type = connecting_le_.find(address_with_type);
    if (connecting_addr_with_type == connecting_le_.end()) {
      LOG_WARN("No prior connection request for %s", address_with_type.ToString().c_str());
    } else {
      connecting_le_.erase(connecting_addr_with_type);
    }
    connecting_le_.clear();

    if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
      create_connection_timeout_alarms_.at(address_with_type).Cancel();
      create_connection_timeout_alarms_.erase(address_with_type);
@@ -629,68 +630,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
          connectability_state_machine_text(connectability_state_).c_str());
      return;
    }
    connectability_state_ = ConnectabilityState::ARMING;
    AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
    create_le_connection(empty, false, false);
  }

  void disarm_connectability() {
    if (connectability_state_ != ConnectabilityState::ARMED && connectability_state_ != ConnectabilityState::ARMING) {
      LOG_ERROR(
          "Attempting to disarm le connection state machine in unexpected state:%s",
          connectability_state_machine_text(connectability_state_).c_str());
      return;
    }
    connectability_state_ = ConnectabilityState::DISARMING;
    le_acl_connection_interface_->EnqueueCommand(
        LeCreateConnectionCancelBuilder::Create(),
        handler_->BindOnce(&le_impl::on_create_connection_cancel_complete, common::Unretained(this)));
  }

  void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list, bool is_direct) {
    if (le_client_callbacks_ == nullptr) {
      LOG_ERROR("No callbacks to call");
      return;
    }

    if (connections.alreadyConnected(address_with_type)) {
      LOG_INFO("Device already connected, return");
      return;
    }

    // TODO: Configure default LE connection parameters?
    if (add_to_connect_list) {
      add_device_to_connect_list(address_with_type);
      if (is_direct) {
        direct_connections_.insert(address_with_type);
        if (create_connection_timeout_alarms_.find(address_with_type) == create_connection_timeout_alarms_.end()) {
          create_connection_timeout_alarms_.emplace(
              std::piecewise_construct,
              std::forward_as_tuple(address_with_type.GetAddress(), address_with_type.GetAddressType()),
              std::forward_as_tuple(handler_));
          create_connection_timeout_alarms_.at(address_with_type)
              .Schedule(
                  common::BindOnce(&le_impl::on_create_connection_timeout, common::Unretained(this), address_with_type),
                  kCreateConnectionTimeoutMs);
        }
      }
    }

    if (!address_manager_registered) {
      auto policy = le_address_manager_->Register(this);
      address_manager_registered = true;

      // Pause connection, wait for set random address complete
      if (policy == LeAddressManager::AddressPolicy::USE_RESOLVABLE_ADDRESS ||
          policy == LeAddressManager::AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) {
        pause_connection = true;
      }
    }

    if (pause_connection) {
      canceled_connections_.insert(address_with_type);
      return;
    }
    connectability_state_ = ConnectabilityState::ARMING;
    connecting_le_ = connect_list;

    uint16_t le_scan_interval = kScanIntervalSlow;
    uint16_t le_scan_window = kScanWindowSlow;
@@ -712,9 +654,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    uint16_t supervision_timeout = 0x001f4;
    ASSERT(check_connection_parameters(conn_interval_min, conn_interval_max, conn_latency, supervision_timeout));

    connecting_le_.insert(address_with_type);
    connectability_state_ = ConnectabilityState::ARMING;

    AddressWithType address_with_type = connection_peer_address_with_type_;
    if (initiator_filter_policy == InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST) {
      address_with_type = AddressWithType();
    }
@@ -788,6 +728,85 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    }
  }

  void disarm_connectability() {
    if (connectability_state_ != ConnectabilityState::ARMED && connectability_state_ != ConnectabilityState::ARMING) {
      LOG_ERROR(
          "Attempting to disarm le connection state machine in unexpected state:%s",
          connectability_state_machine_text(connectability_state_).c_str());
      return;
    }
    connectability_state_ = ConnectabilityState::DISARMING;
    le_acl_connection_interface_->EnqueueCommand(
        LeCreateConnectionCancelBuilder::Create(),
        handler_->BindOnce(&le_impl::on_create_connection_cancel_complete, common::Unretained(this)));
  }

  void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list, bool is_direct) {
    if (le_client_callbacks_ == nullptr) {
      LOG_ERROR("No callbacks to call");
      return;
    }

    if (connections.alreadyConnected(address_with_type)) {
      LOG_INFO("Device already connected, return");
      return;
    }

    // TODO: Configure default LE connection parameters?
    if (add_to_connect_list) {
      add_device_to_connect_list(address_with_type);
      if (is_direct) {
        direct_connections_.insert(address_with_type);
        if (create_connection_timeout_alarms_.find(address_with_type) == create_connection_timeout_alarms_.end()) {
          create_connection_timeout_alarms_.emplace(
              std::piecewise_construct,
              std::forward_as_tuple(address_with_type.GetAddress(), address_with_type.GetAddressType()),
              std::forward_as_tuple(handler_));
          create_connection_timeout_alarms_.at(address_with_type)
              .Schedule(
                  common::BindOnce(&le_impl::on_create_connection_timeout, common::Unretained(this), address_with_type),
                  kCreateConnectionTimeoutMs);
        }
      }
    }

    if (!address_manager_registered) {
      auto policy = le_address_manager_->Register(this);
      address_manager_registered = true;

      // Pause connection, wait for set random address complete
      if (policy == LeAddressManager::AddressPolicy::USE_RESOLVABLE_ADDRESS ||
          policy == LeAddressManager::AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) {
        pause_connection = true;
      }
    }

    if (pause_connection) {
      canceled_connections_.insert(address_with_type);
      return;
    }

    switch (connectability_state_) {
      case ConnectabilityState::ARMED:
      case ConnectabilityState::ARMING:
        // Ignored, if we add new device to the filter accept list, create connection command will be sent by OnResume.
        LOG_DEBUG(
            "Deferred until filter accept list updated create connection state %s",
            connectability_state_machine_text(connectability_state_).c_str());
        break;
      default:
        // If we added to filter accept list then the arming of the le state machine
        // must wait until the filter accept list command as completed
        if (add_to_connect_list) {
          canceled_connections_.insert(address_with_type);
          LOG_DEBUG("Deferred until filter accept list has completed");
        } else {
          handler_->CallOn(this, &le_impl::arm_connectability);
        }
        break;
    }
  }

  void on_create_connection_timeout(AddressWithType address_with_type) {
    LOG_INFO("on_create_connection_timeout, address: %s", address_with_type.ToString().c_str());
    if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
@@ -960,6 +979,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  // Set of devices that will not be removed from connect list after direct connect timeout
  std::unordered_set<AddressWithType> background_connections_;
  std::unordered_set<AddressWithType> connect_list;
  AddressWithType connection_peer_address_with_type_;  // Direct peer address UNSUPPORTEDD
  bool address_manager_registered = false;
  bool ready_to_unregister = false;
  bool pause_connection = false;
+32 −8
Original line number Diff line number Diff line
@@ -652,7 +652,10 @@ void log_classic_pairing_other_hci_event(EventView packet) {
    }
    case EventCode::REMOTE_OOB_DATA_REQUEST: {
      RemoteOobDataRequestView remote_oob_data_request_view = RemoteOobDataRequestView::Create(std::move(packet));
      ASSERT(remote_oob_data_request_view.IsValid());
      if (!remote_oob_data_request_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_view not valid");
        return;
      }
      address = remote_oob_data_request_view.GetBdAddr();
      break;
    }
@@ -665,7 +668,10 @@ void log_classic_pairing_other_hci_event(EventView packet) {
    }
    case EventCode::REMOTE_NAME_REQUEST_COMPLETE: {
      RemoteNameRequestCompleteView remote_name_request_complete_view = RemoteNameRequestCompleteView::Create(std::move(packet));
      ASSERT(remote_name_request_complete_view.IsValid());
      if (!remote_name_request_complete_view.IsValid()) {
        LOG_WARN("remote_name_request_complete_view not valid");
        return;
      }
      address = remote_name_request_complete_view.GetBdAddr();
      status = remote_name_request_complete_view.GetStatus();
      break;
@@ -831,14 +837,20 @@ void log_classic_pairing_command_status(std::unique_ptr<CommandView>& command_vi
    case OpCode::REMOTE_OOB_DATA_REQUEST_REPLY: {
      RemoteOobDataRequestReplyView remote_oob_data_request_reply_view
      = RemoteOobDataRequestReplyView::Create(std::move(security_command_view));
      ASSERT(remote_oob_data_request_reply_view.IsValid());
      if (!remote_oob_data_request_reply_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_reply_view is not valid.");
        return;
      }
      address = remote_oob_data_request_reply_view.GetBdAddr();
      break;
    }
    case OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY: {
      RemoteOobDataRequestNegativeReplyView remote_oob_data_request_negative_reply_view
      = RemoteOobDataRequestNegativeReplyView::Create(std::move(security_command_view));
      ASSERT(remote_oob_data_request_negative_reply_view.IsValid());
      if (!remote_oob_data_request_negative_reply_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_negative_reply_view is not valid.");
        return;
      }
      address = remote_oob_data_request_negative_reply_view.GetBdAddr();
      break;
    }
@@ -994,19 +1006,31 @@ void log_classic_pairing_command_complete(EventView event_view, std::unique_ptr<
    }
    case OpCode::REMOTE_OOB_DATA_REQUEST_REPLY: {
      auto remote_oob_data_request_reply_complete_view = RemoteOobDataRequestReplyCompleteView::Create(std::move(command_complete_view));
      ASSERT(remote_oob_data_request_reply_complete_view.IsValid());
      if (!remote_oob_data_request_reply_complete_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_reply_complete_view is not valid.");
        return;
      }
      status = remote_oob_data_request_reply_complete_view.GetStatus();
      auto remote_oob_data_request_reply_view = RemoteOobDataRequestReplyView::Create(std::move(security_command_view));
      ASSERT(remote_oob_data_request_reply_view.IsValid());
      if (!remote_oob_data_request_reply_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_reply_view is not valid.");
        return;
      }
      address = remote_oob_data_request_reply_view.GetBdAddr();
      break;
    }
    case OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY: {
      auto remote_oob_data_request_negative_reply_complete_view = RemoteOobDataRequestNegativeReplyCompleteView::Create(std::move(command_complete_view));
      ASSERT(remote_oob_data_request_negative_reply_complete_view.IsValid());
      if (!remote_oob_data_request_negative_reply_complete_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_negative_reply_complete_view is not valid.");
        return;
      }
      status = remote_oob_data_request_negative_reply_complete_view.GetStatus();
      auto remote_oob_data_request_negative_reply_view = RemoteOobDataRequestNegativeReplyView::Create(std::move(security_command_view));
      ASSERT(remote_oob_data_request_negative_reply_view.IsValid());
      if (!remote_oob_data_request_negative_reply_view.IsValid()) {
        LOG_WARN("remote_oob_data_request_negative_reply_view is not valid.");
        return;
      }
      address = remote_oob_data_request_negative_reply_view.GetBdAddr();
      break;
    }
Loading