Fix reintroduction of b/10845061
Prevent crash in case where NLP is not available. Also fix an integer overflow bug that remained uncaught. BUG: 22345134 Change-Id: If6ff7b12f0d15bb2fe97589f8b0be10f9ed06197
This commit is contained in:
@@ -37,7 +37,7 @@ import android.util.Log;
|
||||
|
||||
public class FusionEngine implements LocationListener {
|
||||
public interface Callback {
|
||||
public void reportLocation(Location location);
|
||||
void reportLocation(Location location);
|
||||
}
|
||||
|
||||
private static final String TAG = "FusedLocation";
|
||||
@@ -45,7 +45,7 @@ public class FusionEngine implements LocationListener {
|
||||
private static final String GPS = LocationManager.GPS_PROVIDER;
|
||||
private static final String FUSED = LocationProviderBase.FUSED_PROVIDER;
|
||||
|
||||
public static final long SWITCH_ON_FRESHNESS_CLIFF_NS = 11 * 1000000000; // 11 seconds
|
||||
public static final long SWITCH_ON_FRESHNESS_CLIFF_NS = 11 * 1000000000L; // 11 seconds
|
||||
|
||||
private final Context mContext;
|
||||
private final LocationManager mLocationManager;
|
||||
@@ -60,7 +60,7 @@ public class FusionEngine implements LocationListener {
|
||||
private boolean mEnabled;
|
||||
private ProviderRequestUnbundled mRequest;
|
||||
|
||||
private final HashMap<String, ProviderStats> mStats = new HashMap<String, ProviderStats>();
|
||||
private final HashMap<String, ProviderStats> mStats = new HashMap<>();
|
||||
|
||||
public FusionEngine(Context context, Looper looper) {
|
||||
mContext = context;
|
||||
@@ -72,9 +72,7 @@ public class FusionEngine implements LocationListener {
|
||||
mLooper = looper;
|
||||
|
||||
mStats.put(GPS, new ProviderStats());
|
||||
mStats.get(GPS).available = mLocationManager.isProviderEnabled(GPS);
|
||||
mStats.put(NETWORK, new ProviderStats());
|
||||
mStats.get(NETWORK).available = mLocationManager.isProviderEnabled(NETWORK);
|
||||
|
||||
}
|
||||
|
||||
@@ -119,35 +117,35 @@ public class FusionEngine implements LocationListener {
|
||||
}
|
||||
|
||||
private static class ProviderStats {
|
||||
public boolean available;
|
||||
public boolean requested;
|
||||
public long requestTime;
|
||||
public long minTime;
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(available ? "AVAILABLE" : "UNAVAILABLE");
|
||||
s.append(requested ? " REQUESTED" : " ---");
|
||||
return s.toString();
|
||||
return (requested ? " REQUESTED" : " ---");
|
||||
}
|
||||
}
|
||||
|
||||
private void enableProvider(String name, long minTime) {
|
||||
ProviderStats stats = mStats.get(name);
|
||||
if (stats == null) return;
|
||||
|
||||
if (!stats.requested) {
|
||||
stats.requestTime = SystemClock.elapsedRealtime();
|
||||
stats.requested = true;
|
||||
stats.minTime = minTime;
|
||||
mLocationManager.requestLocationUpdates(name, minTime, 0, this, mLooper);
|
||||
} else if (stats.minTime != minTime) {
|
||||
stats.minTime = minTime;
|
||||
mLocationManager.requestLocationUpdates(name, minTime, 0, this, mLooper);
|
||||
if (mLocationManager.isProviderEnabled(name)) {
|
||||
if (!stats.requested) {
|
||||
stats.requestTime = SystemClock.elapsedRealtime();
|
||||
stats.requested = true;
|
||||
stats.minTime = minTime;
|
||||
mLocationManager.requestLocationUpdates(name, minTime, 0, this, mLooper);
|
||||
} else if (stats.minTime != minTime) {
|
||||
stats.minTime = minTime;
|
||||
mLocationManager.requestLocationUpdates(name, minTime, 0, this, mLooper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void disableProvider(String name) {
|
||||
ProviderStats stats = mStats.get(name);
|
||||
if (stats == null) return;
|
||||
|
||||
if (stats.requested) {
|
||||
stats.requested = false;
|
||||
@@ -156,7 +154,7 @@ public class FusionEngine implements LocationListener {
|
||||
}
|
||||
|
||||
private void updateRequirements() {
|
||||
if (mEnabled == false || mRequest == null) {
|
||||
if (!mEnabled || mRequest == null) {
|
||||
mRequest = null;
|
||||
disableProvider(NETWORK);
|
||||
disableProvider(GPS);
|
||||
@@ -248,7 +246,7 @@ public class FusionEngine implements LocationListener {
|
||||
mFusedLocation.setExtras(dstExtras);
|
||||
}
|
||||
dstExtras.putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION,
|
||||
(Location) srcParcelable);
|
||||
srcParcelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,25 +276,15 @@ public class FusionEngine implements LocationListener {
|
||||
|
||||
/** Called on mLooper thread */
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
ProviderStats stats = mStats.get(provider);
|
||||
if (stats == null) return;
|
||||
|
||||
stats.available = true;
|
||||
}
|
||||
public void onProviderEnabled(String provider) { }
|
||||
|
||||
/** Called on mLooper thread */
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
ProviderStats stats = mStats.get(provider);
|
||||
if (stats == null) return;
|
||||
|
||||
stats.available = false;
|
||||
}
|
||||
public void onProviderDisabled(String provider) { }
|
||||
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("mEnabled=" + mEnabled).append(' ').append(mRequest).append('\n');
|
||||
s.append("mEnabled=").append(mEnabled).append(' ').append(mRequest).append('\n');
|
||||
s.append("fused=").append(mFusedLocation).append('\n');
|
||||
s.append(String.format("gps %s\n", mGpsLocation));
|
||||
s.append(" ").append(mStats.get(GPS)).append('\n');
|
||||
|
||||
Reference in New Issue
Block a user