am f2fe3505: am 31518f74: Merge "Use build property for CEC device OSD name" into klp-modular-dev

* commit 'f2fe3505dac16dfa990fbab56713abab6ba0bc54':
  Use build property for CEC device OSD name
This commit is contained in:
Jinsuk Kim
2014-04-03 02:11:40 +00:00
committed by Android Git Automerger
4 changed files with 30 additions and 66 deletions

View File

@@ -29,7 +29,6 @@ import android.os.IBinder;
interface IHdmiCecService { interface IHdmiCecService {
IBinder allocateLogicalDevice(int type, IHdmiCecListener listener); IBinder allocateLogicalDevice(int type, IHdmiCecListener listener);
void removeServiceListener(IBinder b, IHdmiCecListener listener); void removeServiceListener(IBinder b, IHdmiCecListener listener);
void setOsdName(IBinder b, String name);
void sendActiveSource(IBinder b); void sendActiveSource(IBinder b);
void sendInactiveSource(IBinder b); void sendInactiveSource(IBinder b);
void sendImageViewOn(IBinder b); void sendImageViewOn(IBinder b);

View File

@@ -55,7 +55,6 @@ abstract class HdmiCecDevice {
private final Binder mBinder = new Binder(); private final Binder mBinder = new Binder();
private final HdmiCecService mService; private final HdmiCecService mService;
private String mName;
private boolean mIsActiveSource; private boolean mIsActiveSource;
/** /**
@@ -106,24 +105,6 @@ abstract class HdmiCecDevice {
return mType; 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. * Register a listener to be invoked when events occur.
* *

View File

@@ -23,6 +23,7 @@ import android.hardware.hdmi.HdmiCecMessage;
import android.hardware.hdmi.IHdmiCecListener; import android.hardware.hdmi.IHdmiCecListener;
import android.hardware.hdmi.IHdmiCecService; import android.hardware.hdmi.IHdmiCecService;
import android.os.Binder; import android.os.Binder;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.text.TextUtils; import android.text.TextUtils;
@@ -76,6 +77,9 @@ public final class HdmiCecService extends SystemService {
public void onStart() { public void onStart() {
mNativePtr = nativeInit(this); mNativePtr = nativeInit(this);
if (mNativePtr != 0) { 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()); publishBinderService(Context.HDMI_CEC_SERVICE, new BinderService());
} }
} }
@@ -138,22 +142,6 @@ public final class HdmiCecService extends SystemService {
return HdmiCec.DEVICE_INACTIVE; 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 * 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 * received. The native part uses the return value to generate the message
@@ -175,8 +163,7 @@ public final class HdmiCecService extends SystemService {
synchronized (mLock) { synchronized (mLock) {
for (int i = 0; i < mLogicalDevices.size(); ++i) { for (int i = 0; i < mLogicalDevices.size(); ++i) {
HdmiCecDevice device = mLogicalDevices.valueAt(i); HdmiCecDevice device = mLogicalDevices.valueAt(i);
pw.println("Device: name=" + device.getName() + pw.println("Device: type=" + device.getType() +
", type=" + device.getType() +
", active=" + device.isActiveSource()); ", active=" + device.isActiveSource());
} }
} }
@@ -211,6 +198,10 @@ public final class HdmiCecService extends SystemService {
nativeSendMessage(mNativePtr, type, address, opcode, params); 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 class ListenerRecord implements IBinder.DeathRecipient {
private final IHdmiCecListener mListener; private final IHdmiCecListener mListener;
private final int mType; private final int mType;
@@ -259,7 +250,6 @@ public final class HdmiCecService extends SystemService {
Log.e(TAG, "Device type not supported yet."); Log.e(TAG, "Device type not supported yet.");
return null; return null;
} }
device.setName(HdmiCec.getDefaultDeviceName(address));
device.initialize(); device.initialize();
mLogicalDevices.put(type, device); 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 @Override
public void sendActiveSource(IBinder b) { public void sendActiveSource(IBinder b) {
enforceAccessPermission(); enforceAccessPermission();
@@ -408,4 +386,5 @@ public final class HdmiCecService extends SystemService {
private static native void nativeSendMessage(long handler, int deviceType, int destination, private static native void nativeSendMessage(long handler, int deviceType, int destination,
int opcode, byte[] params); int opcode, byte[] params);
private static native int nativeGetPhysicalAddress(long handler); private static native int nativeGetPhysicalAddress(long handler);
private static native void nativeSetOsdName(long handler, byte[] name);
} }

View File

@@ -20,7 +20,7 @@
#include "ScopedPrimitiveArray.h" #include "ScopedPrimitiveArray.h"
#include <cstring> #include <string>
#include <deque> #include <deque>
#include <map> #include <map>
@@ -34,7 +34,6 @@ static struct {
jmethodID handleMessage; jmethodID handleMessage;
jmethodID handleHotplug; jmethodID handleHotplug;
jmethodID getActiveSource; jmethodID getActiveSource;
jmethodID getOsdName;
jmethodID getLanguage; jmethodID getLanguage;
} gHdmiCecServiceClassInfo; } gHdmiCecServiceClassInfo;
@@ -84,6 +83,7 @@ public:
void sendSetMenuLanguage(cec_logical_address_t srcAddr, cec_logical_address_t dstAddr); void sendSetMenuLanguage(cec_logical_address_t srcAddr, cec_logical_address_t dstAddr);
void sendCecMessage(const cec_message_t& message); void sendCecMessage(const cec_message_t& message);
void setOsdName(const char* name, size_t len);
private: private:
enum { enum {
@@ -156,6 +156,7 @@ private:
std::deque<MessageEntry> mMessageQueue; std::deque<MessageEntry> mMessageQueue;
uint16_t mPhysicalAddress; uint16_t mPhysicalAddress;
std::string mOsdName;
}; };
@@ -373,6 +374,10 @@ void HdmiCecHandler::sendCecMessage(const cec_message_t& message) {
mDevice->send_message(mDevice, &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 // static
void HdmiCecHandler::onReceived(const hdmi_event_t* event, void* arg) { void HdmiCecHandler::onReceived(const hdmi_event_t* event, void* arg) {
HdmiCecHandler* handler = static_cast<HdmiCecHandler*>(arg); HdmiCecHandler* handler = static_cast<HdmiCecHandler*>(arg);
@@ -504,18 +509,9 @@ void HdmiCecHandler::handleRequestActiveSource() {
} }
void HdmiCecHandler::handleGetOsdName(const cec_message_t& msg) { void HdmiCecHandler::handleGetOsdName(const cec_message_t& msg) {
cec_logical_address_t addr = msg.destination; if (!mOsdName.empty()) {
JNIEnv* env = AndroidRuntime::getJNIEnv(); sendSetOsdName(msg.destination, msg.initiator, mOsdName.c_str(), mOsdName.length());
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);
} }
checkAndClearExceptionFromCallback(env, __FUNCTION__);
} }
void HdmiCecHandler::handleGiveDeviceVendorID(const cec_message_t& msg) { void HdmiCecHandler::handleGiveDeviceVendorID(const cec_message_t& msg) {
@@ -562,8 +558,6 @@ static jlong nativeInit(JNIEnv* env, jclass clazz, jobject callbacksObj) {
"handleHotplug", "(Z)V"); "handleHotplug", "(Z)V");
GET_METHOD_ID(gHdmiCecServiceClassInfo.getActiveSource, clazz, GET_METHOD_ID(gHdmiCecServiceClassInfo.getActiveSource, clazz,
"getActiveSource", "()I"); "getActiveSource", "()I");
GET_METHOD_ID(gHdmiCecServiceClassInfo.getOsdName, clazz,
"getOsdName", "(I)[B");
GET_METHOD_ID(gHdmiCecServiceClassInfo.getLanguage, clazz, GET_METHOD_ID(gHdmiCecServiceClassInfo.getLanguage, clazz,
"getLanguage", "(I)Ljava/lang/String;"); "getLanguage", "(I)Ljava/lang/String;");
@@ -603,6 +597,15 @@ static jint nativeGetPhysicalAddress(JNIEnv* env, jclass clazz, jlong handlerPtr
return handler->getPhysicalAddress(); 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[] = { static JNINativeMethod sMethods[] = {
/* name, signature, funcPtr */ /* name, signature, funcPtr */
{ "nativeInit", "(Lcom/android/server/hdmi/HdmiCecService;)J", { "nativeInit", "(Lcom/android/server/hdmi/HdmiCecService;)J",
@@ -615,6 +618,8 @@ static JNINativeMethod sMethods[] = {
(void *)nativeRemoveLogicalAddress }, (void *)nativeRemoveLogicalAddress },
{ "nativeGetPhysicalAddress", "(J)I", { "nativeGetPhysicalAddress", "(J)I",
(void *)nativeGetPhysicalAddress }, (void *)nativeGetPhysicalAddress },
{ "nativeSetOsdName", "(J[B)V",
(void *)nativeSetOsdName },
}; };
#define CLASS_PATH "com/android/server/hdmi/HdmiCecService" #define CLASS_PATH "com/android/server/hdmi/HdmiCecService"