Merge "Fixes on handling messages from apps to host." into nyc-dev am: 60f2c17e27

am: 10a05037d3

* commit '10a05037d31d39d789e2dfc176656db76bec20d7':
  Fixes on handling messages from apps to host.

Change-Id: Ida77c88cd8fc1f19100fe06e8b1032d6eaf20806
This commit is contained in:
Daniel Estrada Alva
2016-04-29 19:30:21 +00:00
committed by android-build-merger
2 changed files with 31 additions and 18 deletions

View File

@@ -357,6 +357,7 @@ public class ContextHubInfo {
retVal += "\n\tPeakMips : " + mPeakMips;
retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW";
retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW";
retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes";
retVal += "\n\tSupported sensors : " + Arrays.toString(mSupportedSensors);
retVal += "\n\tMemory Regions : " + Arrays.toString(mMemoryRegions);
@@ -375,6 +376,7 @@ public class ContextHubInfo {
mStoppedPowerDrawMw = in.readFloat();
mSleepPowerDrawMw = in.readFloat();
mPeakPowerDrawMw = in.readFloat();
mMaxPacketLengthBytes = in.readInt();
int numSupportedSensors = in.readInt();
mSupportedSensors = new int[numSupportedSensors];
@@ -398,6 +400,7 @@ public class ContextHubInfo {
out.writeFloat(mStoppedPowerDrawMw);
out.writeFloat(mSleepPowerDrawMw);
out.writeFloat(mPeakPowerDrawMw);
out.writeInt(mMaxPacketLengthBytes);
out.writeInt(mSupportedSensors.length);
out.writeIntArray(mSupportedSensors);
@@ -414,4 +417,4 @@ public class ContextHubInfo {
return new ContextHubInfo[size];
}
};
}
}

View File

@@ -44,7 +44,6 @@ static constexpr int HEADER_FIELD_MSG_TYPE=0;
static constexpr int HEADER_FIELD_HUB_HANDLE=2;
static constexpr int HEADER_FIELD_APP_INSTANCE=3;
namespace android {
namespace {
@@ -164,9 +163,20 @@ static int get_hub_id_for_app_instance(int id) {
return db.hubInfo.hubs[hubHandle].hub_id;
}
static int get_app_instance_for_app_id(uint64_t app_id) {
auto end = db.appInstances.end();
for (auto current = db.appInstances.begin(); current != end; ++current) {
if (current->second.appInfo.app_name.id == app_id) {
return current->first;
}
}
ALOGD("Cannot find app for app instance %d.", app_id);
return -1;
}
static int set_dest_app(hub_message_t *msg, int id) {
if (!db.appInstances.count(id)) {
ALOGD("%s: Cannod find app for app instance %d", __FUNCTION__, id);
ALOGD("%s: Cannot find app for app instance %d", __FUNCTION__, id);
return -1;
}
@@ -301,7 +311,7 @@ static void initContextHubService() {
}
}
static int onMessageReceipt(int *header, int headerLen, char *msg, int msgLen) {
static int onMessageReceipt(uint32_t *header, size_t headerLen, char *msg, size_t msgLen) {
JNIEnv *env;
if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) {
@@ -396,14 +406,9 @@ static bool sanity_check_cookie(void *cookie, uint32_t hub_id) {
int context_hub_callback(uint32_t hubId,
const struct hub_message_t *msg,
void *cookie) {
int msgHeader[MSG_HEADER_SIZE];
if (!msg) {
return -1;
}
msgHeader[HEADER_FIELD_MSG_TYPE] = msg->message_type;
if (!sanity_check_cookie(cookie, hubId)) {
ALOGW("Incorrect cookie %" PRId32 " for cookie %p! Bailing",
hubId, cookie);
@@ -411,17 +416,22 @@ int context_hub_callback(uint32_t hubId,
return -1;
}
msgHeader[HEADER_FIELD_HUB_HANDLE] = *(uint32_t*)cookie;
uint32_t messageType = msg->message_type;
uint32_t hubHandle = *(uint32_t*) cookie;
if (msgHeader[HEADER_FIELD_MSG_TYPE] < CONTEXT_HUB_TYPE_PRIVATE_MSG_BASE &&
msgHeader[HEADER_FIELD_MSG_TYPE] != 0 ) {
handle_os_message(msgHeader[HEADER_FIELD_MSG_TYPE],
msgHeader[HEADER_FIELD_HUB_HANDLE],
(char *)msg->message,
msg->message_len);
if (messageType < CONTEXT_HUB_TYPE_PRIVATE_MSG_BASE) {
handle_os_message(messageType, hubHandle, (char*) msg->message, msg->message_len);
} else {
onMessageReceipt(msgHeader, sizeof(msgHeader),
(char *)msg->message, msg->message_len);
int appHandle = get_app_instance_for_app_id(msg->app_name.id);
if (appHandle < 0) {
ALOGE("Filtering out message due to invalid App Instance.");
} else {
uint32_t msgHeader[MSG_HEADER_SIZE] = {};
msgHeader[HEADER_FIELD_MSG_TYPE] = messageType;
msgHeader[HEADER_FIELD_HUB_HANDLE] = hubHandle;
msgHeader[HEADER_FIELD_APP_INSTANCE] = appHandle;
onMessageReceipt(msgHeader, MSG_HEADER_SIZE, (char*) msg->message, msg->message_len);
}
}
return 0;