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

Commit 22788299 authored by Jooyung Han's avatar Jooyung Han
Browse files

Use std::optional instead of std::unique_ptr

Since Android R, Parcel provides read/write methods for "@nullable"
values using std::optional.

Bug: 149784838
Tag: #refactor
Test: atest --host bluetooth_test_gd
Change-Id: Iae76dc0d7a991888687cf572a43b26b28ad2e93d
parent 7ffb80c3
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -41,28 +41,19 @@ status_t ScanFilter::writeToParcel(Parcel* parcel) const {

  // TODO(jpawlowski) make type casting nicer
  // uuid won't really keep ownership, it's just for type casting
  std::unique_ptr<UUID> uuid;
  UUID tmp;
  std::optional<UUID> uuid;

  if (service_uuid_) {
    tmp = *service_uuid_;
    uuid.reset(&tmp);
  } else {
    uuid.reset(nullptr);
    uuid = *service_uuid_;
  }
  status = parcel->writeNullableParcelable(uuid);
  uuid.release();
  if (status != OK) return status;

  uuid.reset();
  if (service_uuid_mask_) {
    tmp = *service_uuid_mask_;
    uuid.reset(&tmp);
  } else {
    uuid.reset(nullptr);
    uuid = *service_uuid_mask_;
  }
  status = parcel->writeNullableParcelable(uuid);
  uuid.release();

  return status;
}