[MOD-2334] Android: Ti.Map will crash with userLocation enabled when Android M permissions are denied
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-08-10T01:14:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.2.0 |
Components | Map |
Labels | android, map, permissions |
Reporter | Michael Gangolf |
Assignee | Gary Mathews |
Created | 2017-04-23T12:10:52.000+0000 |
Updated | 2017-08-29T00:25:03.000+0000 |
Description
A MapView with
userLocation:true
in TSS will crash the app if you don't allow the Android M ACCESS_FINE_LOCATION.
While it is correct behavior, that it shouldn't display the userLocation because of the permissions it would be nice to still use the app and just display a warning instead of crashing.
*Workaround*
remove the TSS entry and add userLocation in your controller once you've checked the Ti.Geolocation.requestLocationPermissions
.
*Fix*
A better fix would be to add a permission check at:
https://github.com/appcelerator-modules/ti.map/blob/24e9a4014f42dc4412f29979736b13f0f2c8caff/android/src/ti/map/TiUIMapView.java#L302
*untested example*
Context context = TiApplication.getInstance().getApplicationContext();
if (Build.VERSION.SDK_INT < 23 || context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
map.setMyLocationEnabled(enabled);
} else {
Log.e(TAG, "Enable ACCESS_FINE_LOCATION permission to use userLocation")
}
Hello, Can you provide a demo app for us to test the issue? Thanks.
Of course, sorry: * add
<module>ti.map</module>
to tiapp.xml * add this to the<android>
block (no real key needed):* add
Alloy.Globals.Map = require('ti.map');
to alloy.js *index.xml**index.tss*
Run the app. Crash: {noformat} [ERROR] TiApplication: (main) [1519,1519] Sending event: exception on thread: main msg:java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION; Titanium 6.0.3,2017/03/22 12:00,undefined [ERROR] TiApplication: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION {noformat}
PR: https://github.com/appcelerator-modules/ti.map/pull/208
FR Passed. PR merged.
Verified the fix with module 3.3.0. Closing. Studio Ver: 4.9.1.201707200100 SDK Ver: 6.2.0.v20170828140722 OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.3 Appc NPM: 4.2.9 Appc CLI: 6.2.3 Ti CLI Ver: 5.0.14 Alloy Ver: 1.9.13 Node Ver: 6.10.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 --- Android 6.0.1 ⇨ google Pixel --- Android 7.1.1 Map Module : 3.3.0