_NOTE: Packaging can be done without running postmarketOS on a real device._
There's at least for quite a few Samsung phones an open source component, that talks to RIL instead of ofono. If we had RIL, then we should be able to use it. See #598 for details.
@tssk and I have started work in the feature/android-rild branch.
In contrary to other software, the RIL daemon was not meant to be packaged for normal Linux distributions. To get it working, we write our own Makefiles and patch stuff out, that is Android specific and not useful for us (e.g. wakelocks are already stubbed out).
We package Android 7.x source code, which still gets maintained, because 8.x made the compilation process more complex with project treble.
Dependencies (may be incomplete, in brackets is the package name in postmarketOS):
rild (android-ril)
- nanopb (nanopb)
- librilutils (android-ril)
- libril (android-ril)
- libhardware_legacy (patched out)
- libcutils (android-libcutils)
- liblog (android-liblog)
Status:
How to help:
pmbootstrap init (defaults are fine)git checkout feature/android-rildpmbootstrap build android-rilpmbootstrap logediting aports/android/*@tssk wrote in https://github.com/postmarketOS/pmbootstrap/pull/804#issuecomment-338461706:
For the next step - it seems that utils/Log.h is missing - probably part of cutils. And I am not sure that includes from libcutils and cutils is the same?
I have found utils/Log.h here (this is from the 7.x branch, it doesn't seem to exist in the 8.x branch - but we use 7.x anyway, so it should be in the source we download). So we might need to create a libcutils-dev subpackage, which installs the utils/ header files to /usr/include/android/, so they can be used by other Android packages.
@ollieparanoid Are you sure libcutils is the right name?
Uh right, it would be android-libcutils-dev if you mean that. Or do you mean something else?
No, I mean if the cutils is correct.. seems to me that meybe cutils and utils is something different.
Oh, you mean to make all of the includes part of existing android-libcutils-dev package to get all the necessary thing together. Sorry I did not get it.
The Android repos were moved from github.com/android to github.com/aosp-mirror so the links should be updated. I'll try to get a bit more compiling/linking today/tomorrow.
I got it as far as
cc -c pb_decode.c -o pb_decode.o -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -Iinclude -Idebian/include -Dchar16_t=uint16_t -fPIC -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -shared -Wl,-soname,libprotobuf-c-nano.so.0 -Wl,-rpath=/usr/lib/android -lpthread -L/usr/lib/android -L. -llog
cc -c pb_encode.c -o pb_encode.o -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -Iinclude -Idebian/include -Dchar16_t=uint16_t -fPIC -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -shared -Wl,-soname,libprotobuf-c-nano.so.0 -Wl,-rpath=/usr/lib/android -lpthread -L/usr/lib/android -L. -llog
ar rcs libprotobuf-c-nano.a pb_decode.o pb_encode.o
cc librilutils/librilutils.c librilutils/record_stream.c -o librilutils.so.0 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -Iinclude -Idebian/include -Dchar16_t=uint16_t -fPIC -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -shared -Wl,-soname,librilutils.so.0 -Wl,-rpath=/usr/lib/android -lpthread -L/usr/lib/android -L. -llog
ln -s librilutils.so.0 librilutils.so
protoc --proto_path=. --nanopb_out=. --plugin=/usr/bin/protoc-gen-nanopb librilutils/proto/sap-api.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: librilutils/proto/sap-api.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
cc libril/RilSapSocket.cpp libril/RilSocket.cpp libril/ril.cpp libril/ril_event.cpp -o libril.so.0 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -Iinclude -I.. -Ilibril -I/usr/include/android -Dchar16_t=uint16_t -fPIC -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -shared -Wl,-soname,libril.so.0 -Wl,-rpath=/usr/lib/android -lpthread -L/usr/lib/android -L. -llog
libril/RilSapSocket.cpp:24:0: warning: "LOG_TAG" redefined
#define LOG_TAG "RIL_UIM_SOCKET"
In file included from /usr/include/android/cutils/log.h:1:0,
from /usr/include/android/utils/Log.h:31,
from libril/rilSocketQueue.h:20,
from libril/RilSocket.h:20,
from libril/RilSapSocket.h:21,
from libril/RilSapSocket.cpp:21:
/usr/include/android/log/log.h:65:0: note: this is the location of the previous definition
#define LOG_TAG NULL
libril/ril.cpp:29:10: fatal error: binder/Parcel.h: No such file or directory
#include <binder/Parcel.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [libril.mk:12: build] Error 1
but now libril wants many of the binder and bionic headers (which don't exist in GNU/Linux or Alpine)
I have the current makefiles and patches on https://github.com/z3ntu/ril-stuff in the form of Arch packages (but taking the makefile and patches and putting them in APKBUILD instead of PKGBUILD files shouldn't be hard as the two packaging formats are very similar).
Patches and Makefiles are partly stolen from Debian and partly from the WIP branch here 馃槈
@z3ntu Nice work!
binder/Parcel.h - comes from here https://android.googlesource.com/platform/frameworks/native/+/android-7.0.0_r34/include/binder/
including it leads to linux/binder.h which can be found in linux-headers under linux/android/binder.h
patching/symlinking it leads to sys/limits.h which can be found in musl-dev under linux/limits.h
patching/symlinking leads to sys/system_properties.h which is not available in Alpine
pulling it from https://android.googlesource.com/platform/development/+/android-7.0.0_r34/ndk/platforms/android-21/include/sys/ leads to hell -> currently available here https://github.com/tssk/pmbootstrap/tree/feature/android-rild :)
I was just blindly following includes without understanding if it is really necessary.
Great work, both of you! I've just looked up what binder is for:
Binder is an Android-specific interprocess communication mechanism, and remote method invocation system.
- That is, one Android process can call a routine in another Android process, using binder to indentify the method to invoke and pass the arguments between processes.
- note that Android does NOT use SysV IPC for interprocess communication
- the binder implementation is in the kernel source at: drivers/android/binder.c, with include file: include/uapi/linux/android/binder.h
After more research, I've come to the B2G wiki:
The Java code communicates with the rild socket via the Binder IPC system, using objects known as Parcels. Parcels are simply flattened, serialized data structures. libbinder exists for C++ in glue/gonk/frameworks.
The glue/gonk stuff are compatibility libraries from the boot2gecko project as I understand, they seem to have packaged the whole ril daemon actually, with their own compatibility stuff. I think packaging that might be fruitful, or at least using relevant parts from B2G.
@ollieparanoid I was aware of the content of the first quote but good job finding the second one :)
OK, after some brave (read dangerous) modifications of Header files I am down to these few error:
ril.cpp:4134:26: error: invalid type argument of unary '*' (have 'int')
ril.cpp:4135:32: error: invalid type argument of unary '*' (have 'int')
ril.cpp:4138:28: error: 'int RilSocket::commandFd' is protected within this context
ril.cpp:4139:34: error: 'int RilSocket::listenFd' is protected within this context
Does someone see what might be the problem?
Should I try to modify the code itself acording to stack-overflow examples?
+1 for modifying the code more. as stated earlier, we can make it pretty once it is working 馃槃
Pushed it here https://github.com/postmarketOS/pmbootstrap/pull/807 to keep track. But I have some problem applying one patch -> atomic.h does anyone see whats wrong?
Binder is also in mainline so non android kernels would work.
@opendata26 but a bunch of binder stuff (eg binder/Parcel.h) is not in the kernel but in userspace.
I think someone mentioned, that android-rild was packaged for Debian (or any other distribution would also be fine). Does anyone have a link?
reading more into how Boot2Gecko did things
From reading their architecture wiki page, it looks like B2G didn't package/use AOSP ril code at all. I think they only run the proprietary ril daemon from the vendor, and use their own code to talk to the daemon (with a version of binder nevertheless).
If someone is interested in looking into this more, I suggest kindly asking people from the B2G project if they have an idea how we could implement this and make it work with ofono.
I didn't find THAT but I found https://github.com/morphis/rild-launcher , maybe it could be interesting, but no idea what it actually is
Most helpful comment
I didn't find THAT but I found https://github.com/morphis/rild-launcher , maybe it could be interesting, but no idea what it actually is