File: platform_service.cpp

package info (click to toggle)
anbox 0.0~git20210106-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 6,916 kB
  • sloc: cpp: 50,603; ansic: 5,056; sh: 1,150; xml: 850; java: 780; python: 460; makefile: 35; lisp: 7
file content (162 lines) | stat: -rw-r--r-- 5,415 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "android/service/platform_service.h"
#include "anbox/rpc/channel.h"

#include "anbox_rpc.pb.h"
#include "anbox_bridge.pb.h"

#define LOG_TAG "Anboxd"
#include <cutils/log.h>

#include <utils/String8.h>

using namespace android;

namespace android {
PlatformService::PlatformService(const std::shared_ptr<anbox::PlatformApiStub> &platform_api_stub) :
    platform_api_stub_(platform_api_stub) {
}

status_t PlatformService::boot_finished() {
    platform_api_stub_->boot_finished();
    return OK;
}

anbox::PlatformApiStub::WindowStateUpdate::Window PlatformService::unpack_window_state(const Parcel &data) {
    bool has_surface = data.readByte() != 0;

    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();
    auto rotation_angle = data.readInt32();

    return anbox::PlatformApiStub::WindowStateUpdate::Window{
        -1, // Display id will be added by the caller
        has_surface,
        package_name.string(),
        {frame_left, frame_top, frame_right, frame_bottom},
        task_id,
        stack_id,
    };
}

status_t PlatformService::update_window_state(const Parcel &data) {
    anbox::PlatformApiStub::WindowStateUpdate state;

    const auto num_displays = data.readInt32();
    for (auto n = 0; n < num_displays; n++) {
        const auto display_id = data.readInt32();
        const auto num_windows = data.readInt32();
        for (auto m = 0; m < num_windows; m++) {
            auto window = unpack_window_state(data);
            window.display_id = display_id;
            state.updated_windows.push_back(window);
        }
    }

    const auto num_removed_windows = data.readInt32();
    for (auto n = 0; n < num_removed_windows; n++) {
        auto window = unpack_window_state(data);
        state.removed_windows.push_back(window);
    }

    platform_api_stub_->update_window_state(state);

    return OK;
}

status_t PlatformService::update_application_list(const Parcel &data) {
    anbox::PlatformApiStub::ApplicationListUpdate update;
    const auto num_packages = data.readInt32();
    for (auto n = 0; n < num_packages; n++) {
        String8 name(data.readString16());
        String8 package_name(data.readString16());

        auto p = anbox::PlatformApiStub::ApplicationListUpdate::Application{
                name.string(),
                package_name.string(),
        };

        String8 action(data.readString16());
        String8 uri(data.readString16());
        String8 type(data.readString16());
        String8 component_package(data.readString16());
        String8 component_class(data.readString16());

        std::vector<std::string> categories;
        unsigned int num_categories = data.readInt32();
        for (int m = 0; m < num_categories; m++)
            categories.push_back(String8(data.readString16()).string());

        p.launch_intent.action = action;
        p.launch_intent.uri = uri;
        p.launch_intent.type = type;
        p.launch_intent.package = component_package;
        p.launch_intent.component = component_class;
        p.launch_intent.categories = categories;

        data.readByteVector(&p.icon);

        // Send updates with icons separately to not overflow protobuf
        if (p.icon.size() > 0) {
          anbox::PlatformApiStub::ApplicationListUpdate with_icon_update;
          with_icon_update.applications.push_back(p);
          platform_api_stub_->update_application_list(with_icon_update);
        } else {
          update.applications.push_back(p);
        }
    }

    const auto num_removed_packages = data.readInt32();
    for (auto n = 0; n < num_removed_packages; n++) {
      String8 package_name(data.readString16());
      update.removed_applications.push_back(package_name.string());
    }

    platform_api_stub_->update_application_list(update);

    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