Synchronize clipboard bi-directional with the android container
This commit is contained in:
parent
5512f79941
commit
db3499fd89
16 changed files with 213 additions and 4 deletions
|
|
@ -21,6 +21,9 @@
|
|||
#include "anbox_rpc.pb.h"
|
||||
#include "anbox_bridge.pb.h"
|
||||
|
||||
#define LOG_TAG "Anboxd"
|
||||
#include <cutils/log.h>
|
||||
|
||||
namespace anbox {
|
||||
PlatformApiStub::PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel) :
|
||||
rpc_channel_(rpc_channel) {
|
||||
|
|
@ -87,4 +90,55 @@ void PlatformApiStub::update_application_list(const ApplicationListUpdate &updat
|
|||
|
||||
rpc_channel_->send_event(seq);
|
||||
}
|
||||
|
||||
void PlatformApiStub::on_clipboard_data_set(Request<protobuf::rpc::Void> *request) {
|
||||
request->wh.result_received();
|
||||
}
|
||||
|
||||
void PlatformApiStub::set_clipboard_data(const ClipboardData &data) {
|
||||
auto c = std::make_shared<Request<protobuf::rpc::Void>>();
|
||||
|
||||
protobuf::bridge::ClipboardData message;
|
||||
message.set_text(data.text);
|
||||
|
||||
{
|
||||
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||
c->wh.expect_result();
|
||||
}
|
||||
|
||||
rpc_channel_->call_method("set_clipboard_data", &message, c->response.get(),
|
||||
google::protobuf::NewCallback(
|
||||
this, &PlatformApiStub::on_clipboard_data_set, c.get()));
|
||||
|
||||
c->wh.wait_for_all();
|
||||
|
||||
if (c->response->has_error()) throw std::runtime_error(c->response->error());
|
||||
}
|
||||
|
||||
void PlatformApiStub::on_clipboard_data_get(Request<protobuf::bridge::ClipboardData> *request) {
|
||||
request->wh.result_received();
|
||||
}
|
||||
|
||||
PlatformApiStub::ClipboardData PlatformApiStub::get_clipboard_data() {
|
||||
auto c = std::make_shared<Request<protobuf::bridge::ClipboardData>>();
|
||||
|
||||
protobuf::rpc::Void message;
|
||||
|
||||
received_clipboard_data_ = ClipboardData{};
|
||||
|
||||
{
|
||||
std::lock_guard<decltype(mutex_)> lock(mutex_);
|
||||
c->wh.expect_result();
|
||||
}
|
||||
|
||||
rpc_channel_->call_method("get_clipboard_data", &message, c->response.get(),
|
||||
google::protobuf::NewCallback(
|
||||
this, &PlatformApiStub::on_clipboard_data_get, c.get()));
|
||||
|
||||
c->wh.wait_for_all();
|
||||
|
||||
if (c->response->has_error()) throw std::runtime_error(c->response->error());
|
||||
|
||||
return ClipboardData{c->response->text()};
|
||||
}
|
||||
} // namespace anbox
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ namespace protobuf {
|
|||
namespace rpc {
|
||||
class Void;
|
||||
} // namespace rpc
|
||||
namespace bridge {
|
||||
class ClipboardData;
|
||||
} // namespace bridge
|
||||
} // namespace protobuf
|
||||
namespace rpc {
|
||||
class Channel;
|
||||
|
|
@ -80,17 +83,29 @@ public:
|
|||
|
||||
void update_application_list(const ApplicationListUpdate &update);
|
||||
|
||||
struct ClipboardData {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
void set_clipboard_data(const ClipboardData &data);
|
||||
ClipboardData get_clipboard_data();
|
||||
|
||||
private:
|
||||
template<typename Response>
|
||||
struct Request {
|
||||
Request() : response(std::make_shared<Response>()), success(true) { }
|
||||
std::shared_ptr<Response> response;
|
||||
bool success;
|
||||
common::WaitHandle wh;
|
||||
};
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
void on_clipboard_data_set(Request<protobuf::rpc::Void> *request);
|
||||
void on_clipboard_data_get(Request<protobuf::bridge::ClipboardData> *request);
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
std::shared_ptr<rpc::Channel> rpc_channel_;
|
||||
|
||||
ClipboardData received_clipboard_data_;
|
||||
};
|
||||
} // namespace anbox
|
||||
|
||||
|
|
|
|||
|
|
@ -124,4 +124,25 @@ status_t PlatformService::update_application_list(const Parcel &data) {
|
|||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t PlatformService::set_clipboard_data(const Parcel &data) {
|
||||
if (data.readInt32() == 0)
|
||||
return OK;
|
||||
String8 text(data.readString16());
|
||||
const auto clip_data = anbox::PlatformApiStub::ClipboardData{text.string()};
|
||||
platform_api_stub_->set_clipboard_data(clip_data);
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t PlatformService::get_clipboard_data(const Parcel &data, Parcel *reply) {
|
||||
(void) data;
|
||||
const auto clip_data = platform_api_stub_->get_clipboard_data();
|
||||
if (clip_data.text.empty()) {
|
||||
reply->writeInt32(0);
|
||||
return OK;
|
||||
}
|
||||
reply->writeInt32(1);
|
||||
reply->writeString16(String16(clip_data.text.c_str(), clip_data.text.length()));
|
||||
return OK;
|
||||
}
|
||||
} // namespace android
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public:
|
|||
status_t boot_finished() override;
|
||||
status_t update_window_state(const Parcel &data) override;
|
||||
status_t update_application_list(const Parcel &data) override;
|
||||
status_t set_clipboard_data(const Parcel &data) override;
|
||||
status_t get_clipboard_data(const Parcel &data, Parcel *reply) override;
|
||||
|
||||
private:
|
||||
anbox::PlatformApiStub::WindowStateUpdate::Window unpack_window_state(const Parcel &data);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,18 @@ status_t BpPlatformService::update_application_list(const Parcel&) {
|
|||
return remote()->transact(IPlatformService::UPDATE_APPLICATION_LIST, data, &reply);
|
||||
}
|
||||
|
||||
status_t BpPlatformService::set_clipboard_data(const Parcel&) {
|
||||
Parcel data, reply;
|
||||
data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor());
|
||||
return remote()->transact(IPlatformService::SET_CLIPBOARD_DATA, data, &reply);
|
||||
}
|
||||
|
||||
status_t BpPlatformService::get_clipboard_data(const Parcel&, Parcel*) {
|
||||
Parcel data, reply;
|
||||
data.writeInterfaceToken(IPlatformService::getInterfaceDescriptor());
|
||||
return remote()->transact(IPlatformService::GET_CLIPBOARD_DATA, data, &reply);
|
||||
}
|
||||
|
||||
IMPLEMENT_META_INTERFACE(PlatformService, "org.anbox.IPlatformService");
|
||||
|
||||
status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data,
|
||||
|
|
@ -54,6 +66,12 @@ status_t BnPlatformService::onTransact(uint32_t code, const Parcel &data,
|
|||
case UPDATE_APPLICATION_LIST:
|
||||
CHECK_INTERFACE(IPlatformService, data, reply);
|
||||
return update_application_list(data);
|
||||
case SET_CLIPBOARD_DATA:
|
||||
CHECK_INTERFACE(IPlatformService, data, reply);
|
||||
return set_clipboard_data(data);
|
||||
case GET_CLIPBOARD_DATA:
|
||||
CHECK_INTERFACE(IPlatformService, data, reply);
|
||||
return get_clipboard_data(data, reply);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,11 +37,15 @@ public:
|
|||
BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
|
||||
UPDATE_WINDOW_STATE = IBinder::FIRST_CALL_TRANSACTION + 1,
|
||||
UPDATE_APPLICATION_LIST = IBinder::FIRST_CALL_TRANSACTION + 2,
|
||||
SET_CLIPBOARD_DATA = IBinder::FIRST_CALL_TRANSACTION + 3,
|
||||
GET_CLIPBOARD_DATA = IBinder::FIRST_CALL_TRANSACTION + 4,
|
||||
};
|
||||
|
||||
virtual status_t boot_finished() = 0;
|
||||
virtual status_t update_window_state(const Parcel &data) = 0;
|
||||
virtual status_t update_application_list(const Parcel &data) = 0;
|
||||
virtual status_t set_clipboard_data(const Parcel &data) = 0;
|
||||
virtual status_t get_clipboard_data(const Parcel &data, Parcel *reply) = 0;
|
||||
};
|
||||
|
||||
class BpPlatformService : public BpInterface<IPlatformService> {
|
||||
|
|
@ -51,6 +55,8 @@ public:
|
|||
status_t boot_finished() override;
|
||||
status_t update_window_state(const Parcel &data) override;
|
||||
status_t update_application_list(const Parcel &data) override;
|
||||
status_t set_clipboard_data(const Parcel &data) override;
|
||||
status_t get_clipboard_data(const Parcel &data, Parcel *reply) override;
|
||||
};
|
||||
|
||||
class BnPlatformService : public BnInterface<IPlatformService> {
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
#include "anbox/bridge/platform_api_skeleton.h"
|
||||
#include "anbox/application/launcher_storage.h"
|
||||
#include "anbox/logger.h"
|
||||
#include "anbox/platform/policy.h"
|
||||
#include "anbox/wm/manager.h"
|
||||
#include "anbox/wm/window_state.h"
|
||||
#include "anbox/logger.h"
|
||||
|
||||
#include "anbox_bridge.pb.h"
|
||||
|
||||
|
|
@ -27,14 +28,40 @@ namespace anbox {
|
|||
namespace bridge {
|
||||
PlatformApiSkeleton::PlatformApiSkeleton(
|
||||
const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<platform::Policy> &platform_policy,
|
||||
const std::shared_ptr<wm::Manager> &window_manager,
|
||||
const std::shared_ptr<application::LauncherStorage> &launcher_storage)
|
||||
: pending_calls_(pending_calls),
|
||||
platform_policy_(platform_policy),
|
||||
window_manager_(window_manager),
|
||||
launcher_storage_(launcher_storage) {}
|
||||
|
||||
PlatformApiSkeleton::~PlatformApiSkeleton() {}
|
||||
|
||||
|
||||
void PlatformApiSkeleton::set_clipboard_data(anbox::protobuf::bridge::ClipboardData const *request,
|
||||
anbox::protobuf::rpc::Void *response,
|
||||
google::protobuf::Closure *done) {
|
||||
(void)response;
|
||||
|
||||
if (request->has_text())
|
||||
platform_policy_->set_clipboard_data(platform::Policy::ClipboardData{request->text()});
|
||||
|
||||
done->Run();
|
||||
}
|
||||
|
||||
void PlatformApiSkeleton::get_clipboard_data(anbox::protobuf::rpc::Void const *request,
|
||||
anbox::protobuf::bridge::ClipboardData *response,
|
||||
google::protobuf::Closure *done) {
|
||||
(void)request;
|
||||
|
||||
auto data = platform_policy_->get_clipboard_data();
|
||||
if (!data.text.empty())
|
||||
response->set_text(data.text);
|
||||
|
||||
done->Run();
|
||||
}
|
||||
|
||||
void PlatformApiSkeleton::handle_boot_finished_event(
|
||||
const anbox::protobuf::bridge::BootFinishedEvent &event) {
|
||||
(void)event;
|
||||
|
|
|
|||
|
|
@ -32,11 +32,15 @@ namespace rpc {
|
|||
class Void;
|
||||
} // namespace rpc
|
||||
namespace bridge {
|
||||
class ClipboardData;
|
||||
class BootFinishedEvent;
|
||||
class WindowStateUpdateEvent;
|
||||
class ApplicationListUpdateEvent;
|
||||
} // namespace bridge
|
||||
} // namespace protobuf
|
||||
namespace platform {
|
||||
class Policy;
|
||||
} // namespace platform
|
||||
namespace rpc {
|
||||
class PendingCallCache;
|
||||
} // namespace rpc
|
||||
|
|
@ -51,10 +55,18 @@ class PlatformApiSkeleton {
|
|||
public:
|
||||
PlatformApiSkeleton(
|
||||
const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<platform::Policy> &platform_policy,
|
||||
const std::shared_ptr<wm::Manager> &window_manager,
|
||||
const std::shared_ptr<application::LauncherStorage> &launcher_storage);
|
||||
virtual ~PlatformApiSkeleton();
|
||||
|
||||
void set_clipboard_data(anbox::protobuf::bridge::ClipboardData const *request,
|
||||
anbox::protobuf::rpc::Void *response,
|
||||
google::protobuf::Closure *done);
|
||||
void get_clipboard_data(anbox::protobuf::rpc::Void const *request,
|
||||
anbox::protobuf::bridge::ClipboardData *response,
|
||||
google::protobuf::Closure *done);
|
||||
|
||||
void handle_boot_finished_event(
|
||||
const anbox::protobuf::bridge::BootFinishedEvent &event);
|
||||
void handle_window_state_update_event(
|
||||
|
|
@ -66,6 +78,7 @@ class PlatformApiSkeleton {
|
|||
|
||||
private:
|
||||
std::shared_ptr<rpc::PendingCallCache> pending_calls_;
|
||||
std::shared_ptr<platform::Policy> platform_policy_;
|
||||
std::shared_ptr<wm::Manager> window_manager_;
|
||||
std::shared_ptr<application::LauncherStorage> launcher_storage_;
|
||||
std::function<void()> boot_finished_handler_;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,12 @@ PlatformMessageProcessor::PlatformMessageProcessor(
|
|||
|
||||
PlatformMessageProcessor::~PlatformMessageProcessor() {}
|
||||
|
||||
void PlatformMessageProcessor::dispatch(rpc::Invocation const &invocation) {}
|
||||
void PlatformMessageProcessor::dispatch(rpc::Invocation const &invocation) {
|
||||
if (invocation.method_name() == "set_clipboard_data")
|
||||
invoke(this, server_.get(), &PlatformApiSkeleton::set_clipboard_data, invocation);
|
||||
else if (invocation.method_name() == "get_clipboard_data")
|
||||
invoke(this, server_.get(), &PlatformApiSkeleton::get_clipboard_data, invocation);
|
||||
}
|
||||
|
||||
void PlatformMessageProcessor::process_event_sequence(
|
||||
const std::string &raw_events) {
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ anbox::cmds::Run::Run(const BusFactory &bus_factory)
|
|||
android_api_stub->set_rpc_channel(rpc_channel);
|
||||
|
||||
auto server = std::make_shared<bridge::PlatformApiSkeleton>(
|
||||
pending_calls, window_manager, launcher_storage);
|
||||
pending_calls, policy, window_manager, launcher_storage);
|
||||
server->register_boot_finished_handler(
|
||||
[&]() { DEBUG("Android successfully booted"); });
|
||||
return std::make_shared<bridge::PlatformMessageProcessor>(
|
||||
|
|
|
|||
|
|
@ -37,6 +37,16 @@ std::shared_ptr<wm::Window> DefaultPolicy::create_window(
|
|||
return std::make_shared<::NullWindow>(task, frame);
|
||||
}
|
||||
|
||||
void DefaultPolicy::set_clipboard_data(const ClipboardData &data) {
|
||||
(void)data;
|
||||
ERROR("Not implemented");
|
||||
}
|
||||
|
||||
DefaultPolicy::ClipboardData DefaultPolicy::get_clipboard_data() {
|
||||
ERROR("Not implemented");
|
||||
return ClipboardData{};
|
||||
}
|
||||
|
||||
std::shared_ptr<audio::Sink> DefaultPolicy::create_audio_sink() {
|
||||
ERROR("Not implemented");
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class DefaultPolicy : public Policy {
|
|||
std::shared_ptr<wm::Window> create_window(
|
||||
const anbox::wm::Task::Id &task,
|
||||
const anbox::graphics::Rect &frame) override;
|
||||
void set_clipboard_data(const ClipboardData &data) override;
|
||||
ClipboardData get_clipboard_data() override;
|
||||
std::shared_ptr<audio::Sink> create_audio_sink() override;
|
||||
std::shared_ptr<audio::Source> create_audio_source() override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ class Policy {
|
|||
virtual std::shared_ptr<wm::Window> create_window(
|
||||
const anbox::wm::Task::Id &task, const anbox::graphics::Rect &frame) = 0;
|
||||
|
||||
struct ClipboardData {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
virtual void set_clipboard_data(const ClipboardData &data) = 0;
|
||||
virtual ClipboardData get_clipboard_data() = 0;
|
||||
|
||||
virtual std::shared_ptr<audio::Sink> create_audio_sink() = 0;
|
||||
virtual std::shared_ptr<audio::Source> create_audio_source() = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@ message ResizeTask {
|
|||
required Rect rect = 3;
|
||||
}
|
||||
|
||||
message ClipboardData {
|
||||
optional string text = 1;
|
||||
|
||||
optional string error = 127;
|
||||
optional StructuredError structured_error = 128;
|
||||
}
|
||||
|
||||
message BootFinishedEvent {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -265,6 +265,25 @@ DisplayManager::DisplayInfo PlatformPolicy::display_info() const {
|
|||
return display_info_;
|
||||
}
|
||||
|
||||
void PlatformPolicy::set_clipboard_data(const ClipboardData &data) {
|
||||
if (data.text.empty())
|
||||
return;
|
||||
SDL_SetClipboardText(data.text.c_str());
|
||||
}
|
||||
|
||||
PlatformPolicy::ClipboardData PlatformPolicy::get_clipboard_data() {
|
||||
if (!SDL_HasClipboardText())
|
||||
return ClipboardData{};
|
||||
|
||||
auto text = SDL_GetClipboardText();
|
||||
if (!text)
|
||||
return ClipboardData{};
|
||||
|
||||
auto data = ClipboardData{text};
|
||||
SDL_free(text);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::shared_ptr<audio::Sink> PlatformPolicy::create_audio_sink() {
|
||||
return std::make_shared<AudioSink>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,9 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
|
|||
|
||||
void set_renderer(const std::shared_ptr<Renderer> &renderer);
|
||||
|
||||
void set_clipboard_data(const ClipboardData &data) override;
|
||||
ClipboardData get_clipboard_data() override;
|
||||
|
||||
std::shared_ptr<audio::Sink> create_audio_sink() override;
|
||||
std::shared_ptr<audio::Source> create_audio_source() override;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue