summaryrefslogtreecommitdiffhomepage
path: root/android/lib
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2024-02-05 17:52:40 +0100
committerAlbin <albin@mullvad.net>2024-02-05 17:52:40 +0100
commitd805c6e12522f3b5adaaac21626beae4ab8021d7 (patch)
treef74203cf70bf23b59768d710749e8a400d8c667d /android/lib
parent8bdc0e8dcc52bf82c3e39903257d1b430dc6c2b9 (diff)
parentf7cb264dbfbc0356bc4426d17ce6eb045c122d81 (diff)
downloadmullvadvpn-d805c6e12522f3b5adaaac21626beae4ab8021d7.tar.xz
mullvadvpn-d805c6e12522f3b5adaaac21626beae4ab8021d7.zip
Merge branch 'try-replacing-ktfmt-with-detekt-droid-559'
Diffstat (limited to 'android/lib')
-rw-r--r--android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt31
-rw-r--r--android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt4
-rw-r--r--android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/HandlerFlow.kt15
-rw-r--r--android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt2
4 files changed, 21 insertions, 31 deletions
diff --git a/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt b/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt
index f9239516d9..6b3098fad0 100644
--- a/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt
+++ b/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingRepository.kt
@@ -131,12 +131,8 @@ class BillingRepository(context: Context) {
val activity = activityProvider()
// Launch the billing flow
billingClient.launchBillingFlow(activity, billingFlowParams)
- } catch (t: Throwable) {
- if (t is BillingException) {
- t.toBillingResult()
- } else {
- throw t
- }
+ } catch (t: BillingException) {
+ t.toBillingResult()
}
}
@@ -150,15 +146,12 @@ class BillingRepository(context: Context) {
.build()
billingClient.queryPurchasesAsync(queryPurchaseHistoryParams)
- } catch (t: Throwable) {
- if (t is BillingException) {
- t.toPurchasesResult()
- } else {
- throw t
- }
+ } catch (t: BillingException) {
+ t.toPurchasesResult()
}
}
+ @Suppress("TooGenericExceptionCaught")
private suspend fun queryProductDetails(productIds: List<String>): ProductDetailsResult {
return try {
ensureConnected()
@@ -174,15 +167,13 @@ class BillingRepository(context: Context) {
params.setProductList(productList)
billingClient.queryProductDetails(params.build())
+ } catch (billingException: BillingException) {
+ ProductDetailsResult(billingException.toBillingResult(), null)
} catch (t: Throwable) {
- if (t is BillingException) {
- return ProductDetailsResult(t.toBillingResult(), null)
- } else {
- return ProductDetailsResult(
- BillingResult.newBuilder().setResponseCode(BillingResponseCode.ERROR).build(),
- null
- )
- }
+ ProductDetailsResult(
+ BillingResult.newBuilder().setResponseCode(BillingResponseCode.ERROR).build(),
+ null
+ )
}
}
}
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt
index 06a2de9148..536fea3d24 100644
--- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt
+++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonStringExtensions.kt
@@ -10,7 +10,9 @@ private const val SPACE_CHAR = ' '
fun String.parseAsDateTime(): DateTime? {
return try {
DateTime.parse(this, DateTimeFormat.forPattern(EXPIRY_FORMAT))
- } catch (ex: Exception) {
+ } catch (ex: IllegalArgumentException) {
+ null
+ } catch (ex: UnsupportedOperationException) {
null
}
}
diff --git a/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/HandlerFlow.kt b/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/HandlerFlow.kt
index 4d60cf4d7b..7b839a3658 100644
--- a/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/HandlerFlow.kt
+++ b/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/HandlerFlow.kt
@@ -27,15 +27,12 @@ class HandlerFlow<T>(looper: Looper, private val extractor: (Message) -> T) :
try {
channel.trySendBlocking(extractedData)
- } catch (exception: Exception) {
- when (exception) {
- is ClosedSendChannelException,
- is CancellationException -> {
- Log.w("mullvad", "Received a message after HandlerFlow was closed", exception)
- removeCallbacksAndMessages(null)
- }
- else -> throw exception
- }
+ } catch (exception: ClosedSendChannelException) {
+ Log.w("mullvad", "Received a message after HandlerFlow was closed", exception)
+ removeCallbacksAndMessages(null)
+ } catch (exception: CancellationException) {
+ Log.w("mullvad", "Received a message after HandlerFlow was cancelled", exception)
+ removeCallbacksAndMessages(null)
}
}
}
diff --git a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
index 1d43b6f9f9..94b097fe13 100644
--- a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
+++ b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
@@ -141,7 +141,7 @@ open class TalpidVpnService : VpnService() {
return when (address) {
is Inet4Address -> 32
is Inet6Address -> 128
- else -> throw RuntimeException("Invalid IP address (not IPv4 nor IPv6)")
+ else -> throw IllegalArgumentException("Invalid IP address (not IPv4 nor IPv6)")
}
}