Merge pull request #93 from geeksville/dev

fix a couple of subtle autobugs (see commits for details) and we were leaking macaddrs (PII) into logs
This commit is contained in:
Kevin Hester 2020-07-07 10:52:34 -07:00 committed by GitHub
commit 0b39644584
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 27 deletions

View file

@ -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"

View file

@ -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

View file

@ -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);
}

View file

@ -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) {

View file

@ -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

View file

@ -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)
}
}