Loading common/support/NativeHandle.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,13 @@ namespace android { using aidl::android::hardware::common::NativeHandle; /** * Checks if a NativeHandle is null */ bool isAidlNativeHandleEmpty(const NativeHandle& handle) { return handle.fds.empty() && handle.ints.empty(); } static native_handle_t* fromAidl(const NativeHandle& handle, bool doDup) { native_handle_t* to = native_handle_create(handle.fds.size(), handle.ints.size()); if (!to) return nullptr; Loading common/support/include/aidlcommonsupport/NativeHandle.h +5 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,11 @@ namespace android { /** * Checks if a NativeHandle is empty. */ bool isAidlNativeHandleEmpty(const aidl::android::hardware::common::NativeHandle& handle); /** * Creates a libcutils native handle from an AIDL native handle, but it does not * dup internally, so it will contain the same FDs as the handle itself. The Loading common/support/test.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ static NativeHandle makeTestAidlHandle() { TEST(ConvertNativeHandle, MakeFromAidlEmpty) { NativeHandle handle; EXPECT_TRUE(isAidlNativeHandleEmpty(handle)); native_handle_t* to = makeFromAidl(handle); checkEq(handle, to, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle Loading @@ -70,6 +71,7 @@ TEST(ConvertNativeHandle, MakeFromAidlEmpty) { TEST(ConvertNativeHandle, MakeFromAidl) { NativeHandle handle = makeTestAidlHandle(); EXPECT_FALSE(isAidlNativeHandleEmpty(handle)); native_handle_t* to = makeFromAidl(handle); checkEq(handle, to, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle Loading Loading @@ -106,6 +108,7 @@ static native_handle_t* makeTestLibcutilsHandle() { TEST(ConvertNativeHandle, MakeToAidlEmpty) { native_handle_t* handle = native_handle_create(0, 0); NativeHandle to = makeToAidl(handle); EXPECT_TRUE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle now EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -114,6 +117,7 @@ TEST(ConvertNativeHandle, MakeToAidlEmpty) { TEST(ConvertNativeHandle, MakeToAidl) { native_handle_t* handle = makeTestLibcutilsHandle(); NativeHandle to = makeToAidl(handle); EXPECT_FALSE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle now EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -122,6 +126,7 @@ TEST(ConvertNativeHandle, MakeToAidl) { TEST(ConvertNativeHandle, DupToAidlEmpty) { native_handle_t* handle = native_handle_create(0, 0); NativeHandle to = dupToAidl(handle); EXPECT_TRUE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, true /*exceptFds*/); EXPECT_EQ(0, native_handle_close(handle)); EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -130,6 +135,7 @@ TEST(ConvertNativeHandle, DupToAidlEmpty) { TEST(ConvertNativeHandle, DupToAidl) { native_handle_t* handle = makeTestLibcutilsHandle(); NativeHandle to = dupToAidl(handle); EXPECT_FALSE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, true /*exceptFds*/); EXPECT_EQ(0, native_handle_close(handle)); EXPECT_EQ(0, native_handle_delete(handle)); Loading Loading
common/support/NativeHandle.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,13 @@ namespace android { using aidl::android::hardware::common::NativeHandle; /** * Checks if a NativeHandle is null */ bool isAidlNativeHandleEmpty(const NativeHandle& handle) { return handle.fds.empty() && handle.ints.empty(); } static native_handle_t* fromAidl(const NativeHandle& handle, bool doDup) { native_handle_t* to = native_handle_create(handle.fds.size(), handle.ints.size()); if (!to) return nullptr; Loading
common/support/include/aidlcommonsupport/NativeHandle.h +5 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,11 @@ namespace android { /** * Checks if a NativeHandle is empty. */ bool isAidlNativeHandleEmpty(const aidl::android::hardware::common::NativeHandle& handle); /** * Creates a libcutils native handle from an AIDL native handle, but it does not * dup internally, so it will contain the same FDs as the handle itself. The Loading
common/support/test.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ static NativeHandle makeTestAidlHandle() { TEST(ConvertNativeHandle, MakeFromAidlEmpty) { NativeHandle handle; EXPECT_TRUE(isAidlNativeHandleEmpty(handle)); native_handle_t* to = makeFromAidl(handle); checkEq(handle, to, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle Loading @@ -70,6 +71,7 @@ TEST(ConvertNativeHandle, MakeFromAidlEmpty) { TEST(ConvertNativeHandle, MakeFromAidl) { NativeHandle handle = makeTestAidlHandle(); EXPECT_FALSE(isAidlNativeHandleEmpty(handle)); native_handle_t* to = makeFromAidl(handle); checkEq(handle, to, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle Loading Loading @@ -106,6 +108,7 @@ static native_handle_t* makeTestLibcutilsHandle() { TEST(ConvertNativeHandle, MakeToAidlEmpty) { native_handle_t* handle = native_handle_create(0, 0); NativeHandle to = makeToAidl(handle); EXPECT_TRUE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle now EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -114,6 +117,7 @@ TEST(ConvertNativeHandle, MakeToAidlEmpty) { TEST(ConvertNativeHandle, MakeToAidl) { native_handle_t* handle = makeTestLibcutilsHandle(); NativeHandle to = makeToAidl(handle); EXPECT_FALSE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, false /*exceptFds*/); // no native_handle_close b/c fds are owned by NativeHandle now EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -122,6 +126,7 @@ TEST(ConvertNativeHandle, MakeToAidl) { TEST(ConvertNativeHandle, DupToAidlEmpty) { native_handle_t* handle = native_handle_create(0, 0); NativeHandle to = dupToAidl(handle); EXPECT_TRUE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, true /*exceptFds*/); EXPECT_EQ(0, native_handle_close(handle)); EXPECT_EQ(0, native_handle_delete(handle)); Loading @@ -130,6 +135,7 @@ TEST(ConvertNativeHandle, DupToAidlEmpty) { TEST(ConvertNativeHandle, DupToAidl) { native_handle_t* handle = makeTestLibcutilsHandle(); NativeHandle to = dupToAidl(handle); EXPECT_FALSE(isAidlNativeHandleEmpty(to)); checkEq(to, handle, true /*exceptFds*/); EXPECT_EQ(0, native_handle_close(handle)); EXPECT_EQ(0, native_handle_delete(handle)); Loading