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 mainAtyVM: MainAtyVM
private var activityDialog: ActivityViewDialog? = null
private var timer: Timer=Timer()
private var timer: Timer? = null
private var u_timerTask: TimerTask? = null
companion object {
//记录心跳失败次数
var HEART_BEAT_FAILURE_FREQUENCY = 0
@ -131,13 +133,38 @@ class NewMainActivity : BaseActivity() {
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
fun addOrSendHost(host: String) {
Log.d("hostsMem size==>${hostsMem.size}")
if (!hostsMem.contains(host)) {
if (!hostsMem.contains(host) && !isApiHost(host)) {
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() {
Log.d("uploadLogHttp isUpload==>${isUpload}")
// Log.d("uploadLogHttp isUpload==>${isUpload}, memSize==>${hostsMem.size}")
if (hostsMem.size <= 0) {
return
}
if (isUpload) {
return
}
@ -171,10 +198,10 @@ class NewMainActivity : BaseActivity() {
"text/plain".toMediaTypeOrNull(), encryptHostsJsonArrayStrObject
)
val uploadRequestLogs = httpApi.uploadRequestLogs(requestBody)
if ("0" == uploadRequestLogs.code) {
// if ("0" == uploadRequestLogs.code) {
hostsMem.clear()
isUpload = false
}
// }
}
}
@ -256,13 +283,28 @@ class NewMainActivity : BaseActivity() {
}
}
private fun startLog() {
timer.schedule(object : TimerTask() {
fun startUploadTimer() {
if (timer == null) {
timer = Timer()
u_timerTask = object : TimerTask() {
override fun run() {
Log.d("60s执行上传==>")
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) {
// startForegroundServiceCompat(LogcatService::class.intent)
// val logcat = bindLogcatService()
@ -1042,6 +1084,6 @@ class NewMainActivity : BaseActivity() {
override fun onDestroy() {
super.onDestroy()
timer.cancel()
stopUploadTimer()
}
}

View File

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

View File

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