[RTT] Fix legacy API crash on invalid RTT results
Legacy RTT API permitted access of results (e.g. distance) even when the measurement failed - the new API throws an exception. Add checks to the translation code (from new to legacy) so that exceptions aren't thrown - results are simply 0. Bug: 73297815 Test: builds, integration test is being developed Change-Id: I8286e36afe5597cc372e65b75f03a382ca0cd2b3
This commit is contained in:
@@ -15,6 +15,7 @@ import android.net.wifi.rtt.WifiRttManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
@@ -986,11 +987,16 @@ public class RttManager {
|
||||
legacyResults[i] = new RttResult();
|
||||
legacyResults[i].status = result.getStatus();
|
||||
legacyResults[i].bssid = result.getMacAddress().toString();
|
||||
legacyResults[i].distance = result.getDistanceMm() / 10;
|
||||
legacyResults[i].distanceStandardDeviation =
|
||||
result.getDistanceStdDevMm() / 10;
|
||||
legacyResults[i].rssi = result.getRssi();
|
||||
legacyResults[i].ts = result.getRangingTimestampUs();
|
||||
if (result.getStatus() == RangingResult.STATUS_SUCCESS) {
|
||||
legacyResults[i].distance = result.getDistanceMm() / 10;
|
||||
legacyResults[i].distanceStandardDeviation =
|
||||
result.getDistanceStdDevMm() / 10;
|
||||
legacyResults[i].rssi = result.getRssi();
|
||||
legacyResults[i].ts = result.getRangingTimestampUs();
|
||||
} else {
|
||||
// just in case legacy API needed some relatively real timestamp
|
||||
legacyResults[i].ts = SystemClock.elapsedRealtime() * 1000;
|
||||
}
|
||||
}
|
||||
listener.onSuccess(legacyResults);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user