Skip to content

Commit c4c74fc

Browse files
PubNub SDK v5.1.3 release.
1 parent 826e81c commit c4c74fc

File tree

10 files changed

+83
-33
lines changed

10 files changed

+83
-33
lines changed

.pubnub.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
name: kotlin
2-
version: 5.1.2
2+
version: 5.1.3
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-5.1.2-all.jar
6+
- build/libs/pubnub-kotlin-5.1.3-all.jar
77
changelog:
8+
-
9+
version: v5.1.3
10+
date: 2021-03-24
11+
changes:
12+
-
13+
type: bug
14+
text: "Properly canceling HTTP requests when OkHttp client 3.14.9 used."
815
-
916
version: v5.1.2
1017
date: 2021-03-09

CHANGELOG.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
## [v5.1.2](https://github.com/pubnub/kotlin/releases/tag/v5.1.2)
2-
March 9 2021
1+
## [v5.1.3](https://github.com/pubnub/kotlin/releases/tag/v5.1.3)
2+
March 24 2021
33

4-
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.1.1...v5.1.2)
4+
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.1.2...v5.1.3)
55

6-
- In some specific timing conditions subscription loop could loose reference to one of the retrofit call and we would loose posibility to control it. In the meantime we'd start yet another subscription call. One of them is obviously not necessary Synchronization has been improved so it's no longer possible.
7-
- It was not possible to properly cancel the OkHttp connection when Google Security Provider (ProviderInstaller) is being used.
6+
- Properly canceling HTTP requests when OkHttp client 3.14.9 used.
87

98

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2323
<dependency>
2424
<groupId>com.pubnub</groupId>
2525
<artifactId>pubnub-gson</artifactId>
26-
<version>5.1.2</version>
26+
<version>5.1.3</version>
2727
</dependency>
2828
```
2929

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ plugins {
99
id "jacoco"
1010
id 'org.jetbrains.dokka' version '0.10.1'
1111
id 'org.unbroken-dome.test-sets' version '3.0.1'
12+
id "com.github.ben-manes.versions" version '0.38.0'
1213
}
1314

1415
group = 'com.pubnub'
15-
version = '5.1.2'
16+
version = '5.1.3'
1617

1718
repositories {
1819
mavenCentral()

src/main/kotlin/com/pubnub/api/PubNub.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class PubNub(val configuration: PNConfiguration) {
7979

8080
private companion object Constants {
8181
private const val TIMESTAMP_DIVIDER = 1000
82-
private const val SDK_VERSION = "5.1.2"
82+
private const val SDK_VERSION = "5.1.3"
8383
private const val MAX_SEQUENCE = 65535
8484
}
8585

src/main/kotlin/com/pubnub/api/managers/RetrofitManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.pubnub.api.services.SubscribeService
1818
import com.pubnub.api.services.TimeService
1919
import okhttp3.Call
2020
import okhttp3.OkHttpClient
21-
import okhttp3.PNCallFactory
21+
import com.pubnub.okhttp3.PNCallFactory
2222
import okhttp3.logging.HttpLoggingInterceptor
2323
import retrofit2.Retrofit
2424
import java.util.concurrent.ExecutorService
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.pubnub.okhttp3
2+
3+
import okhttp3.Call
4+
import okhttp3.Connection
5+
import org.slf4j.LoggerFactory
6+
import java.net.SocketException
7+
import kotlin.reflect.full.declaredMemberFunctions
8+
import kotlin.reflect.jvm.isAccessible
9+
10+
internal class PNCall(
11+
private val realCall: Call
12+
) : Call by realCall {
13+
private val log = LoggerFactory.getLogger("PNCall")
14+
15+
override fun cancel() {
16+
try {
17+
realCall.getConnection()?.socket()?.shutdownInput()
18+
} catch (se: SocketException) {
19+
log.warn("Caught exception when canceling call", se)
20+
} catch (uoe: UnsupportedOperationException) {
21+
// silent catch
22+
}
23+
realCall.cancel()
24+
}
25+
26+
private fun Call.getConnection(): Connection? =
27+
when {
28+
isTransmitterAvailable() -> accessField("transmitter")?.accessField("connection")
29+
isStreamAllocationAvailable() -> callPrivateFunction("streamAllocation")?.accessField("connection")
30+
else -> {
31+
log.warn("Unrecognized version of OkHttp client. This may cause unexpected behavior when Security Provider updated on Android")
32+
null
33+
}
34+
} as Connection?
35+
36+
private fun <T : Call> T.isTransmitterAvailable(): Boolean = this::class.java.hasField("transmitter")
37+
38+
private fun <T : Call> T.isStreamAllocationAvailable(): Boolean = this::class.java
39+
.hasMethod("streamAllocation")
40+
41+
private fun <T : Any> T.accessField(fieldName: String): Any? {
42+
return javaClass.getDeclaredField(fieldName).let { field ->
43+
field.isAccessible = true
44+
return@let field.get(this)
45+
}
46+
}
47+
48+
private fun <T : Any> T.callPrivateFunction(name: String, vararg args: Any?): Any? =
49+
this::class
50+
.declaredMemberFunctions
51+
.firstOrNull { it.name == name }
52+
?.apply { isAccessible = true }
53+
?.call(this, *args)
54+
55+
private fun Class<*>.hasField(fieldName: String): Boolean =
56+
try { getDeclaredField(fieldName) != null } catch (e: Exception) { false }
57+
58+
private fun Class<*>.hasMethod(methodName: String): Boolean = declaredMethods.any { it.name == methodName }
59+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package okhttp3
1+
package com.pubnub.okhttp3
2+
3+
import okhttp3.Call
4+
import okhttp3.Request
25

36
internal class PNCallFactory(private val callFactory: Call.Factory) : Call.Factory {
47
override fun newCall(request: Request): Call {
5-
return PNCall(callFactory.newCall(request) as RealCall)
8+
return PNCall(callFactory.newCall(request))
69
}
710
}

src/main/kotlin/okhttp3/PNCall.kt

-19
This file was deleted.

src/test/kotlin/com/pubnub/api/legacy/PubNubTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class PubNubTest : BaseTest() {
6767
fun getVersionAndTimeStamp() {
6868
val version = pubnub.version
6969
val timeStamp = pubnub.timestamp()
70-
assertEquals("5.1.2", version)
70+
assertEquals("5.1.3", version)
7171
assertTrue(timeStamp > 0)
7272
}
7373
}

0 commit comments

Comments
 (0)