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 "android/service/platform_service.h"
19 #include "anbox/rpc/channel.h"
21 #include "anbox_rpc.pb.h"
22 #include "anbox_bridge.pb.h"
24 #define LOG_TAG "Anboxd"
25 #include <cutils/log.h>
27 #include <utils/String8.h>
29 using namespace android;
32 PlatformService::PlatformService(const std::shared_ptr<anbox::PlatformApiStub> &platform_api_stub) :
33 platform_api_stub_(platform_api_stub) {
36 status_t PlatformService::boot_finished() {
37 platform_api_stub_->boot_finished();
41 anbox::PlatformApiStub::WindowStateUpdate::Window PlatformService::unpack_window_state(const Parcel &data) {
42 bool has_surface = data.readByte() != 0;
44 String8 package_name(data.readString16());
46 auto frame_left = data.readInt32();
47 auto frame_top = data.readInt32();
48 auto frame_right = data.readInt32();
49 auto frame_bottom = data.readInt32();
50 auto task_id = data.readInt32();
51 auto stack_id = data.readInt32();
52 auto rotation_angle = data.readInt32();
54 return anbox::PlatformApiStub::WindowStateUpdate::Window{
55 -1, // Display id will be added by the caller
57 package_name.string(),
58 {frame_left, frame_top, frame_right, frame_bottom},
64 status_t PlatformService::update_window_state(const Parcel &data) {
65 anbox::PlatformApiStub::WindowStateUpdate state;
67 const auto num_displays = data.readInt32();
68 for (auto n = 0; n < num_displays; n++) {
69 const auto display_id = data.readInt32();
70 const auto num_windows = data.readInt32();
71 for (auto m = 0; m < num_windows; m++) {
72 auto window = unpack_window_state(data);
73 window.display_id = display_id;
74 state.updated_windows.push_back(window);
78 const auto num_removed_windows = data.readInt32();
79 for (auto n = 0; n < num_removed_windows; n++) {
80 auto window = unpack_window_state(data);
81 state.removed_windows.push_back(window);
84 platform_api_stub_->update_window_state(state);
89 status_t PlatformService::update_application_list(const Parcel &data) {
90 anbox::PlatformApiStub::ApplicationListUpdate update;
91 const auto num_packages = data.readInt32();
92 for (auto n = 0; n < num_packages; n++) {
93 String8 name(data.readString16());
94 String8 package_name(data.readString16());
96 auto p = anbox::PlatformApiStub::ApplicationListUpdate::Application{
98 package_name.string(),
101 String8 action(data.readString16());
102 String8 uri(data.readString16());
103 String8 type(data.readString16());
104 String8 component_package(data.readString16());
105 String8 component_class(data.readString16());
107 std::vector<std::string> categories;
108 unsigned int num_categories = data.readInt32();
109 for (int m = 0; m < num_categories; m++)
110 categories.push_back(String8(data.readString16()).string());
112 p.launch_intent.action = action;
113 p.launch_intent.uri = uri;
114 p.launch_intent.type = type;
115 p.launch_intent.package = component_package;
116 p.launch_intent.component = component_class;
117 p.launch_intent.categories = categories;
119 data.readByteVector(&p.icon);
121 // Send updates with icons separately to not overflow protobuf
122 if (p.icon.size() > 0) {
123 anbox::PlatformApiStub::ApplicationListUpdate with_icon_update;
124 with_icon_update.applications.push_back(p);
125 platform_api_stub_->update_application_list(with_icon_update);
127 update.applications.push_back(p);
131 const auto num_removed_packages = data.readInt32();
132 for (auto n = 0; n < num_removed_packages; n++) {
133 String8 package_name(data.readString16());
134 update.removed_applications.push_back(package_name.string());
137 platform_api_stub_->update_application_list(update);
142 status_t PlatformService::set_clipboard_data(const Parcel &data) {
143 if (data.readInt32() == 0)
145 String8 text(data.readString16());
146 const auto clip_data = anbox::PlatformApiStub::ClipboardData{text.string()};
147 platform_api_stub_->set_clipboard_data(clip_data);
151 status_t PlatformService::get_clipboard_data(const Parcel &data, Parcel *reply) {
153 const auto clip_data = platform_api_stub_->get_clipboard_data();
154 if (clip_data.text.empty()) {
155 reply->writeInt32(0);
158 reply->writeInt32(1);
159 reply->writeString16(String16(clip_data.text.c_str(), clip_data.text.length()));
162 } // namespace android