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

Commit de926d52 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7028657 from 502c8130 to sc-release

Change-Id: I1c85977501a4a9c0ec3aa1fccd80211445f63a84
parents 29c51387 502c8130
Loading
Loading
Loading
Loading
+113 −26
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ CERT_HOST_LOGS="/tmp/logs/HostOnlyCert"
CERT_DEVICE_LOGS="TODO: Add this"
CERT_TEST_VENV=${ANDROID_BUILD_TOP}/out/dist/bluetooth_venv
OUT_TARGET="${ANDROID_BUILD_TOP}/out/target"
TEST_CONFIG="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/gd/cert/android_devices_config.json"
TEST_CONFIG="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/gd/cert/host_config.json"
TEST_FILTER="-tf ${ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/gd/cert/all_cert_testcases"
BUILD_TARGET="bluetooth_stack_with_facade"

@@ -82,6 +82,14 @@ SKIP_SOONG_BUILD=false
USE_ASHMEM_VENV=true
VERBOSE_MODE=false

# Directory for test configs to modify
CONFIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

## Verify devices connected and valid
DUT_SERIAL="DUT Not Set"
DUT_ADB="DUT Not Set"
DUT_NAME="DUT Not Set"

# Used for position arguments needed for later
POSITIONAL=()
function parse_options {
@@ -105,8 +113,12 @@ function parse_options {
        echo -e "    Places the virtual environment on disk rather than in ashmem which is default."
        echo -e "${BLUE}  --gotta-go-fast${NOCOLOR}"
        echo -e "    Makes use of ashmem as best as possible for targeted speed increases."
        echo -e "${BLUE}  --host${NOCOLOR}" 
        echo -e "    Run the test on the host machine [i.e. simulated]." 
        echo -e "${BLUE}  --device${NOCOLOR}"
        echo -e "    Run the test on the 2 real devices."
        echo -e "${BLUE}  --rust${NOCOLOR}"
        echo -e "    Run the test using the rust implementation on the 2 real devices."
        echo -e "${BLUE}  --rhost${NOCOLOR}"
        echo -e "    Run the test using the rust implementation on the host."
        echo -e "${BLUE}  --repeat=<N>${NOCOLOR}"
        echo -e "    Repeat the test sequence N (int) number of times."
        echo -e "${BLUE}  --skip-soong-build${NOCOLOR}"
@@ -124,8 +136,8 @@ function parse_options {
        shift
        exit 0
        ;;
        # This will cause the bluetooth_venv to be created in ashmem
        # Increases --clean build times by 40% (~21 seconds on my machine)
        # This will cause the bluetooth_venv to NOT be created in ashmem
        # Using ashmem increases --clean build times by 40% (~21 seconds on my machine)
        --disable-ashmem-venv)
        USE_ASHMEM_VENV=false
        shift # past argument
@@ -134,8 +146,31 @@ function parse_options {
        GOTTA_GO_FAST=true
        shift # past argument
        ;;
        --host)
        TEST_CONFIG=$ANDROID_BUILD_TOP/packages/modules/Bluetooth/system/gd/cert/host_config.json
        --device)
        TEST_CONFIG="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth/system/gd/cert/devices_config.json"
        RR="$(cat ${TEST_CONFIG}|grep \"CERT\\\|DUT\")"
        if [ "$RR" != "" ]; then
        DUT_SERIAL="$(menu-adb DUT)"
        DUT_ADB="adb -s ${DUT_SERIAL}"
        DUT_NAME="$(adb devices -l | grep -v "List of device" | grep ${DUT_SERIAL} | awk '{ print $6 }' | cut -d ':' -f 2)"
        CERT_SERIAL="$(menu-adb CERT)"
        CERT_ADB="adb -s ${CERT_SERIAL}"
        CERT_NAME="$(adb devices -l | grep -v "List of device" | grep ${CERT_SERIAL} | awk '{ print $6 }' | cut -d ':' -f 2)"

        if [ "${CERT_SERIAL}" == "${DUT_SERIAL}" ]; then
            echo
            echo "ERROR: CERT and DUT cannot be the same device, or you only have one device connected!"
            echo
            exit 1
        fi

        ## Set android devices in config
        pushd .
        cd "${CONFIG_DIR}"
        popd
        sed -i "s/\"DUT\"/\"${DUT_SERIAL}\"/g" ${CONFIG_DIR}/devices_config.json
        sed -i "s/\"CERT\"/\"${CERT_SERIAL}\"/g" ${CONFIG_DIR}/devices_config.json
        fi
        shift # past argument
        ;;
        # Repeat running the specified test cases by N times in one single setup
@@ -326,6 +361,58 @@ function run_tests {
    fi
}

function menu-adb() {
    TMP=$(adb devices -l | grep -v "List of device" | awk '{ print $1 }')
    # TODO(optedoblivion): If the device doesn't have a name (offline), it misnames them
    NTMP=$(adb devices -l | grep -v "List of device" | awk '{ print $6 }' | cut -d ':' -f 2)
    SERIALS=($TMP)
    DEVICES=($NTMP)
    LEN=${#SERIALS[@]}
    result=0
    if [ $LEN -lt 1 ]; then
        echo "No devices connected!"
        return 1
    fi

    if [ "$LEN" == "" ]; then
        LEN=0
    fi

    answer=0

    DEVICE_NAME="$1 device"

    if [ $LEN -gt 1 ]; then
        echo "+-------------------------------------------------+" 1>&2
        echo "| Choose a ${DEVICE_NAME}:                         " 1>&2
        echo "+-------------------------------------------------+" 1>&2
        echo "|                                                 |" 1>&2
        let fixed_len=$LEN-1
        for i in `seq 0 $fixed_len`;
        do
            serial=${SERIALS[i]}
            device=${DEVICES[i]}
            echo "| $i) $serial $device" 1>&2
            ## TODO[MSB]: Find character count, fill with space and ending box wall
        done
        echo "|                                                 |" 1>&2
        echo "+-------------------------------------------------+" 1>&2
        echo 1>&2
        echo -n "Index number: " 1>&2
        read answer
    fi

    if [ $answer -ge $LEN ]; then
        echo
        echo "Please choose a correct index!" 1>&2
        echo
        return 1
    fi

    SERIAL=${SERIALS[$answer]}
    echo $SERIAL
}

function main {
    check_environment
    parse_options $@
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string&
}

void InitFlags::Load(const char** flags) {
  const char** flags_copy = flags;
  SetAll(false);
  while (flags != nullptr && *flags != nullptr) {
    std::string flag_element = *flags;
@@ -80,6 +81,7 @@ void InitFlags::Load(const char** flags) {
    }
  }

  flags = flags_copy;
  rust::Vec<rust::String> rusted_flags = rust::Vec<rust::String>();
  while (flags != nullptr && *flags != nullptr) {
    rusted_flags.push_back(rust::String(*flags));
+4 −2
Original line number Diff line number Diff line
@@ -61,8 +61,10 @@ struct AclManager::impl {
    hci_queue_end_ = hci_layer_->GetAclQueueEnd();
    hci_queue_end_->RegisterDequeue(
        handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this)));
    classic_impl_ = new classic_impl(hci_layer_, controller_, handler_, round_robin_scheduler_);
    le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_);
    bool crash_on_unknown_handle = false;
    classic_impl_ =
        new classic_impl(hci_layer_, controller_, handler_, round_robin_scheduler_, crash_on_unknown_handle);
    le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_, crash_on_unknown_handle);
  }

  void Stop() {
+121 −51
Original line number Diff line number Diff line
@@ -38,9 +38,16 @@ struct acl_connection {
};

struct classic_impl : public security::ISecurityManagerListener {
  classic_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler,
               RoundRobinScheduler* round_robin_scheduler)
      : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler) {
  classic_impl(
      HciLayer* hci_layer,
      Controller* controller,
      os::Handler* handler,
      RoundRobinScheduler* round_robin_scheduler,
      bool crash_on_unknown_handle)
      : hci_layer_(hci_layer),
        controller_(controller),
        round_robin_scheduler_(round_robin_scheduler),
        crash_on_unknown_handle_(crash_on_unknown_handle) {
    hci_layer_ = hci_layer;
    controller_ = controller;
    handler_ = handler;
@@ -59,6 +66,15 @@ struct classic_impl : public security::ISecurityManagerListener {
    security_manager_.reset();
  }

  ConnectionManagementCallbacks* get_callbacks(uint16_t handle) {
    auto conn = acl_connections_.find(handle);
    if (conn == acl_connections_.end()) {
      return nullptr;
    } else {
      return conn->second.connection_management_callbacks_;
    }
  }

  void on_classic_event(EventPacketView event_packet) {
    EventCode event_code = event_packet.GetEventCode();
    switch (event_code) {
@@ -101,16 +117,19 @@ struct classic_impl : public security::ISecurityManagerListener {
      case EventCode::LINK_SUPERVISION_TIMEOUT_CHANGED:
        on_link_supervision_timeout_changed(event_packet);
        break;
      case EventCode::CENTRAL_LINK_KEY_COMPLETE:
        on_central_link_key_complete(event_packet);
        break;
      default:
        LOG_ALWAYS_FATAL("Unhandled event code %s", EventCodeText(event_code).c_str());
    }
  }

  void on_classic_disconnect(uint16_t handle, ErrorCode reason) {
    if (acl_connections_.count(handle) == 1) {
      auto& connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks != nullptr) {
      round_robin_scheduler_->Unregister(handle);
      connection.connection_management_callbacks_->OnDisconnection(reason);
      callbacks->OnDisconnection(reason);
      acl_connections_.erase(handle);
    }
  }
@@ -122,11 +141,6 @@ struct classic_impl : public security::ISecurityManagerListener {
    client_handler_ = handler;
  }

  void handle_disconnect(uint16_t handle, DisconnectReason reason) {
    acl_connection_interface_->EnqueueCommand(hci::DisconnectBuilder::Create(handle, reason),
                                              handler_->BindOnce(&check_command_status<DisconnectStatusView>));
  }

  void on_incoming_connection(EventPacketView packet) {
    ConnectionRequestView request = ConnectionRequestView::Create(packet);
    ASSERT(request.IsValid());
@@ -206,16 +220,18 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = connection_complete.GetConnectionHandle();
    ASSERT(acl_connections_.count(handle) == 0);
    auto queue = std::make_shared<AclConnection::Queue>(10);
    acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
                             std::forward_as_tuple(AddressWithType{address, AddressType::PUBLIC_DEVICE_ADDRESS},
                                                   queue->GetDownEnd(), handler_));
    auto conn_pair = acl_connections_.emplace(
        std::piecewise_construct,
        std::forward_as_tuple(handle),
        std::forward_as_tuple(
            AddressWithType{address, AddressType::PUBLIC_DEVICE_ADDRESS}, queue->GetDownEnd(), handler_));
    ASSERT(conn_pair.second);  // Make sure it's not a duplicate
    round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::CLASSIC, handle, queue);
    std::unique_ptr<ClassicAclConnection> connection(
        new ClassicAclConnection(std::move(queue), acl_connection_interface_, handle, address));
    connection->locally_initiated_ = locally_initiated;
    auto& connection_proxy = check_and_get_connection(handle);
    auto& connection_proxy = conn_pair.first->second;
    connection_proxy.connection_management_callbacks_ = connection->GetEventCallbacks();
    connection_proxy.connection_management_callbacks_->OnRoleChange(current_role);
    client_handler_->Post(common::BindOnce(&ConnectionCallbacks::OnConnectSuccess,
@@ -246,6 +262,13 @@ struct classic_impl : public security::ISecurityManagerListener {
      LOG_ERROR("Received on_connection_packet_type_changed with error code %s", error_code.c_str());
      return;
    }
    uint16_t handle = packet_type_changed.GetConnectionHandle();
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    // We don't handle this event; we didn't do this in legacy stack either.
  }

@@ -261,9 +284,14 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = complete_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    KeyFlag key_flag = complete_view.GetKeyFlag();
    acl_connection.connection_management_callbacks_->OnCentralLinkKeyComplete(key_flag);
    callbacks->OnCentralLinkKeyComplete(key_flag);
  }

  void on_authentication_complete(EventPacketView packet) {
@@ -278,8 +306,13 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = authentication_complete.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    acl_connection.connection_management_callbacks_->OnAuthenticationComplete();
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnAuthenticationComplete();
  }

  void cancel_connect(Address address) {
@@ -330,8 +363,13 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = complete_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    acl_connection.connection_management_callbacks_->OnChangeConnectionLinkKeyComplete();
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnChangeConnectionLinkKeyComplete();
  }

  void on_read_clock_offset_complete(EventPacketView packet) {
@@ -346,9 +384,14 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = complete_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    uint16_t clock_offset = complete_view.GetClockOffset();
    acl_connection.connection_management_callbacks_->OnReadClockOffsetComplete(clock_offset);
    callbacks->OnReadClockOffsetComplete(clock_offset);
  }

  void on_mode_change(EventPacketView packet) {
@@ -363,10 +406,15 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = mode_change_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    Mode current_mode = mode_change_view.GetCurrentMode();
    uint16_t interval = mode_change_view.GetInterval();
    acl_connection.connection_management_callbacks_->OnModeChange(current_mode, interval);
    callbacks->OnModeChange(current_mode, interval);
  }

  void on_qos_setup_complete(EventPacketView packet) {
@@ -381,14 +429,18 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = complete_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    ServiceType service_type = complete_view.GetServiceType();
    uint32_t token_rate = complete_view.GetTokenRate();
    uint32_t peak_bandwidth = complete_view.GetPeakBandwidth();
    uint32_t latency = complete_view.GetLatency();
    uint32_t delay_variation = complete_view.GetDelayVariation();
    acl_connection.connection_management_callbacks_->OnQosSetupComplete(service_type, token_rate, peak_bandwidth,
                                                                        latency, delay_variation);
    callbacks->OnQosSetupComplete(service_type, token_rate, peak_bandwidth, latency, delay_variation);
  }

  void on_role_change(EventPacketView packet) {
@@ -423,14 +475,19 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = complete_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    FlowDirection flow_direction = complete_view.GetFlowDirection();
    ServiceType service_type = complete_view.GetServiceType();
    uint32_t token_rate = complete_view.GetTokenRate();
    uint32_t token_bucket_size = complete_view.GetTokenBucketSize();
    uint32_t peak_bandwidth = complete_view.GetPeakBandwidth();
    uint32_t access_latency = complete_view.GetAccessLatency();
    acl_connection.connection_management_callbacks_->OnFlowSpecificationComplete(
    callbacks->OnFlowSpecificationComplete(
        flow_direction, service_type, token_rate, token_bucket_size, peak_bandwidth, access_latency);
  }

@@ -441,33 +498,50 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = flush_occurred_view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    acl_connection.connection_management_callbacks_->OnFlushOccurred();
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnFlushOccurred();
  }

  void on_read_remote_version_information(
      uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version) {
    auto acl_connection = acl_connections_.find(handle);
    if (acl_connection != acl_connections_.end()) {
      acl_connection->second.connection_management_callbacks_->OnReadRemoteVersionInformationComplete(
          version, manufacturer_name, sub_version);
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnReadRemoteVersionInformationComplete(version, manufacturer_name, sub_version);
  }

  void on_read_remote_supported_features_complete(EventPacketView packet) {
    auto view = ReadRemoteSupportedFeaturesCompleteView::Create(packet);
    ASSERT_LOG(view.IsValid(), "Read remote supported features packet invalid");
    uint16_t handle = view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    acl_connection.connection_management_callbacks_->OnReadRemoteExtendedFeaturesComplete(0, 1, view.GetLmpFeatures());
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnReadRemoteExtendedFeaturesComplete(0, 1, view.GetLmpFeatures());
  }

  void on_read_remote_extended_features_complete(EventPacketView packet) {
    auto view = ReadRemoteExtendedFeaturesCompleteView::Create(packet);
    ASSERT_LOG(view.IsValid(), "Read remote extended features packet invalid");
    uint16_t handle = view.GetConnectionHandle();
    auto& acl_connection = acl_connections_.find(handle)->second;
    acl_connection.connection_management_callbacks_->OnReadRemoteExtendedFeaturesComplete(
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnReadRemoteExtendedFeaturesComplete(
        view.GetPageNumber(), view.GetMaximumPageNumber(), view.GetExtendedLmpFeatures());
  }

@@ -490,12 +564,6 @@ struct classic_impl : public security::ISecurityManagerListener {
        std::move(builder), handler_->BindOnce(&check_command_status<RejectConnectionRequestStatusView>));
  }

  acl_connection& check_and_get_connection(uint16_t handle) {
    auto connection = acl_connections_.find(handle);
    ASSERT(connection != acl_connections_.end());
    return connection->second;
  }

  void OnDeviceBonded(bluetooth::hci::AddressWithType device) override {}
  void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) override {}
  void OnDeviceBondFailed(bluetooth::hci::AddressWithType device, security::PairingFailure status) override {}
@@ -511,13 +579,14 @@ struct classic_impl : public security::ISecurityManagerListener {
      return;
    }
    uint16_t handle = encryption_change_view.GetConnectionHandle();
    auto acl_connection = acl_connections_.find(handle);
    if (acl_connection == acl_connections_.end()) {
      LOG_INFO("Invalid handle (already closed?) %d", handle);
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    EncryptionEnabled enabled = encryption_change_view.GetEncryptionEnabled();
    acl_connection->second.connection_management_callbacks_->OnEncryptionChange(enabled);
    callbacks->OnEncryptionChange(enabled);
  }

  void set_security_module(security::SecurityModule* security_module) {
@@ -548,6 +617,7 @@ struct classic_impl : public security::ISecurityManagerListener {
  std::queue<std::pair<Address, std::unique_ptr<CreateConnectionBuilder>>> pending_outgoing_connections_;

  std::unique_ptr<security::SecurityManager> security_manager_;
  bool crash_on_unknown_handle_ = false;
};

}  // namespace acl_manager
Loading