• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Checks if a NativeHandle is empty.
26  */
27 bool isAidlNativeHandleEmpty(const aidl::android::hardware::common::NativeHandle& handle);
28 
29 /**
30  * Creates a libcutils native handle from an AIDL native handle, but it does not
31  * dup internally, so it will contain the same FDs as the handle itself. The
32  * result should be deleted with native_handle_delete.
33  */
34 native_handle_t* makeFromAidl(const aidl::android::hardware::common::NativeHandle& handle);
35 
36 /**
37  * Creates a libcutils native handle from an AIDL native handle with a dup
38  * internally. It's expected the handle is cleaned up with native_handle_close
39  * and native_handle_delete.
40  */
41 native_handle_t* dupFromAidl(const aidl::android::hardware::common::NativeHandle& handle);
42 
43 /**
44  * Creates an AIDL native handle from a libcutils native handle, but does not
45  * dup internally, so the result will contain the same FDs as the handle itself.
46  *
47  * Warning: this passes ownership of the FDs to the ScopedFileDescriptor
48  * objects.
49  */
50 aidl::android::hardware::common::NativeHandle makeToAidl(const native_handle_t* handle);
51 
52 /**
53  * Creates an AIDL native handle from a libcutils native handle with a dup
54  * internally.
55  */
56 aidl::android::hardware::common::NativeHandle dupToAidl(const native_handle_t* handle);
57 
58 }  // namespace android
59