5

Now wait just one moment before you mark this as a duplicate, because this is a very specific question.

I'm not asking if you can write an application using another language which is a binding using the NDK; what I want to know is:

  1. At a hardware level, how does dalvik interact with the Linux kernel on android devices?

The answer to (1) as I understand it, is that because android is fundamentally a Linux system, this is done via syscalls. Which is to say, at some level the davlik/art VM must interact with the C Linux kernel through a C API.

  1. If you had root permission on a device, why could you not do the same thing from a native system binary?

So, certainly it would be a painful experience, but technically is there any reason why it would not be possible to write an application purely in C, without using the android run-time at all?

(Note: Not without the run-time; obviously the run-time must be present to do various things like device initialization; but a stand alone binary that did not interact with the run-time).

(I can think of a few reasons why this might be the case, specifically the run-time requiring exclusive hardware access to various hardware, but I can't find any specific documentation about it)

mehdi lotfi
  • 11,194
  • 18
  • 82
  • 128
Doug
  • 32,844
  • 38
  • 166
  • 222
  • possible duplicate of [100% Native C Application on Android?](http://stackoverflow.com/questions/5434384/100-native-c-application-on-android) – Vyacheslav Pukhanov Aug 07 '14 at 05:57
  • http://stackoverflow.com/questions/1002164/write-applications-in-c-or-c-for-android – nobalG Aug 07 '14 at 06:06
  • What are you trying to do exactly...? – elcuco Aug 07 '14 at 06:15
  • @elcuco actually nothing; what someone asked on the SDL mailing list is: can you use embedded android and take advantage of the android device drivers without interacting with them through the android runtime. My immediate gut feeling was no... but trying to justify this, I can't find any specific reason why the answer is no. – Doug Aug 07 '14 at 07:22
  • 1
    You cannot do this. All devices are managed through the corresponding daemons. You cannot (usually) open a 2nd handle. – elcuco Aug 07 '14 at 08:17

1 Answers1

1

It is possible, this is how daemons work on Android (think RILD for example). However you cannot gain access to the Android facilities (graphics, location, etc) as there is no API from C.

Note that in order to speak to the Android API, your process needs to be a child of zygote. If you spawn a process from an ADB shell, or from init you will not be a fork() of zygote and will not have direct access to the JVM.

elcuco
  • 8,948
  • 9
  • 47
  • 69
  • technically the device drivers are located in the kernel; why would you not be able to access the hardware via syscalls? – Doug Aug 07 '14 at 07:19
  • Yes. You create the device driver in the kernel, which lets userspace communicate using a device (usually a char device). When I did it, all I had to do is open `/dev/ttyS2`, but the theory is the same. – elcuco Aug 07 '14 at 08:15