From 1536343b3f8bfe0018dbcd422928cb8c77db85f4 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Tue, 4 Jun 2024 22:05:29 -0400 Subject: [PATCH] fix: Add connection timeouts for notification handling ...and do not fail operations if notification handling fails -- notifications are best-effort. --- .../openeuicc/util/EuiccChannelFragmentUtils.kt | 15 ++++++++++----- .../typeblog/lpac_jni/impl/HttpInterfaceImpl.kt | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app-common/src/main/java/im/angry/openeuicc/util/EuiccChannelFragmentUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/EuiccChannelFragmentUtils.kt index efe2326..aff4154 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/EuiccChannelFragmentUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/EuiccChannelFragmentUtils.kt @@ -48,11 +48,16 @@ suspend fun T.beginTrackedOperation(op: suspend () -> Boolean) where T : Fra Log.d(TAG, "Latest notification is $latestSeq before operation") if (op()) { Log.d(TAG, "Operation has requested notification handling") - // Note that the exact instance of "channel" might have changed here if reconnected; - // so we MUST use the automatic getter for "channel" - channel.lpa.notifications.filter { it.seqNumber > latestSeq }.forEach { - Log.d(TAG, "Handling notification $it") - channel.lpa.handleNotification(it.seqNumber) + try { + // Note that the exact instance of "channel" might have changed here if reconnected; + // so we MUST use the automatic getter for "channel" + channel.lpa.notifications.filter { it.seqNumber > latestSeq }.forEach { + Log.d(TAG, "Handling notification $it") + channel.lpa.handleNotification(it.seqNumber) + } + } catch (e: Exception) { + // Ignore any error during notification handling + e.printStackTrace() } } Log.d(TAG, "Operation complete") diff --git a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/HttpInterfaceImpl.kt b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/HttpInterfaceImpl.kt index bfad50c..356ccb2 100644 --- a/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/HttpInterfaceImpl.kt +++ b/libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/HttpInterfaceImpl.kt @@ -33,6 +33,7 @@ class HttpInterfaceImpl: HttpInterface { sslContext.init(null, trustManagers, SecureRandom()) val conn = parsedUrl.openConnection() as HttpsURLConnection + conn.connectTimeout = 2000 conn.sslSocketFactory = sslContext.socketFactory conn.requestMethod = "POST" conn.doInput = true