Implement RPC for window state synchronization

This commit is contained in:
Simon Fels 2016-11-15 07:54:19 +01:00
commit 0f5006493b
11 changed files with 89 additions and 78 deletions

View file

@ -55,7 +55,7 @@ void PlatformApiStub::handle_boot_finished_response(Request<protobuf::rpc::Void>
boot_finished_wait_handle_.result_received(); boot_finished_wait_handle_.result_received();
} }
void PlatformApiStub::update_window_state() { void PlatformApiStub::update_window_state(const anbox::protobuf::bridge::WindowStateUpdate &window_state) {
auto c = std::make_shared<Request<protobuf::rpc::Void>>(); auto c = std::make_shared<Request<protobuf::rpc::Void>>();
ALOGI("Updating window state"); ALOGI("Updating window state");
@ -65,11 +65,9 @@ void PlatformApiStub::update_window_state() {
update_window_state_wait_handle_.expect_result(); update_window_state_wait_handle_.expect_result();
} }
protobuf::rpc::Void message;
rpc_channel_->call_method( rpc_channel_->call_method(
"update_window_state", "update_window_state",
&message, c->response.get(), &window_state, c->response.get(),
google::protobuf::NewCallback(this, &PlatformApiStub::handle_update_window_state_response, c.get())); google::protobuf::NewCallback(this, &PlatformApiStub::handle_update_window_state_response, c.get()));
update_window_state_wait_handle_.wait_for_all(); update_window_state_wait_handle_.wait_for_all();
@ -78,28 +76,4 @@ void PlatformApiStub::update_window_state() {
void PlatformApiStub::handle_update_window_state_response(Request<protobuf::rpc::Void> *request) { void PlatformApiStub::handle_update_window_state_response(Request<protobuf::rpc::Void> *request) {
update_window_state_wait_handle_.result_received(); update_window_state_wait_handle_.result_received();
} }
void PlatformApiStub::remove_window() {
auto c = std::make_shared<Request<protobuf::rpc::Void>>();
ALOGI("Remove window");
{
std::lock_guard<decltype(mutex_)> 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<protobuf::rpc::Void> *request) {
update_window_state_wait_handle_.result_received();
}
} // namespace anbox } // namespace anbox

View file

@ -26,7 +26,11 @@ namespace anbox {
namespace protobuf { namespace protobuf {
namespace rpc { namespace rpc {
class Void; class Void;
class WindowStateUpdate;
} // namespace rpc } // namespace rpc
namespace bridge {
class WindowStateUpdate;
} // namespace bridge
} // namespace protobuf } // namespace protobuf
namespace rpc { namespace rpc {
class Channel; class Channel;
@ -36,8 +40,7 @@ public:
PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel); PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel);
void boot_finished(); void boot_finished();
void update_window_state(); void update_window_state(const anbox::protobuf::bridge::WindowStateUpdate &window_state);
void remove_window();
private: private:
template<typename Response> template<typename Response>
@ -49,12 +52,10 @@ private:
void handle_boot_finished_response(Request<protobuf::rpc::Void> *request); void handle_boot_finished_response(Request<protobuf::rpc::Void> *request);
void handle_update_window_state_response(Request<protobuf::rpc::Void> *request); void handle_update_window_state_response(Request<protobuf::rpc::Void> *request);
void handle_remove_window_response(Request<protobuf::rpc::Void> *request);
mutable std::mutex mutex_; mutable std::mutex mutex_;
common::WaitHandle boot_finished_wait_handle_; common::WaitHandle boot_finished_wait_handle_;
common::WaitHandle update_window_state_wait_handle_; common::WaitHandle update_window_state_wait_handle_;
common::WaitHandle remove_window_wait_handle_;
std::shared_ptr<rpc::Channel> rpc_channel_; std::shared_ptr<rpc::Channel> rpc_channel_;
}; };

View file

@ -19,9 +19,14 @@
#include "android/service/platform_api_stub.h" #include "android/service/platform_api_stub.h"
#include "anbox/rpc/channel.h" #include "anbox/rpc/channel.h"
#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h"
#define LOG_TAG "Anboxd" #define LOG_TAG "Anboxd"
#include <cutils/log.h> #include <cutils/log.h>
#include <utils/String8.h>
using namespace android; using namespace android;
namespace android { namespace android {
@ -34,13 +39,50 @@ status_t PlatformService::boot_finished() {
return OK; return OK;
} }
status_t PlatformService::update_window_state() { void PlatformService::unpack_window_state(anbox::protobuf::bridge::WindowStateUpdate_WindowState *window, const Parcel &data) {
platform_api_stub_->update_window_state(); window->set_has_surface(data.readByte() != 0);
return OK;
String8 package_name(data.readString16());
auto frame_left = data.readInt32();
auto frame_top = data.readInt32();
auto frame_right = data.readInt32();
auto frame_bottom = data.readInt32();
auto task_id = data.readInt32();
auto stack_id = data.readInt32();
window->set_package_name(package_name.string());
window->set_frame_left(frame_left);
window->set_frame_top(frame_top);
window->set_frame_right(frame_right);
window->set_frame_bottom(frame_bottom);
window->set_task_id(task_id);
window->set_stack_id(stack_id);
} }
status_t PlatformService::remove_window() { status_t PlatformService::update_window_state(const Parcel &data) {
platform_api_stub_->remove_window(); anbox::protobuf::bridge::WindowStateUpdate window_state;
const auto num_displays = data.readInt32();
for (auto n = 0; n < num_displays; n++) {
const auto display_id = data.readInt32();
for (auto m = 0; m < num_windows; m++) {
auto window = window_state.add_windows();
window->set_display_id(display_id);
unpack_window_state(window, data);
}
}
const auto num_removed_windows = data.readInt32();
for (auto n = 0; n < num_removed_windows; n++) {
auto window = window_state.add_removed_windows();
window->set_display_id(0);
unpack_window_state(window, data);
}
platform_api_stub_->update_window_state(window_state);
return OK; return OK;
} }
} // namespace android } // namespace android

View file

@ -20,10 +20,17 @@
#include "android/service/platform_service_interface.h" #include "android/service/platform_service_interface.h"
#include <binder/Parcel.h>
#include <memory> #include <memory>
namespace anbox { namespace anbox {
class PlatformApiStub; class PlatformApiStub;
namespace protobuf {
namespace bridge {
class WindowStateUpdate_WindowState;
} // namespace bridge
} // namespace protobuf
} // namespace anbox } // namespace anbox
namespace android { namespace android {
@ -34,10 +41,10 @@ public:
PlatformService(const std::shared_ptr<anbox::PlatformApiStub> &platform_api_stub); PlatformService(const std::shared_ptr<anbox::PlatformApiStub> &platform_api_stub);
status_t boot_finished() override; status_t boot_finished() override;
status_t update_window_state() override; status_t update_window_state(const Parcel &data) override;
status_t remove_window() override;
private: private:
void unpack_window_state(anbox::protobuf::bridge::WindowStateUpdate_WindowState *window, const Parcel &data);
std::shared_ptr<anbox::PlatformApiStub> platform_api_stub_; std::shared_ptr<anbox::PlatformApiStub> platform_api_stub_;
}; };
} // namespace android } // namespace android

View file

@ -28,18 +28,12 @@ status_t BpPlatformService::boot_finished() {
return remote()->transact(IPlatformService::BOOT_FINISHED, data, &reply); return remote()->transact(IPlatformService::BOOT_FINISHED, data, &reply);
} }
status_t BpPlatformService::update_window_state() { status_t BpPlatformService::update_window_state(const Parcel&) {
Parcel data, reply; Parcel data, reply;
data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor()); data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor());
return remote()->transact(IPlatformService::UPDATE_WINDOW_STATE, data, &reply); 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"); IMPLEMENT_META_INTERFACE(PlatformService, "org.anbox.IPlatformService");
status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data, status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data,
@ -50,10 +44,7 @@ status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data,
return boot_finished(); return boot_finished();
case UPDATE_WINDOW_STATE: case UPDATE_WINDOW_STATE:
CHECK_INTERFACE(IPlatformService, data, reply); CHECK_INTERFACE(IPlatformService, data, reply);
return update_window_state(); return update_window_state(data);
case REMOVE_WINDOW:
CHECK_INTERFACE(IPlatformService, data, reply);
return remove_window();
default: default:
break; break;
} }

View file

@ -33,14 +33,13 @@ public:
DECLARE_META_INTERFACE(PlatformService); DECLARE_META_INTERFACE(PlatformService);
enum { enum {
// Keep this synchronized with frameworks/base/services/java/com/android/server/wm/AnboxPlatformServiceProxy.java
BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
UPDATE_WINDOW_STATE = IBinder::FIRST_CALL_TRANSACTION + 1, UPDATE_WINDOW_STATE = IBinder::FIRST_CALL_TRANSACTION + 1,
REMOVE_WINDOW = IBinder::FIRST_CALL_TRANSACTION + 2,
}; };
virtual status_t boot_finished() = 0; virtual status_t boot_finished() = 0;
virtual status_t update_window_state() = 0; virtual status_t update_window_state(const Parcel &data) = 0;
virtual status_t remove_window() = 0;
}; };
class BpPlatformService : public BpInterface<IPlatformService> { class BpPlatformService : public BpInterface<IPlatformService> {
@ -48,8 +47,7 @@ public:
BpPlatformService(const sp<IBinder> &binder); BpPlatformService(const sp<IBinder> &binder);
status_t boot_finished() override; status_t boot_finished() override;
status_t update_window_state() override; status_t update_window_state(const Parcel &data) override;
status_t remove_window() override;
}; };
class BnPlatformService : public BnInterface<IPlatformService> { class BnPlatformService : public BnInterface<IPlatformService> {

View file

@ -33,6 +33,7 @@ class Void;
} // namespace rpc } // namespace rpc
namespace bridge { namespace bridge {
class Notification; class Notification;
class WindowStateUpdate;
} // namespace bridge } // namespace bridge
} // namespace protobuf } // namespace protobuf
namespace rpc { namespace rpc {
@ -48,14 +49,10 @@ public:
anbox::protobuf::rpc::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) = 0; google::protobuf::Closure *done) = 0;
virtual void update_window_state(anbox::protobuf::rpc::Void const *request, virtual void update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) = 0; 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: private:
std::shared_ptr<rpc::PendingCallCache> pending_calls_; std::shared_ptr<rpc::PendingCallCache> pending_calls_;
}; };

View file

@ -38,8 +38,6 @@ void PlatformMessageProcessor::dispatch(rpc::Invocation const& invocation) {
invoke(this, server_.get(), &PlatformApiSkeleton::boot_finished, invocation); invoke(this, server_.get(), &PlatformApiSkeleton::boot_finished, invocation);
else if (invocation.method_name() == "update_window_state") else if (invocation.method_name() == "update_window_state")
invoke(this, server_.get(), &PlatformApiSkeleton::update_window_state, invocation); 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&) { void PlatformMessageProcessor::process_event_sequence(const std::string&) {

View file

@ -26,3 +26,19 @@ message SetDnsServers {
} }
repeated Server servers = 2; repeated Server servers = 2;
} }
message WindowStateUpdate {
message WindowState {
required int32 display_id = 1;
required bool has_surface = 2;
required string package_name = 3;
required int32 frame_left = 4;
required int32 frame_top = 5;
required int32 frame_right = 6;
required int32 frame_bottom = 7;
required int32 task_id = 8;
required int32 stack_id = 9;
}
repeated WindowState windows = 1;
repeated WindowState removed_windows = 2;
}

View file

@ -45,7 +45,7 @@ void PlatformApiSekeleton::boot_finished(anbox::protobuf::rpc::Void const *reque
done->Run(); done->Run();
} }
void PlatformApiSekeleton::update_window_state(anbox::protobuf::rpc::Void const *request, void PlatformApiSekeleton::update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) { google::protobuf::Closure *done) {
(void) request; (void) request;
@ -53,16 +53,6 @@ void PlatformApiSekeleton::update_window_state(anbox::protobuf::rpc::Void const
DEBUG(""); 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(); done->Run();
} }

View file

@ -26,6 +26,7 @@ class Dispatcher;
} // namespace common } // namespace common
namespace bridge { namespace bridge {
class AndroidApiStub; class AndroidApiStub;
class WindowStateUpdate;
} // namespace bridge } // namespace bridge
namespace rpc { namespace rpc {
class PendingCallCache; class PendingCallCache;
@ -40,14 +41,10 @@ public:
anbox::protobuf::rpc::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) override; google::protobuf::Closure *done) override;
void update_window_state(anbox::protobuf::rpc::Void const *request, void update_window_state(anbox::protobuf::bridge::WindowStateUpdate const *request,
anbox::protobuf::rpc::Void *response, anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) override; google::protobuf::Closure *done) override;
void remove_window(anbox::protobuf::rpc::Void const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) override;
void on_boot_finished(const std::function<void()> &action); void on_boot_finished(const std::function<void()> &action);
private: private: