Can google TangoUX work together with tango C API? - android

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

Related

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.

How do I obtain the Android context in BeanShell for SL4A?

I started exploring BeanShell for SL4A because I read that it could access the entire Android API. This would facilitate experimenting with API features and programming ideas without the need for a computer or compilation.
However, much of the API is accessed through a Context, and I don't know how to obtain this. Although both SL4A and BeanShell are well-documented, the combination of the two seems to be very poorly documented.
For example, to access android.net.ConnectivityManager, the developer reference states that I need to call Context.getSystemService(Context.CONNECTIVITY_SERVICE) to get an instance. But without a context, I don't think I'm able to access the methods of the ConnectivityManager.
So how do I obtain the Context?
Dahrrr…
While researching and formulating the question, I found out that this is an unresolved issue:
Notes for Java interpreters
Beanshell and Rhino can both directly access the android api. However, many Android api calls required a context, which, due to the way they are run, these interpreters don't have. A solution is being sought... suggestions appreciated.
I don't know sl4a or beanshell but i know Rhino. So i suppose that you can create scriptable objects too. If this is correct you can do something like this (in java):
// first create a simple scope called -> scope
// inject context.
Object injectObject = Context.javaToJS(android_context, scope); // ('Context' of rhino library)
ScriptableObject.putProperty(scope, "android_context_name", injectObject);
// so then execute your script with the injected object
execute(javascript_context, host, scope, scriptId, source, settings);
When you finish injected the the context you can access him via: "android_context_name". (inside your script).
When you run your bean shell script, it will be thru an android app ?
There are such available
e.g : BeanShell Executor, that will allow you to run a script.
So I assume the context will be passed from the app to the script being executed.

How to call a custom system call from C in Linux

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.

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)

Android JNI blocks on native to Java calls

I have a pretty basic question regarding JNI calls to Java in Android NDK. I have no problems with making the actual calls, but I am not sure whether the Java call is blocked or not when it is called from C.
My question is specifically whether the c call blocks while the Java method is executed, or if it returns immediately. The reason I am asking is that I pass a byteArray to Java and I wonder if Java has access to it after the call is initiated.
JNI calls are like nornal function call. Your native code continues running when JNI call (and Java function) returns.
You should be careful about your selection of JNI calls, some can become blocking. For example getting a Critical pointer to a byte array and not releasing it can block the jvm from continuing to operate.

Categories

Resources