Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fake gps for android running in virtual-box

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]

like image 976
Vikram.exe Avatar asked Feb 25 '23 07:02

Vikram.exe


2 Answers

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

enter image description here

Now to complete this flow, following steps were required:

  1. I created my own libgps.so exporting the function gps_get_interface (declared in gps.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.

  2. 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).

  3. 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.

  4. Now to send any fake/dummy location back to an app running inside Android VM, you just need to notify the host service, and the rest is communicated back to VBox Additions -> libgps.so -> GpsLocationProvider service -> and finally to the App 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.

like image 174
Vikram.exe Avatar answered Mar 04 '23 18:03

Vikram.exe


How about trying to use a mock location using setTestProviderLocation?

like image 34
user432209 Avatar answered Mar 04 '23 18:03

user432209