Linux AOSP RIL

Linux AOSP RIL is a simple attempt to provide native AOSP RIL features in a standard Linux environment:the result is available in github.

The original goal of my attempt was to provide a shared library that could be used for simply testing a native RIL library in x86 systems. So, no rild and no sockets involved, but direct requests sending through ril callback onRequest.

Linux AOSP RIL

Linux AOSP RIL challenges

A few open points were to be solved, before reaching the target:

  1. Provide a way to build the library outside AOSP build environment
  2. Replace or remove native ril parts that are incompatible (or unnecessary) in Linux
  3. Provide a library user that implements parts of the behavior exhibited by other components of the whole AOSP ril (e.g. telephony framework)

1. Providing a way to build the library outside AOSP build environment

Current AOSP native ril does not require a complex build system, so I wrote a simple Makefile. Note the introduction of the symbol LINUX (that will be used to isolate Linux dependent changes) and the references to pthread and libbsd (for strl* functions).

2. Replace or remove native ril parts that are incompatible (or unnecessary) in Linux

Among the features available in AOSP and not in Linux there were:

  • RLOGx macro: I simply replaced them with the same macro based on fprintf, added a new file log.h. There’s a lot of room for improvements here (e.g. use logcat)
  • Android properties functions: just replaced with some stubs in ril_linux.*, since they seems to be mainly used in emulator
  • Socket management: used in AOSP to communicate with the other parts of the ril, removed due to the different way of using the library
  • Other minor functions (like ril_nano_time or requestToString) available in different components of AOSP ril: just copied from the originals
  • AOSP telephony include files have been integrated in order to have all the needed structures and symbols: probably there are more than really needed, but they are not harmful

The changes have been isolated with the symbol LINUX.

3. Provide a library user that implements parts of the behavior exhibited by other components of the whole AOSP ril

A simple example for request RIL_REQUEST_RADIO_POWER is available in directory tests.

The application implements the callbacks available in struct RIL_Env and pass them to RIL_Init. RIL_Init returns a reference to RIL_RadioFunctions that can be used to send request with the onRequest method.

An important difference is related to the meaning of RIL_Token, formally a void *: in the original ril it is used for storing requests related information (see RequestInfo definition in libril/ril_internal.h), while here I’m simply using it as a transaction id to link request and response (not really needed currently, but ready for further development).

The test application should be started with the modem port as an argument, e.g.

sudo tests/request_radio_power -d /dev/ttyUSB3

This simple example made me also to fix an issue in AOSP ril related to a wrong assert in requestRadioPower

Is it useful?

Let me clarify that this Linux AOSP RIL implementation is missing all the real abilities of the Android ril as a whole, since most of them are implemented in the Java telephony framework (the native ril can be considered as a simple pipe), but, besides being a slim API that can be used for simple tasks, Linux AOSP ril can be useful to run tools that cannot be easily integrated in an Android build environment (e.g. CodeSonar), or, as already suggested, execute unit tests for native code in more common and convenient platforms like x86 (and avoid using tricks like, for example, this one).

Currently the github project is just a simple spike: if someone would like to contribute for improving the project, patches are welcome.