Implement RPC commands on the Android side

This commit is contained in:
Simon Fels 2016-06-28 19:46:35 +02:00
commit d7c73bf766
7 changed files with 94 additions and 5 deletions

View file

@ -19,3 +19,8 @@ target_link_libraries(anboxd
pthread
process-cpp
anbox-protobuf)
# As we're adding Android specific bits in this project we can't
# build this safely within default build anymore. We keep this
# for easy integration into used IDEs.
set_target_properties(anboxd
PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)

View file

@ -19,6 +19,16 @@
#include "anbox_bridge.pb.h"
#include <core/posix/exec.h>
#include <core/posix/child_process.h>
namespace {
std::map<std::string,std::string> common_env = {
{"ANDROID_DATA", "/data"},
{"ANDROID_ROOT", "/system"},
};
}
namespace anbox {
namespace android {
Server::Server() {
@ -30,20 +40,60 @@ Server::~Server() {
void Server::install_application(anbox::protobuf::bridge::InstallApplication const *request,
anbox::protobuf::bridge::Void *response,
google::protobuf::Closure *done) {
(void) request;
(void) response;
std::vector<std::string> argv = {
"/system/bin/pm",
"install",
request->path(),
};
auto process = core::posix::exec("/system/bin/sh", argv, common_env, core::posix::StandardStream::empty);
process.wait_for(core::posix::wait::Flags::untraced);
done->Run();
}
void Server::launch_application(anbox::protobuf::bridge::LaunchApplication const *request,
anbox::protobuf::bridge::Void *response,
google::protobuf::Closure *done) {
(void) request;
(void) response;
std::string intent = request->package_name();
intent += "/";
intent += request->activity();
std::vector<std::string> argv = {
"/system/bin/am",
"start",
intent,
};
auto process = core::posix::exec("/system/bin/sh", argv, common_env, core::posix::StandardStream::empty);
process.wait_for(core::posix::wait::Flags::untraced);
done->Run();
}
void Server::set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request,
anbox::protobuf::bridge::Void *response,
google::protobuf::Closure *done) {
(void) response;
std::vector<std::string> argv = {
"resolver",
"setnetdns",
"0",
request->domain(),
};
for (int n = 0; n < request->servers_size(); n++)
argv.push_back(request->servers(n).address());
auto process = core::posix::exec("/system/bin/ndc", argv, common_env, core::posix::StandardStream::empty);
process.wait_for(core::posix::wait::Flags::untraced);
done->Run();
}
} // namespace anbox
} // namespace network

View file

@ -29,6 +29,7 @@ namespace protobuf {
namespace bridge {
class InstallApplication;
class LaunchApplication;
class SetDnsServers;
class Void;
} // namespace bridge
} // namespace protobuf
@ -45,6 +46,10 @@ public:
void launch_application(anbox::protobuf::bridge::LaunchApplication const *request,
anbox::protobuf::bridge::Void *response,
google::protobuf::Closure *done);
void set_dns_servers(anbox::protobuf::bridge::SetDnsServers const *request,
anbox::protobuf::bridge::Void *response,
google::protobuf::Closure *done);
};
} // namespace android
} // namespace anbox