Commit 9b321c9e authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Add speculative fix for geolocation crash on older Androids.

BUG=819730

Change-Id: I772f0a960ecc79cc43d0f924448b2c7823755fb6
Reviewed-on: https://chromium-review.googlesource.com/953659Reviewed-by: default avatarMaria Khomenko <mariakhomenko@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541639}
parent 30edc2db
......@@ -44,19 +44,29 @@ class GeolocationTracker {
private final Handler mHandler;
private final Runnable mCancelRunnable;
private boolean mRegistrationFailed;
private SelfCancelingListener(LocationManager manager) {
mLocationManager = manager;
mHandler = new Handler();
mCancelRunnable = new Runnable() {
@Override
public void run() {
mLocationManager.removeUpdates(SelfCancelingListener.this);
try {
mLocationManager.removeUpdates(SelfCancelingListener.this);
} catch (Exception e) {
if (!mRegistrationFailed) throw e;
}
sListener = null;
}
};
mHandler.postDelayed(mCancelRunnable, REQUEST_TIMEOUT_MS);
}
private void markRegistrationFailed() {
mRegistrationFailed = true;
}
@Override
public void onLocationChanged(Location location) {
mHandler.removeCallbacks(mCancelRunnable);
......@@ -131,7 +141,13 @@ class GeolocationTracker {
String provider = LocationManager.NETWORK_PROVIDER;
if (locationManager.isProviderEnabled(provider)) {
sListener = new SelfCancelingListener(locationManager);
locationManager.requestSingleUpdate(provider, sListener, null);
try {
locationManager.requestSingleUpdate(provider, sListener, null);
} catch (NullPointerException ex) {
// https://crbug.com/819730: This can trigger an NPE due to a underlying
// OS/framework bug. By ignoring this, we will not get a newer location age.
sListener.markRegistrationFailed();
}
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment