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

Commit 31518f74 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Android (Google) Code Review
Browse files

Merge "Use build property for CEC device OSD name" into klp-modular-dev

parents 7b4c9725 60b17cc0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.os.IBinder;
interface IHdmiCecService {
    IBinder allocateLogicalDevice(int type, IHdmiCecListener listener);
    void removeServiceListener(IBinder b, IHdmiCecListener listener);
    void setOsdName(IBinder b, String name);
    void sendActiveSource(IBinder b);
    void sendInactiveSource(IBinder b);
    void sendImageViewOn(IBinder b);
+0 −19
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ abstract class HdmiCecDevice {
    private final Binder mBinder = new Binder();
    private final HdmiCecService mService;

    private String mName;
    private boolean mIsActiveSource;

    /**
@@ -106,24 +105,6 @@ abstract class HdmiCecDevice {
        return mType;
    }

    /**
     * Set the name of the device. The name will be transferred via the message
     * <Set OSD Name> to other HDMI-CEC devices connected through HDMI
     * cables and shown on TV screen to identify the devicie.
     *
     * @param name name of the device
     */
    public void setName(String name) {
        mName = name;
    }

    /**
     * Return the name of this device.
     */
    public String getName() {
        return mName;
    }

    /**
     * Register a listener to be invoked when events occur.
     *
+10 −31
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.hardware.hdmi.HdmiCecMessage;
import android.hardware.hdmi.IHdmiCecListener;
import android.hardware.hdmi.IHdmiCecService;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
@@ -76,6 +77,9 @@ public final class HdmiCecService extends SystemService {
    public void onStart() {
        mNativePtr = nativeInit(this);
        if (mNativePtr != 0) {
            // TODO: Consider using a dedicated, configurable identifier for OSD name, maybe from
            //       Settings. It should be ASCII only, not a very long one (limited to 15 chars).
            setOsdNameLocked(Build.MODEL);
            publishBinderService(Context.HDMI_CEC_SERVICE, new BinderService());
        }
    }
@@ -138,22 +142,6 @@ public final class HdmiCecService extends SystemService {
        return HdmiCec.DEVICE_INACTIVE;
    }

    /**
     * Called by native when a request for the device OSD name was received.
     * The native part uses the return value to generate the message
     * <Set Osd Name> in response.
     */
    private byte[] getOsdName(int type) {
        // TODO: Consider getting the OSD name from device name instead.
        synchronized (mLock) {
            HdmiCecDevice device = mLogicalDevices.get(type);
            if (device != null) {
                return device.getName().getBytes(Charset.forName("US-ASCII"));
            }
        }
        return null;
    }

    /**
     * Called by native when a request for the menu language of the device was
     * received. The native part uses the return value to generate the message
@@ -175,8 +163,7 @@ public final class HdmiCecService extends SystemService {
        synchronized (mLock) {
            for (int i = 0; i < mLogicalDevices.size(); ++i) {
                HdmiCecDevice device = mLogicalDevices.valueAt(i);
                pw.println("Device: name=" + device.getName() +
                           ", type=" + device.getType() +
                pw.println("Device: type=" + device.getType() +
                           ", active=" + device.isActiveSource());
            }
        }
@@ -211,6 +198,10 @@ public final class HdmiCecService extends SystemService {
        nativeSendMessage(mNativePtr, type, address, opcode, params);
    }

    private void setOsdNameLocked(String name) {
        nativeSetOsdName(mNativePtr, name.getBytes(Charset.forName("US-ASCII")));
    }

    private final class ListenerRecord implements IBinder.DeathRecipient {
        private final IHdmiCecListener mListener;
        private final int mType;
@@ -259,7 +250,6 @@ public final class HdmiCecService extends SystemService {
                            Log.e(TAG, "Device type not supported yet.");
                            return null;
                        }
                        device.setName(HdmiCec.getDefaultDeviceName(address));
                        device.initialize();
                        mLogicalDevices.put(type, device);
                    }
@@ -282,18 +272,6 @@ public final class HdmiCecService extends SystemService {
            }
        }

        @Override
        public void setOsdName(IBinder b, String name) {
            enforceAccessPermission();
            if (TextUtils.isEmpty(name)) {
                throw new IllegalArgumentException("name must not be null");
            }
            synchronized (mLock) {
                HdmiCecDevice device = getLogicalDeviceLocked(b);
                device.setName(name);
            }
        }

        @Override
        public void sendActiveSource(IBinder b) {
            enforceAccessPermission();
@@ -408,4 +386,5 @@ public final class HdmiCecService extends SystemService {
    private static native void nativeSendMessage(long handler, int deviceType, int destination,
            int opcode, byte[] params);
    private static native int nativeGetPhysicalAddress(long handler);
    private static native void nativeSetOsdName(long handler, byte[] name);
}
+20 −15
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@

#include "ScopedPrimitiveArray.h"

#include <cstring>
#include <string>
#include <deque>
#include <map>

@@ -34,7 +34,6 @@ static struct {
    jmethodID handleMessage;
    jmethodID handleHotplug;
    jmethodID getActiveSource;
    jmethodID getOsdName;
    jmethodID getLanguage;
} gHdmiCecServiceClassInfo;

@@ -84,6 +83,7 @@ public:
    void sendSetMenuLanguage(cec_logical_address_t srcAddr, cec_logical_address_t dstAddr);

    void sendCecMessage(const cec_message_t& message);
    void setOsdName(const char* name, size_t len);

private:
    enum {
@@ -156,6 +156,7 @@ private:

    std::deque<MessageEntry> mMessageQueue;
    uint16_t mPhysicalAddress;
    std::string mOsdName;
};


@@ -373,6 +374,10 @@ void HdmiCecHandler::sendCecMessage(const cec_message_t& message) {
    mDevice->send_message(mDevice, &message);
}

void HdmiCecHandler::setOsdName(const char* name, size_t len) {
    mOsdName.assign(name, min(len, CEC_MESSAGE_BODY_MAX_LENGTH - 1));
}

// static
void HdmiCecHandler::onReceived(const hdmi_event_t* event, void* arg) {
    HdmiCecHandler* handler = static_cast<HdmiCecHandler*>(arg);
@@ -504,18 +509,9 @@ void HdmiCecHandler::handleRequestActiveSource() {
}

void HdmiCecHandler::handleGetOsdName(const cec_message_t& msg) {
    cec_logical_address_t addr = msg.destination;
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jbyteArray res = (jbyteArray) env->CallObjectMethod(mCallbacksObj,
            gHdmiCecServiceClassInfo.getOsdName,
            getDeviceType(addr));
    jbyte *name = env->GetByteArrayElements(res, NULL);
    if (name != NULL) {
        sendSetOsdName(addr, msg.initiator, reinterpret_cast<const char *>(name),
                env->GetArrayLength(res));
        env->ReleaseByteArrayElements(res, name, JNI_ABORT);
    if (!mOsdName.empty()) {
        sendSetOsdName(msg.destination, msg.initiator, mOsdName.c_str(), mOsdName.length());
    }
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
}

void HdmiCecHandler::handleGiveDeviceVendorID(const cec_message_t& msg) {
@@ -562,8 +558,6 @@ static jlong nativeInit(JNIEnv* env, jclass clazz, jobject callbacksObj) {
            "handleHotplug", "(Z)V");
    GET_METHOD_ID(gHdmiCecServiceClassInfo.getActiveSource, clazz,
            "getActiveSource", "()I");
    GET_METHOD_ID(gHdmiCecServiceClassInfo.getOsdName, clazz,
            "getOsdName", "(I)[B");
    GET_METHOD_ID(gHdmiCecServiceClassInfo.getLanguage, clazz,
            "getLanguage", "(I)Ljava/lang/String;");

@@ -603,6 +597,15 @@ static jint nativeGetPhysicalAddress(JNIEnv* env, jclass clazz, jlong handlerPtr
    return handler->getPhysicalAddress();
}

static void nativeSetOsdName(JNIEnv* env, jclass clazz, jlong handlerPtr, jbyteArray name) {
    HdmiCecHandler *handler = reinterpret_cast<HdmiCecHandler *>(handlerPtr);
    jsize len = env->GetArrayLength(name);
    if (len > 0) {
        ScopedByteArrayRO namePtr(env, name);
        handler->setOsdName(reinterpret_cast<const char *>(namePtr.get()), len);
    }
}

static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    { "nativeInit", "(Lcom/android/server/hdmi/HdmiCecService;)J",
@@ -615,6 +618,8 @@ static JNINativeMethod sMethods[] = {
            (void *)nativeRemoveLogicalAddress },
    { "nativeGetPhysicalAddress", "(J)I",
            (void *)nativeGetPhysicalAddress },
    { "nativeSetOsdName", "(J[B)V",
            (void *)nativeSetOsdName },
};

#define CLASS_PATH "com/android/server/hdmi/HdmiCecService"