Fix location permission crash (NavigationService)

This commit is contained in:
Alexey Kulish 2016-03-29 18:48:32 +03:00
parent 5fa6036c3e
commit b431724a1a

View file

@ -144,6 +144,9 @@ public class NavigationService extends Service implements LocationListener {
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(serviceOffProvider, 0, 0, NavigationService.this);
} catch (SecurityException e) {
Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show();
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
Toast.makeText(this, R.string.gps_not_available, Toast.LENGTH_LONG).show();
Log.d(PlatformUtil.TAG, "GPS location provider not available"); //$NON-NLS-1$
@ -202,7 +205,11 @@ public class NavigationService extends Service implements LocationListener {
usedBy = 0;
// remove updates
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.removeUpdates(this);
} catch (SecurityException e) {
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
}
if (!isContinuous()) {
WakeLock lock = getLock(this);
@ -225,7 +232,11 @@ public class NavigationService extends Service implements LocationListener {
if (!isContinuous()) {
// unregister listener and wait next time
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.removeUpdates(this);
} catch (SecurityException e) {
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
}
WakeLock lock = getLock(this);
if (lock.isHeld()) {
lock.release();