@@ -99,8 +99,6 @@ class SensorWebSocketServer(private val context: Context, address: InetSocketAdd
9999 clientWebsocket.setAttachment(TouchSensors ())
100100 notifyConnectionsChanged()
101101 }
102-
103- // TODO : handleGPSRequest(websocket) never gets called when app has no location permission
104102 CONNECTION_PATH_GPS -> handleGPSRequest(clientWebsocket)
105103 else -> clientWebsocket.close(CLOSE_CODE_UNSUPPORTED_REQUEST , " unsupported request" )
106104
@@ -254,31 +252,31 @@ class SensorWebSocketServer(private val context: Context, address: InetSocketAdd
254252
255253
256254
257- @SuppressLint(" MissingPermission" )
258255 private fun handleGPSRequest (clientWebsocket : WebSocket )
259256 {
260- if (! hasLocationPermission())
257+
258+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M &&
259+ context.checkSelfPermission(Manifest .permission.ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED )
261260 {
261+ // Reason message must be 123 bytes or less
262262 clientWebsocket.close(
263- CLOSE_CODE_PERMISSION_DENIED ,
264- " App has No permission to access location. Go to your device's installed apps settings and allow location permission to Sensor Server app "
263+ CLOSE_CODE_PERMISSION_DENIED ,
264+ " Location permission required. Please enable it in your device's App Settings. "
265265 )
266266 return
267267 }
268268
269-
269+ // In Android 5.0 permissions are granted at installation time
270270 locationManager.requestLocationUpdates(
271- LocationManager .GPS_PROVIDER ,
272- 0 ,
273- 0f ,
274- this ,
275- handlerThread.looper
271+ LocationManager .GPS_PROVIDER ,
272+ 0 ,
273+ 0f ,
274+ this ,
275+ handlerThread.looper
276276 )
277277
278278 clientWebsocket.setAttachment( GPS () )
279279
280-
281-
282280 notifyConnectionsChanged()
283281 }
284282
@@ -321,18 +319,6 @@ class SensorWebSocketServer(private val context: Context, address: InetSocketAdd
321319 {
322320 // super.onStatusChanged(provider, status, extras)
323321 }
324-
325- private fun hasLocationPermission (): Boolean
326- {
327- return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M )
328- {
329- context.checkSelfPermission(Manifest .permission.ACCESS_FINE_LOCATION ) == PackageManager .PERMISSION_GRANTED
330- }
331- else true
332-
333- // prior to android marshmallow dangerous permission are prompt at install time
334- }
335-
336322 override fun onClose (clientWebsocket : WebSocket , code : Int , reason : String , remote : Boolean )
337323 {
338324 Log .i(TAG ," Connection closed ${clientWebsocket.remoteSocketAddress} with exit code $code additional info: $reason " )
0 commit comments