bug fix :更新用户使用时长回调时间由10s更改为60s

This commit is contained in:
level 2025-06-30 15:34:33 +08:00
parent fe601e0364
commit 53bc91c07a
3 changed files with 28 additions and 2 deletions

View File

@ -66,6 +66,7 @@ import com.yingmao.clash.util.ActivityResultLifecycle
import com.yingmao.clash.util.CommonUtils
import com.yingmao.clash.util.MarqueeTextView
import com.yingmao.clash.util.PayUtils
import com.yingmao.clash.util.Utils
import com.yingmao.clash.util.startClashService
import com.yingmao.clash.util.stopClashService
import com.yingmao.clash.view.RxToast
@ -384,7 +385,12 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher
MMKV.defaultMMKV().encode(BZYConstants.CONNECTID, dataInfo.data.id)
val serviceIntent = Intent(requireContext(), ConnectionService::class.java)
serviceIntent.putExtra("receiver", resultReceiver)
requireContext().startService(serviceIntent)
val serviceRunning =
Utils.isServiceRunning(requireContext(), ConnectionService::class.java)
android.util.Log.i("AppStartupStatus","data::"+serviceRunning)
if(!serviceRunning){
requireContext().startService(serviceIntent)
}
}
}
}
@ -994,4 +1000,13 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher
})
dialog.show()
}
override fun onDestroy() {
super.onDestroy()
val serviceRunning =
Utils.isServiceRunning(requireContext(), ConnectionService::class.java)
if(serviceRunning){
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
requireContext().stopService(serviceIntent)
}
}
}

View File

@ -13,7 +13,7 @@ import com.yingmao.clash.fragment.AccelerateViewModel;
public class ConnectionService extends Service {
private static final String TAG = "TimerService";
private static final long INTERVAL_MILLIS = 10000; // 10
private static final long INTERVAL_MILLIS = 60000; // 60
private Handler handler = new Handler();
private Intent intent;
private Runnable runnable = new Runnable() {

View File

@ -2,6 +2,7 @@ package com.yingmao.clash.util
import android.Manifest
import android.app.Activity
import android.app.ActivityManager
import android.content.Context
import android.content.pm.PackageManager
import android.media.MediaDrm
@ -286,5 +287,15 @@ object Utils {
v.requestLayout()
}
}
fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val runningServices = manager.getRunningServices(Int.MAX_VALUE)
for (service in runningServices) {
if (serviceClass.name == service.service.className) {
return true
}
}
return false
}
}