DO NOT MERGE: Always return non null from getGpsStatus

Even though getGpsStatus is marked Nullable, some applications expect it
to always return non-null.

Bug: 161311411
Test: presubmits
Change-Id: I8d58621588253af1dc917711e230cfd176afec37
This commit is contained in:
Soonil Nagarkar
2020-07-15 11:28:58 -07:00
parent 218b61acf4
commit d9df33d1c0
2 changed files with 14 additions and 0 deletions

View File

@@ -151,6 +151,15 @@ public final class GpsStatus {
return status; return status;
} }
/**
* Builds an empty GpsStatus.
*
* @hide
*/
static GpsStatus createEmpty() {
return new GpsStatus();
}
private GpsStatus() { private GpsStatus() {
} }

View File

@@ -1922,12 +1922,17 @@ public class LocationManager {
GnssStatus gnssStatus = mGnssStatusListenerManager.getGnssStatus(); GnssStatus gnssStatus = mGnssStatusListenerManager.getGnssStatus();
int ttff = mGnssStatusListenerManager.getTtff(); int ttff = mGnssStatusListenerManager.getTtff();
// even though this method is marked nullable, there are legacy applications that expect
// this to never return null, so avoid breaking those apps
if (gnssStatus != null) { if (gnssStatus != null) {
if (status == null) { if (status == null) {
status = GpsStatus.create(gnssStatus, ttff); status = GpsStatus.create(gnssStatus, ttff);
} else { } else {
status.setStatus(gnssStatus, ttff); status.setStatus(gnssStatus, ttff);
} }
} else if (status == null) {
status = GpsStatus.createEmpty();
} }
return status; return status;
} }