Loading core/java/android/hardware/soundtrigger/SoundTrigger.java +29 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.system.OsConstants.EPIPE; import android.annotation.Nullable; import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.app.ActivityThread; import android.media.AudioFormat; import android.os.Handler; import android.os.Parcel; Loading Loading @@ -1439,6 +1440,17 @@ public class SoundTrigger { */ public static final int SERVICE_STATE_DISABLED = 1; /** * @return returns current package name. */ static String getCurrentOpPackageName() { String packageName = ActivityThread.currentOpPackageName(); if (packageName == null) { return ""; } return packageName; } /** * Returns a list of descriptors for all hardware modules loaded. * @param modules A ModuleProperties array where the list will be returned. Loading @@ -1452,7 +1464,23 @@ public class SoundTrigger { * @hide */ @UnsupportedAppUsage public static native int listModules(ArrayList <ModuleProperties> modules); public static int listModules(ArrayList<ModuleProperties> modules) { return listModules(getCurrentOpPackageName(), modules); } /** * Returns a list of descriptors for all hardware modules loaded. * @param opPackageName * @param modules A ModuleProperties array where the list will be returned. * @return - {@link #STATUS_OK} in case of success * - {@link #STATUS_ERROR} in case of unspecified error * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission * - {@link #STATUS_NO_INIT} if the native service cannot be reached * - {@link #STATUS_BAD_VALUE} if modules is null * - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails */ private static native int listModules(String opPackageName, ArrayList<ModuleProperties> modules); /** * Get an interface on a hardware module to control sound models and recognition on Loading core/java/android/hardware/soundtrigger/SoundTriggerModule.java +3 −2 Original line number Diff line number Diff line Loading @@ -46,9 +46,10 @@ public class SoundTriggerModule { SoundTriggerModule(int moduleId, SoundTrigger.StatusListener listener, Handler handler) { mId = moduleId; mEventHandlerDelegate = new NativeEventHandlerDelegate(listener, handler); native_setup(new WeakReference<SoundTriggerModule>(this)); native_setup(SoundTrigger.getCurrentOpPackageName(), new WeakReference<SoundTriggerModule>(this)); } private native void native_setup(Object module_this); private native void native_setup(String opPackageName, Object moduleThis); @Override protected void finalize() { Loading core/jni/android_hardware_SoundTrigger.cpp +15 −7 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -395,7 +396,7 @@ static sp<SoundTrigger> setSoundTrigger(JNIEnv* env, jobject thiz, const sp<Soun static jint android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, jobject jModules) jstring opPackageName, jobject jModules) { ALOGV("listModules"); Loading @@ -411,7 +412,10 @@ android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, 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; } Loading @@ -419,7 +423,7 @@ android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, 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) { Loading Loading @@ -470,16 +474,20 @@ exit: } 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; } Loading Loading @@ -816,14 +824,14 @@ android_hardware_SoundTrigger_getModelState(JNIEnv *env, jobject thiz, 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", Loading Loading
core/java/android/hardware/soundtrigger/SoundTrigger.java +29 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.system.OsConstants.EPIPE; import android.annotation.Nullable; import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.app.ActivityThread; import android.media.AudioFormat; import android.os.Handler; import android.os.Parcel; Loading Loading @@ -1439,6 +1440,17 @@ public class SoundTrigger { */ public static final int SERVICE_STATE_DISABLED = 1; /** * @return returns current package name. */ static String getCurrentOpPackageName() { String packageName = ActivityThread.currentOpPackageName(); if (packageName == null) { return ""; } return packageName; } /** * Returns a list of descriptors for all hardware modules loaded. * @param modules A ModuleProperties array where the list will be returned. Loading @@ -1452,7 +1464,23 @@ public class SoundTrigger { * @hide */ @UnsupportedAppUsage public static native int listModules(ArrayList <ModuleProperties> modules); public static int listModules(ArrayList<ModuleProperties> modules) { return listModules(getCurrentOpPackageName(), modules); } /** * Returns a list of descriptors for all hardware modules loaded. * @param opPackageName * @param modules A ModuleProperties array where the list will be returned. * @return - {@link #STATUS_OK} in case of success * - {@link #STATUS_ERROR} in case of unspecified error * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission * - {@link #STATUS_NO_INIT} if the native service cannot be reached * - {@link #STATUS_BAD_VALUE} if modules is null * - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails */ private static native int listModules(String opPackageName, ArrayList<ModuleProperties> modules); /** * Get an interface on a hardware module to control sound models and recognition on Loading
core/java/android/hardware/soundtrigger/SoundTriggerModule.java +3 −2 Original line number Diff line number Diff line Loading @@ -46,9 +46,10 @@ public class SoundTriggerModule { SoundTriggerModule(int moduleId, SoundTrigger.StatusListener listener, Handler handler) { mId = moduleId; mEventHandlerDelegate = new NativeEventHandlerDelegate(listener, handler); native_setup(new WeakReference<SoundTriggerModule>(this)); native_setup(SoundTrigger.getCurrentOpPackageName(), new WeakReference<SoundTriggerModule>(this)); } private native void native_setup(Object module_this); private native void native_setup(String opPackageName, Object moduleThis); @Override protected void finalize() { Loading
core/jni/android_hardware_SoundTrigger.cpp +15 −7 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -395,7 +396,7 @@ static sp<SoundTrigger> setSoundTrigger(JNIEnv* env, jobject thiz, const sp<Soun static jint android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, jobject jModules) jstring opPackageName, jobject jModules) { ALOGV("listModules"); Loading @@ -411,7 +412,10 @@ android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, 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; } Loading @@ -419,7 +423,7 @@ android_hardware_SoundTrigger_listModules(JNIEnv *env, jobject clazz, 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) { Loading Loading @@ -470,16 +474,20 @@ exit: } 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; } Loading Loading @@ -816,14 +824,14 @@ android_hardware_SoundTrigger_getModelState(JNIEnv *env, jobject thiz, 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", Loading