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 { ...@@ -44,19 +44,29 @@ class GeolocationTracker {
private final Handler mHandler; private final Handler mHandler;
private final Runnable mCancelRunnable; private final Runnable mCancelRunnable;
private boolean mRegistrationFailed;
private SelfCancelingListener(LocationManager manager) { private SelfCancelingListener(LocationManager manager) {
mLocationManager = manager; mLocationManager = manager;
mHandler = new Handler(); mHandler = new Handler();
mCancelRunnable = new Runnable() { mCancelRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
try {
mLocationManager.removeUpdates(SelfCancelingListener.this); mLocationManager.removeUpdates(SelfCancelingListener.this);
} catch (Exception e) {
if (!mRegistrationFailed) throw e;
}
sListener = null; sListener = null;
} }
}; };
mHandler.postDelayed(mCancelRunnable, REQUEST_TIMEOUT_MS); mHandler.postDelayed(mCancelRunnable, REQUEST_TIMEOUT_MS);
} }
private void markRegistrationFailed() {
mRegistrationFailed = true;
}
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
mHandler.removeCallbacks(mCancelRunnable); mHandler.removeCallbacks(mCancelRunnable);
...@@ -131,7 +141,13 @@ class GeolocationTracker { ...@@ -131,7 +141,13 @@ class GeolocationTracker {
String provider = LocationManager.NETWORK_PROVIDER; String provider = LocationManager.NETWORK_PROVIDER;
if (locationManager.isProviderEnabled(provider)) { if (locationManager.isProviderEnabled(provider)) {
sListener = new SelfCancelingListener(locationManager); sListener = new SelfCancelingListener(locationManager);
try {
locationManager.requestSingleUpdate(provider, sListener, null); 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