2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "anbox/bridge/platform_api_skeleton.h"
19 #include "anbox/application/database.h"
20 #include "anbox/platform/base_platform.h"
21 #include "anbox/wm/manager.h"
22 #include "anbox/wm/window_state.h"
23 #include "anbox/logger.h"
27 #endif // defined(Status)
29 #include "anbox_bridge.pb.h"
31 #ifdef USE_PROTOBUF_CALLBACK_HEADER
32 #include <google/protobuf/stubs/callback.h>
37 PlatformApiSkeleton::PlatformApiSkeleton(
38 const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
39 const std::shared_ptr<platform::BasePlatform> &platform,
40 const std::shared_ptr<wm::Manager> &window_manager,
41 const std::shared_ptr<application::Database> &app_db)
42 : pending_calls_(pending_calls),
44 window_manager_(window_manager),
47 PlatformApiSkeleton::~PlatformApiSkeleton() {}
50 void PlatformApiSkeleton::set_clipboard_data(anbox::protobuf::bridge::ClipboardData const *request,
51 anbox::protobuf::rpc::Void *response,
52 google::protobuf::Closure *done) {
55 if (request->has_text())
56 platform_->set_clipboard_data(platform::BasePlatform::ClipboardData{request->text()});
61 void PlatformApiSkeleton::get_clipboard_data(anbox::protobuf::rpc::Void const *request,
62 anbox::protobuf::bridge::ClipboardData *response,
63 google::protobuf::Closure *done) {
66 auto data = platform_->get_clipboard_data();
67 if (!data.text.empty())
68 response->set_text(data.text);
73 void PlatformApiSkeleton::handle_boot_finished_event(const anbox::protobuf::bridge::BootFinishedEvent&) {
74 if (boot_finished_handler_)
75 boot_finished_handler_();
78 void PlatformApiSkeleton::handle_window_state_update_event(const anbox::protobuf::bridge::WindowStateUpdateEvent &event) {
79 auto convert_window_state = [](
80 const ::anbox::protobuf::bridge::WindowStateUpdateEvent_WindowState
82 return wm::WindowState(
83 wm::Display::Id(window.display_id()), window.has_surface(),
84 graphics::Rect(window.frame_left(), window.frame_top(),
85 window.frame_right(), window.frame_bottom()),
86 window.package_name(), wm::Task::Id(window.task_id()),
87 wm::Stack::Id(window.stack_id()));
90 wm::WindowState::List updated;
91 for (int n = 0; n < event.windows_size(); n++) {
92 const auto window = event.windows(n);
93 updated.push_back(convert_window_state(window));
96 wm::WindowState::List removed;
97 for (int n = 0; n < event.removed_windows_size(); n++) {
98 const auto window = event.removed_windows(n);
99 removed.push_back(convert_window_state(window));
102 window_manager_->apply_window_state_update(updated, removed);
105 void PlatformApiSkeleton::handle_application_list_update_event(const anbox::protobuf::bridge::ApplicationListUpdateEvent &event) {
106 for (int n = 0; n < event.removed_applications_size(); n++) {
107 application::Database::Item item;
109 const auto app = event.removed_applications(n);
110 item.package = app.package();
112 if (item.package.empty())
115 app_db_->remove(item);
118 for (int n = 0; n < event.applications_size(); n++) {
119 application::Database::Item item;
121 const auto app = event.applications(n);
122 item.name = app.name();
123 item.package = app.package();
125 const auto li = app.launch_intent();
126 item.launch_intent.action = li.action();
127 item.launch_intent.uri = li.uri();
128 item.launch_intent.type = li.uri();
129 item.launch_intent.package = li.package();
130 item.launch_intent.component = li.component();
132 for (int m = 0; m < li.categories_size(); m++)
133 item.launch_intent.categories.push_back(li.categories(m));
135 item.icon = std::vector<char>(app.icon().begin(), app.icon().end());
137 if (item.package.empty())
140 app_db_->store_or_update(item);
144 void PlatformApiSkeleton::register_boot_finished_handler(const std::function<void()> &action) {
145 boot_finished_handler_ = action;
147 } // namespace bridge