aboutsummaryrefslogtreecommitdiffstats
path: root/android/ui-core-protocol.c
blob: fa1a31afed7d993295327cd9810abb9ca5ad79c6 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* Copyright (C) 2010 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/

/*
 * This file contains helper routines that are used to establish communication
 * between UI and Core components of the emulator. This is a temporary file
 * where we will collect functional dependencies between UI and Core in the
 * process of separating UI and Core in the emulator build. Ideally at the
 * end this will be replaced with a message protocol over sockets, or other
 * means of interprocess communication.
 */

#include "android/android.h"
#include "android/globals.h"
#include "android/hw-control.h"
#include "android/ui-core-protocol.h"
#if !defined(CONFIG_STANDALONE_UI)
#include "telephony/modem_driver.h"
#include "trace.h"
#include "audio/audio.h"
/* Implemented in vl-android.c */
extern void qemu_system_shutdown_request(void);
extern char* qemu_find_file(int type, const char* filename);
#endif  // CONFIG_STANDALONE_UI

int
android_core_get_hw_lcd_density(void)
{
    return android_hw->hw_lcd_density;
}

void
android_core_set_brightness_change_callback(AndroidHwLightBrightnessCallback callback,
                                            void* opaque)
{
    AndroidHwControlFuncs  funcs;

    funcs.light_brightness = callback;
#if !defined(CONFIG_STANDALONE_UI)
    android_hw_control_init( opaque, &funcs );
#endif  // CONFIG_STANDALONE_UI
}

int
android_core_get_base_port(void)
{
#if !defined(CONFIG_STANDALONE_UI)
    return android_base_port;
#else
    return 5554;
#endif  // CONFIG_STANDALONE_UI
}

void
android_core_sensors_set_coarse_orientation( AndroidCoarseOrientation  orient )
{
#if !defined(CONFIG_STANDALONE_UI)
    android_sensors_set_coarse_orientation(orient);
#endif  // CONFIG_STANDALONE_UI
}

void
android_core_set_network_enabled(int enabled)
{
    /* Temporary implementation for the monolitic (core + ui) builds. */
#if !defined(CONFIG_STANDALONE_UI)
    if (android_modem) {
        amodem_set_data_registration(
                android_modem,
        qemu_net_disable ? A_REGISTRATION_UNREGISTERED
            : A_REGISTRATION_HOME);
    }
#endif  // CONFIG_STANDALONE_UI
}

void
android_core_toggle_network(void)
{
    /* Temporary implementation for the monolitic (core + ui) builds. */
#if !defined(CONFIG_STANDALONE_UI)
    qemu_net_disable = !qemu_net_disable;
    android_core_set_network_enabled(!qemu_net_disable);
#endif  // CONFIG_STANDALONE_UI
}

int
android_core_is_network_disabled(void)
{
    /* Temporary implementation for the monolitic (core + ui) builds. */
#if !defined(CONFIG_STANDALONE_UI)
    return qemu_net_disable;
#else
    return 0;
#endif  // CONFIG_STANDALONE_UI
}

void android_core_tracing_start(void)
{
#if !defined(CONFIG_STANDALONE_UI)
    start_tracing();
#endif  // CONFIG_STANDALONE_UI
}

void android_core_tracing_stop(void)
{
#if !defined(CONFIG_STANDALONE_UI)
    stop_tracing();
#endif  // CONFIG_STANDALONE_UI
}

int
android_core_get_android_netspeed(int index, NetworkSpeed* netspeed) {
    /* This is a temporary code used to support current behavior of the
     *monolitic (core + ui in one executable) emulator executed with
     * -help-netspeed option. In the future, when ui and core get separated,
     * behavior of help may change, and this code should be reviewed. */
#if !defined(CONFIG_STANDALONE_UI)
    if (index >= android_netspeeds_count ||
        android_netspeeds[index].name == NULL) {
        return -1;
    }
    *netspeed = android_netspeeds[index];
    return 0;
#else
    return -1;
#endif  // !CONFIG_STANDALONE_UI
}

int
android_core_get_android_netdelay(int index, NetworkLatency* delay) {
    /* This is a temporary code used to support current behavior of the
     * monolitic (core + ui in one executable) emulator executed with
     * -help-netdelays option. In the future, when ui and core get separated,
     * behavior of help may change, and this code should be reviewed. */
#if !defined(CONFIG_STANDALONE_UI)
    if (index >= android_netdelays_count ||
        android_netdelays[index].name == NULL) {
        return -1;
    }
    *delay = android_netdelays[index];
    return 0;
#else
    return -1;
#endif  // !CONFIG_STANDALONE_UI
}

int
android_core_audio_get_backend_name(int is_input, int index,
                                    char* name, size_t name_buf_size,
                                    char* descr, size_t descr_buf_size) {
    /* This is a temporary code used to support current behavior of the
     * monolitic (core + ui in one executable) emulator executed with
     * -help-audio-in, and -help-audio-in options. In the future, when ui and
     * core get separated, behavior of help may change, and this code should
     * be reviewed. */
#if !defined(CONFIG_STANDALONE_UI)
    const char* descr_ptr = NULL;
    const char* name_ptr = audio_get_backend_name(is_input, index, &descr_ptr);
    if (name_ptr == NULL) {
        return -1;
    }
    if (name != NULL && name_buf_size) {
        strncpy(name, name_ptr, name_buf_size);
        name[name_buf_size - 1] = '\0';
    }
    if (descr != NULL && descr_buf_size && descr_ptr != NULL) {
        strncpy(descr, descr_ptr, descr_buf_size);
        descr[descr_buf_size - 1] = '\0';
    }
    return 0;
#else
    return -1;
#endif  // !CONFIG_STANDALONE_UI
}

void
android_core_system_shutdown_request(void)
{
    /* Temporary implementation for the monolitic (core + ui) builds. */
#if !defined(CONFIG_STANDALONE_UI)
    qemu_system_shutdown_request();
#endif  // !CONFIG_STANDALONE_UI
}

int
android_core_qemu_find_file(int type, const char *filename,
                            char* path, size_t path_buf_size)
{
    /* Temporary implementation for the monolitic (core + ui) builds. */
#if !defined(CONFIG_STANDALONE_UI)
    char* filepath = qemu_find_file(type, filename);
    if (filepath == NULL) {
        return -1;
    }
    strncpy(path, filepath, path_buf_size);
    filepath[path_buf_size - 1] = '\0';
    qemu_free(filepath);
    return 0;
#else
    return -1;
#endif  // !CONFIG_STANDALONE_UI
}