From 8f3745c71b2b8747d66842d9e7af4829fdea8ee0 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 29 Aug 2020 19:22:12 -0700 Subject: [PATCH] don't send autobugs if the user is a dummy that refuses location access --- .../geeksville/mesh/service/MeshService.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index d2e1808fc..8468cbb98 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -29,6 +29,7 @@ import com.geeksville.mesh.MeshProtos.MeshPacket import com.geeksville.mesh.MeshProtos.ToRadio import com.geeksville.mesh.R import com.geeksville.util.* +import com.google.android.gms.common.api.ApiException import com.google.android.gms.common.api.ResolvableApiException import com.google.android.gms.location.* import com.google.protobuf.ByteString @@ -262,20 +263,30 @@ class MeshService : Service(), Logging { locationSettingsResponse.addOnFailureListener { exception -> errormsg("Failed to listen to GPS") - if (exception is ResolvableApiException) { - exceptionReporter { - // Location settings are not satisfied, but this can be fixed - // by showing the user a dialog. - // Show the dialog by calling startResolutionForResult(), - // and check the result in onActivityResult(). - // exception.startResolutionForResult(this@MainActivity, REQUEST_CHECK_SETTINGS) + when (exception) { + is ResolvableApiException -> + exceptionReporter { + // Location settings are not satisfied, but this can be fixed + // by showing the user a dialog. - // For now just punt and show a dialog - warnUserAboutLocation() - } - } else - Exceptions.report(exception) + // Show the dialog by calling startResolutionForResult(), + // and check the result in onActivityResult(). + // exception.startResolutionForResult(this@MainActivity, REQUEST_CHECK_SETTINGS) + + // For now just punt and show a dialog + warnUserAboutLocation() + } + is ApiException -> + if (exception.statusCode == 17) { + // error: cancelled by user + errormsg("User cancelled location access", exception) + } else { + Exceptions.report(exception) + } + else -> + Exceptions.report(exception) + } } val client = LocationServices.getFusedLocationProviderClient(this)