Implement RPC commands on the Android side
This commit is contained in:
parent
ed23744a17
commit
d7c73bf766
7 changed files with 94 additions and 5 deletions
|
|
@ -9,8 +9,12 @@ LOCAL_SRC_FILES := \
|
|||
external/process-cpp-minimal/src/core/posix/signal.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/signalable.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/standard_stream.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/wait.cpp
|
||||
external/process-cpp-minimal/src/core/posix/wait.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/fork.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/exec.cpp \
|
||||
external/process-cpp-minimal/src/core/posix/child_process.cpp
|
||||
LOCAL_CFLAGS := \
|
||||
-DANDROID \
|
||||
-fexceptions
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(LOCAL_PATH)/external/process-cpp-minimal/include
|
||||
|
|
@ -26,11 +30,12 @@ LOCAL_SRC_FILES := \
|
|||
android/service/host_connector.cpp \
|
||||
android/service/local_socket_connection.cpp \
|
||||
android/service/message_processor.cpp \
|
||||
android/service/server.cpp \
|
||||
src/anbox/common/fd.cpp \
|
||||
src/anbox/bridge/message_processor.cpp \
|
||||
src/anbox/bridge/pending_call_cache.cpp \
|
||||
src/anbox/bridge/rpc_channel.cpp \
|
||||
src/anbox/protobuf/bridge.proto
|
||||
src/anbox/protobuf/anbox_bridge.proto
|
||||
proto_header_dir := $(call local-generated-sources-dir)/proto/$(LOCAL_PATH)/src/anbox/protobuf
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(proto_header_dir) \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ public:
|
|||
*/
|
||||
wait::Result wait_for(const wait::Flags& flags);
|
||||
|
||||
#ifndef ANDROID
|
||||
/**
|
||||
* @brief Access this process's stderr.
|
||||
*/
|
||||
|
|
@ -128,6 +129,7 @@ public:
|
|||
* @brief Access this process's stdout.
|
||||
*/
|
||||
std::istream& cout();
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend ChildProcess fork(const std::function<posix::exit::Status()>&, const StandardStream&);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@
|
|||
|
||||
#include <core/posix/child_process.h>
|
||||
|
||||
#ifndef ANDROID
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
|
|
@ -33,7 +35,13 @@
|
|||
#include <sys/eventfd.h>
|
||||
#include <sys/signalfd.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifndef ANDROID
|
||||
namespace io = boost::iostreams;
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -279,12 +287,14 @@ struct ChildProcess::Private
|
|||
const ChildProcess::Pipe& stdin,
|
||||
const ChildProcess::Pipe& stdout)
|
||||
: pipes{stderr, stdin, stdout},
|
||||
#ifndef ANDROID
|
||||
serr(pipes.stderr.read_fd(), io::never_close_handle),
|
||||
sin(pipes.stdin.write_fd(), io::never_close_handle),
|
||||
sout(pipes.stdout.read_fd(), io::never_close_handle),
|
||||
cerr(&serr),
|
||||
cin(&sin),
|
||||
cout(&sout),
|
||||
#endif
|
||||
original_parent_pid(::getpid()),
|
||||
original_child_pid(pid)
|
||||
{
|
||||
|
|
@ -308,12 +318,15 @@ struct ChildProcess::Private
|
|||
ChildProcess::Pipe stdout;
|
||||
ChildProcess::Pipe stderr;
|
||||
} pipes;
|
||||
|
||||
#ifndef ANDROID
|
||||
io::stream_buffer<io::file_descriptor_source> serr;
|
||||
io::stream_buffer<io::file_descriptor_sink> sin;
|
||||
io::stream_buffer<io::file_descriptor_source> sout;
|
||||
std::istream cerr;
|
||||
std::ostream cin;
|
||||
std::istream cout;
|
||||
#endif
|
||||
|
||||
// We need to store the original parent pid as we might have been forked
|
||||
// and with our automatic cleanup in place, it might happen that the d'tor
|
||||
|
|
@ -371,14 +384,18 @@ wait::Result ChildProcess::wait_for(const wait::Flags& flags)
|
|||
{
|
||||
result.status = wait::Result::Status::stopped;
|
||||
result.detail.if_stopped.signal = static_cast<Signal>(WSTOPSIG(status));
|
||||
} else if (WIFCONTINUED(status))
|
||||
}
|
||||
#ifndef ANDROID
|
||||
else if (WIFCONTINUED(status))
|
||||
{
|
||||
result.status = wait::Result::Status::continued;
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef ANDROID
|
||||
std::istream& ChildProcess::cerr()
|
||||
{
|
||||
return d->cerr;
|
||||
|
|
@ -393,5 +410,6 @@ std::istream& ChildProcess::cout()
|
|||
{
|
||||
return d->cout;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@
|
|||
#include <core/posix/exit.h>
|
||||
#include <core/posix/fork.h>
|
||||
|
||||
#ifndef ANDROID
|
||||
#include "backtrace.h"
|
||||
#endif
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
|
@ -38,12 +40,14 @@ void redirect_stream_to_fd(int fd, int stream)
|
|||
|
||||
void print_backtrace(std::ostream& out, const std::string& line_prefix)
|
||||
{
|
||||
#ifndef ANDROID
|
||||
core::posix::backtrace::visit_with_handler([&out, line_prefix](const core::posix::backtrace::Frame& frame)
|
||||
{
|
||||
out << line_prefix << std::dec << std::setw(2) << frame.depth() << "@" << std::hex << std::setw(14) << frame.frame_pointer() << ": "
|
||||
<< (frame.symbol().is_cxx() ? frame.symbol().demangled() : frame.symbol().raw()) << std::endl;
|
||||
return true;
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue