Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2bb94fc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add package name when loadModules and attach."

parents 82cd3ec3 1f4b4dd7
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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.
@@ -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
+3 −2
Original line number Diff line number Diff line
@@ -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() {
+15 −7
Original line number Diff line number Diff line
@@ -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 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");

@@ -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;
    }
@@ -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) {
@@ -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;
    }
@@ -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",