Ensure that we have an valid intent before we launch it

This commit is contained in:
Simon Fels 2017-06-07 07:25:34 +02:00
commit edd8960009
6 changed files with 46 additions and 0 deletions

View file

@ -21,6 +21,12 @@
namespace anbox {
namespace android {
bool Intent::valid() const {
// At the moment we only support component+package for intents
// (see android/service/android_api_skeleton.cpp for more details)
return !(component.empty() && package.empty());
}
std::ostream &operator<<(std::ostream &out, const Intent &intent) {
out << "[";
if (!intent.action.empty())

View file

@ -31,6 +31,8 @@ struct Intent {
std::string package;
std::string component;
std::vector<std::string> categories;
bool valid() const;
};
std::ostream &operator<<(std::ostream &out, const Intent &intent);

View file

@ -79,6 +79,11 @@ anbox::cmds::Launch::Launch()
stack_));
action([this](const cli::Command::Context&) {
if (!intent_.valid()) {
ERROR("The intent you provided is invalid. Please provide a correct launch intent.");
return EXIT_FAILURE;
}
auto trap = core::posix::trap_signals_for_process({core::posix::Signal::sig_term, core::posix::Signal::sig_int});
trap->signal_raised().connect([trap](const core::posix::Signal& signal) {
INFO("Signal %i received. Good night.", static_cast<int>(signal));