fix 审计日志上传

This commit is contained in:
cyh 2024-09-18 16:37:43 +08:00
parent ab6041ec70
commit 31cc77fb6b
3 changed files with 84 additions and 20 deletions

View File

@ -109,7 +109,9 @@ class NewMainActivity : BaseActivity() {
private lateinit var drawer: DrawerLayout private lateinit var drawer: DrawerLayout
private lateinit var mainAtyVM: MainAtyVM private lateinit var mainAtyVM: MainAtyVM
private var activityDialog: ActivityViewDialog? = null private var activityDialog: ActivityViewDialog? = null
private var timer: Timer=Timer() private var timer: Timer? = null
private var u_timerTask: TimerTask? = null
companion object { companion object {
//记录心跳失败次数 //记录心跳失败次数
var HEART_BEAT_FAILURE_FREQUENCY = 0 var HEART_BEAT_FAILURE_FREQUENCY = 0
@ -131,13 +133,38 @@ class NewMainActivity : BaseActivity() {
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
fun addOrSendHost(host: String) { fun addOrSendHost(host: String) {
Log.d("hostsMem size==>${hostsMem.size}") Log.d("hostsMem size==>${hostsMem.size}")
if (!hostsMem.contains(host)) { if (!hostsMem.contains(host) && !isApiHost(host)) {
hostsMem.add(host + "{" + dateFormat.format(Date())) hostsMem.add(host + "{" + dateFormat.format(Date()))
} }
} }
fun isApiHost(host: String): Boolean {
val mmkv = MMKV.defaultMMKV()
var isApiHost = false;
val originalUrl =
mmkv.decodeString(BZYConstants.MMKV_KEY_CURRENT_HOST, BuildConfig.service_url)
val routerHost = mmkv.decodeStringSet(BZYConstants.MMKV_KEY_ROUTER_HOST, HashSet())
// Log.d("originalUrl==>${originalUrl}, host==>${host}")
if (originalUrl?.contains(host) == true) {
isApiHost = true
return isApiHost
}
// Log.d("isApiHost==>${isApiHost}")
routerHost?.forEach { rh ->
isApiHost = rh.contains(host)
// Log.d("rh==>${rh}, host==>${host}, isApiHost==>${isApiHost}")
}
return isApiHost
}
fun uploadLogHttp() { fun uploadLogHttp() {
Log.d("uploadLogHttp isUpload==>${isUpload}") // Log.d("uploadLogHttp isUpload==>${isUpload}, memSize==>${hostsMem.size}")
if (hostsMem.size <= 0) {
return
}
if (isUpload) { if (isUpload) {
return return
} }
@ -171,10 +198,10 @@ class NewMainActivity : BaseActivity() {
"text/plain".toMediaTypeOrNull(), encryptHostsJsonArrayStrObject "text/plain".toMediaTypeOrNull(), encryptHostsJsonArrayStrObject
) )
val uploadRequestLogs = httpApi.uploadRequestLogs(requestBody) val uploadRequestLogs = httpApi.uploadRequestLogs(requestBody)
if ("0" == uploadRequestLogs.code) { // if ("0" == uploadRequestLogs.code) {
hostsMem.clear() hostsMem.clear()
isUpload = false isUpload = false
} // }
} }
} }
@ -256,13 +283,28 @@ class NewMainActivity : BaseActivity() {
} }
} }
private fun startLog() { fun startUploadTimer() {
timer.schedule(object : TimerTask() { if (timer == null) {
timer = Timer()
u_timerTask = object : TimerTask() {
override fun run() { override fun run() {
Log.d("60s执行上传==>") Log.d("60s执行上传==>")
uploadLogHttp() uploadLogHttp()
} }
}, 0,60000) }
}
timer?.schedule(u_timerTask, 60000, 60000)
}
fun stopUploadTimer() {
timer?.cancel()
timer = null
u_timerTask?.cancel()
u_timerTask = null
}
private fun startLog() {
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
// startForegroundServiceCompat(LogcatService::class.intent) // startForegroundServiceCompat(LogcatService::class.intent)
// val logcat = bindLogcatService() // val logcat = bindLogcatService()
@ -1042,6 +1084,6 @@ class NewMainActivity : BaseActivity() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
timer.cancel() stopUploadTimer()
} }
} }

View File

@ -228,6 +228,7 @@ class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
} }
rxDialogSureCancel.setSureListener { rxDialogSureCancel.setSureListener {
// Core.stopService() // Core.stopService()
stop_u_timer()
stopClash() stopClash()
rxDialogSureCancel.cancel() rxDialogSureCancel.cancel()
reConnection = false reConnection = false
@ -285,6 +286,7 @@ class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
val vpnRequest = context?.startClashService() val vpnRequest = context?.startClashService()
try { try {
start_u_timer()
if (vpnRequest != null) { if (vpnRequest != null) {
val result = startActivityForResult( val result = startActivityForResult(
ActivityResultContracts.StartActivityForResult(), vpnRequest ActivityResultContracts.StartActivityForResult(), vpnRequest
@ -293,10 +295,13 @@ class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
if (result.resultCode == RESULT_OK) { if (result.resultCode == RESULT_OK) {
stateChanged(Clash_Starting, true) stateChanged(Clash_Starting, true)
context?.startClashService() context?.startClashService()
// clashRunning = true // clashRunning = true
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
stop_u_timer()
e.printStackTrace() e.printStackTrace()
} }
@ -347,6 +352,7 @@ class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
} }
accelerateIv.isSelected = false accelerateIv.isSelected = false
clashRunning = false clashRunning = false
stop_u_timer()
} }
Intents.ACTION_CLASH_REQUEST_STOP -> { Intents.ACTION_CLASH_REQUEST_STOP -> {
@ -564,14 +570,30 @@ class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
} }
private fun goRechargeWeb() { private fun goRechargeWeb() {
if (activity!=null) {
var mact = activity as NewMainActivity var mact = activity as NewMainActivity
mact.goRechargeWeb() mact.goRechargeWeb()
} }
}
private fun goNewRecharge() { private fun goNewRecharge() {
if (activity!=null) {
var mact = activity as NewMainActivity var mact = activity as NewMainActivity
mact.goBackupRechargeWeb() mact.goBackupRechargeWeb()
} }
}
private fun start_u_timer() {
if (activity!=null) {
var mact = activity as NewMainActivity
mact.startUploadTimer()
}
}
private fun stop_u_timer() {
if (activity!=null) {
var mact = activity as NewMainActivity
mact.stopUploadTimer()
}
}
private fun checkGlo() { private fun checkGlo() {

View File

@ -51,8 +51,8 @@ subprojects {
minSdk = 21 minSdk = 21
//noinspection ExpiredTargetSdkVersion //noinspection ExpiredTargetSdkVersion
targetSdk = 31 targetSdk = 31
versionName = "1.0.1.8" versionName = "1.0.1.9"
versionCode = 1018 versionCode = 1019
resValue("string", "release_name", "v$versionName") resValue("string", "release_name", "v$versionName")
resValue("integer", "release_code", "$versionCode") resValue("integer", "release_code", "$versionCode")
externalNativeBuild { externalNativeBuild {