Fix missing api version check for usb/ip

This commit is contained in:
世界
2026-07-06 21:15:32 +08:00
parent 0445098157
commit 01d24b4439
2 changed files with 13 additions and 18 deletions
@@ -169,23 +169,6 @@ interface PlatformInterfaceWrapper : PlatformInterface {
override fun localDNSTransport(): LocalDNSTransport? = LocalResolver override fun localDNSTransport(): LocalDNSTransport? = LocalResolver
@OptIn(ExperimentalEncodingApi::class)
override fun systemCertificates(): StringIterator {
val certificates = mutableListOf<String>()
val keyStore = KeyStore.getInstance("AndroidCAStore")
if (keyStore != null) {
keyStore.load(null, null)
val aliases = keyStore.aliases()
while (aliases.hasMoreElements()) {
val cert = keyStore.getCertificate(aliases.nextElement())
certificates.add(
"-----BEGIN CERTIFICATE-----\n" + Base64.encode(cert.encoded) + "\n-----END CERTIFICATE-----",
)
}
}
return StringArray(certificates.iterator())
}
override fun startNeighborMonitor(listener: NeighborUpdateListener?) { override fun startNeighborMonitor(listener: NeighborUpdateListener?) {
if (listener == null) return if (listener == null) return
val callback = object : INeighborTableCallback.Stub() { val callback = object : INeighborTableCallback.Stub() {
@@ -52,6 +52,10 @@ data class USBIPStatusState(
) )
class USBIPStatusViewModel : BaseViewModel<USBIPStatusState, Nothing>() { class USBIPStatusViewModel : BaseViewModel<USBIPStatusState, Nothing>() {
companion object {
private const val MIN_API_VERSION_USBIP = 2
}
private var subscription: USBIPServerStatusSubscription? = null private var subscription: USBIPServerStatusSubscription? = null
override fun createInitialState() = USBIPStatusState() override fun createInitialState() = USBIPStatusState()
@@ -62,8 +66,16 @@ class USBIPStatusViewModel : BaseViewModel<USBIPStatusState, Nothing>() {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
val client = CommandTarget.standaloneClient()
if (client.getAPIVersion() < MIN_API_VERSION_USBIP) {
viewModelScope.launch {
updateState { copy(servers = emptyList(), isSubscribed = false) }
subscription = null
}
return@launch
}
subscription = subscription =
CommandTarget.standaloneClient().subscribeUSBIPServerStatus( client.subscribeUSBIPServerStatus(
object : USBIPServerStatusHandler { object : USBIPServerStatusHandler {
override fun onStatusUpdate(status: USBIPServerStatusUpdate) { override fun onStatusUpdate(status: USBIPServerStatusUpdate) {
val servers = convertUpdate(status) val servers = convertUpdate(status)