NVDQ
NVDQ

Reputation: 23

Different between native C code run in jni and run in the shell in Android

I have a native C Android application. First I build native C code into shared library and jni will use this library. This library uses some kernel loadable module .ko, some already loaded, some must loaded by "insmod" command.

I also build an executable that use this library and it run ok by command line. But the jni which do the same work as executable run fail when it calls function that need kernel module to be loaded.

So what is the difference between them? Do I need grant some permission for my app?

Upvotes: 2

Views: 463

Answers (1)

shizhen
shizhen

Reputation: 12583

I think your device is rooted.

I also build an executable that use this library and it run ok by command line.

Maybe you run this command with su and can execute it without issue.

But, if you execute your binary from App by JNI, then you are actually running the command with a normal user permission which may have issue if your C code invokes some kernel functions.

Have you tried below code in your app?

Runtime.getRuntime().exec("su").

Here is some reference for you http://muzikant-android.blogspot.com/2011/02/how-to-get-root-access-and-execute.html?_sm_au_=iqsHGF7FqZfPGrJb

Upvotes: 1

Related Questions