How to call a custom system call from C in Linux - android

I have implemented a custom system call sys_mycall for ARM architecture. After building and downloading on the phone the log is showing that sys_mycall is running.
My doubt is:
how do I call this system call from a C file.
can I somehow call this system call from java (using JNI or something). Just some hint on how to implement this on Android is required.

1) look at man 2 syscall for int syscall(int number, ...) with it you should be able call your sys call and pass the parameters you need/want.
2) Yes, use JNI for this. Create a JNI function to call your C code and from there just make the syscall.

This can be done using Android NDK
here is an example to call C code from Android application.

Related

How can I produce a call chain of Android application layer function call to linux kernel system calls?

I have been trying to get behind the call chain of some of the android framework's app initiated termination functions such as System.exit(0), finish(), finishAndRemoveTask(), etc. I have used strace to find system level traces, for System.exit() function of android application layer, I believe the kernel system level signal is SigKill, as this claim is supported by the following strace log.
I wanted to get behind the system-level calls or signals behind other android application layer functions such as finish().
I have tried to use Android Studio's built-in debugger, however, that only gives me all the call chains in java API level. I wanted to debug and get the full call chain from java function to native C/C++ library calls to kernel system level calls. That is function X() in java calls function Y() in native C/C++ libraries and that calls system level function Z(). I need the call chain flow from X -> Y -> Z.
How can I achieve that? I have also tried simpleperf but that does not provide the complete call-graph from application layer to system level calls.

Can google TangoUX work together with tango C API?

I tried it, but failed. Is this possible ? If not, how do you create similar connection/hold-tight screen ?
You can only use it from Java layer. Try surface the data from JNI to java, and use it in the activity.
Yes It's possible, but not straight forward.
As Jason Guo said, you have to get the necessary information from the C API and send it back to the Java TangoUx via the JNI.
Basically, in your TangoService callback (C) functions you need to call the appropiate TangoUX function (java):
TangoService_connectOnXYZijAvailable -> mTangoUx.updateXyzCount
TangoService_connectOnPoseAvailable -> mTangoUx.updatePoseStatus
TangoService_connectOnTangoEvent -> mTangoUx.updateTangoEvent
For that, you have to see how JNI is used to call java functions:
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
Be careful because the C callbacks are not executed in the main java thread. So you need to update the JNIEnv in each callback (using the JavaVM class). This link have some useful information although it uses an old version of the JNI.
http://android.wooyd.org/JNIExample/files/JNIExample.pdf

Android : Logging all API calls

I'm working on a collage project about security in Android. One part of the project attempts to capture and log all API function called by the selected APK. This can't be done with a external programs so in the project we are working with the Android source code to modify the ROM.
At the present time we only have two possible solutions:
DVM JNI Bridge
The API is Java code so, obviously, the Dalvik Virtual Machine needs a bridge to execute JNI code. The function which handle all cases is dvmCallJNIMethod(const u4* args, JValue* pResult, const Method* method, Thread* self). In this function we can get the name and the class of the called function.
This function can log all the JNI code executed, which includes API calls. But there is no easy way to distinct between private calls and API calls. And, if we wanted to execute some code depending on the risk of the API call executed, we would have to create a huge and inefficient switch.
API Framework
another solution To log all API calls is creating a new interface for the framework. With a new logging class and a simple inheritance should be easy to log all calls and add a risk parameter. But it would mean changing a lot of code. Also, Java code has worst performance than C, so it might not be the most efficient way.
More over, we would like to ask you a few questions about Android DVM and the API.
1.Which is exactly the call flow between DVM and the API?
2.Could be the DVM monitor a good idea to log the calls?
3.Which role have the shared libraries in all of this?
4.Are all API calls really Java code?
Thanks for your time.

Calling RILD layer functions for implement call conferencing in android

I want to implement Call conferencing in android, for this I am trying to call RILD functions from my android code, but not able to get the way of how to call RILD functions. I know how to call c and c++ functions from android using NDK, I also got RIL source code from here : Ril
For become more specific, I want to implement call conferencing when I am in call with some one and at the same time I got call from a specific number, so I will detect that specific number via applying call receivers and will try to call c and c++ functions of RILD via java code for implement call conferencing.
Please tell me the way of implementing call conferencing in android by calling RILD.
Call conferencing is a modem feature. There are APIs in the Android framework which are called when conference calling is activated. Call conferencing would work if the relevant APIs are implemented in the RIL. Here are a few APIs for conference calling:
RIL_REQUEST_CONFERENCE
RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND
RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
For detailed information, you can visit the following link: https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h
Hope this helps :)

Android NDK: JNI "main" to deal with messages?

I'm trying to build an Android application that uses an existing C library for some background operation (i.e. does some radio scans, tunes to stations etc). As a stand-alone C executable, the main-loop can deal with message handling from lower levels (hardware components). My understanding is that using JNI, no main function is required because
1) a shared library is created and
2) the shared library is "alive" for as long as the java thread that loaded it is alive.
So assuming that the C library uses multiple threads: where should then the message handling that normally is done in the initial main-loop be done? Is it as simple as by calling C functions that are declared together with the JNI functions?
Re 2) library is "alive" in the meaning of persisting in the memory. But it does not do anything on its own. If you need the library to "do something" even if no functions are being called through JNI, then you need a separate native thread of course. You can create the thread and start a message loop within a regular JNI function call (init method or use JNI_OnLoad for that purpose). It will keep on running when the JNI function call returns. You then also need a teardown method which stops the thread and tears it down (JNI_OnUnload can be used for that)

Categories

Resources