Loading core/java/android/hardware/location/ContextHubInfo.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -357,6 +357,7 @@ public class ContextHubInfo { retVal += "\n\tPeakMips : " + mPeakMips; retVal += "\n\tPeakMips : " + mPeakMips; retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW"; retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW"; retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW"; retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW"; retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes"; retVal += "\n\tSupported sensors : " + Arrays.toString(mSupportedSensors); retVal += "\n\tSupported sensors : " + Arrays.toString(mSupportedSensors); retVal += "\n\tMemory Regions : " + Arrays.toString(mMemoryRegions); retVal += "\n\tMemory Regions : " + Arrays.toString(mMemoryRegions); Loading @@ -375,6 +376,7 @@ public class ContextHubInfo { mStoppedPowerDrawMw = in.readFloat(); mStoppedPowerDrawMw = in.readFloat(); mSleepPowerDrawMw = in.readFloat(); mSleepPowerDrawMw = in.readFloat(); mPeakPowerDrawMw = in.readFloat(); mPeakPowerDrawMw = in.readFloat(); mMaxPacketLengthBytes = in.readInt(); int numSupportedSensors = in.readInt(); int numSupportedSensors = in.readInt(); mSupportedSensors = new int[numSupportedSensors]; mSupportedSensors = new int[numSupportedSensors]; Loading @@ -398,6 +400,7 @@ public class ContextHubInfo { out.writeFloat(mStoppedPowerDrawMw); out.writeFloat(mStoppedPowerDrawMw); out.writeFloat(mSleepPowerDrawMw); out.writeFloat(mSleepPowerDrawMw); out.writeFloat(mPeakPowerDrawMw); out.writeFloat(mPeakPowerDrawMw); out.writeInt(mMaxPacketLengthBytes); out.writeInt(mSupportedSensors.length); out.writeInt(mSupportedSensors.length); out.writeIntArray(mSupportedSensors); out.writeIntArray(mSupportedSensors); Loading core/jni/android_hardware_location_ContextHubService.cpp +27 −17 Original line number Original line Diff line number Diff line Loading @@ -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_HUB_HANDLE=2; static constexpr int HEADER_FIELD_APP_INSTANCE=3; static constexpr int HEADER_FIELD_APP_INSTANCE=3; namespace android { namespace android { namespace { namespace { Loading Loading @@ -164,9 +163,20 @@ static int get_hub_id_for_app_instance(int id) { return db.hubInfo.hubs[hubHandle].hub_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) { static int set_dest_app(hub_message_t *msg, int id) { if (!db.appInstances.count(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; return -1; } } Loading Loading @@ -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; JNIEnv *env; if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) { if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) { Loading Loading @@ -396,14 +406,9 @@ static bool sanity_check_cookie(void *cookie, uint32_t hub_id) { int context_hub_callback(uint32_t hubId, int context_hub_callback(uint32_t hubId, const struct hub_message_t *msg, const struct hub_message_t *msg, void *cookie) { void *cookie) { int msgHeader[MSG_HEADER_SIZE]; if (!msg) { if (!msg) { return -1; return -1; } } msgHeader[HEADER_FIELD_MSG_TYPE] = msg->message_type; if (!sanity_check_cookie(cookie, hubId)) { if (!sanity_check_cookie(cookie, hubId)) { ALOGW("Incorrect cookie %" PRId32 " for cookie %p! Bailing", ALOGW("Incorrect cookie %" PRId32 " for cookie %p! Bailing", hubId, cookie); hubId, cookie); Loading @@ -411,17 +416,22 @@ int context_hub_callback(uint32_t hubId, return -1; 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 && if (messageType < CONTEXT_HUB_TYPE_PRIVATE_MSG_BASE) { msgHeader[HEADER_FIELD_MSG_TYPE] != 0 ) { handle_os_message(messageType, hubHandle, (char*) msg->message, msg->message_len); handle_os_message(msgHeader[HEADER_FIELD_MSG_TYPE], } else { msgHeader[HEADER_FIELD_HUB_HANDLE], int appHandle = get_app_instance_for_app_id(msg->app_name.id); (char *)msg->message, if (appHandle < 0) { msg->message_len); ALOGE("Filtering out message due to invalid App Instance."); } else { } else { onMessageReceipt(msgHeader, sizeof(msgHeader), uint32_t msgHeader[MSG_HEADER_SIZE] = {}; (char *)msg->message, msg->message_len); 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; return 0; Loading Loading
core/java/android/hardware/location/ContextHubInfo.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -357,6 +357,7 @@ public class ContextHubInfo { retVal += "\n\tPeakMips : " + mPeakMips; retVal += "\n\tPeakMips : " + mPeakMips; retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW"; retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW"; retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW"; retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW"; retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes"; retVal += "\n\tSupported sensors : " + Arrays.toString(mSupportedSensors); retVal += "\n\tSupported sensors : " + Arrays.toString(mSupportedSensors); retVal += "\n\tMemory Regions : " + Arrays.toString(mMemoryRegions); retVal += "\n\tMemory Regions : " + Arrays.toString(mMemoryRegions); Loading @@ -375,6 +376,7 @@ public class ContextHubInfo { mStoppedPowerDrawMw = in.readFloat(); mStoppedPowerDrawMw = in.readFloat(); mSleepPowerDrawMw = in.readFloat(); mSleepPowerDrawMw = in.readFloat(); mPeakPowerDrawMw = in.readFloat(); mPeakPowerDrawMw = in.readFloat(); mMaxPacketLengthBytes = in.readInt(); int numSupportedSensors = in.readInt(); int numSupportedSensors = in.readInt(); mSupportedSensors = new int[numSupportedSensors]; mSupportedSensors = new int[numSupportedSensors]; Loading @@ -398,6 +400,7 @@ public class ContextHubInfo { out.writeFloat(mStoppedPowerDrawMw); out.writeFloat(mStoppedPowerDrawMw); out.writeFloat(mSleepPowerDrawMw); out.writeFloat(mSleepPowerDrawMw); out.writeFloat(mPeakPowerDrawMw); out.writeFloat(mPeakPowerDrawMw); out.writeInt(mMaxPacketLengthBytes); out.writeInt(mSupportedSensors.length); out.writeInt(mSupportedSensors.length); out.writeIntArray(mSupportedSensors); out.writeIntArray(mSupportedSensors); Loading
core/jni/android_hardware_location_ContextHubService.cpp +27 −17 Original line number Original line Diff line number Diff line Loading @@ -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_HUB_HANDLE=2; static constexpr int HEADER_FIELD_APP_INSTANCE=3; static constexpr int HEADER_FIELD_APP_INSTANCE=3; namespace android { namespace android { namespace { namespace { Loading Loading @@ -164,9 +163,20 @@ static int get_hub_id_for_app_instance(int id) { return db.hubInfo.hubs[hubHandle].hub_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) { static int set_dest_app(hub_message_t *msg, int id) { if (!db.appInstances.count(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; return -1; } } Loading Loading @@ -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; JNIEnv *env; if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) { if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) { Loading Loading @@ -396,14 +406,9 @@ static bool sanity_check_cookie(void *cookie, uint32_t hub_id) { int context_hub_callback(uint32_t hubId, int context_hub_callback(uint32_t hubId, const struct hub_message_t *msg, const struct hub_message_t *msg, void *cookie) { void *cookie) { int msgHeader[MSG_HEADER_SIZE]; if (!msg) { if (!msg) { return -1; return -1; } } msgHeader[HEADER_FIELD_MSG_TYPE] = msg->message_type; if (!sanity_check_cookie(cookie, hubId)) { if (!sanity_check_cookie(cookie, hubId)) { ALOGW("Incorrect cookie %" PRId32 " for cookie %p! Bailing", ALOGW("Incorrect cookie %" PRId32 " for cookie %p! Bailing", hubId, cookie); hubId, cookie); Loading @@ -411,17 +416,22 @@ int context_hub_callback(uint32_t hubId, return -1; 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 && if (messageType < CONTEXT_HUB_TYPE_PRIVATE_MSG_BASE) { msgHeader[HEADER_FIELD_MSG_TYPE] != 0 ) { handle_os_message(messageType, hubHandle, (char*) msg->message, msg->message_len); handle_os_message(msgHeader[HEADER_FIELD_MSG_TYPE], } else { msgHeader[HEADER_FIELD_HUB_HANDLE], int appHandle = get_app_instance_for_app_id(msg->app_name.id); (char *)msg->message, if (appHandle < 0) { msg->message_len); ALOGE("Filtering out message due to invalid App Instance."); } else { } else { onMessageReceipt(msgHeader, sizeof(msgHeader), uint32_t msgHeader[MSG_HEADER_SIZE] = {}; (char *)msg->message, msg->message_len); 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; return 0; Loading