Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WiFi Device-to-AP Round-Trip-Time (RTT)

Tags:

android

wifi

With Android API-Level 21, respectively 23 some methods to measure the Wifi roundtrip time (RTT) were added to the SDK:

  • WifiManager.isDeviceToApRttSupported()
  • ScanResult.is80211mcResponder()

But I do not find any information how to use the API to measure the RTT.

The relevant class RttManager is still marked as System API.

Is there any way to perform Device-To-AP RTT measurement?

like image 461
Christopher Avatar asked Sep 22 '16 13:09

Christopher


1 Answers

Starting with Android P a public API for Wi-Fi RTT (IEEE 802.11mc) is now available.

WiFiRttManager

Add the following to your AndroidManifest:

<manifest ...>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-feature android:name="android.hardware.wifi.rtt" />
    ...
</manifest>

Get instance of WiFiRttManager:

final WifiRttManager rttManager = (WifiRttManager) context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE);

Check if device supports Rtt measurements:

rttManager.isAvailable();

Perform a ranging:

// A ScanResult can be retrieved by e.g. perform a WiFi scan for WiFi's in range -> https://developer.android.com/reference/android/net/wifi/ScanResult.html 
final RangingRequest request = new RangingRequest.Builder()
                               .addAccessPoint(scanResult)
                               .build();
final RangingResultCallback callback = new RangingResultCallback() {
    public void onRangingResults(List<RangingResult> results) {
        // Handle result, e.g. get distance to Access Point
    }

    public void onRangingFailure(int code) {
        // Handle failure
    }
};
// Start ranging and return result on main thread.
rttManager.startRanging(request, callback, null);

Please notice that the Access Point has to support Wi-Fi RTT (IEEE 802.11mc) as well!

Update: A sample app can be found here: Android Wifi RttManager sample

like image 158
Christopher Avatar answered Sep 20 '22 13:09

Christopher