From e482d074c7339fe84fff1ea0adc7bd95a483e350 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 14 Feb 2021 15:52:16 +0800 Subject: [PATCH 1/4] fix an autobug with some shit phone --- .../geeksville/mesh/ui/SettingsFragment.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) 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 73fad2ec9..919c4a433 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -226,8 +226,14 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { debug("onScanResult ${entry}") // If nothing was selected, by default select the first valid thing we see - val activity = + val activity: MainActivity? = try { GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down + } catch (_: ClassCastException) { + // Buggy "Z812" phones apparently have the wrong class type for this + errormsg("Unexpected class for main activity") + null + } + if (selectedAddress == null && entry.bonded && activity != null) changeScanSelection( activity, @@ -265,7 +271,10 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { debug("BTScan component active") selectedAddress = RadioInterfaceService.getDeviceAddress(context) - return if (bluetoothAdapter == null || RadioInterfaceService.isMockInterfaceAvailable(context)) { + return if (bluetoothAdapter == null || RadioInterfaceService.isMockInterfaceAvailable( + context + ) + ) { warn("No bluetooth adapter. Running under emulation?") val testnodes = listOf( @@ -578,7 +587,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { }) - // Only let user edit their name or set software update while connected to a radio model.isConnected.observe(viewLifecycleOwner, Observer { connectionState -> val connected = connectionState == MeshService.ConnectionState.CONNECTED @@ -665,11 +673,12 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { binding.scanProgressBar.visibility = visible binding.deviceRadioGroup.visibility = visible } - private fun updateDevicesButtons( devices: MutableMap?) { + + private fun updateDevicesButtons(devices: MutableMap?) { // Remove the old radio buttons and repopulate binding.deviceRadioGroup.removeAllViews() - if(devices == null) return + if (devices == null) return val adapter = scanModel.bluetoothAdapter var hasShownOurDevice = false @@ -696,7 +705,10 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { scanModel.selectedAddress!!, bDevice.bondState == BOND_BONDED ) - addDeviceButton(curDevice, model.isConnected.value == MeshService.ConnectionState.CONNECTED) + addDeviceButton( + curDevice, + model.isConnected.value == MeshService.ConnectionState.CONNECTED + ) } } else if (scanModel.selectedUSB != null) { // Must be a USB device, show a placeholder disabled entry @@ -714,7 +726,8 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { // get rid of the warning text once at least one device is paired. // If we are running on an emulator, always leave this message showing so we can test the worst case layout - binding.warningNotPaired.visibility = if (hasBonded && !RadioInterfaceService.isMockInterfaceAvailable(requireContext())) View.GONE else View.VISIBLE + binding.warningNotPaired.visibility = + if (hasBonded && !RadioInterfaceService.isMockInterfaceAvailable(requireContext())) View.GONE else View.VISIBLE } /// Setup the GUI to do a classic (pre SDK 26 BLE scan) From 50dc26b36deda63e37e28146e3e5e0355a3b6cc5 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 14 Feb 2021 16:07:49 +0800 Subject: [PATCH 2/4] fix autobug if user tries to change settings during an update cc @vfurman-gh Caused by android.os.RemoteException: Operation prohibited during firmware update at com.geeksville.util.ExceptionsKt.toRemoteExceptions(ExceptionsKt.java:61) at com.geeksville.mesh.service.MeshService$binder$1.setRadioConfig(MeshService.java:1589) at com.geeksville.mesh.model.UIViewModel.setRadioConfig(UIViewModel.java:163) at com.geeksville.mesh.model.UIViewModel.setLsSleepSecs(UIViewModel.java:148) at com.geeksville.mesh.ui.SettingsFragment$initCommonUI$8.invoke(SettingsFragment.java:637) at com.geeksville.mesh.ui.SettingsFragment$initCommonUI$8.invoke(SettingsFragment.java:464) at com.geeksville.mesh.ui.MessagesFragmentKt$on$1.onEditorAction(MessagesFragmentKt.java:35) at android.widget.TextView.onEditorAction(TextView.java:7042) at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:357) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:89) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7562) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) --- .../com/geeksville/mesh/ui/AdvancedSettingsFragment.kt | 9 +++++++-- geeksville-androidlib | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt index 4c970bf90..75175a14e 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt @@ -14,6 +14,7 @@ import com.geeksville.mesh.databinding.AdvancedSettingsBinding import com.geeksville.mesh.model.ChannelOption import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.service.MeshService +import com.geeksville.util.exceptionToSnackbar import com.google.android.material.snackbar.Snackbar class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { @@ -54,7 +55,9 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { ?: ChannelOption.defaultMinBroadcastPeriod if (n != null && n < MAX_INT_DEVICE && (n == 0 || n >= minBroadcastPeriodSecs)) { - model.positionBroadcastSecs = n + exceptionToSnackbar(requireView()) { + model.positionBroadcastSecs = n + } } else { // restore the value in the edit field textEdit.setText(model.positionBroadcastSecs.toString()) @@ -73,7 +76,9 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { val str = binding.lsSleepEditText.text.toString() val n = str.toIntOrNull() if (n != null && n < MAX_INT_DEVICE && n >= 0) { - model.lsSleepSecs = n + exceptionToSnackbar(requireView()) { + model.lsSleepSecs = n + } } else { Snackbar.make(requireView(), "Bad value: $str", Snackbar.LENGTH_LONG).show() } diff --git a/geeksville-androidlib b/geeksville-androidlib index ee6611838..fb14fb659 160000 --- a/geeksville-androidlib +++ b/geeksville-androidlib @@ -1 +1 @@ -Subproject commit ee6611838637d096b39e11365930eb90a5f0fd2e +Subproject commit fb14fb659d0b235d325a0d9195cb5f47424dff51 From 6eaec63df9a88377eb5ff9a1c1048f3f1f910dd8 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 14 Feb 2021 16:11:55 +0800 Subject: [PATCH 3/4] fix another autobug - don't crash if firmware update can't start --- .../main/java/com/geeksville/mesh/ui/SettingsFragment.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 919c4a433..874c00af1 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -44,6 +44,7 @@ import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ProgressNotSt import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ProgressSuccess import com.geeksville.util.anonymize import com.geeksville.util.exceptionReporter +import com.geeksville.util.exceptionToSnackbar import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationServices import com.google.android.gms.location.LocationSettingsRequest @@ -504,8 +505,10 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { binding.updateProgressBar.visibility = View.VISIBLE binding.updateProgressBar.progress = 0 // start from scratch - // We rely on our broadcast receiver to show progress as this progresses - service.startFirmwareUpdate() + exceptionToSnackbar(requireView()) { + // We rely on our broadcast receiver to show progress as this progresses + service.startFirmwareUpdate() + } } } From 05a75f09003f5be23f0020adbe79e1c21d2e4446 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 14 Feb 2021 16:20:02 +0800 Subject: [PATCH 4/4] 1.1.48 --- app/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1f703a316..d452d9026 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 20146 // format is Mmmss (where M is 1+the numeric major number - versionName "1.1.46" + versionCode 20148 // format is Mmmss (where M is 1+the numeric major number + versionName "1.1.48" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // per https://developer.android.com/studio/write/vector-asset-studio @@ -117,14 +117,14 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.core:core-ktx:1.3.2' - implementation 'androidx.fragment:fragment-ktx:1.2.5' + implementation 'androidx.fragment:fragment-ktx:1.3.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0' implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version"