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

Commit 9e02620e authored by Jack He's avatar Jack He
Browse files

Metrics: Log manfuacturer information from Device ID profile to statsd

Bug: 112969790
Test: make, test drive with statsd
Change-Id: Ie22aaad07037f97017186ad1f1d9ad124e4756c0
parent 7a98b40a
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -827,6 +827,35 @@ void LogSocketConnectionState(
  }
}

void LogManufacturerInfo(const RawAddress& address,
                         android::bluetooth::DeviceInfoSrcEnum source_type,
                         const std::string& source_name,
                         const std::string& manufacturer,
                         const std::string& model,
                         const std::string& hardware_version,
                         const std::string& software_version) {
  std::string obfuscated_id;
  if (!address.IsEmpty()) {
    obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
  }
  // nullptr and size 0 represent missing value for obfuscated_id
  android::util::BytesField obfuscated_id_field(
      address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
      address.IsEmpty() ? 0 : obfuscated_id.size());
  int ret = android::util::stats_write(
      android::util::BLUETOOTH_DEVICE_INFO_REPORTED, obfuscated_id_field,
      source_type, source_name.c_str(), manufacturer.c_str(), model.c_str(),
      hardware_version.c_str(), software_version.c_str());
  if (ret < 0) {
    LOG(WARNING) << __func__ << ": failed for " << address << ", source_type "
                 << source_type << ", source_name " << source_name
                 << ", manufacturer " << manufacturer << ", model " << model
                 << ", hardware_version " << hardware_version
                 << ", software_version " << software_version << ", error "
                 << ret;
  }
}

}  // namespace common

}  // namespace bluetooth
+19 −0
Original line number Diff line number Diff line
@@ -460,6 +460,25 @@ void LogSocketConnectionState(
    android::bluetooth::SocketConnectionstateEnum connection_state,
    int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
    android::bluetooth::SocketRoleEnum socket_role);

/**
 * Logs when a Bluetooth device's manufacturer information is learnt
 *
 * @param address address of associated device
 * @param source_type where is this device info obtained from
 * @param source_name name of the data source, internal or external
 * @param manufacturer name of the manufacturer of this device
 * @param model model of this device
 * @param hardware_version hardware version of this device
 * @param software_version software version of this device
 */
void LogManufacturerInfo(const RawAddress& address,
                         android::bluetooth::DeviceInfoSrcEnum source_type,
                         const std::string& source_name,
                         const std::string& manufacturer,
                         const std::string& model,
                         const std::string& hardware_version,
                         const std::string& software_version);
}  // namespace common

}  // namespace bluetooth
+21 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ static uint16_t sdpu_find_most_specific_service_uuid(tSDP_DISC_REC* p_rec) {
void sdpu_log_attribute_metrics(const RawAddress& bda,
                                tSDP_DISCOVERY_DB* p_db) {
  CHECK_NE(p_db, nullptr);
  bool has_di_record = false;
  for (tSDP_DISC_REC* p_rec = p_db->p_first_rec; p_rec != nullptr;
       p_rec = p_rec->p_next_rec) {
    uint16_t service_uuid = sdpu_find_most_specific_service_uuid(p_rec);
@@ -261,6 +262,26 @@ void sdpu_log_attribute_metrics(const RawAddress& bda,
        break;
      }
    }
    if (service_uuid == UUID_SERVCLASS_PNP_INFORMATION) {
      has_di_record = true;
    }
  }
  // Log the first DI record if there is one
  if (has_di_record) {
    tSDP_DI_GET_RECORD di_record = {};
    if (SDP_GetDiRecord(1, &di_record, p_db) == SDP_SUCCESS) {
      auto version_array = to_little_endian_array(di_record.spec_id);
      bluetooth::common::LogSdpAttribute(
          bda, UUID_SERVCLASS_PNP_INFORMATION, ATTR_ID_SPECIFICATION_ID,
          version_array.size(), version_array.data());
      std::stringstream ss;
      // [N - native]::SDP::[DIP - Device ID Profile]
      ss << "N:SDP::DIP::" << loghex(di_record.rec.vendor_id_source);
      bluetooth::common::LogManufacturerInfo(
          bda, android::bluetooth::DeviceInfoSrcEnum::DEVICE_INFO_INTERNAL,
          ss.str(), loghex(di_record.rec.vendor), loghex(di_record.rec.product),
          loghex(di_record.rec.version), "");
    }
  }
}