Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2334] Android: Ti.Map will crash with userLocation enabled when Android M permissions are denied

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-08-10T01:14:56.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.2.0
ComponentsMap
Labelsandroid, map, permissions
ReporterMichael Gangolf
AssigneeGary Mathews
Created2017-04-23T12:10:52.000+0000
Updated2017-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")
}

Comments

  1. Sharif AbuDarda 2017-04-25

    Hello, Can you provide a demo app for us to test the issue? Thanks.
  2. Michael Gangolf 2017-04-25

    Of course, sorry: * add <module>ti.map</module> to tiapp.xml * add this to the <android> block (no real key needed):
    <manifest>
           <application>
               <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="my-key"/>
           </application>
       </manifest>
       
    * add Alloy.Globals.Map = require('ti.map'); to alloy.js *index.xml*
       <Alloy>
       	<Window class="container">
       		<View id="mapview" module="ti.map"/>
       	</Window>
       </Alloy>
       
    *index.tss*
       "#mapview": {
       	userLocation:true
       }
       
    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}
  3. Michael Gangolf 2017-07-05

    PR: https://github.com/appcelerator-modules/ti.map/pull/208
  4. Lokesh Choudhary 2017-08-10

    FR Passed. PR merged.
  5. Lokesh Choudhary 2017-08-29

    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

JSON Source