How to interface with device drivers in an apk

76 views
Skip to first unread message

Shahin Ansari

unread,
Sep 10, 2015, 3:32:14 PM9/10/15
to Android Linux Kernel Development
Greetings-
In order to learn more about the device drivers on the Android platform, I built an tutorial code and was able to interface with it from a user program. 
Here is the code I used for device driver:
/* Example Minimal Character Device Driver */
#include <linux/module.h>
static int __init hello_init(void)
{
printk("Hello Example Init\n");
return 0;
}
static void __exit hello_exit(void)
{
printk("Hello Example Exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("Hello World Example");
MODULE_LICENSE("GPL");

Here is the code for the user space executable:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
/* Our file descriptor */
int fd;
int rc = 0;
char *rd_buf[16];
printf("%s: entered\n", argv[0]);
/* Open the device */
fd = open("/dev/hello1", O_RDWR);
if ( fd == -1 ) {
perror("open failed");
rc = fd;
exit(-1);
}
printf("%s: open: successful\n", argv[0]);
/* Issue a read */
rc = read(fd, rd_buf, 0);
if ( rc == -1 ) {
perror("read failed");
close(fd);
exit(-1);
}
printf("%s: read: returning %d bytes!\n", argv[0], rc);
close(fd);
return 0;
}

***********************************************
Now I want to move this into an apk, and run it as an app. The only way I know of doing this is via JNI. So I created a HelloJNI project using another online tutorial. I need help with verifying I am on the right track, and what are some of the next steps to get my user program code into my JNI project and run it as an apk. I have already posted to a JNI forum, but I have not heard anything back. I think doing kernel development is a very unique skill, and that may be why other forums can not help me. I have seen similar discussions on this list and have reviewed them to ensure I provide all the information I should.
Thanks in Advance,
Sean

Durgadoss Ramanathan

unread,
Sep 11, 2015, 2:01:10 AM9/11/15
to android...@googlegroups.com
I believe you are on the right track. Did your HelloJNI work ?

Also, JNI may be a preferred way; but not a must. You should be able to use JAVA APIs (BufferedReader & friends) from your app to interact with these files. Watch out for permission issues etc..

Thanks,
Durga

--
--
unsubscribe: android-kerne...@googlegroups.com
website: http://groups.google.com/group/android-kernel
---
You received this message because you are subscribed to the Google Groups "Android Linux Kernel Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-kerne...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards
Durgadoss

Ramesh rama

unread,
Sep 11, 2015, 2:07:35 AM9/11/15
to Android Linux Kernel Development
Are you able to Interact with JNI from Apk ?

Shahin Ansari

unread,
Sep 11, 2015, 7:06:40 AM9/11/15
to Android Linux Kernel Development
Yes. JNI works. That is, I created a HelloJNI, and the app runs. I then proceeded to add more methods for different data types, and I am able to see the corresponding handles (I think that is what they are called; the translated version of the method I created in the "MainActivity") in my JNI folder header file.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages