1 // 2 // Copyright 2017, The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #pragma once 18 19 #include <binder/Parcel.h> 20 #include <binder/Parcelable.h> 21 22 namespace android { 23 namespace os { 24 25 class ParcelFileDescriptor : public android::Parcelable { 26 public: ParcelFileDescriptor()27 ParcelFileDescriptor() : fd_(-1), takeOwnership_(false) {} 28 ~ParcelFileDescriptor() = default; 29 30 // Write |this| parcelable to the given |parcel|. Keep in mind that 31 // implementations of writeToParcel must be manually kept in sync 32 // with readFromParcel and the Java equivalent versions of these methods. 33 // 34 // Returns android::OK on success and an appropriate error otherwise. 35 android::status_t writeToParcel(android::Parcel* parcel) const override; 36 37 // Read data from the given |parcel| into |this|. After readFromParcel 38 // completes, |this| should have equivalent state to the object that 39 // wrote itself to the parcel. 40 // 41 // Returns android::OK on success and an appropriate error otherwise. 42 android::status_t readFromParcel(const android::Parcel* parcel) override; 43 44 void setFileDescriptor(int fd, bool takeOwnership); 45 46 private: 47 int fd_; 48 bool takeOwnership_; 49 }; 50 51 } // namespace os 52 } // namespace android 53