cleanup mockinterface detection

1.2-legacy
Kevin Hester 2021-03-29 20:45:11 +08:00
rodzic 5b653d29f8
commit 9e42634402
4 zmienionych plików z 13 dodań i 18 usunięć

Wyświetl plik

@ -105,8 +105,6 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
return bluetoothManager.adapter
}
fun toInterfaceName(deviceName: String) = "x$deviceName"
/** Return true if this address is still acceptable. For BLE that means, still bonded */
override fun addressValid(context: Context, rest: String): Boolean {
val allPaired =

Wyświetl plik

@ -1,5 +1,8 @@
package com.geeksville.mesh.service
import android.content.Context
import com.geeksville.android.BuildUtils
import com.geeksville.android.GeeksvilleApplication
import com.geeksville.android.Logging
import com.geeksville.mesh.*
import com.geeksville.mesh.model.getInitials
@ -14,6 +17,9 @@ class MockInterface(private val service: RadioInterfaceService) : Logging, IRadi
rest: String
): IRadioInterface = MockInterface(service)
override fun addressValid(context: Context, rest: String): Boolean =
BuildUtils.isEmulator || ((context.applicationContext as GeeksvilleApplication).isInTestLab)
init {
registerFactory()
}

Wyświetl plik

@ -76,18 +76,12 @@ class RadioInterfaceService : Service(), Logging {
var address = prefs.getString(DEVADDR_KEY, null)
// If we are running on the emulator we default to the mock interface, so we can have some data to show to the user
if (address == null && isMockInterfaceAvailable(context))
if (address == null && MockInterface.addressValid(context, ""))
address = MockInterface.prefix.toString()
return address
}
/** return true if we should show the mock interface on this device
* (ie are we in an emulator or in testlab
*/
fun isMockInterfaceAvailable(context: Context) =
isEmulator || ((context.applicationContext as GeeksvilleApplication).isInTestLab)
/** Like getDeviceAddress, but filtered to return only devices we are currently bonded with
*
* at

Wyświetl plik

@ -38,10 +38,7 @@ import com.geeksville.mesh.android.bluetoothManager
import com.geeksville.mesh.android.usbManager
import com.geeksville.mesh.databinding.SettingsFragmentBinding
import com.geeksville.mesh.model.UIViewModel
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.mesh.service.*
import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ACTION_UPDATE_PROGRESS
import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ProgressNotStarted
import com.geeksville.mesh.service.SoftwareUpdateService.Companion.ProgressSuccess
@ -275,10 +272,7 @@ 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 || MockInterface.addressValid(context, "")) {
warn("No bluetooth adapter. Running under emulation?")
val testnodes = listOf(
@ -790,7 +784,10 @@ 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
if (hasBonded && !MockInterface.addressValid(requireContext(), ""))
View.GONE
else
View.VISIBLE
}
/// Setup the GUI to do a classic (pre SDK 26 BLE scan)