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

Commit bb3b104e authored by Ryo Hashimoto's avatar Ryo Hashimoto
Browse files

Use ParcelFileDescriptor implementation in libbinder

Bug: 80377815
Test: build
Change-Id: I0a415181827d6c4dc2243cf14b9fb120effce982
parent 1bfcef12
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ cc_library_shared {
    srcs: [
        "android/bluetooth/bluetooth_device.cc",
        "android/bluetooth/IBluetoothSocketManager.aidl",
        "android/os/parcel_file_descriptor.cc",
        "android/os/parcel_uuid.cc",
/* TODO: Uncomment this files as they get converted one-by-one into native implementation
        "android/bluetooth/IBluetooth.aidl",
+0 −43
Original line number Diff line number Diff line
//
//  Copyright 2017, The Android Open Source Project
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#include "android/os/parcel_file_descriptor.h"
#include <base/logging.h>

using android::OK;
using android::Parcel;
using android::status_t;

namespace android {
namespace os {

status_t ParcelFileDescriptor::writeToParcel(Parcel* parcel) const {
  CHECK(fd_ >= 0);
  return parcel->writeParcelFileDescriptor(fd_, takeOwnership_);
}

status_t ParcelFileDescriptor::readFromParcel(const Parcel* parcel) {
  LOG(FATAL) << "Don't know how to read ParcelFileDescriptor";
  return OK;
}

void ParcelFileDescriptor::setFileDescriptor(int fd, bool takeOwnership) {
  fd_ = fd;
  takeOwnership_ = takeOwnership;
}

}  // namespace os
}  // namespace android
+0 −52
Original line number Diff line number Diff line
//
//  Copyright 2017, The Android Open Source Project
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#pragma once

#include <binder/Parcel.h>
#include <binder/Parcelable.h>

namespace android {
namespace os {

class ParcelFileDescriptor : public android::Parcelable {
 public:
  ParcelFileDescriptor() : fd_(-1), takeOwnership_(false) {}
  ~ParcelFileDescriptor() = default;

  // Write |this| parcelable to the given |parcel|.  Keep in mind that
  // implementations of writeToParcel must be manually kept in sync
  // with readFromParcel and the Java equivalent versions of these methods.
  //
  // Returns android::OK on success and an appropriate error otherwise.
  android::status_t writeToParcel(android::Parcel* parcel) const override;

  // Read data from the given |parcel| into |this|.  After readFromParcel
  // completes, |this| should have equivalent state to the object that
  // wrote itself to the parcel.
  //
  // Returns android::OK on success and an appropriate error otherwise.
  android::status_t readFromParcel(const android::Parcel* parcel) override;

  void setFileDescriptor(int fd, bool takeOwnership);

 private:
  int fd_;
  bool takeOwnership_;
};

}  // namespace os
}  // namespace android