diff --git a/android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java b/android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java index e7d78d0d8b..8b7f63fac6 100644 --- a/android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java +++ b/android/flavors/gms-enabled/com/mapswithme/maps/location/GoogleFusedLocationProvider.java @@ -37,16 +37,17 @@ class GoogleFusedLocationProvider extends BaseLocationProvider // Documentation is inconsistent with the code: "returns null if no locations are available". // https://developers.google.com/android/reference/com/google/android/gms/location/LocationResult#getLastLocation() //noinspection ConstantConditions - if (location == null) - return; - mListener.onLocationChanged(location); + if (location != null) + mListener.onLocationChanged(location); } @Override public void onLocationAvailability(@NonNull LocationAvailability availability) { - if (!availability.isLocationAvailable()) - mListener.onLocationError(ERROR_GPS_OFF); + if (!availability.isLocationAvailable()) { + LOGGER.w(TAG, "isLocationAvailable returned false"); + //mListener.onLocationError(ERROR_GPS_OFF); + } } } diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java index 460dc8ad59..ade44eb630 100644 --- a/android/src/com/mapswithme/maps/location/LocationHelper.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -319,11 +319,15 @@ public enum LocationHelper implements Initializable, AppBackgroundTrack public void onLocationError(int errCode) { mLogger.d(TAG, "onLocationError(): " + errCode); - if (errCode == ERROR_NOT_SUPPORTED && !(mLocationProvider instanceof AndroidNativeProvider)) + if (errCode == ERROR_NOT_SUPPORTED && + LocationUtils.areLocationServicesTurnedOn(mContext) && + !(mLocationProvider instanceof AndroidNativeProvider)) { - // Try to downgrade to native provider first before notifying the user. + // If location service is enabled, try to downgrade to the native provider first + // and restart the service before notifying the user. mLogger.d(TAG, "Downgrading to use native provider"); mLocationProvider = new AndroidNativeProvider(mContext, this); + restart(); return; } diff --git a/android/src/com/mapswithme/util/LocationUtils.java b/android/src/com/mapswithme/util/LocationUtils.java index 88084d1878..6d37a6c854 100644 --- a/android/src/com/mapswithme/util/LocationUtils.java +++ b/android/src/com/mapswithme/util/LocationUtils.java @@ -5,6 +5,7 @@ import android.content.ContentResolver; import android.content.Context; import android.location.Location; import android.location.LocationManager; +import android.os.Build; import android.provider.Settings; import android.view.Surface; @@ -99,17 +100,20 @@ public class LocationUtils return newLocation.getAccuracy() < lastAccuracy; } - - @SuppressLint("InlinedApi") - @SuppressWarnings("deprecation") public static boolean areLocationServicesTurnedOn(@NonNull Context context) { - final ContentResolver resolver = context.getContentResolver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) + { + final LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + return lm.isLocationEnabled(); + } + try { - return Settings.Secure.getInt(resolver, Settings.Secure.LOCATION_MODE) + return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE) != Settings.Secure.LOCATION_MODE_OFF; - } catch (Settings.SettingNotFoundException e) + } + catch (Settings.SettingNotFoundException e) { e.printStackTrace(); return false;