Skip to content

Commit 90a3f7c

Browse files
committed
integrate libndt7
1 parent 63ceda8 commit 90a3f7c

35 files changed

+1322
-84
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ android {
7474
}
7575

7676
dependencies {
77+
implementation project(":libndt7")
7778
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
7879
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
7980
implementation 'androidx.core:core-ktx:1.3.2'
@@ -133,7 +134,7 @@ dependencies {
133134
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
134135

135136
// TODO: remove okhttp in the future
136-
implementation "com.squareup.okhttp3:okhttp:4.10.0"
137+
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
137138
implementation 'com.github.kongzue.DialogX:DialogX:0.0.43.beta13'
138139

139140
implementation 'com.github.getActivity:XXPermissions:16.6'

app/src/main/java/com/lcl/lclmeasurementtool/MainActivityViewModel.kt

Lines changed: 201 additions & 38 deletions
Large diffs are not rendered by default.

app/src/main/java/com/lcl/lclmeasurementtool/Utils/ECDSA.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ private static ECPoint decodePoint(byte[] data, EllipticCurve curve)
170170
* @return the private key associated with the raw bytes
171171
* @throws InvalidKeySpecException if the key spec is invalid
172172
*/
173-
private static ECPrivateKey decodePKCS8ECPrivateKey(byte[] encoded)
174-
throws InvalidKeySpecException {
173+
private static ECPrivateKey decodePKCS8ECPrivateKey(byte[] encoded) throws InvalidKeySpecException {
175174
KeyFactory keyFactory = getKeyFactory();
176175
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
177176

app/src/main/java/com/lcl/lclmeasurementtool/datasource/SignalStrengthDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ class SignalStrengthDataSource @Inject constructor(
8787
executor.shutdown()
8888
}
8989
}
90-
}.conflate().sample(10000L).distinctUntilChanged()
90+
}.conflate().sample(5000L).distinctUntilChanged()
9191
}

app/src/main/java/com/lcl/lclmeasurementtool/features/iperf/IperfResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ data class IperfResult(
66
val sendBytes: String,
77
val bandWidth: String,
88
val isDownMode: Boolean,
9-
val errorMSg: String?,
9+
val errorMsg: String?,
1010
val status: IperfStatus
1111
)
1212

app/src/main/java/com/lcl/lclmeasurementtool/features/iperf/IperfRunner.kt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class IperfRunner {
3333
rsaKey = IperfConstants.base64Encode(IperfConstants.IC_SSL_PK),
3434
interval = 1.0
3535
)
36+
37+
val regex = "(\\d+\\.\\d+)".toRegex()
3638
}
3739

3840
private val doneSignal = CountDownLatch(1)
@@ -46,6 +48,7 @@ class IperfRunner {
4648
IperfResult(123.123f, 123.124f, "100", "40.3", true, null, IperfStatus.FINISHED),
4749
).flowOn(Dispatchers.IO).cancellable()
4850

51+
4952
@OptIn(ExperimentalCoroutinesApi::class)
5053
fun getTestResult(config: IperfConfig, cacheDir: File) = callbackFlow {
5154
val client = IperfClient()
@@ -60,17 +63,21 @@ class IperfRunner {
6063

6164
Log.d(TAG, "isDown = $isDown, bandWidth = $bandWidth")
6265
if (!channel.isClosedForSend) {
63-
channel.trySend(
64-
IperfResult(
65-
timeStart,
66-
timeEnd,
67-
sendBytes,
68-
bandWidth,
69-
isDown,
70-
null,
71-
IperfStatus.RUNNING
66+
val match = regex.find(bandWidth)
67+
match?.let {matchResult ->
68+
val (speed) = matchResult.destructured
69+
channel.trySend(
70+
IperfResult(
71+
timeStart,
72+
timeEnd,
73+
sendBytes,
74+
speed,
75+
isDown,
76+
null,
77+
IperfStatus.RUNNING
78+
)
7279
)
73-
)
80+
}
7481
} else {
7582
client.cancelTest()
7683
}
@@ -85,17 +92,21 @@ class IperfRunner {
8592
) {
8693
Log.d(TAG, "isDown = $isDown, bandWidth = $bandWidth")
8794
if (!channel.isClosedForSend) {
88-
channel.trySend(
89-
IperfResult(
90-
timeStart,
91-
timeEnd,
92-
sendBytes,
93-
bandWidth,
94-
isDown,
95-
null,
96-
IperfStatus.FINISHED
95+
val match = regex.find(bandWidth)
96+
match?.let {matchResult ->
97+
val (speed) = matchResult.destructured
98+
channel.trySend(
99+
IperfResult(
100+
timeStart,
101+
timeEnd,
102+
sendBytes,
103+
speed,
104+
isDown,
105+
null,
106+
IperfStatus.FINISHED
107+
)
97108
)
98-
)
109+
}
99110
} else {
100111
client.cancelTest()
101112
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.lcl.lclmeasurementtool.features.mlab
2+
3+
import net.measurementlab.ndt7.android.NDTTest
4+
import net.measurementlab.ndt7.android.models.ClientResponse
5+
6+
interface MLabCallback {
7+
fun onDownloadProgress(clientResponse: ClientResponse)
8+
fun onUploadProgress(clientResponse: ClientResponse)
9+
fun onFinish(clientResponse: ClientResponse?, error: Throwable?, testType: NDTTest.TestType)
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.lcl.lclmeasurementtool.features.mlab
2+
3+
import net.measurementlab.ndt7.android.NDTTest
4+
5+
data class MLabResult(
6+
val speed: String?,
7+
val type: NDTTest.TestType,
8+
val errorMsg: String?,
9+
val status: MLabTestStatus
10+
)
11+
12+
enum class MLabTestStatus {
13+
RUNNING,
14+
FINISHED,
15+
ERROR
16+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.lcl.lclmeasurementtool.features.mlab
2+
3+
import android.util.Log
4+
import kotlinx.coroutines.channels.awaitClose
5+
import kotlinx.coroutines.flow.callbackFlow
6+
import net.measurementlab.ndt7.android.NDTTest
7+
import net.measurementlab.ndt7.android.models.ClientResponse
8+
import net.measurementlab.ndt7.android.utils.DataConverter
9+
import okhttp3.OkHttpClient
10+
import java.util.concurrent.TimeUnit
11+
12+
class MLabRunner(httpClient: OkHttpClient, private val callback: MLabCallback): NDTTest(httpClient) {
13+
override fun onDownloadProgress(clientResponse: ClientResponse) {
14+
super.onDownloadProgress(clientResponse)
15+
callback.onDownloadProgress(clientResponse)
16+
}
17+
18+
override fun onUploadProgress(clientResponse: ClientResponse) {
19+
super.onUploadProgress(clientResponse)
20+
callback.onUploadProgress(clientResponse)
21+
}
22+
23+
override fun onFinished(
24+
clientResponse: ClientResponse?,
25+
error: Throwable?,
26+
testType: TestType
27+
) {
28+
super.onFinished(clientResponse, error, testType)
29+
callback.onFinish(clientResponse, error, testType)
30+
}
31+
32+
companion object {
33+
const val TAG = "MLabRunner"
34+
35+
fun runTest(testType: TestType) = callbackFlow {
36+
val callback = object : MLabCallback {
37+
override fun onDownloadProgress(clientResponse: ClientResponse) {
38+
val speed = DataConverter.convertToMbps(clientResponse)
39+
Log.d(TAG, "client download is $speed")
40+
channel.trySend(MLabResult(speed, TestType.DOWNLOAD, null, MLabTestStatus.RUNNING))
41+
}
42+
43+
override fun onUploadProgress(clientResponse: ClientResponse) {
44+
val speed = DataConverter.convertToMbps(clientResponse)
45+
Log.d(TAG, "client upload is $speed")
46+
channel.trySend(MLabResult(speed, TestType.UPLOAD, null, MLabTestStatus.RUNNING))
47+
}
48+
49+
override fun onFinish(
50+
clientResponse: ClientResponse?,
51+
error: Throwable?,
52+
testType: TestType
53+
) {
54+
if (clientResponse != null) {
55+
Log.d(TAG, "client finish test $testType")
56+
channel.trySend(MLabResult(DataConverter.convertToMbps(clientResponse), testType, null, MLabTestStatus.FINISHED))
57+
} else {
58+
channel.trySend(MLabResult(null, testType, error?.message, MLabTestStatus.ERROR))
59+
}
60+
61+
if (testType == TestType.UPLOAD) channel.close()
62+
}
63+
}
64+
65+
val testRunner = MLabRunner(createHttpClient(), callback)
66+
67+
testRunner.startTest(testType)
68+
Log.d(TAG, "right after the testRunner.startTest(testType) call")
69+
awaitClose {
70+
Log.d(TAG, "channel is about to close ...")
71+
testRunner.stopTest()
72+
}
73+
}
74+
75+
private fun createHttpClient(connectTimeout: Long = 10, readTimeout: Long = 10, writeTimeout: Long = 10): OkHttpClient {
76+
return OkHttpClient.Builder()
77+
.connectTimeout(connectTimeout, TimeUnit.SECONDS)
78+
.readTimeout(readTimeout, TimeUnit.SECONDS)
79+
.writeTimeout(writeTimeout, TimeUnit.SECONDS)
80+
.build()
81+
}
82+
}
83+
}
84+

app/src/main/java/com/lcl/lclmeasurementtool/model/datamodel/BaseMeasureDataModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package com.lcl.lclmeasurementtool.model.datamodel
22

33
import kotlinx.serialization.SerialName
44

5-
interface BaseMeasureDataModel {
5+
@kotlinx.serialization.Serializable
6+
sealed interface BaseMeasureDataModel {
67
@SerialName("latitude")
78
var latitude: Double
89

0 commit comments

Comments
 (0)