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,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