在虚拟盒中运行的 Android 假 GPS
我正在尝试在虚拟盒中运行的 Android 中虚拟化 GPS 设备。我想促进在 android 中运行的应用程序使用 gps 设备或以某种方式获取假 gps 位置。我已经开始查看 android 模拟器源代码,但与此同时,任何人都有任何好的起点。
[更新]
为了更清楚一点,整个应用程序堆栈将类似于:
Android app (with gps functionality) to be tested ----> (developed by end user)
Android virtual machine ----> (Guest OS)
virtual box ---->
Microsoft Windows ---> Host OS
现在,理想情况下我希望拥有我的应用程序(例如 adb
或 < code>ddms) 在 Windows 中运行,用户可以在其中为 GPS 设备设置一些坐标值(在没有实际 GPS 的情况下,否则虚拟化现有的 GPS)。这些坐标可供 Android 应用程序使用。基本上,这与通过运行 Android 映像的虚拟盒提供现有 Android 模拟器(使用 ddms)的功能相同。
我没有运行 android 模拟器,也没有使用 eclipse。 :( [更新结束]
I am trying to virtualize GPS device in android running in virtual-box. I want to facilitate an app running in android to use the gps device or get a fake gps location some how. I have started looking at the android emulator source code but meanwhile, any one has any good place to start with.
[UPDATE]
To make it a bit more clear, the whole application stack would be some thing like:
Android app (with gps functionality) to be tested ----> (developed by end user)
Android virtual machine ----> (Guest OS)
virtual box ---->
Microsoft Windows ---> Host OS
Now, Ideally I would like to have my application (like adb
or ddms
) running in Windows from where the user can set some coordinate values for gps device (in absence of actual GPS, else virtualize the existing GPS) . These coordinates would be available to the android app. Basically, this is same as providing the functionality of existing android emulator (using ddms) through virtual-box
running an android image.
I am NOT running android emulator and I am not using eclipse. :(
[UPDATE ENDS]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是我的做法(以及 android 堆栈(在 vbox 上运行)如何工作的简要概述)。
具有 GPS 功能的 Android 应用程序,使用 JNI 接口(在框架/base/core/jni/android_location_GpsLocationProvider.cpp 中导出)向用户模式共享库(通常是 libgps.so 或 libhardware_legacy.so)的底层实现注册一些回调)
这些注册的回调负责向应用程序通知 GPS 修复(或 GPS 位置更改)。
这是一个简单的图像,演示了来自
Android -> 的调用流程。垂直框-> Windows
现在要完成此流程,需要执行以下步骤:
我创建了我的自己的
libgps.so
导出函数gps_get_interface
(在gps.h
中声明),由JNI接口使用。支持 GPS 的应用程序会获取从此 libgps.so 返回的最新坐标,该库实际上是由 GpsLocationProvider 服务动态加载的。使用 Vbox 标头创建另一个共享对象,并包含用于连接、断开连接以及向在主机操作系统中运行的
主机服务
发送功能请求的例程。这些是带有预定义 ioctl 编号的简单 ioctl 调用(例如:VBOX_GUEST_IOCTL_HGCM_CONNECT 等)。创建一个主机服务(实际上是一个DLL,由
VBox Host Service
加载),可以处理从HGCM调用传递的参数,并以共享对象创建的格式返回所需的数据步骤2理解。现在要将任何虚假/虚拟位置发送回
Android VM
内运行的应用程序,您只需通知主机服务
,其余的将被传回VBox 添加
->libgps.so
->GpsLocationProvider 服务
->最后发送到支持 GPS 的应用
。希望这能帮助某人尝试类似的事情,或者帮助某人了解 Android 堆栈的工作原理。
注意:编译 hgcm 代码并将其与 android lib 链接也有点复杂,因为 android libc(以及其他一些库)中实现的函数数量有限。为了避免这一切,您可以直接打开设备 (/dev/vboxguest) 并以 vbox 和主机服务已知的格式对其发出 ioctl 调用。
This is how I did it (and a brief overview of how android stack (running on vbox) works).
An Android app having GPS functionality, registers some callbacks with the underlying implementation of user mode shared lib (typically libgps.so or libhardware_legacy.so) using JNI interfaces (as exported in
frameworks/base/core/jni/android_location_GpsLocationProvider.cpp
)These registered callbacks are responsible for notifying GPS fix (or change in gps location) to the app.
Here is a simple image demonstrating call flow from
Android -> VBox -> Windows
Now to complete this flow, following steps were required:
I created my own
libgps.so
exporting the functiongps_get_interface
(declared ingps.h
), which is used by JNI interface. An app with gps support gets the latest coordinates returned from this libgps.so, which is actually loaded dynamically by the GpsLocationProvider service.Create one more shared object using Vbox headers and containing routines to connect, disconnect, and send function request to the
host service
, running in host OS. These are simple ioctl calls with pre-defined ioctl-numbers (eg: VBOX_GUEST_IOCTL_HGCM_CONNECT etc).Create a host service (which actually is a DLL, loaded by
VBox Host Service
) with can handle the parameters passed from HGCM calls and return the required data in a format that the shared object created in step 2 understands.Now to send any fake/dummy location back to an app running inside
Android VM
, you just need to notify thehost service
, and the rest is communicated back toVBox Additions
->libgps.so
->GpsLocationProvider service
-> and finally to theApp with GPS Support
.Hope this will help some one trying some thing similar or help some one understanding how android stack works.
NOTE: Compiling the hgcm code and linking it with android lib is also a bit complicated because of the limited number of functions implemented in android libc (and some other libs as well). To avoid this all, you can directly open the device (/dev/vboxguest) and issue ioctl calls on it in the format that is known to vbox and your host service.
尝试使用模拟位置如何
setTestProviderLocation
?How about trying to use a mock location using
setTestProviderLocation
?你在日食吗?如果是这样,请使用 ddms 将模拟位置发送到虚拟设备。
Are you in eclipse? If so use the ddms to send mock locations to the virtual device.
如果您使用的是 Eclipse,请转到 DDMS 透视图,然后转到模拟器控制部分。在那里您将看到 2 个纬度和经度文本框。然后单击“发送”,该信息将被发送到模拟器。
或者,您可以 telnet 到模拟器并传递 GPS 信息:
例子
远程登录本地主机 5554
地理修复 -82.411629 28.054553
http://www.devx.com/wireless/Article/39239/ 1954年
If you are using eclipse go to DDMS perpective, then go to Emulator Control section. There you will see 2 textbox for latitude and longitude. Then you click on send and that info will be sent to the emulator.
Alternatively you could telnet into the emulator a pass the GPS info:
Example
telnet localhost 5554
geo fix -82.411629 28.054553
http://www.devx.com/wireless/Article/39239/1954