From 324407eeaa6f1a171cde32e8f561f9785743c155 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Wed, 21 Dec 2016 08:39:21 +0100 Subject: [PATCH] Allow clients to specify the launch bounds of a new activity --- android/service/android_api_skeleton.cpp | 15 +++++++++++++-- src/anbox/application_manager.h | 3 ++- src/anbox/bridge/android_api_stub.cpp | 11 ++++++++++- src/anbox/bridge/android_api_stub.h | 3 ++- src/anbox/dbus/skeleton/application_manager.cpp | 13 ++++++++++--- src/anbox/dbus/skeleton/application_manager.h | 2 +- src/anbox/dbus/stub/application_manager.cpp | 5 +++-- src/anbox/dbus/stub/application_manager.h | 2 +- src/anbox/protobuf/anbox_bridge.proto | 1 + 9 files changed, 43 insertions(+), 12 deletions(-) diff --git a/android/service/android_api_skeleton.cpp b/android/service/android_api_skeleton.cpp index 03ae1c7..29fc40a 100644 --- a/android/service/android_api_skeleton.cpp +++ b/android/service/android_api_skeleton.cpp @@ -28,6 +28,7 @@ #include #include +#include namespace { std::map common_env = { @@ -48,9 +49,9 @@ void AndroidApiSkeleton::wait_for_process(core::posix::ChildProcess &process, const auto result = process.wait_for(core::posix::wait::Flags::untraced); if (result.status != core::posix::wait::Result::Status::exited || result.detail.if_exited.status != core::posix::exit::Status::success) { - response->set_error("Failed to install application"); + response->set_error("Failed to execute process"); // FIXME once we add proper error codes/domains we need to add structured error - // info the response here. + // info to the response here. } } @@ -76,6 +77,16 @@ void AndroidApiSkeleton::launch_application(anbox::protobuf::bridge::LaunchAppli "--stack", "2", }; + if (request->has_launch_bounds()) { + argv.push_back("--launch-bounds"); + std::stringstream launch_bounds; + launch_bounds << request->launch_bounds().left() << " " + << request->launch_bounds().top() << " " + << request->launch_bounds().right() << " " + << request->launch_bounds().bottom(); + argv.push_back(launch_bounds.str()); + } + if (intent.has_action()) { argv.push_back("-a"); argv.push_back(intent.action()); diff --git a/src/anbox/application_manager.h b/src/anbox/application_manager.h index 577ff09..f67e45a 100644 --- a/src/anbox/application_manager.h +++ b/src/anbox/application_manager.h @@ -19,6 +19,7 @@ #define ANBOX_APPLICATION_MANAGER_H_ #include "anbox/android/intent.h" +#include "anbox/graphics/rect.h" #include "anbox/do_not_copy_or_move.h" #include @@ -26,7 +27,7 @@ namespace anbox { class ApplicationManager : public DoNotCopyOrMove { public: - virtual void launch(const android::Intent &intent) = 0; + virtual void launch(const android::Intent &intent, const graphics::Rect &launch_bounds = graphics::Rect::Invalid) = 0; }; } // namespace anbox diff --git a/src/anbox/bridge/android_api_stub.cpp b/src/anbox/bridge/android_api_stub.cpp index 2b7892d..30a9854 100644 --- a/src/anbox/bridge/android_api_stub.cpp +++ b/src/anbox/bridge/android_api_stub.cpp @@ -45,7 +45,8 @@ void AndroidApiStub::ensure_rpc_channel() { if (!channel_) throw std::runtime_error("No remote client connected"); } -void AndroidApiStub::launch(const android::Intent &intent) { +void AndroidApiStub::launch(const android::Intent &intent, + const graphics::Rect &launch_bounds) { ensure_rpc_channel(); auto c = std::make_shared>(); @@ -56,6 +57,14 @@ void AndroidApiStub::launch(const android::Intent &intent) { launch_wait_handle_.expect_result(); } + if (launch_bounds != graphics::Rect::Invalid) { + auto rect = message.mutable_launch_bounds(); + rect->set_left(launch_bounds_.left()); + rect->set_top(launch_bounds_.top()); + rect->set_right(launch_bounds_.right()); + rect->set_bottom(launch_bounds_.bottom()); + } + auto launch_intent = message.mutable_intent(); if (!intent.action.empty()) launch_intent->set_action(intent.action); diff --git a/src/anbox/bridge/android_api_stub.h b/src/anbox/bridge/android_api_stub.h index 81d154f..35d7eab 100644 --- a/src/anbox/bridge/android_api_stub.h +++ b/src/anbox/bridge/android_api_stub.h @@ -43,7 +43,7 @@ class AndroidApiStub : public anbox::ApplicationManager { void set_rpc_channel(const std::shared_ptr &channel); void reset_rpc_channel(); - void launch(const android::Intent &intent) override; + void launch(const android::Intent &intent, const graphics::Rect &launch_bounds = graphics::Rect::Invalid) override; void set_focused_task(const std::int32_t &id); void remove_task(const std::int32_t &id); @@ -71,6 +71,7 @@ class AndroidApiStub : public anbox::ApplicationManager { common::WaitHandle set_focused_task_handle_; common::WaitHandle remove_task_handle_; common::WaitHandle resize_task_handle_; + graphics::Rect launch_bounds_ = graphics::Rect::Invalid; }; } // namespace bridge } // namespace anbox diff --git a/src/anbox/dbus/skeleton/application_manager.cpp b/src/anbox/dbus/skeleton/application_manager.cpp index 2b5e3bc..563c6fa 100644 --- a/src/anbox/dbus/skeleton/application_manager.cpp +++ b/src/anbox/dbus/skeleton/application_manager.cpp @@ -40,10 +40,17 @@ ApplicationManager::ApplicationManager( reader >> intent.package; reader >> intent.component; + std::int32_t left, top, right, bottom; + reader >> left; + reader >> top; + reader >> right; + reader >> bottom; + graphics::Rect launch_bounds{left,top,right,bottom}; + core::dbus::Message::Ptr reply; try { - launch(intent); + launch(intent, launch_bounds); reply = core::dbus::Message::make_method_return(msg); } catch (std::exception const &err) { reply = core::dbus::Message::make_error(msg, "org.anbox.Error.Failed", @@ -56,8 +63,8 @@ ApplicationManager::ApplicationManager( ApplicationManager::~ApplicationManager() {} -void ApplicationManager::launch(const android::Intent &intent) { - impl_->launch(intent); +void ApplicationManager::launch(const android::Intent &intent, const graphics::Rect &launch_bounds) { + impl_->launch(intent, launch_bounds); } } // namespace skeleton } // namespace dbus diff --git a/src/anbox/dbus/skeleton/application_manager.h b/src/anbox/dbus/skeleton/application_manager.h index af45ddd..03c5e40 100644 --- a/src/anbox/dbus/skeleton/application_manager.h +++ b/src/anbox/dbus/skeleton/application_manager.h @@ -34,7 +34,7 @@ class ApplicationManager : public anbox::ApplicationManager { const std::shared_ptr &impl); ~ApplicationManager(); - void launch(const android::Intent &intent) override; + void launch(const android::Intent &intent, const graphics::Rect &launch_bounds = graphics::Rect::Invalid) override; private: core::dbus::Bus::Ptr bus_; diff --git a/src/anbox/dbus/stub/application_manager.cpp b/src/anbox/dbus/stub/application_manager.cpp index 06c548a..ca395dd 100644 --- a/src/anbox/dbus/stub/application_manager.cpp +++ b/src/anbox/dbus/stub/application_manager.cpp @@ -38,12 +38,13 @@ ApplicationManager::ApplicationManager(const core::dbus::Bus::Ptr &bus, ApplicationManager::~ApplicationManager() {} -void ApplicationManager::launch(const android::Intent &intent) { +void ApplicationManager::launch(const android::Intent &intent, const graphics::Rect &launch_bounds) { auto result = object_->invoke_method_synchronously< anbox::dbus::interface::ApplicationManager::Methods::Launch, anbox::dbus::interface::ApplicationManager::Methods::Launch::ResultType>( intent.action, intent.uri, intent.type, intent.flags, intent.package, - intent.component); + intent.component, launch_bounds.left(), launch_bounds.top(), + launch_bounds.right(), launch_bounds.bottom()); if (result.is_error()) throw std::runtime_error(result.error().print()); } diff --git a/src/anbox/dbus/stub/application_manager.h b/src/anbox/dbus/stub/application_manager.h index 6042409..ee85917 100644 --- a/src/anbox/dbus/stub/application_manager.h +++ b/src/anbox/dbus/stub/application_manager.h @@ -37,7 +37,7 @@ class ApplicationManager : public anbox::ApplicationManager { const core::dbus::Object::Ptr &object); ~ApplicationManager(); - void launch(const android::Intent &intent) override; + void launch(const android::Intent &intent, const graphics::Rect &launch_bounds = graphics::Rect::Invalid) override; private: core::dbus::Bus::Ptr bus_; diff --git a/src/anbox/protobuf/anbox_bridge.proto b/src/anbox/protobuf/anbox_bridge.proto index 239e10d..2bbb600 100644 --- a/src/anbox/protobuf/anbox_bridge.proto +++ b/src/anbox/protobuf/anbox_bridge.proto @@ -33,6 +33,7 @@ message Notification { message LaunchApplication { required Intent intent = 1; + optional Rect launch_bounds = 2; } message SetFocusedTask {