From 6ee8734cf380de44a5b3081d8ec7ae01fb121ca3 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Fri, 11 Nov 2016 09:41:10 +0100 Subject: [PATCH] Add first stub methods to send window status updates from Android to host --- android/service/platform_api_stub.cpp | 49 ++++++++++++++++++- android/service/platform_api_stub.h | 6 +++ android/service/platform_service.cpp | 10 ++++ android/service/platform_service.h | 4 +- .../service/platform_service_interface.cpp | 20 +++++++- android/service/platform_service_interface.h | 6 +++ src/anbox/bridge/platform_api_skeleton.h | 6 ++- .../bridge/platform_message_processor.cpp | 8 +-- src/anbox/ubuntu/platform_api_skeleton.cpp | 31 ++++++++---- src/anbox/ubuntu/platform_api_skeleton.h | 8 ++- 10 files changed, 130 insertions(+), 18 deletions(-) diff --git a/android/service/platform_api_stub.cpp b/android/service/platform_api_stub.cpp index 373df0f..289c859 100644 --- a/android/service/platform_api_stub.cpp +++ b/android/service/platform_api_stub.cpp @@ -52,7 +52,54 @@ void PlatformApiStub::boot_finished() { } void PlatformApiStub::handle_boot_finished_response(Request*) { - ALOGI("handle_boot_finished_response"); boot_finished_wait_handle_.result_received(); } + +void PlatformApiStub::update_window_state() { + auto c = std::make_shared>(); + + ALOGI("Updating window state"); + + { + std::lock_guard lock(mutex_); + update_window_state_wait_handle_.expect_result(); + } + + protobuf::rpc::Void message; + + rpc_channel_->call_method( + "update_window_state", + &message, c->response.get(), + google::protobuf::NewCallback(this, &PlatformApiStub::handle_update_window_state_response, c.get())); + + update_window_state_wait_handle_.wait_for_all(); +} + +void PlatformApiStub::handle_update_window_state_response(Request *request) { + update_window_state_wait_handle_.result_received(); +} + +void PlatformApiStub::remove_window() { + auto c = std::make_shared>(); + + ALOGI("Remove window"); + + { + std::lock_guard lock(mutex_); + remove_window_wait_handle_.expect_result(); + } + + protobuf::rpc::Void message; + + rpc_channel_->call_method( + "remove_window", + &message, c->response.get(), + google::protobuf::NewCallback(this, &PlatformApiStub::handle_remove_window_response, c.get())); + + remove_window_wait_handle_.wait_for_all(); +} + +void PlatformApiStub::handle_remove_window_response(Request *request) { + update_window_state_wait_handle_.result_received(); +} } // namespace anbox diff --git a/android/service/platform_api_stub.h b/android/service/platform_api_stub.h index a18bc55..02271ba 100644 --- a/android/service/platform_api_stub.h +++ b/android/service/platform_api_stub.h @@ -36,6 +36,8 @@ public: PlatformApiStub(const std::shared_ptr &rpc_channel); void boot_finished(); + void update_window_state(); + void remove_window(); private: template @@ -46,9 +48,13 @@ private: }; void handle_boot_finished_response(Request *request); + void handle_update_window_state_response(Request *request); + void handle_remove_window_response(Request *request); mutable std::mutex mutex_; common::WaitHandle boot_finished_wait_handle_; + common::WaitHandle update_window_state_wait_handle_; + common::WaitHandle remove_window_wait_handle_; std::shared_ptr rpc_channel_; }; diff --git a/android/service/platform_service.cpp b/android/service/platform_service.cpp index 78d45d0..858708f 100644 --- a/android/service/platform_service.cpp +++ b/android/service/platform_service.cpp @@ -33,4 +33,14 @@ status_t PlatformService::boot_finished() { platform_api_stub_->boot_finished(); return OK; } + +status_t PlatformService::update_window_state() { + platform_api_stub_->update_window_state(); + return OK; +} + +status_t PlatformService::remove_window() { + platform_api_stub_->remove_window(); + return OK; +} } // namespace android diff --git a/android/service/platform_service.h b/android/service/platform_service.h index 6fff224..cf07a17 100644 --- a/android/service/platform_service.h +++ b/android/service/platform_service.h @@ -29,11 +29,13 @@ class PlatformApiStub; namespace android { class PlatformService : public BnPlatformService { public: - static const char* service_name() { return "anbox.PlatformService"; } + static const char* service_name() { return "org.anbox.PlatformService"; } PlatformService(const std::shared_ptr &platform_api_stub); status_t boot_finished() override; + status_t update_window_state() override; + status_t remove_window() override; private: std::shared_ptr platform_api_stub_; diff --git a/android/service/platform_service_interface.cpp b/android/service/platform_service_interface.cpp index f523738..14e83cd 100644 --- a/android/service/platform_service_interface.cpp +++ b/android/service/platform_service_interface.cpp @@ -28,7 +28,19 @@ status_t BpPlatformService::boot_finished() { return remote()->transact(IPlatformService::BOOT_FINISHED, data, &reply); } -IMPLEMENT_META_INTERFACE(PlatformService, "anbox.IPlatformService"); +status_t BpPlatformService::update_window_state() { + Parcel data, reply; + data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor()); + return remote()->transact(IPlatformService::UPDATE_WINDOW_STATE, data, &reply); +} + +status_t BpPlatformService::remove_window() { + Parcel data, reply; + data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor()); + return remote()->transact(IPlatformService::REMOVE_WINDOW, data, &reply); +} + +IMPLEMENT_META_INTERFACE(PlatformService, "org.anbox.IPlatformService"); status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { @@ -36,6 +48,12 @@ status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data, case BOOT_FINISHED: CHECK_INTERFACE(IPlatformService, data, reply); return boot_finished(); + case UPDATE_WINDOW_STATE: + CHECK_INTERFACE(IPlatformService, data, reply); + return update_window_state(); + case REMOVE_WINDOW: + CHECK_INTERFACE(IPlatformService, data, reply); + return remove_window(); default: break; } diff --git a/android/service/platform_service_interface.h b/android/service/platform_service_interface.h index 0a6c75a..343354e 100644 --- a/android/service/platform_service_interface.h +++ b/android/service/platform_service_interface.h @@ -34,9 +34,13 @@ public: enum { BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, + UPDATE_WINDOW_STATE = IBinder::FIRST_CALL_TRANSACTION + 1, + REMOVE_WINDOW = IBinder::FIRST_CALL_TRANSACTION + 2, }; virtual status_t boot_finished() = 0; + virtual status_t update_window_state() = 0; + virtual status_t remove_window() = 0; }; class BpPlatformService : public BpInterface { @@ -44,6 +48,8 @@ public: BpPlatformService(const sp &binder); status_t boot_finished() override; + status_t update_window_state() override; + status_t remove_window() override; }; class BnPlatformService : public BnInterface { diff --git a/src/anbox/bridge/platform_api_skeleton.h b/src/anbox/bridge/platform_api_skeleton.h index aafe417..b07c5d6 100644 --- a/src/anbox/bridge/platform_api_skeleton.h +++ b/src/anbox/bridge/platform_api_skeleton.h @@ -48,10 +48,14 @@ public: anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) = 0; - virtual void handle_notification(anbox::protobuf::bridge::Notification const *request, + virtual void update_window_state(anbox::protobuf::rpc::Void const *request, anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) = 0; + virtual void remove_window(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) = 0; + private: std::shared_ptr pending_calls_; }; diff --git a/src/anbox/bridge/platform_message_processor.cpp b/src/anbox/bridge/platform_message_processor.cpp index 599a3cb..bfe7e42 100644 --- a/src/anbox/bridge/platform_message_processor.cpp +++ b/src/anbox/bridge/platform_message_processor.cpp @@ -34,10 +34,12 @@ PlatformMessageProcessor::~PlatformMessageProcessor() { } void PlatformMessageProcessor::dispatch(rpc::Invocation const& invocation) { - if (invocation.method_name() == "handle_notification") - invoke(this, server_.get(), &PlatformApiSkeleton::handle_notification, invocation); - else if (invocation.method_name() == "boot_finished") + if (invocation.method_name() == "boot_finished") invoke(this, server_.get(), &PlatformApiSkeleton::boot_finished, invocation); + else if (invocation.method_name() == "update_window_state") + invoke(this, server_.get(), &PlatformApiSkeleton::update_window_state, invocation); + else if (invocation.method_name() == "remove_window") + invoke(this, server_.get(), &PlatformApiSkeleton::remove_window, invocation); } void PlatformMessageProcessor::process_event_sequence(const std::string&) { diff --git a/src/anbox/ubuntu/platform_api_skeleton.cpp b/src/anbox/ubuntu/platform_api_skeleton.cpp index d7645cd..5cf0261 100644 --- a/src/anbox/ubuntu/platform_api_skeleton.cpp +++ b/src/anbox/ubuntu/platform_api_skeleton.cpp @@ -33,15 +33,6 @@ PlatformApiSekeleton::PlatformApiSekeleton(const std::shared_ptrRun(); -} - void PlatformApiSekeleton::boot_finished(anbox::protobuf::rpc::Void const *request, anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) { @@ -54,6 +45,28 @@ void PlatformApiSekeleton::boot_finished(anbox::protobuf::rpc::Void const *reque done->Run(); } +void PlatformApiSekeleton::update_window_state(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) { + (void) request; + (void) response; + + DEBUG(""); + + done->Run(); +} + +void PlatformApiSekeleton::remove_window(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) { + (void) request; + (void) response; + + DEBUG(""); + + done->Run(); +} + void PlatformApiSekeleton::on_boot_finished(const std::function &action) { on_boot_finished_action_ = action; } diff --git a/src/anbox/ubuntu/platform_api_skeleton.h b/src/anbox/ubuntu/platform_api_skeleton.h index a00f391..5e33a71 100644 --- a/src/anbox/ubuntu/platform_api_skeleton.h +++ b/src/anbox/ubuntu/platform_api_skeleton.h @@ -36,11 +36,15 @@ public: PlatformApiSekeleton(const std::shared_ptr &pending_calls); virtual ~PlatformApiSekeleton(); - void handle_notification(anbox::protobuf::bridge::Notification const *request, + void boot_finished(anbox::protobuf::rpc::Void const *request, + anbox::protobuf::rpc::Void *response, + google::protobuf::Closure *done) override; + + void update_window_state(anbox::protobuf::rpc::Void const *request, anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) override; - void boot_finished(anbox::protobuf::rpc::Void const *request, + void remove_window(anbox::protobuf::rpc::Void const *request, anbox::protobuf::rpc::Void *response, google::protobuf::Closure *done) override;