Install the HDMI CEC and HDMI connection APEX packages plus the android.hardware.hdmi.cec.xml feature file, set the playback-device CEC properties, and give system ownership of /dev/cec0 in ueventd. The connection HAL now reports a single HDMI output port and monitors /sys/class/drm/card0-HDMI-A-1/status with poll(), reporting hotplug transitions through the AIDL callback and shutting the monitor thread down through an eventfd. The CEC HAL now polls POLLPRI for CEC_DQEVENT and POLLIN for CEC_RECEIVE, guards the ioctl paths against an uninitialised adapter, and bounds message length by CEC_MAX_MSG_SIZE.
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
/*
|
|
* Copyright (C) 2022 The Android Open Source Project
|
|
* Copyright (C) 2025 KonstaKANG
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <aidl/android/hardware/tv/hdmi/connection/BnHdmiConnection.h>
|
|
#include <aidl/android/hardware/tv/hdmi/connection/Result.h>
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <thread>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
namespace android {
|
|
namespace hardware {
|
|
namespace tv {
|
|
namespace hdmi {
|
|
namespace connection {
|
|
namespace implementation {
|
|
|
|
using ::aidl::android::hardware::tv::hdmi::connection::BnHdmiConnection;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortInfo;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::HdmiPortType;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::HpdSignal;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnection;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::IHdmiConnectionCallback;
|
|
using ::aidl::android::hardware::tv::hdmi::connection::Result;
|
|
|
|
struct HdmiConnection : public BnHdmiConnection {
|
|
HdmiConnection();
|
|
~HdmiConnection();
|
|
::ndk::ScopedAStatus getPortInfo(std::vector<HdmiPortInfo>* _aidl_return) override;
|
|
::ndk::ScopedAStatus isConnected(int32_t portId, bool* _aidl_return) override;
|
|
::ndk::ScopedAStatus setCallback(
|
|
const std::shared_ptr<IHdmiConnectionCallback>& callback) override;
|
|
::ndk::ScopedAStatus setHpdSignal(HpdSignal signal, int32_t portId) override;
|
|
::ndk::ScopedAStatus getHpdSignal(int32_t portId, HpdSignal* _aidl_return) override;
|
|
|
|
private:
|
|
void monitorLoop();
|
|
void signalMonitorStop();
|
|
|
|
std::vector<HdmiPortInfo> mPortInfos;
|
|
std::vector<HpdSignal> mHpdSignal;
|
|
|
|
std::mutex mCallbackMutex;
|
|
std::shared_ptr<IHdmiConnectionCallback> mCallback;
|
|
std::thread mMonitorThread;
|
|
int mStopFd = -1;
|
|
|
|
} // namespace implementation
|
|
} // namespace connection
|
|
} // namespace hdmi
|
|
} // Namespace tv
|
|
} // namespace hardware
|
|
} // namespace android
|