Example indoor map

Android P and Wi-Fi RTT

Recently, Google launched the first developer preview build of Android™ P.  With this, several new features were announced, including two that caught my attention.  Those being Neural Networks 1.1 and Wi-Fi RTT. Wi-Fi RTT peaked my initial interest because it was something completely new in Android P.

 

What is Wi-Fi RTT?

 

Wi-Fi Round Trip Time is a part of the IEEE 802.11mc specification.  This specification defines how to determine a device’s distance from wireless access points, henceforth referred to as APs.  Given the location and distances from three different APs, we can use multilateration to determine a device’s location within a couple of meters.

 

How Does Wi-Fi RTT Work?

 

The formula that holds the key to allowing us to determine the distance from a device to an AP comes from high school physics, d = vt.  In other words, distance is equal to your velocity, or in this case speed, times the time you’re traveling. So, if we measure the amount of time it takes for data to get from an AP to our device and then multiply that by the speed, which for wireless signals is the speed of light, we will get the distance to that AP, which can be used in the multilateration algorithm.

 

This is Creepy!

 

My first reaction, and the first of many people who I talked to about this feature, was that being able to know my location within a couple of meters is a new level of creepy.  However, when I thought about this more, I realized it isn’t any more creepy compared to the location services we have right now. Currently, we can typically pinpoint a device’s location to roughly the building they are located at, which the extra fine tuning of the location information doesn’t make it any more creepy.  Also, since this is in the location framework on Android P, all of the built in permission settings still apply, including the app by app location permissions that have been in place since Android Marshmallow. It will be up to each user if they want to gain the additional benefits of the fine grained location information.  Additionally, all of the distance calculations are done on the device so the APs do not know your location.

 

What are the Benefits?

 

Some of the greatest areas that I can see immediate benefit from these high precision locations are in the realm of automation, indoor navigation, and smart home voice commands.  An example in the automation realm would be if a device operates in different rooms indoors, it could use the location to know exactly what room it is in and perform the proper tasks for that room.  Indoor navigation would be a great thing for events like conventions where you have a bunch of people coming to a new area and needing to find their way around the space in a hurry without having to find a map with a “You are here” indicator on it.  Home voice commands is the canonical example Google provided in the announcement in letting the assistant know which room you mean when you say, “Turn off the lights.” I look forward to seeing the many other beneficial uses that we come up with.

 

Where’s the Code?

 

While I wanted to have a working sample available for everyone, that won’t be the case currently as there is a bug with the startRanging method (https://issuetracker.google.com/issues/74362130).  However, I will give my understanding of the general flow for the process, which the elements of this can be referenced at their documentation at https://developer.android.com/reference/android/net/wifi/rtt/package-summary.html:

 

  1. Add the ACCESS_FINE_LOCATION and ACCESS_WIFI_STATE to your manifest
  2. Verify you have the ACCESS_FINE_LOCATION permission in your app, if not request the permission
  3. Get the WifiManager and WifiRttManager
  4. Using WifiManager, get a list of wifi networks you can see as a list containing ScanResult objects
  5. Using the scanResults create a RangingRequest via RangingRequest.Builder().addAccessPoints(scanResults).build()
  6. From here, you would then use the WifiRttManager you previously referenced to startRanging and within the callback’s onRangingResult(), you would then be able to access each of the AP’s RangingResult object.
    1. Within each RangingResult, you should be able to get the distance via getDistanceMm() and then the location of the AP via the LocationConfigurationInformation obtained from getReportedLocationConfigurationInformation()
    2. The latitude and longitude can be obtained via the methods getLatitude() and getLongitude() on the LocationConfigurationInformation object.  Additionally, you can get your altitude if you want to distinguish between different floors in the building you are in.
  7. From here you would use a multilateration algorithm to determine the location.

 

Look forward to a follow up post in the future, when the bug is patched, where we take a dive into the guts of the code and the multilateration algorithm.
 

References

 

*Android is a trademark of Google LLC.

Comments

I agree that inside geolocation is creepy, which is why I turn off location unless I need it.
But for rescue services being able to locate a phone to within ~2m would be great, or even better, transmit a rescuer's location to within ~2m. Dementia patient who is wandering in an urban or some suburban areas. Large, even small area, searches for the fire service - trying to search a club warehouse or gym in total darkness.
Maybe as a way to "ground truth" cell tower pings - I have been told of one case near us where when they checked the cell tower they found that the antenna locations were off by 180 degrees.

Looking at Android P APIs it seems they removed the getReportedLocationConfigurationInformation method.
https://developer.android.com/sdk/api_diff/p-dp2-incr/changes/android.n…
So no way now to get the position of the AP to be able to apply the trilateration.
This position should be known by the Application developed on top probably.
Don't know if Google is planing to manage Access Point positions on Google Maps.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

About the Author

James Simshaw, Senior Software Engineer

James went to Oregon State University to get a degree in computer science, and came out with degrees in computer science and mathematics. Having traversed the technical realm and some non-technical stops, James has found that his passions relate to solving problems and puzzles while helping improve the lives of others. Now, with his love of open source software, James is currently creating Android apps to enhance the lives of others.

James loves great stories, from anime, manga, novels, television shows to video games, board games, and Dungeons and Dragons. In addition to these, James loves attending conventions throughout the year.

Ready for transformation?