1/* Copyright (C) 2010 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10** GNU General Public License for more details.
11*/
12
13/*
14 * Contains implementation of the API for calling into the Core with the UI
15 * control commands for standalone (monolithic) emulator.
16 */
17
18#include "android/android.h"
19#include "android/globals.h"
20#include "android/hw-sensors.h"
21#include "telephony/modem_driver.h"
22#include "android-trace.h"
23#include "audio/audio.h"
24#include "android/protocol/core-commands-api.h"
25
26/* Implemented in vl-android.c */
27extern char* qemu_find_file(int type, const char* filename);
28
29int
30corecmd_set_coarse_orientation(AndroidCoarseOrientation orient)
31{
32    android_sensors_set_coarse_orientation(orient);
33    return 0;
34}
35
36int
37corecmd_toggle_network()
38{
39    qemu_net_disable = !qemu_net_disable;
40    if (android_modem) {
41        amodem_set_data_registration(
42                android_modem,
43        qemu_net_disable ? A_REGISTRATION_UNREGISTERED
44            : A_REGISTRATION_HOME);
45    }
46    return 0;
47}
48
49int corecmd_trace_control(int start)
50{
51    if (start) {
52        start_tracing();
53    } else {
54        stop_tracing();
55    }
56    return 0;
57}
58
59int corecmd_is_network_disabled()
60{
61    return qemu_net_disable;
62}
63
64int
65corecmd_get_netspeed(int index, NetworkSpeed** netspeed)
66{
67    if (index >= android_netspeeds_count ||
68        android_netspeeds[index].name == NULL) {
69        return -1;
70    }
71    *netspeed = (NetworkSpeed*)malloc(sizeof(NetworkSpeed));
72    memcpy(*netspeed, &android_netspeeds[index], sizeof(NetworkSpeed));
73    return 0;
74}
75
76int
77corecmd_get_netdelay(int index, NetworkLatency** netdelay)
78{
79    if (index >= android_netdelays_count ||
80        android_netdelays[index].name == NULL) {
81        return -1;
82    }
83    *netdelay = (NetworkLatency*)malloc(sizeof(NetworkLatency));
84    memcpy(*netdelay, &android_netdelays[index], sizeof(NetworkLatency));
85    return 0;
86}
87
88int
89corecmd_get_qemu_path(int type,
90                      const char* filename,
91                      char* path,
92                      size_t path_buf_size)
93{
94    char* filepath = qemu_find_file(type, filename);
95    if (filepath == NULL) {
96        return -1;
97    }
98    strncpy(path, filepath, path_buf_size);
99    path[path_buf_size - 1] = '\0';
100    qemu_free(filepath);
101    return 0;
102}
103
104int
105corecmd_get_hw_lcd_density(void)
106{
107    return android_hw->hw_lcd_density;
108}
109