Hi, playing with the "edge cases" of our app, I tried to don't allow the permission for the location and checked the "Never ask again". When doing that, it seems Mapbox asks in an infinite loop the permission.
In the logcat, I see that block repeating infinitely:
04-25 11:53:12.794 1418 1437 I ActivityManager: START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller cmp=com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity (has extras)} from uid 10371 pid 15958
04-25 11:53:12.795 1418 1437 E BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-25 11:53:12.797 1418 1455 D RestartProcessManager: Duration is too short, ignore : 306 in com.sparks
04-25 11:53:12.797 15958 15958 D AppTracker: App Event: stop
04-25 11:53:12.804 1418 4065 D WifiService: getConnectionInfo uid=1000
04-25 11:53:12.806 1418 1455 D RestartProcessManager: Update Total Launch Times :com.google.android.packageinstaller
04-25 11:53:12.806 1418 1455 D RestartProcessManager: sLastRunningPackage (null) : com.google.android.packageinstaller
04-25 11:53:12.810 15958 16115 D NativeCrypto: jniThrowException: java/net/SocketTimeoutException: Read timed out
04-25 11:53:12.829 16324 16324 E BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-25 11:53:12.829 16324 16324 E BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-25 11:53:12.836 1418 1455 D RestartProcessManager: Update Total Launch Times :com.sparks
04-25 11:53:12.836 1418 1455 D RestartProcessManager: updateSelf : com.sparks, size : 30
04-25 11:53:12.836 1418 1455 D RestartProcessManager: Increase Total Launch Time : com.sparks, times : 2, index : 29
04-25 11:53:12.836 1418 1455 D RestartProcessManager: Last Running Package : com.sparks , start time 1524649992836
04-25 11:53:12.848 3589 3589 D BlurWallpaper2.Engine: onVisibilityChanged# false -> true
04-25 11:53:12.849 3589 3589 D BlurWallpaper2.Engine: onVisibilityChanged# true -> false
04-25 11:53:12.857 867 888 E Sensors : sns_reg_la.c(188):reg read: offset 2304, num bytes: 1
04-25 11:53:12.867 1418 4065 D WifiService: getConnectionInfo uid=1000
04-25 11:53:12.868 1418 4065 D WifiService: getConnectionInfo uid=1000
04-25 11:53:12.869 15958 15958 D AppTracker: App Event: start
04-25 11:53:12.871 1418 4065 D WifiService: getConnectionInfo uid=1000
04-25 11:53:12.871 1418 4065 D WifiService: getConnectionInfo uid=1000
We ask the permission with those lines:
MapboxGL.requestAndroidLocationPermissions().then((isGranted) => {
if (isGranted) {
// Do something here
}
});
Do you have the same issue ? Or is it just us ? We tried on two different phones but only OnePlus (5 and 5T).
I found the bug and it's not really related to Mapbox but if someone has the same issue as me, here is the reason.
We check the location at each AppState change from background to active state. When the app goes active, we use MapboxGL.requestAndroidLocationPermissions() to check the permissions and request them if needed.
As the request is in "never_ask_again" state, the permission is not really asked and the permission window is directly dismissed (automatically). But it's a modal, so the AppState changes from active to background and then from background to active.
Meaning that a new request is asked, conducting to an infinite loop.
To solve this, I simply added a "debounce" trick before calling the MapboxGL.requestAndroidLocationPermissions() method:
const date = +new Date();
if (date - this._lastLocationAsk < 10000) return;
this._lastLocationAsk = date;
It can be added to the requestAndroidLocationPermissions method itself but I think this bug is just an edge case and my trick can cause some issues in some other use cases.
@Gp2mv3 thanks a lot this happened to me as well. Debounce is not a perfect solution because it will still be fired every 10s because the issue is recursive. The best solution is to avoid calling that on this kind of state change and only call once at startup as stated in: https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/90
Most helpful comment
I found the bug and it's not really related to Mapbox but if someone has the same issue as me, here is the reason.
We check the location at each AppState change from background to active state. When the app goes active, we use
MapboxGL.requestAndroidLocationPermissions()to check the permissions and request them if needed.As the request is in "never_ask_again" state, the permission is not really asked and the permission window is directly dismissed (automatically). But it's a modal, so the AppState changes from active to background and then from background to active.
Meaning that a new request is asked, conducting to an infinite loop.
To solve this, I simply added a "debounce" trick before calling the
MapboxGL.requestAndroidLocationPermissions()method:It can be added to the
requestAndroidLocationPermissionsmethod itself but I think this bug is just an edge case and my trick can cause some issues in some other use cases.