diff --git a/app/build.gradle b/app/build.gradle index be3da5d86..3835898b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 10790 // format is Mmmss (where M is 1+the numeric major number - versionName "0.7.90" + versionCode 10791 // format is Mmmss (where M is 1+the numeric major number + versionName "0.7.91" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -137,7 +137,7 @@ dependencies { implementation 'com.google.android.gms:play-services-auth:18.0.0' // Add the Firebase SDK for Crashlytics. - implementation 'com.google.firebase:firebase-crashlytics:17.1.0' + implementation 'com.google.firebase:firebase-crashlytics:17.1.1' // alas implementation bug deep in the bowels when I tried it for my SyncBluetoothDevice class // implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3" diff --git a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl index 61daff671..c8c5d09e7 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IMeshService.aidl @@ -62,6 +62,7 @@ interface IMeshService { /// If a macaddress we will try to talk to our device, if null we will be idle. /// Any current connection will be dropped (even if the device address is the same) before reconnecting. /// Users should not call this directly, only used internally by the MeshUtil activity + /// Returns true if the device address actually changed, or false if no change was needed boolean setDeviceAddress(String deviceAddr); /// Get basic device hardware info about our connected radio. Will never return NULL. Will throw diff --git a/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl b/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl index 6bd32d13f..1be0c0ad6 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl @@ -14,5 +14,6 @@ interface IRadioInterfaceService { /// If a macaddress we will try to talk to our device, if null we will be idle. /// Any current connection will be dropped (even if the device address is the same) before reconnecting. /// Users should not call this directly, called only by MeshService + /// Returns true if the device address actually changed, or false if no change was needed boolean setDeviceAddress(String deviceAddr); } 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 1b4de88e3..ed94684bb 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -1508,7 +1508,7 @@ class MeshService : Service(), Logging { val binder = object : IMeshService.Stub() { override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions { - debug("Passing through device change to radio service: $deviceAddr") + debug("Passing through device change to radio service: ${deviceAddr.anonymize}") val res = radio.service.setDeviceAddress(deviceAddr) if (res) { diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index c9bb06521..acf156a17 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -12,6 +12,7 @@ import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.Logging import com.geeksville.concurrent.handledLaunch import com.geeksville.mesh.IRadioInterfaceService +import com.geeksville.util.anonymize import com.geeksville.util.ignoreException import com.geeksville.util.toRemoteExceptions import kotlinx.coroutines.CoroutineScope @@ -126,6 +127,14 @@ class RadioInterfaceService : Service(), Logging { private val nopIf = NopInterface() private var radioIf: IRadioInterface = nopIf + /** true if we have started our interface + * + * Note: an interface may be started without necessarily yet having a connection + */ + private var isStarted = false + + /// true if our interface is currently connected to a device + private var isConnected = false /** * If the user turns on bluetooth after we start, make sure to try and reconnected then @@ -165,8 +174,6 @@ class RadioInterfaceService : Service(), Logging { ) } - private var isConnected = false - fun onConnect() { if (!isConnected) { isConnected = true @@ -210,7 +217,8 @@ class RadioInterfaceService : Service(), Logging { if (address == null) warn("No bonded mesh radio, can't start interface") else { - info("Starting radio $address") + info("Starting radio ${address.anonymize}") + isStarted = true if (logSends) sentPacketsLog = BinaryLogFile(this, "sent_log.pb") @@ -236,6 +244,7 @@ class RadioInterfaceService : Service(), Logging { private fun stopInterface() { val r = radioIf info("stopping interface $r") + isStarted = false radioIf = nopIf r.close() @@ -257,7 +266,7 @@ class RadioInterfaceService : Service(), Logging { */ @SuppressLint("NewApi") private fun setBondedDeviceAddress(address: String?): Boolean { - return if (getBondedDeviceAddress(this) == address && isConnected) { + return if (getBondedDeviceAddress(this) == address && isStarted) { warn("Ignoring setBondedDevice $address, because we are already using that device") false } else { @@ -273,7 +282,7 @@ class RadioInterfaceService : Service(), Logging { // The device address "n" can be used to mean none - debug("Setting bonded device to $address") + debug("Setting bonded device to ${address.anonymize}") getPrefs(this).edit(commit = true) { this.remove(DEVADDR_KEY_OLD) // remove any old version of the key diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 5932afa0e..e5c158f85 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -38,10 +38,8 @@ import com.geeksville.mesh.service.BluetoothInterface import com.geeksville.mesh.service.MeshService import com.geeksville.mesh.service.RadioInterfaceService import com.geeksville.mesh.service.SerialInterface -import com.geeksville.util.Exceptions import com.geeksville.util.anonymize import com.geeksville.util.exceptionReporter -import com.google.android.gms.common.api.ResolvableApiException import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationServices import com.google.android.gms.location.LocationSettingsRequest @@ -788,24 +786,27 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { locationSettingsResponse.addOnFailureListener { exception -> errormsg("Failed to get location access") - if (exception is ResolvableApiException) { - exceptionReporter { - // Location settings are not satisfied, but this can be fixed - // by showing the user a dialog. + // We always show the toast regardless of what type of exception we receive. Because even non + // resolvable api exceptions mean user still needs to fix something. + + ///if (exception is ResolvableApiException) { - // Show the dialog by calling startResolutionForResult(), - // and check the result in onActivityResult(). - // exception.startResolutionForResult(this@MainActivity, REQUEST_CHECK_SETTINGS) + // Location settings are not satisfied, but this can be fixed + // by showing the user a dialog. - // For now just punt and show a dialog - Toast.makeText( - requireContext(), - getString(R.string.location_disabled_warning), - Toast.LENGTH_SHORT - ).show() - } - } 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 + Toast.makeText( + requireContext(), + getString(R.string.location_disabled_warning), + Toast.LENGTH_SHORT + ).show() + + //} else + // Exceptions.report(exception) } }