Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App force close when GPS is disabled from the notification drawer. #4984

Open
sourabhsharmait opened this issue Feb 23, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@sourabhsharmait
Copy link

Summary

In Android version 10, When user using the location services and disabled the location from drawer. App got crash. We tried to debug it on Android studio cat log but didn't able to find any way to fix it in our react native project.

Reproducible sample code

"react-native-maps": "^1.10.3",

Steps to reproduce

Disable the locaiton from drawer. Try on and off

Expected result

App should not crash

Actual result

Got Crash

React Native Maps Version

1.10.3

What platforms are you seeing the problem on?

Android

React Native Version

0.72.4

What version of Expo are you using?

Not using Expo

Device(s)

realme 3i

Additional information

FATAL EXCEPTION: mqt_native_modules
Process: com.enviro, PID: 8697
java.lang.AbstractMethodError: abstract method "void android.location.LocationListener.onProviderDisabled(java.lang.String)"
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:365)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:275)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:291)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:227)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:919)

Screenshot 2024-02-23 at 4 03 01 PM
@sourabhsharmait sourabhsharmait added the bug Something isn't working label Feb 23, 2024
@mateki0
Copy link
Collaborator

mateki0 commented Feb 25, 2024

Hi @sourabhsharmait thanks for reporting this bug. Can you provide any reproducible sample? I mean the mapView component and the component in which it is used.
I have tried to reproduce it in android simulator with Android 10, but it works fine. Maybe it is happening only on devices but I don't have any with Android 10 right now.

@sourabhsharmait
Copy link
Author

sourabhsharmait commented Feb 27, 2024

In our code, we are using only geolocation library. I dont know why its showing the name of this library folder while trying to debugging in Android Studio.

The screenshot above is also share from android studio logs. I guess map library might be internally interconnected with Geo location. For more clarity on this issue, I am sharing below code related to fetching current location. This got crash only when user tried to disable the location form notification drawer.

import Geolocation from '@react-native-community/geolocation';

useEffect(() => {
getCurrentLocation();
}, []);

useEffect(() => {
// getCurrentLocation();
const handleAppStateChange = (nextAppState) => {
console.log('nextAppState', nextAppState);
if (appState.match(/inactive|background/) && nextAppState === 'active') {
getCurrentLocation();
}
setAppState(nextAppState);

};

const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);

return () => {
  appStateSubscription.remove();
};

}, [appState]);

const getCurrentLocation = async () => {
try {
const result = await Promise.race([
request(
Platform.OS === "ios" ? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE : PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
),
new Promise((_, reject) => setTimeout(() => reject('Location request timed out'), 7000)),
]);

  setPermissionStatus(result);
  onLocationChange(null);
  if (result === RESULTS.GRANTED) {
    Geolocation.getCurrentPosition(
      (position) => {
        const { latitude, longitude } = position.coords;
        onLocationChange({ latitude, longitude, permissionStatus });
        setRetryCount(0); // Reset retry count on successful location retrieval
      },
      (error) => {
        onLocationChange("location_faild");
        // if (error?.message == 'No location provider available.') {
        //   Alert.alert('GPS Disabled',
        //     'To use this app, please enable GPS (location services) on your device. ' +
        //     'You can enable it in your device settings.', [
        //     { text: AppString.OK, style: 'cancel', onPress: () => navigation.goBack() },
        //   ]);
        //   return;
        // }
        // if (retryCount < getMaxRetries) {
        //   setRetryCount(retryCount + 1);
        //   setTimeout(getCurrentLocation, 1000); // Retry Fetch Location here
        // } else {
        //   onLocationChange("Failed");
        //   console.log("Failed to retrieve location");
        // }
      },
      { timeout: 60000, enableHighAccuracy: false } // Added enableHighAccuracy: false
    );
  } else if (result === RESULTS.DENIED) {
    onLocationChange('location_faild');
    alertPopup();
  } else if (result === RESULTS.BLOCKED) {
    onLocationChange('location_faild');
    alertPopup();
  } else if (result == RESULTS.UNAVAILABLE) {
    onLocationChange('location_faild');
  }
} catch (error) {
  console.error(error);
  onLocationChange(null);
}

};

@mateki0
Copy link
Collaborator

mateki0 commented Feb 28, 2024

Thanks for the code @sourabhsharmait. I think that you should report this bug here https://github.com/michalchudziak/react-native-geolocation. Because even if I reproduce the bug I wouldn't be able to help you since I don't know geolocation source code.
Both libraries may use the same native location services but I can't see any usage of rn-maps in geolocation library.

@sourabhsharmait
Copy link
Author

Ok @mateki0 I will report this bug on geolocation library. Thanks for the guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants