dpa99c / react-native-launch-navigator

A React Native module for launching today's most popular navigation/ride apps to navigate to a destination.
143 stars 34 forks source link

LaunchNavigator.isAppAvailable() returns true for disabled apps #12

Closed mortenpj closed 5 years ago

mortenpj commented 5 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior:

LaunchNavigator.isAppAvailable(LaunchNavigator.APP.GOOGLE_MAPS) returns true even when google maps have been disabled

Expected behavior:

LaunchNavigator.isAppAvailable(LaunchNavigator.APP.GOOGLE_MAPS) should return false when app is not available for using or launching

Steps to reproduce: Use android phone where Google maps can not be uninstalled. Press and hold over google maps icon until menu appears, choose disable app. Method LaunchNavigator.isAppAvailable(LaunchNavigator.APP.GOOGLE_MAPS) returns true

Environment information Not relevant for this bug

Have verified the bug with this phone, but would imagine its a problem for all phones where google maps can only be disabled and not uninstalled

Runtime issue

Other information: Same bug was fixed for phonegap https://github.com/dpa99c/phonegap-launch-navigator/issues/182

dpa99c commented 5 years ago

This module contains the code fix that was added by the commit to fix phonegap-launch-navigator#182. Therefore the behaviour should be the same for both the Phonegap plugin and this React Native module.

It's possible that on newer Android versions this fix no longer works - I'll need to test this to confirm.

dpa99c commented 5 years ago

I tested disabling of Google Maps using the example project on a Pixel 2 XL running Android Q. After disabling Google Maps and restarting the app, this module correctly detected Google Maps as unavailable

2019-07-02 08:36:24.377 11110-11138/com.rnlnexample D/LaunchNavigator[native]: google_maps is not available

Please build and run the example project on your device with Google Maps disabled - make sure to disable Google Maps before launching the example app.

mortenpj commented 5 years ago

I have verified that the code used in our application does not return the expected value. I see when I clone the git repo of the launcher example google maps is indeed not showing in the list. However this example project doesnt use the specific method which returns the incorrect value when google maps is disabled.

The specific method I'm using and which returns true even when google maps is disabled is the foloowing: LaunchNavigator.isAppAvailable(LaunchNavigator.APP.GOOGLE_MAPS)

I could also with some minor changes in the example project, reproduce it. (There might be a easier way but this is the way I could make the code run atleast)

In LNAppPicker.js change the method async getAvailableApps(): Promise to the following:

async getAvailableApps(): Promise{ LaunchNavigator.getAvailableApps() .then((apps) => { console.log("->getAvailableApps()"); let googleMapsApps = []; if(LaunchNavigator.isAppAvailable(LaunchNavigator.APP.GOOGLE_MAPS)){ googleMapsApps["google_maps"] = { name: "Google maps is available", available: true }; } else { googleMapsApps["google_maps"] = { name: "Google maps is disabled", available: true }; } this.setState({availableApps: googleMapsApps}); }) .catch((error) => { console.error(error); }); }

This will make it so it only shows one option in the selection list, but when google maps is disabled I expect this code to now show me the option "Google maps is disabled". However it shows the option "Google maps is available"

This is reproduced on a Samsung S7 edge running Android version 8.0.0 (Physical device)

dpa99c commented 5 years ago

OK, thanks for being explicit - I hadn't realised the example project doesn't actually use that method - it probably should so it can validate it going forward. Definitely sounds like a bug then. Will fix and push out in a patch release shortly.

mortenpj commented 5 years ago

That sounds great. Thanks for very fast responses

dpa99c commented 5 years ago

Finally had time to look into this.

The problem is a documentation issue rather than a bug in functionality. The actual method documentation is correct - it shows that isAppAvailable() returns a Promise (not a boolean). However the Advanced usage example is wrong and implies it returns a boolean.

Correct usage is:

LaunchNavigator.isAppAvailable(app).then((isAvailable) => console.log(app+" is available: " + isAvailable));

If you follow this usage, upon disabling Google Maps, the promise callback value for isAvailable will be false.

I'll fix the example mentioned above to resolve this issue.

mortenpj commented 5 years ago

Ah, I understand, I was specifically looking to detect if the app was available so I must have looked at the advanced usage documentation. I'll change it to use promise, and I assume I'll get the expected result.

Thank you