1 /* 2 * Copyright (C) 2020 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 <aidl/android/hardware/common/NativeHandle.h> 20 #include <cutils/native_handle.h> 21 22 namespace android { 23 24 /** 25 * Creates a libcutils native handle from an AIDL native handle, but it does not 26 * dup internally, so it will contain the same FDs as the handle itself. The 27 * result should be deleted with native_handle_delete. 28 */ 29 native_handle_t* makeFromAidl(const aidl::android::hardware::common::NativeHandle& handle); 30 31 /** 32 * Creates a libcutils native handle from an AIDL native handle with a dup 33 * internally. It's expected the handle is cleaned up with native_handle_close 34 * and native_handle_delete. 35 */ 36 native_handle_t* dupFromAidl(const aidl::android::hardware::common::NativeHandle& handle); 37 38 /** 39 * Creates an AIDL native handle from a libcutils native handle, but does not 40 * dup internally, so the result will contain the same FDs as the handle itself. 41 * 42 * Warning: this passes ownership of the FDs to the ScopedFileDescriptor 43 * objects. 44 */ 45 aidl::android::hardware::common::NativeHandle makeToAidl(const native_handle_t* handle); 46 47 /** 48 * Creates an AIDL native handle from a libcutils native handle with a dup 49 * internally. 50 */ 51 aidl::android::hardware::common::NativeHandle dupToAidl(const native_handle_t* handle); 52 53 } // namespace android 54