From a9095ba488ea18aeafaf9c3a8258bf9f459bda71 Mon Sep 17 00:00:00 2001 From: Jungshik Jang Date: Fri, 2 May 2014 13:06:22 +0900 Subject: [PATCH] Implement more native api for Hdmi cec. HAL interface for CEC has more apis that haven't connected with HdmiCecController. Here is a list of apis. 1. addLogicalAddress 2. clearLogicalAddress 3. getPhysicalAddress 4. getVersion 5. getVendorId Verified that it does not affect to other components in nakasi Change-Id: I535bde47c43dd25bbede002c0a2aefbe86779076 --- .../server/hdmi/HdmiCecController.java | 66 ++++++++++++++- ..._android_server_hdmi_HdmiCecController.cpp | 81 ++++++++++++++++++- 2 files changed, 143 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java index c87fc99807f50..b103a4dc29b48 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecController.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java @@ -40,7 +40,7 @@ import java.util.List; * *

Declared as package-private, accessed by {@link HdmiControlService} only. */ -class HdmiCecController { +final class HdmiCecController { private static final String TAG = "HdmiCecController"; private static final byte[] EMPTY_BODY = EmptyArray.BYTE; @@ -313,6 +313,63 @@ class HdmiCecController { return mDeviceInfos.get(logicalAddress); } + /** + * Add a new logical address to the device. Device's HW should be notified + * when a new logical address is assigned to a device, so that it can accept + * a command having available destinations. + * + *

Declared as package-private. accessed by {@link HdmiControlService} only. + * + * @param newLogicalAddress a logical address to be added + * @return 0 on success. Otherwise, returns negative value + */ + int addLogicalAddress(int newLogicalAddress) { + if (HdmiCec.isValidAddress(newLogicalAddress)) { + return nativeAddLogicalAddress(mNativePtr, newLogicalAddress); + } else { + return -1; + } + } + + /** + * Clear all logical addresses registered in the device. + * + *

Declared as package-private. accessed by {@link HdmiControlService} only. + */ + void clearLogicalAddress() { + nativeClearLogicalAddress(mNativePtr); + } + + /** + * Return the physical address of the device. + * + *

Declared as package-private. accessed by {@link HdmiControlService} only. + * + * @return CEC physical address of the device. The range of success address + * is between 0x0000 and 0xFFFF. If failed it returns -1 + */ + int getPhysicalAddress() { + return nativeGetPhysicalAddress(mNativePtr); + } + + /** + * Return CEC version of the device. + * + *

Declared as package-private. accessed by {@link HdmiControlService} only. + */ + int getVersion() { + return nativeGetVersion(mNativePtr); + } + + /** + * Return vendor id of the device. + * + *

Declared as package-private. accessed by {@link HdmiControlService} only. + */ + int getVendorId() { + return nativeGetVendorId(mNativePtr); + } + private void init(HdmiControlService service, long nativePtr) { mIoHandler = new IoHandler(service.getServiceLooper()); mControlHandler = new ControlHandler(service.getServiceLooper()); @@ -364,6 +421,11 @@ class HdmiCecController { } private static native long nativeInit(HdmiCecController handler); - private static native int nativeSendCecCommand(long contollerPtr, int srcAddress, + private static native int nativeSendCecCommand(long controllerPtr, int srcAddress, int dstAddress, byte[] body); + private static native int nativeAddLogicalAddress(long controllerPtr, int logicalAddress); + private static native void nativeClearLogicalAddress(long controllerPtr); + private static native int nativeGetPhysicalAddress(long controllerPtr); + private static native int nativeGetVersion(long controllerPtr); + private static native int nativeGetVendorId(long controllerPtr); } diff --git a/services/core/jni/com_android_server_hdmi_HdmiCecController.cpp b/services/core/jni/com_android_server_hdmi_HdmiCecController.cpp index 527216d8759c9..27c8876fdf9c0 100644 --- a/services/core/jni/com_android_server_hdmi_HdmiCecController.cpp +++ b/services/core/jni/com_android_server_hdmi_HdmiCecController.cpp @@ -43,6 +43,16 @@ public: // Send message to other device. Note that it runs in IO thread. int sendMessage(const cec_message_t& message); + // Add a logical address to device. + int addLogicalAddress(cec_logical_address_t address); + // Clear all logical address registered to the device. + void clearLogicaladdress(); + // Get physical address of device. + int getPhysicalAddress(); + // Get CEC version from driver. + int getVersion(); + // Get vendor id used for vendor command. + uint32_t getVendorId(); private: // Propagate the message up to Java layer. @@ -94,6 +104,34 @@ int HdmiCecController::sendMessage(const cec_message_t& message) { return mDevice->send_message(mDevice, &message); } +int HdmiCecController::addLogicalAddress(cec_logical_address_t address) { + return mDevice->add_logical_address(mDevice, address); +} + +void HdmiCecController::clearLogicaladdress() { + mDevice->clear_logical_address(mDevice); +} + +int HdmiCecController::getPhysicalAddress() { + uint16_t physicalAddress = 0xFFFF; + if (mDevice->get_physical_address(mDevice, &physicalAddress) == 0) { + return physicalAddress; + } + return -1; +} + +int HdmiCecController::getVersion() { + int version = 0; + mDevice->get_version(mDevice, &version); + return version; +} + +uint32_t HdmiCecController::getVendorId() { + uint32_t vendorId = 0; + mDevice->get_vendor_id(mDevice, &vendorId); + return vendorId; +} + // static void HdmiCecController::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { @@ -180,12 +218,51 @@ static jint nativeSendCecCommand(JNIEnv* env, jclass clazz, jlong controllerPtr, return controller->sendMessage(message); } +static jint nativeAddLogicalAddress(JNIEnv* env, jclass clazz, + jlong controllerPtr, jint logicalAddress) { + HdmiCecController* controller = + reinterpret_cast(controllerPtr); + return controller->addLogicalAddress( + static_cast(logicalAddress)); +} + +static void nativeClearLogicalAddress(JNIEnv* env, jclass clazz, + jlong controllerPtr) { + HdmiCecController* controller = + reinterpret_cast(controllerPtr); + controller->clearLogicaladdress(); +} + +static jint nativeGetPhysicalAddress(JNIEnv* env, jclass clazz, + jlong controllerPtr) { + HdmiCecController* controller = + reinterpret_cast(controllerPtr); + return controller->getPhysicalAddress(); +} + +static jint nativeGetVersion(JNIEnv* env, jclass clazz, + jlong controllerPtr) { + HdmiCecController* controller = + reinterpret_cast(controllerPtr); + return controller->getVersion(); +} + +static jint nativeGetVendorId(JNIEnv* env, jclass clazz, jlong controllerPtr) { + HdmiCecController* controller = + reinterpret_cast(controllerPtr); + return controller->getVendorId(); +} + static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ { "nativeInit", "(Lcom/android/server/hdmi/HdmiCecController;)J", (void *) nativeInit }, - { "nativeSendCecCommand", "(JII[B)I", - (void *) nativeSendCecCommand }, + { "nativeSendCecCommand", "(JII[B)I", (void *) nativeSendCecCommand }, + { "nativeAddLogicalAddress", "(JI)I", (void *) nativeAddLogicalAddress }, + { "nativeClearLogicalAddress", "(J)V", (void *) nativeClearLogicalAddress }, + { "nativeGetPhysicalAddress", "(J)I", (void *) nativeGetPhysicalAddress }, + { "nativeGetVersion", "(J)I", (void *) nativeGetVersion }, + { "nativeGetVendorId", "(J)I", (void *) nativeGetVendorId }, }; #define CLASS_PATH "com/android/server/hdmi/HdmiCecController"