-
Notifications
You must be signed in to change notification settings - Fork 2
/
HttpInterceptor.kt
63 lines (58 loc) · 2.62 KB
/
HttpInterceptor.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.manna.monitor.network.interceptor
import android.os.Build
import android.util.Log
import com.google.auto.service.AutoService
import com.manna.monitor.http.export.HttpDataResult
import com.manna.monitor.http.export.HttpInterceptorListener
import com.manna.monitor.room.export.HttpDataEntity
import com.manna.monitor.room.export.HttpDataManage
import com.manna.monitor.stone.http.GsonProvider
import java.util.ServiceLoader
@AutoService(HttpInterceptorListener::class)
class HttpInterceptor : HttpInterceptorListener {
private val loaderProxy by lazy { ServiceLoader.load(HttpDataManage::class.java) }
override fun onIntercept(httpData: HttpDataResult) {
Log.d("Monitor", "Intercept Okhttp request data : \n${GsonProvider.gson.toJson(httpData)}")
loaderProxy.first().insert(sealRoomData(httpData))
}
private fun sealRoomData(dataResult: HttpDataResult): HttpDataEntity {
Log.d("Monitor", "Sealed room data and insert to database")
return HttpDataEntity(
//your app name
appName = "Monitor-Network",
//your app version name , it is defined in app/build.gradle file
versionName = "1.0.0",
//your app host environment
env = "TEST",
//interface url
url = dataResult.url,
//request body
params = dataResult.body,
//response result, if this field is exist and if necessary
result = dataResult.data,
//response code, if this field is exist and if necessary
errorInfo = dataResult.code,
//response is success, if this field is exist and if necessary
success = dataResult.success,
//request start time
requestTime = dataResult.startTime,
costTime = dataResult.endTime - dataResult.startTime,
httpCode = dataResult.httpCode.toString(),
//get your devices network type ,such as WIFI,4G,5G
networkInfo = "5G",
//devices info
device = "${Build.BRAND} ${Build.MODEL} Android ${Build.VERSION.RELEASE}",
token = "your account token",
userName = "your account name",
phone = "your account phone number",
//when inserting data,this value is 0,means data not reported
// when report data,this value is 1 or 2 ,the 1 : report DingTalk ,the 2 : report Server
//you can custom define it
reportType = 0,
//data record time
createTime = System.currentTimeMillis(),
//autoincrement,no care about
id = null
)
}
}