Interface Android Keystore from NDK - android

Introduction
I am currently working on a solution that would use Android Keystore new features (since Marshmallow , API level 23).
My app use both Java and C++ (NDK) and I have some critical operation that needs to be perform from native code.
I am able to use properly the new Keystore from Java.
Unfortunately, the Android C++ sources are not documented and I have tried to look into it.
Question
I would like to perform operation from both Java and C++.
The only dynamic library that I could use and interface is the IKeystoreService and with its associated library /system/lib/libkeystore_binder.so.
I have been able to include headers and the library and compile it.
But since the only connection point I can use is a Binder between Java and C++ IKeystoreService(s), I can't find which data I am supposed to use in order to achieve a simple AES encryption (for example).
Would anyone have any insight ?
Thanks

Related

Are there any simple way to use c/c++ source code directly on my android application?

I am currently working on an android application that evaluate images in different aspects, and I found that there are lots great open source algorithms can be used.
Problem 1: Most of the algorithms are designed on c/c++/matlab languages that cannot be applied directly.
I've search that NDK is a tool that allows us develop android application by other languages, but the setup procedures are quite complicated that I stuck for days. So before I go further on it, I would like to first ask whether I can include other's c/c++ source code directly like calling java library?
Problem 2: For example, I would like to use Point Matching algorithm's source code in my application, but there are lots files inside as it's just source code but not library/plugin. What are the steps to apply the require functions in my android application?
(the most desired way is to blindly input some images to the alogrithm, and it returns the results like calling functions, which I dont have to understand the working principle of it.)
You can't directly use other C++ libraries, you have to build them for Android first using NDK. If there is a version of the library built for Android, then, of course you can use it directly by linking to it using NDK.
You have two options here. First, you create a regular Java application for Android, write a C++ wrapper for handling calls to native side and build the necessary source files using NDK. Your java application will make calls to wrapper using JNI and the wrapper will call your actual C++ functions as in Java->JNI wrapper on C++->Your actual C++ source.
Second option is going fully native, which will leave out Java, JNI calls and the wrapper. You can access your source files directly as if you were writing a desktop C++ application. In the end you will have to build using NDK but this step is required in any case.
As a suggestion, you can also take a look at OpenCV for image processing purposes. It has libraries built for Android, all you will have to do is to link them.
Short version.
Download opencv4android library. Import it in eclipse and see if everything is fine (compile errors, output, etc.).
Secondly, try to import face detection application and try to understand how it works.
It has a java part and a native part.
In order to understand how it works you must understand how java interacts with C++, more or less how NDK works.
One important aspect is to learn how to create your interfaces in C++, based on the native ones defined in java. When you got there then you can try creating your own application.
After that you can come here and ask specific questions.

Can the Eventful java client library be used for Android?

I am creating an app showing local events for android. I was hoping to use the Eventful API, since that came with its own java-based client library. However, I'm not sure if it's fit for Android, since I know a lot of these java based client libraries use stuff Android doesn't support.
So, does anybody know if it works?
My entire project is available # github if you want to check it out for yourself.
The API is found here.
Android does not have have issues with Java client libraries. It is build on top of standard Java, and can use all of the framework features.
Furthermore, it looks like this API offers a RESTful interface, which is for sure supported by Android.
Bottom line, I do think you can use this API in Android without issue.
I'd say the easiest way is to compile and run an application that embeds the library and tests a few methods.
Typically, you may have issues with the way the networking is handled. There are 2 main ways in android to do HTTP, the Java and the Apache way, I think the Java URL API is fully supported and very close to the actual Java version, but the Apache has some hidden differences.
The main risks you'll have are A/ that it uses classes or packages that are not present on Android. B/ that a class does not behave as expected, which does happen from time to time, as the Android implementation is entirely specific.
Apparently you have already tried to run an android app with the library included? Did you encounter a specific error? If you, can you post the stacktrace?

C++ File adding

Can anyone please tell me how to add a C++ file in to an android project? Is there any method to import classes other than java classes?
The answer is that, you can't really add a C++ file directly to a project, but you can compile it and load it into the code that runs in your process and interface to it using the JNI. This is a way to interface native code to Java. However, be aware that you can't really do that much with the JNI. Getting access to standard Android things like UI, Intents, service connections, etc.., these are all somewhat more difficult to use in native code. And you certainly can't take a UNIX app "off the shelf" and stick it on Android by using the JNI. this is a fairly good looking tutorial on the JNI with Android. However, like I said, using the JNI is not an excuse for learning java and the Android SDK. The main reasons people use native code are for utility code (like crypto stuff) and performance (for example, quite a few Android games use the NDK)..
You have to use android NDK. Just download it and refer from android official site.

Share a native library across two applications

Presently in my Android system, I have developed a native library to communicate
with a connected media device over linux driver and we are accessing it from an
apk application via the Java native interface. This has been working fine till
now.
But we also have another application which needs to access the same native library
in parallel with the first application. As expected, because of the different data
section for the linked native library in the new application this approach is not
working.
To subvert this, we though of writing a new service/application which will be linked
with the native library and other applications access the APIs using binder calls to
this new service/application.
My question is:
Is this new approach feasible? Can someone help me with a better approach.
If yes, then we also need to return buffers in the API and some of the APIs are
callbacks. Can these types of functions be handled using the binder interface?
Thanks,
Ashutosh
Build an external library in a jar that provides the higher level API which in turn accesses the native library. Then use this jar library as any other lib. You may have to check how to put the .so file into the jar file to have a single library file.
I believe that the service approach is exactly how opencv achieves this.... specifically, OpenCV has a manager in thr app store. You can develop an app that implements BaseLoaderCallback, which gets the .so library from this manager. Behind the scenes, this uses a Service, ServiveConnection, and aidl to get the library... if memory serves me right.
Update...
Now that i think about it, i think OpenCV manager might just be passing the path to the library, which can then be loaded with the System.load command, which accepts the library path.

JNI tech. on Android or Linux platform when development ,so?

I face a problem while developing a native C/C++ shared library for Android platform. As we all know that Android use Java language for the upper layer development. Now I have ported my Engine code using ASCII C/C++ to Android using its bionic library, yet when need to design the User Interface, I have to use the JNI to call my engine code.
As far as I know, that is the only choice. The problem is my engine own hundreds of export APIs. If I use the JNI tech. I need to wrap these APIs to a new shared library for use, which will cost a lot of time for development and testing.
Can somebody give some suggestions for this situation? I am not familiar with java or JNI tech by the way.
TIPS:
When I searched the internet, I found some open source for JNI generator such as JNative etc. Until now I do not know is it suitable for Android platform or not.
You can easily use SWIG www.swig.org which will generate the JNI bindings for you.
there is nothing android-specific in that operation, so it will work rather out-of-the-box.

Categories

Resources