Skip to content

Commit 2543074

Browse files
committed
Fix missing api version check for usb/ip
1 parent 85a0478 commit 2543074

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,6 @@ interface PlatformInterfaceWrapper : PlatformInterface {
169169

170170
override fun localDNSTransport(): LocalDNSTransport? = LocalResolver
171171

172-
@OptIn(ExperimentalEncodingApi::class)
173-
override fun systemCertificates(): StringIterator {
174-
val certificates = mutableListOf<String>()
175-
val keyStore = KeyStore.getInstance("AndroidCAStore")
176-
if (keyStore != null) {
177-
keyStore.load(null, null)
178-
val aliases = keyStore.aliases()
179-
while (aliases.hasMoreElements()) {
180-
val cert = keyStore.getCertificate(aliases.nextElement())
181-
certificates.add(
182-
"-----BEGIN CERTIFICATE-----\n" + Base64.encode(cert.encoded) + "\n-----END CERTIFICATE-----",
183-
)
184-
}
185-
}
186-
return StringArray(certificates.iterator())
187-
}
188-
189172
override fun startNeighborMonitor(listener: NeighborUpdateListener?) {
190173
if (listener == null) return
191174
val callback = object : INeighborTableCallback.Stub() {

app/src/main/java/io/nekohasekai/sfa/compose/screen/usbip/USBIPStatusViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ data class USBIPStatusState(
5252
)
5353

5454
class USBIPStatusViewModel : BaseViewModel<USBIPStatusState, Nothing>() {
55+
companion object {
56+
private const val MIN_API_VERSION_USBIP = 2
57+
}
58+
5559
private var subscription: USBIPServerStatusSubscription? = null
5660

5761
override fun createInitialState() = USBIPStatusState()
@@ -62,8 +66,16 @@ class USBIPStatusViewModel : BaseViewModel<USBIPStatusState, Nothing>() {
6266

6367
viewModelScope.launch(Dispatchers.IO) {
6468
try {
69+
val client = CommandTarget.standaloneClient()
70+
if (client.getAPIVersion() < MIN_API_VERSION_USBIP) {
71+
viewModelScope.launch {
72+
updateState { copy(servers = emptyList(), isSubscribed = false) }
73+
subscription = null
74+
}
75+
return@launch
76+
}
6577
subscription =
66-
CommandTarget.standaloneClient().subscribeUSBIPServerStatus(
78+
client.subscribeUSBIPServerStatus(
6779
object : USBIPServerStatusHandler {
6880
override fun onStatusUpdate(status: USBIPServerStatusUpdate) {
6981
val servers = convertUpdate(status)

0 commit comments

Comments
 (0)