From b77b8b5a70b4a3d770dc2cee4ab78b49c82f5a28 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Fri, 6 May 2016 04:30:23 -0700 Subject: cmsdk: Pass the process name and pid for launch boosts * We need this for vendor perf tools. * This also adds a NativeHelper class which loads the JNI library on-demand, since we don't have an entry point. Change-Id: If76ad8f952e86366978ae9cf9d1f107febccc28b --- cm/jni/Android.mk | 11 +-- cm/jni/src/onload.cpp | 2 + ...platform_internal_PerformanceManagerService.cpp | 82 ++++++++++++++++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 cm/jni/src/org_cyanogenmod_platform_internal_PerformanceManagerService.cpp (limited to 'cm/jni') diff --git a/cm/jni/Android.mk b/cm/jni/Android.mk index 5e1da9f..3e8aae4 100644 --- a/cm/jni/Android.mk +++ b/cm/jni/Android.mk @@ -18,19 +18,22 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ src/org_cyanogenmod_platform_internal_CMAudioService.cpp \ + src/org_cyanogenmod_platform_internal_PerformanceManagerService.cpp \ src/onload.cpp LOCAL_C_INCLUDES := \ $(JNI_H_INCLUDE) \ $(TOP)/frameworks/base/core/jni \ - $(TOP)/frameworks/av/include + $(TOP)/frameworks/av/include \ + $(TOP)/hardware/libhardware/include LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ - libmedia \ - liblog \ libcutils \ - libutils \ + libhardware \ + liblog \ + libmedia \ + libutils LOCAL_MODULE := libcmsdk_platform_jni LOCAL_MODULE_TAGS := optional diff --git a/cm/jni/src/onload.cpp b/cm/jni/src/onload.cpp index d9892ba..1ee8fda 100644 --- a/cm/jni/src/onload.cpp +++ b/cm/jni/src/onload.cpp @@ -22,6 +22,7 @@ namespace android { int register_org_cyanogenmod_platform_internal_CMAudioService(JNIEnv* env); +int register_org_cyanogenmod_platform_internal_PerformanceManagerService(JNIEnv* env); }; @@ -39,6 +40,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) ALOG_ASSERT(env, "Could not retrieve the env!"); register_org_cyanogenmod_platform_internal_CMAudioService(env); + register_org_cyanogenmod_platform_internal_PerformanceManagerService(env); return JNI_VERSION_1_4; } diff --git a/cm/jni/src/org_cyanogenmod_platform_internal_PerformanceManagerService.cpp b/cm/jni/src/org_cyanogenmod_platform_internal_PerformanceManagerService.cpp new file mode 100644 index 0000000..71c0577 --- /dev/null +++ b/cm/jni/src/org_cyanogenmod_platform_internal_PerformanceManagerService.cpp @@ -0,0 +1,82 @@ +/* +** +** Copyright 2016, The CyanogenMod Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +//#define LOG_NDEBUG 0 + +#define LOG_TAG "PerformanceManagerService-JNI" + +#include + +#include +#include +#include "core_jni_helpers.h" + +#include + +// ---------------------------------------------------------------------------- + +namespace android { + +static const char* const kClassPathName = + "org/cyanogenmod/platform/internal/PerformanceManagerService"; + +static struct power_module* gPowerModule; + +// ---------------------------------------------------------------------------- + +static void +org_cyanogenmod_platform_internal_PerformanceManagerService_launchBoost( + JNIEnv *env, jobject thiz, jint pid, jstring jPackageName) +{ + if (env == NULL || jPackageName == NULL) { + return; + } + + if (gPowerModule && gPowerModule->powerHint) { + const char *packageName = env->GetStringUTFChars(jPackageName, 0); + launch_boost_info_t *info = (launch_boost_info_t *)malloc(sizeof(launch_boost_info_t)); + info->pid = pid; + info->packageName = packageName; + gPowerModule->powerHint(gPowerModule, POWER_HINT_LAUNCH_BOOST, (void *)info); + ALOGV("Sent LAUNCH BOOST for %s (pid=%d)", info->packageName, info->pid); + + env->ReleaseStringUTFChars(jPackageName, packageName); + free(info); + } +} + +// ---------------------------------------------------------------------------- + +static JNINativeMethod gMethods[] = { + {"native_launchBoost", "(ILjava/lang/String;)V", + (void *)org_cyanogenmod_platform_internal_PerformanceManagerService_launchBoost}, +}; + +int register_org_cyanogenmod_platform_internal_PerformanceManagerService(JNIEnv *env) +{ + status_t err = hw_get_module(POWER_HARDWARE_MODULE_ID, + (hw_module_t const**)&gPowerModule); + if (!err) { + gPowerModule->init(gPowerModule); + } else { + ALOGE("Couldn't load %s module (%s)", POWER_HARDWARE_MODULE_ID, strerror(-err)); + } + + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); +} + +} /* namespace android */ -- cgit v1.1