Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9095ba4 authored by Jungshik Jang's avatar Jungshik Jang
Browse files

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
parent 317510ff
Loading
Loading
Loading
Loading
+64 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.util.List;
 *
 * <p>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.
     *
     * <p>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.
     *
     * <p>Declared as package-private. accessed by {@link HdmiControlService} only.
     */
    void clearLogicalAddress() {
        nativeClearLogicalAddress(mNativePtr);
    }

    /**
     * Return the physical address of the device.
     *
     * <p>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.
     *
     * <p>Declared as package-private. accessed by {@link HdmiControlService} only.
     */
    int getVersion() {
        return nativeGetVersion(mNativePtr);
    }

    /**
     * Return vendor id of the device.
     *
     * <p>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);
}
+79 −2
Original line number Diff line number Diff line
@@ -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<HdmiCecController*>(controllerPtr);
    return controller->addLogicalAddress(
            static_cast<cec_logical_address_t>(logicalAddress));
}

static void nativeClearLogicalAddress(JNIEnv* env, jclass clazz,
        jlong controllerPtr) {
    HdmiCecController* controller =
            reinterpret_cast<HdmiCecController*>(controllerPtr);
    controller->clearLogicaladdress();
}

static jint nativeGetPhysicalAddress(JNIEnv* env, jclass clazz,
        jlong controllerPtr) {
    HdmiCecController* controller =
            reinterpret_cast<HdmiCecController*>(controllerPtr);
    return controller->getPhysicalAddress();
}

static jint nativeGetVersion(JNIEnv* env, jclass clazz,
        jlong controllerPtr) {
    HdmiCecController* controller =
            reinterpret_cast<HdmiCecController*>(controllerPtr);
    return controller->getVersion();
}

static jint nativeGetVendorId(JNIEnv* env, jclass clazz, jlong controllerPtr) {
    HdmiCecController* controller =
            reinterpret_cast<HdmiCecController*>(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"