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

Commit 9885320f authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

service: Use built-in byte vector parser

Change-Id: I72369c0b7678338fc8ccf520b59a95affdfd2994
parent 1616cdd6
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -130,7 +130,8 @@ status_t BnBluetoothGattServer::onTransact(
    int status = data.readInt32();
    int offset = data.readInt32();

    auto value = ReadByteVectorFromParcel(data);
    std::unique_ptr<std::vector<uint8_t>> value;
    data.readByteVector(&value);
    CHECK(value.get());

    bool result = SendResponse(
@@ -147,7 +148,8 @@ status_t BnBluetoothGattServer::onTransact(
    CHECK(char_id);
    bool confirm = data.readInt32();

    auto value = ReadByteVectorFromParcel(data);
    std::unique_ptr<std::vector<uint8_t>> value;
    data.readByteVector(&value);
    CHECK(value.get());

    bool result = SendNotification(server_if, device_address, *char_id, confirm,
@@ -293,7 +295,7 @@ bool BpBluetoothGattServer::SendResponse(
  data.writeInt32(request_id);
  data.writeInt32(status);
  data.writeInt32(offset);
  data.writeByteArray(value.size(), value.data());
  data.writeByteVector(value);

  remote()->transact(IBluetoothGattServer::SEND_RESPONSE_TRANSACTION,
                     data, &reply);
@@ -314,7 +316,7 @@ bool BpBluetoothGattServer::SendNotification(
  data.writeCString(device_address.c_str());
  WriteGattIdentifierToParcel(characteristic_id, &data);
  data.writeInt32(confirm);
  data.writeByteArray(value.size(), value.data());
  data.writeByteVector(value);

  remote()->transact(IBluetoothGattServer::SEND_NOTIFICATION_TRANSACTION,
                     data, &reply);
+6 −4
Original line number Diff line number Diff line
@@ -88,7 +88,8 @@ status_t BnBluetoothGattServerCallback::onTransact(
    bool is_prep = data.readInt32();
    bool need_rsp = data.readInt32();

    auto value = ReadByteVectorFromParcel(data);
    std::unique_ptr<std::vector<uint8_t>> value;
    data.readByteVector(&value);
    CHECK(value.get());

    auto char_id = CreateGattIdentifierFromParcel(data);
@@ -105,7 +106,8 @@ status_t BnBluetoothGattServerCallback::onTransact(
    bool is_prep = data.readInt32();
    bool need_rsp = data.readInt32();

    auto value = ReadByteVectorFromParcel(data);
    std::unique_ptr<std::vector<uint8_t>> value;
    data.readByteVector(&value);
    CHECK(value.get());

    auto desc_id = CreateGattIdentifierFromParcel(data);
@@ -227,7 +229,7 @@ void BpBluetoothGattServerCallback::OnCharacteristicWriteRequest(
  data.writeInt32(offset);
  data.writeInt32(is_prepare_write);
  data.writeInt32(need_response);
  data.writeByteArray(value.size(), value.data());
  data.writeByteVector(value);
  WriteGattIdentifierToParcel(characteristic_id, &data);

  remote()->transact(
@@ -250,7 +252,7 @@ void BpBluetoothGattServerCallback::OnDescriptorWriteRequest(
  data.writeInt32(offset);
  data.writeInt32(is_prepare_write);
  data.writeInt32(need_response);
  data.writeByteArray(value.size(), value.data());
  data.writeByteVector(value);
  WriteGattIdentifierToParcel(descriptor_id, &data);

  remote()->transact(
+6 −26
Original line number Diff line number Diff line
@@ -37,14 +37,15 @@ namespace binder {

void WriteAdvertiseDataToParcel(const AdvertiseData& data, Parcel* parcel) {
  CHECK(parcel);
  parcel->writeByteArray(data.data().size(), data.data().data());  // lol
  parcel->writeByteVector(data.data());
  parcel->writeInt32(data.include_device_name());
  parcel->writeInt32(data.include_tx_power_level());
}

std::unique_ptr<AdvertiseData> CreateAdvertiseDataFromParcel(
    const Parcel& parcel) {
  auto data = ReadByteVectorFromParcel(parcel);
  std::unique_ptr<std::vector<uint8_t>> data;
  parcel.readByteVector(&data);
  CHECK(data.get());

  bool include_device_name = parcel.readInt32();
@@ -281,14 +282,7 @@ void WriteScanResultToParcel(
    parcel->writeInt32(0);
  }

  if (!scan_result.scan_record().empty()) {
    parcel->writeInt32(1);
    parcel->writeByteArray(scan_result.scan_record().size(),
                          scan_result.scan_record().data());
  } else {
    parcel->writeInt32(0);
  }

  parcel->writeByteVector(scan_result.scan_record());
  parcel->writeInt32(scan_result.rssi());
}

@@ -298,7 +292,8 @@ std::unique_ptr<bluetooth::ScanResult> CreateScanResultFromParcel(
  if (parcel.readInt32())
    device_address = parcel.readCString();

  auto scan_record = ReadByteVectorFromParcel(parcel);
  std::unique_ptr<std::vector<uint8_t>> scan_record;
  parcel.readByteVector(&scan_record);
  CHECK(scan_record.get());

  int rssi = parcel.readInt32();
@@ -306,20 +301,5 @@ std::unique_ptr<bluetooth::ScanResult> CreateScanResultFromParcel(
  return std::unique_ptr<ScanResult>(new ScanResult(
      device_address, *scan_record, rssi));
}

std::unique_ptr<std::vector<uint8_t>> ReadByteVectorFromParcel(
    const android::Parcel& parcel) {
  int32_t value_len = parcel.readInt32();
  value_len = std::min(0, value_len);

  std::unique_ptr<std::vector<uint8_t>> p(new std::vector<uint8_t>(value_len));

  android::status_t result = parcel.read(p->data(), value_len);
  if (result != android::NO_ERROR)
    return nullptr;

  return p;
}

}  // namespace binder
}  // namespace ipc
+0 −7
Original line number Diff line number Diff line
@@ -95,12 +95,5 @@ void WriteScanResultToParcel(
std::unique_ptr<bluetooth::ScanResult> CreateScanResultFromParcel(
    const android::Parcel& parcel);

// Reads a byte vector from |parcel| which is packed as a Int32 value
// followed by the indicated number of bytes.
// Returns the read vector, or nullptr if there is an error reading the
// vector.
std::unique_ptr<std::vector<uint8_t>> ReadByteVectorFromParcel(
    const android::Parcel& parcel);

}  // namespace binder
}  // namespace ipc