Skip to content

Commit cd2b3aa

Browse files
author
Yurii Zubrytskyi
committed
[Refactor] Move modem_driver to AndroidEmu
The whole modem_driver is generic with the exception of serial port initialization - where one needs to register save/restore VM handlers. It seems to me that we need to provide an abstraction to register_savevm() call in AndroidEmu, so one could register handlers in the library Change-Id: I28c2591b56e52a9fcd8c531cae4a87dd4a905dec
1 parent cd0e08d commit cd2b3aa

14 files changed

+82
-38
lines changed

Makefile.common

+2-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ common_LOCAL_SRC_FILES += \
727727
android/telephony/remote_call.c \
728728
android/telephony/sim_card.c \
729729
android/telephony/sms.c \
730-
android-qemu1-glue/telephony/modem_driver.c \
730+
android/telephony/modem_driver.c \
731+
android-qemu1-glue/telephony/modem_init.cpp \
731732
android-qemu1-glue/telephony/sysdeps_qemu.c
732733

733734
# sources inherited from upstream, but not fully

android-qemu1-glue/console.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "libslirp.h"
4646
#endif
4747
#include "net/net.h"
48-
#include "android-qemu1-glue/telephony/modem_driver.h"
48+
#include "android/telephony/modem_driver.h"
4949
#include "ui/console.h"
5050

5151
#include <fcntl.h>

android-qemu1-glue/qemu-setup.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "libslirp.h"
1414
#include "qemu-common.h"
1515
#include "sysemu/sysemu.h"
16-
#include "android-qemu1-glue/telephony/modem_driver.h"
16+
#include "android-qemu1-glue/telephony/modem_init.h"
1717

1818
#include "android/console.h"
1919
#include "android/adb-qemud.h"
@@ -363,7 +363,7 @@ void android_emulation_setup( void )
363363
report_console(android_op_report_console, base_port);
364364
}
365365

366-
android_modem_init( base_port );
366+
qemu_android_modem_init( base_port );
367367

368368
/* Save base port. */
369369
android_base_port = base_port;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2015 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+
#include "android-qemu1-glue/telephony/modem_init.h"
13+
14+
#include "android/telephony/modem_driver.h"
15+
16+
extern "C" {
17+
#include "hw/hw.h"
18+
}
19+
20+
#define MODEM_DEV_STATE_SAVE_VERSION 1
21+
22+
static void modem_state_save(QEMUFile* file, void* opaque)
23+
{
24+
amodem_state_save((AModem)opaque, (SysFile*)file);
25+
}
26+
27+
static int modem_state_load(QEMUFile* file, void* opaque, int version_id)
28+
{
29+
if (version_id != MODEM_DEV_STATE_SAVE_VERSION)
30+
return -1;
31+
32+
return amodem_state_load((AModem)opaque, (SysFile*)file);
33+
}
34+
35+
36+
void qemu_android_modem_init(int base_port) {
37+
android_modem_init(base_port);
38+
39+
if (android_modem_serial_line != nullptr) {
40+
register_savevm(nullptr,
41+
"android_modem",
42+
0,
43+
MODEM_DEV_STATE_SAVE_VERSION,
44+
modem_state_save,
45+
modem_state_load,
46+
android_modem);
47+
}
48+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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+
#pragma once
13+
#include "android/utils/compiler.h"
14+
15+
ANDROID_BEGIN_HEADER
16+
17+
/* must be called before the VM runs if there is a modem to emulate */
18+
extern void qemu_android_modem_init(int base_port);
19+
20+
ANDROID_END_HEADER

android/emulation/qemud/android_qemud_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646

4747
#if SUPPORT_LEGACY_QEMUD
4848
#include "android/telephony/modem.h"
49-
#include "android-qemu1-glue/telephony/modem_driver.h"
49+
#include "android/telephony/modem_driver.h"
5050
#endif

android/emulator-window.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "android/utils/bufprint.h"
2929
#include "android/utils/looper.h"
3030

31-
#include "android-qemu1-glue/telephony/modem_driver.h"
31+
#include "android/telephony/modem_driver.h"
3232

3333
#if CONFIG_QT
3434
#include "android/skin/qt/set-ui-emu-agent.h"

android/qemu-cellular-agent-impl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "android/android.h"
1616
#include "android/emulation/control/cellular_agent.h"
1717
#include "android/shaper.h"
18-
#include "android-qemu1-glue/telephony/modem_driver.h"
18+
#include "android/telephony/modem_driver.h"
1919

2020
static void cellular_setSignalStrength(int zeroTo31)
2121
{

android/qemu-telephony-agent-impl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "android/emulation/control/telephony_agent.h"
1616
#include "android/telephony/modem.h"
17-
#include "android-qemu1-glue/telephony/modem_driver.h"
17+
#include "android/telephony/modem_driver.h"
1818

1919
#include <ctype.h>
2020
#include <stdio.h>

android-qemu1-glue/telephony/modem_driver.c renamed to android/telephony/modem_driver.c

+2-27
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* it communicates through a serial port with "rild" (Radio Interface Layer Daemon)
1414
* on the emulated device.
1515
*/
16-
#include "modem_driver.h"
16+
#include "android/telephony/modem_driver.h"
1717

1818
#include "android/telephony/debug.h"
1919
#include "android/utils/debug.h"
2020

21-
#include "hw/hw.h"
21+
#include <string.h>
2222

2323
#define xxDEBUG
2424

@@ -128,38 +128,13 @@ modem_driver_read( void* _md, const uint8_t* src, int len )
128128
D( "%s: done\n", __FUNCTION__ );
129129
}
130130

131-
#define MODEM_DEV_STATE_SAVE_VERSION 1
132-
133-
static void
134-
modem_state_save(QEMUFile* file, void* opaque)
135-
{
136-
amodem_state_save((AModem)opaque, (SysFile*)file);
137-
}
138-
139-
static int
140-
modem_state_load(QEMUFile* file, void* opaque, int version_id)
141-
{
142-
if (version_id != MODEM_DEV_STATE_SAVE_VERSION)
143-
return -1;
144-
145-
return amodem_state_load((AModem)opaque, (SysFile*)file);
146-
}
147-
148131
static void
149132
modem_driver_init(int base_port, ModemDriver* dm, CSerialLine* sl) {
150133
dm->serial_line = sl;
151134
dm->in_pos = 0;
152135
dm->in_sms = 0;
153136
dm->modem = amodem_create( base_port, modem_driver_unsol, dm );
154137

155-
register_savevm(NULL,
156-
"android_modem",
157-
0,
158-
MODEM_DEV_STATE_SAVE_VERSION,
159-
modem_state_save,
160-
modem_state_load,
161-
dm->modem);
162-
163138
android_serialline_addhandlers(sl,
164139
dm,
165140
modem_driver_can_read,

net/net-android.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
#endif
133133

134134
#include "android/android.h"
135-
#include "android-qemu1-glue/telephony/modem_driver.h"
135+
#include "android/telephony/modem_driver.h"
136136

137137
static VLANState *first_vlan;
138138

qemu-char.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
#include "android/hw-kmsg.h"
106106
#include "android/hw-qemud.h"
107107
#include "android/utils/sockets.h"
108-
#include "android-qemu1-glue/telephony/modem_driver.h"
108+
#include "android/telephony/modem_driver.h"
109109
#endif /* CONFIG_ANDROID */
110110

111111
/***********************************************************/

vl-android.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#include "android/wear-agent/android_wear_agent.h"
8888
#include "exec/hwaddr.h"
8989
#include "migration/qemu-file.h"
90-
#include "android-qemu1-glue/telephony/modem_driver.h"
90+
#include "android/telephony/modem_driver.h"
9191
#include <errno.h>
9292
#include <fcntl.h>
9393
#include <signal.h>

0 commit comments

Comments
 (0)