Add package name when loadModules and attach.
Adding package name when loading modules and attaching can help check
the permission of capturing hotword.
Test: test with logging.
Bug: 74078996
Bug: 122721589
Change-Id: I283d2e15283542384822d547bc1f322384172896
diff --git a/core/jni/android_hardware_SoundTrigger.cpp b/core/jni/android_hardware_SoundTrigger.cpp
index c7805ea..03057dc 100644
--- a/core/jni/android_hardware_SoundTrigger.cpp
+++ b/core/jni/android_hardware_SoundTrigger.cpp
@@ -21,6 +21,7 @@
#include "jni.h"
#include <nativehelper/JNIHelp.h>
+#include <nativehelper/ScopedUtfChars.h>
#include "core_jni_helpers.h"
#include <system/sound_trigger.h>
#include <soundtrigger/SoundTriggerCallback.h>
@@ -395,7 +396,7 @@
static jint
android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz,
- jobject jModules)
+ jstring opPackageName, jobject jModules)
{
ALOGV("listModules");
@@ -411,7 +412,10 @@
unsigned int numModules = 0;
struct sound_trigger_module_descriptor *nModules = NULL;
- status_t status = SoundTrigger::listModules(nModules, &numModules);
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+ const String16 opPackageNameString16 = String16(opPackageNameStr.c_str());
+
+ status_t status = SoundTrigger::listModules(opPackageNameString16, nModules, &numModules);
if (status != NO_ERROR || numModules == 0) {
return (jint)status;
}
@@ -419,7 +423,7 @@
nModules = (struct sound_trigger_module_descriptor *)
calloc(numModules, sizeof(struct sound_trigger_module_descriptor));
- status = SoundTrigger::listModules(nModules, &numModules);
+ status = SoundTrigger::listModules(opPackageNameString16, nModules, &numModules);
ALOGV("listModules SoundTrigger::listModules status %d numModules %d", status, numModules);
if (status != NO_ERROR) {
@@ -470,16 +474,20 @@
}
static void
-android_hardware_SoundTrigger_setup(JNIEnv *env, jobject thiz, jobject weak_this)
+android_hardware_SoundTrigger_setup(JNIEnv *env, jobject thiz,
+ jstring opPackageName, jobject weak_this)
{
ALOGV("setup");
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+ const String16 opPackageNameString16 = String16(opPackageNameStr.c_str());
+
sp<JNISoundTriggerCallback> callback = new JNISoundTriggerCallback(env, thiz, weak_this);
sound_trigger_module_handle_t handle =
(sound_trigger_module_handle_t)env->GetIntField(thiz, gModuleFields.mId);
- sp<SoundTrigger> module = SoundTrigger::attach(handle, callback);
+ sp<SoundTrigger> module = SoundTrigger::attach(opPackageNameString16, handle, callback);
if (module == 0) {
return;
}
@@ -816,14 +824,14 @@
static const JNINativeMethod gMethods[] = {
{"listModules",
- "(Ljava/util/ArrayList;)I",
+ "(Ljava/lang/String;Ljava/util/ArrayList;)I",
(void *)android_hardware_SoundTrigger_listModules},
};
static const JNINativeMethod gModuleMethods[] = {
{"native_setup",
- "(Ljava/lang/Object;)V",
+ "(Ljava/lang/String;Ljava/lang/Object;)V",
(void *)android_hardware_SoundTrigger_setup},
{"native_finalize",
"()V",