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]
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.
How about trying to use a mock location using setTestProviderLocation
?
Are you in eclipse? If so use the ddms to send mock locations to the virtual device.
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
精彩评论