Fix NativeHandle creation in TV Input HAL 2.0 default implementation
Bug: 227673740
Test: atest VtsHalTvInputTargetTest
Change-Id: Ic2958ab08c14848d46054c8422ce4298903bf206
diff --git a/tv/input/aidl/default/TvInput.cpp b/tv/input/aidl/default/TvInput.cpp
index ed12cbc..255bef7 100644
--- a/tv/input/aidl/default/TvInput.cpp
+++ b/tv/input/aidl/default/TvInput.cpp
@@ -95,8 +95,8 @@
return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_STATE);
}
mStreamConfigs[in_deviceId][in_streamId]->handle = createNativeHandle(in_streamId);
- mStreamConfigs[in_deviceId][in_streamId]->isOpen = true;
*_aidl_return = makeToAidl(mStreamConfigs[in_deviceId][in_streamId]->handle);
+ mStreamConfigs[in_deviceId][in_streamId]->isOpen = true;
return ::ndk::ScopedAStatus::ok();
}
@@ -112,27 +112,21 @@
ALOGW("Stream with device id %d, stream id %d is already closed", in_deviceId, in_streamId);
return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_STATE);
}
- releaseNativeHandle(mStreamConfigs[in_deviceId][in_streamId]->handle);
+ native_handle_delete(mStreamConfigs[in_deviceId][in_streamId]->handle);
mStreamConfigs[in_deviceId][in_streamId]->handle = nullptr;
mStreamConfigs[in_deviceId][in_streamId]->isOpen = false;
return ::ndk::ScopedAStatus::ok();
}
native_handle_t* TvInput::createNativeHandle(int fd) {
- native_handle_t* nativeHandle = native_handle_create(1, 0);
- if (nativeHandle == nullptr) {
+ native_handle_t* handle = native_handle_create(1, 1);
+ if (handle == nullptr) {
ALOGE("[TVInput] Failed to create native_handle %d", errno);
return nullptr;
}
- if (nativeHandle->numFds > 0) {
- nativeHandle->data[0] = dup(fd);
- }
- return nativeHandle;
-}
-
-void TvInput::releaseNativeHandle(native_handle_t* handle) {
- native_handle_close(handle);
- native_handle_delete(handle);
+ handle->data[0] = dup(0);
+ handle->data[1] = fd;
+ return handle;
}
} // namespace input