fix NullPointerException if location is not set.

Bug: http://b/issue?id=2490154
This commit is contained in:
Bernd Holzhey
2010-03-05 14:13:29 +01:00
parent ff846009ec
commit c44c6d038d

View File

@@ -181,8 +181,7 @@ class DockObserver extends UEventObserver {
public void onLocationChanged(Location location) {
final boolean hasMoved = hasMoved(location);
final boolean hasBetterAccuracy = location.getAccuracy() < mLocation.getAccuracy();
if (hasMoved || hasBetterAccuracy) {
if (hasMoved || hasBetterAccuracy(location)) {
synchronized (this) {
mLocation = location;
}
@@ -201,6 +200,16 @@ class DockObserver extends UEventObserver {
public void onStatusChanged(String provider, int status, Bundle extras) {
}
private boolean hasBetterAccuracy(Location location) {
if (location == null) {
return false;
}
if (mLocation == null) {
return true;
}
return location.getAccuracy() < mLocation.getAccuracy();
}
/*
* The user has moved if the accuracy circles of the two locations
* don't overlap.