I would need to create C++ console application that runs under non-privileged user under Android 5 (rooted). This application listens on some socket port and accepts connections. It is implemented with boost::asio
. When application runs as a root, then everything works. When it runs as an ordinary user, then application crashes when it tries to open acceptor:
const boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 3784);
boost::asio::ip::tcp::acceptor acceptor(ioService);
acceptor.open(endpoint.protocol()); // Here it throws an exception
The exception is a bit confusing but probably it means that I don't have access rights to touch sockets:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): open: Permission denied
Aborted
I tried to run application under user shell
and under user media
. I also tried to run it under user u0_a83
, that is assigned to ProxyDroid
on my device.
I changed /system/etc/permissions/platform.xml
-- I assigned permission android.permission.INTERNET
to user shell
and media
. I also tried to add group media to android.permission.INTERNET
, but nothing has helped.
Btw. this is a special case when I really need to implement application in C++ to run under Android. Implementation in Java is not acceptable in my project.
It seems that the best solution is to use users that are predefined in Android and corresponds to capabilities available on the system: https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h . In my case I can run the app under user inet (3003) that can create sockets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.