On Saturday, October 23, 2010, Dianne Hackborn <[email protected]> wrote: > The Java runtime has wrappers around C++ IBinder. This is what Java's Binder is. You can write a JNI function that returns a Java Binder and in its implementation instantiate a C++ IBinder interface and return it. You will need to use this magic function in libandroid_runtime to do this: > > extern jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val); > I was able to do it this way, I wil post the link to github for reference.
Regards Nitin > The header for this is currently in core/jni/android_util_Binder.h. > 2010/10/22 Samuel Skånberg <[email protected]> > > Hello Dianne, > > Thanks for you quick response! > > In another post a developer asked how one should go about to publish an > IBinder interface of a native service with the system manager. There you > said one should follow four steps > > "1. Declares a shared user ID with the system process, and that its > components will run in the system process. > 2. Has a Service component that implements your "system" service. > 3. Has an intent receiver for BOOT_COMPLETED that, when run, starts the > service. > 4. In the Service implementation publishes its IBinder interface with the > private ServiceManager API." > > http://groups.google.com/group/android-porting/browse_thread/thread/f9a383ce949d1557 > > That seemed like the "right" way to do it because then it integrates > nicely with the rest of the android environment and is being started > automatically after boot. > > I was successful doing the first 3 but can't get it to work with the 4th > and that's what I'm trying to figure out now. In your previous message you > said I should keep all the binder stuff in C++ but from the post I linked > to it seems that it's possible to have a java class that extends the > Service class but that the onBind method return the C++ Binder interface. > > Have I understood it correctly? If so, how do I return the C++ Binder > interface? I have no idea. > > > >> I would recommend keeping all of the Binder stuff in C++, and implementing >> your Java APIs as JNI calls on the C++ Binder interface. Until aidl can >> generate C++ stubs, I think it is easier than maintaining both C++ and >> Java >> interfaces. >> >> 2010/10/20 Samuel Skånberg <[email protected]> >> >>> Well, those links were about JNI. I don't think I should have to use >>> JNI, do you? My service is implemented in C++, linked with binder and >>> the client I want to connect with is a normal android app so I should >>> be able to do >>> >>> >>> ------------------------------------------------------------------------------------- >>> Intent i = new Intent(); >>> i.setClassName("com.example.cppservice", >>> "com.example.cppservice.PokeService"); >>> if (bindService(i, clientConnection, Context.BIND_AUTO_CREATE)) { >>> Log.d(getClass().getSimpleName(), "bindService()"); >>> } else { >>> Log.e(getClass().getSimpleName(), "Could not bindService()"); >>> } >>> >>> ------------------------------------------------------------------------------------- >>> >>> I have no problems compiling the C++ program, that works nicely with >>> the android build system and my Android.mk file. But for some reason, >>> when I run it, it won't show up among the other services in android. >>> Am I missing some fundamental piece, like hooking onto the android >>> systems ServiceManager or something similar? >>> >>> >>> On Oct 20, 5:06 pm, Hamilton Vera <[email protected]> wrote: >>> > Maybe you can find some information here: >>> > >>> > http://www.google.com.br/url?sa=t&source=web&cd=5&ved=0CDwQFjAE&url=h. .. >>> > >>> > http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth. .. >>> > >>> > []'s >>> > >>> > Hamilton Vera >>> > >>> > 2010/10/20 Samuel Skånberg <[email protected]>: >>> > >>> > >>> > >>> > >>> > >>> > > Hello, >>> > >>> > > I want to create a binder service in C++ and be able to bind to that >>> > > se -- unsubscribe: [email protected] website: http://groups.google.com/group/android-porting
