In android, when you open a terminal emulator or connect an adb shell, there is a command service
that you can execute which allows you to interact with system services to some degree. For my purposes the functionality is too limited though and I would like to expand it a little.
Unfortunately this executable is not documented.
I have located the source code here: service.cpp
There is also a file called Android.bp in the same directory with the following content:
cc_binary {
name: "service",
srcs: ["service.cpp"],
shared_libs: [
"libcutils",
"libutils",
"libbinder",
],
cflags: [
"-DXP_UNIX",
"-Wall",
"-Werror",
],
}
cc_binary {
name: "vndservice",
proprietary: true,
srcs: ["service.cpp"],
shared_libs: [
"libcutils",
"libutils",
"libbinder",
],
cflags: [
"-DXP_UNIX",
"-DVENDORSERVICES",
"-Wall",
"-Werror",
],
}
Those cflags look like g++ flags to me. I don’t really know g++, but after a lot of trial and error I ended up with this:
# Download required source code
git clone https://android.googlesource.com/platform/superproject
cd superproject
git submodule init
git submodule update frameworks/native
git submodule update system/libbase
git submodule update system/core
git submodule update system/logging
# Set required include directories in CPATH
export CPATH="./frameworks/native/include:./system/libbase/include:./system/core/libcutils/include:./system/core/libutils/include:./system/logging/liblog/include:./system/core/libsystem/include:./frameworks/native/libs/binder/include"
# Build
g++ -DXP_UNIX -Wall -Werror -o service ./frameworks/native/cmds/service/service.cpp
Unfortunately I get a massive amount of errors:
https://pastebin.com/fnu7LJLU
My G++ version is:
g++ (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Any ideas why this is failing?
Source: Windows Questions C++