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

浪尽此生 提交于 2019-12-24 01:59:22

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/51844210/different-between-native-c-code-run-in-jni-and-run-in-the-shell-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!