Creating a property in Java and in a C file

I am currently facing the current situation:

I would like to create a toggle for Double Tap to Wake gestures that is "on" with the following commit on the Nexus 6 PowerHAL: https://gerrit.omnirom.org/#/c/13930/1/power/power_shamu.c

I would like to achieve this using a system application (written in java) to enable or disable this feature (written to the kernel sysfs path in the above C file).

Clearly I can't just wrap it in an ifdef or whatever, but I was told that I can create a property in the application (Java file) and then inherit it in the C file.

In theory, it would function like this:
  • Enable / disable the feature in the application (Java sets the property on or off)
  • The property is used by the C file to determine what value to write to the sysfs path.

The contents of the sysfs file will be as simple as comparing the file values ​​between enabled and disabled, I am more interested in the logic involved.

I know very little Java, but I have a solid foundation for C ++.

I searched some google searches and couldn't find anything relevant.

Any insight would be great.

- Jake

+3


source to share


1 answer


Android NDK has everything you need

public class MyActivity extends Activity {
    static {
        System.loadLibrary("library");
    }

    /**
     * Native method implemented in C/C++
     */
    public native String toggleFoo();
}

      




#include <string.h>
#include <jni.h>

jstring Java_com_package_MyActivity_toggleFoo(JNIEnv* env, jobject javaThis) {
    return (*env)->NewStringUTF(env, "Hello from native code!");
}

      

0


source







All Articles