Show running test task count in UI and improve test service
This commit is contained in:
1 parent
79d5cad738
commit
29b67c29f5
12 files changed
+48
-7
No files matched your search
@@ -148,6 +148,7 @@ object AppConfig {
|
||||
const val MSG_MEASURE_CONFIG = 7
|
||||
const val MSG_MEASURE_CONFIG_SUCCESS = 71
|
||||
const val MSG_MEASURE_CONFIG_CANCEL = 72
|
||||
const val MSG_MEASURE_CONFIG_FINISH = 73
|
||||
|
||||
/** Notification channel IDs and names. */
|
||||
const val RAY_NG_CHANNEL_ID = "RAY_NG_M_CH_ID"
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.v2ray.ang.service
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import com.v2ray.ang.AppConfig
|
||||
import com.v2ray.ang.AppConfig.MSG_MEASURE_CONFIG
|
||||
import com.v2ray.ang.AppConfig.MSG_MEASURE_CONFIG_CANCEL
|
||||
import com.v2ray.ang.AppConfig.MSG_MEASURE_CONFIG_SUCCESS
|
||||
@@ -15,16 +16,26 @@ import com.v2ray.ang.handler.V2rayConfigManager
|
||||
import com.v2ray.ang.util.MessageUtil
|
||||
import com.v2ray.ang.util.Utils
|
||||
import go.Seq
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.launch
|
||||
import libv2ray.Libv2ray
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class V2RayTestService : Service() {
|
||||
private val realTestScope by lazy { CoroutineScope(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()).asCoroutineDispatcher()) }
|
||||
private val realTestJob = SupervisorJob()
|
||||
private val realDispatcher = Dispatchers.IO.limitedParallelism(
|
||||
Runtime.getRuntime().availableProcessors() * 3
|
||||
)
|
||||
private val realTestScope = CoroutineScope(
|
||||
realTestJob + realDispatcher + CoroutineName("RealTest")
|
||||
)
|
||||
|
||||
// simple counter for currently running tasks
|
||||
private val realTestRunningCount = AtomicInteger(0)
|
||||
|
||||
/**
|
||||
* Initializes the V2Ray environment.
|
||||
@@ -47,13 +58,19 @@ class V2RayTestService : Service() {
|
||||
MSG_MEASURE_CONFIG -> {
|
||||
val guid = intent.serializable<String>("content") ?: ""
|
||||
realTestScope.launch {
|
||||
val result = startRealPing(guid)
|
||||
MessageUtil.sendMsg2UI(this@V2RayTestService, MSG_MEASURE_CONFIG_SUCCESS, Pair(guid, result))
|
||||
realTestRunningCount.incrementAndGet()
|
||||
try {
|
||||
val result = startRealPing(guid)
|
||||
MessageUtil.sendMsg2UI(this@V2RayTestService, MSG_MEASURE_CONFIG_SUCCESS, Pair(guid, result))
|
||||
} finally {
|
||||
val left = realTestRunningCount.decrementAndGet()
|
||||
MessageUtil.sendMsg2UI(this@V2RayTestService, AppConfig.MSG_MEASURE_CONFIG_FINISH, left.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MSG_MEASURE_CONFIG_CANCEL -> {
|
||||
realTestScope.coroutineContext[Job]?.cancelChildren()
|
||||
realTestJob.cancelChildren()
|
||||
}
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
@@ -68,6 +85,14 @@ class V2RayTestService : Service() {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up resources when the service is destroyed.
|
||||
*/
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
realTestJob.cancel()
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the real ping test.
|
||||
* @param guid The GUID of the configuration.
|
||||
|
||||
@@ -445,6 +445,12 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
MmkvManager.encodeServerTestDelayMillis(resultPair.first, resultPair.second)
|
||||
updateListAction.value = getPosition(resultPair.first)
|
||||
}
|
||||
|
||||
AppConfig.MSG_MEASURE_CONFIG_FINISH -> {
|
||||
val content = intent.getStringExtra("content")
|
||||
updateTestResultAction.value =
|
||||
getApplication<AngApplication>().getString(R.string.connection_runing_task_left, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,6 +316,7 @@
|
||||
<string name="connection_test_error_status_code">رمز الخطأ: #%d</string>
|
||||
<string name="connection_connected">متصل، انقر للتحقق من الاتصال</string>
|
||||
<string name="connection_not_connected">غير متصل</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">تم استيراد الاشتراك بنجاح</string>
|
||||
<string name="import_subscription_failure">فشل استيراد الاشتراك</string>
|
||||
|
||||
@@ -315,6 +315,7 @@
|
||||
<string name="connection_test_error_status_code">ত্রুটি কোড: #%d</string>
|
||||
<string name="connection_connected">সংযুক্ত, সংযোগ পরীক্ষা করতে ট্যাপ করুন</string>
|
||||
<string name="connection_not_connected">সংযুক্ত নয়</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">সাবস্ক্রিপশন সফলভাবে আমদানি করা হয়েছে</string>
|
||||
<string name="import_subscription_failure">সাবস্ক্রিপশন আমদানি ব্যর্থ</string>
|
||||
|
||||
@@ -324,6 +324,7 @@
|
||||
<string name="connection_test_error_status_code">کود ختا: #%d</string>
|
||||
<string name="connection_connected">منپیز هڌ، سی واجۊری کیلیک کوݩ</string>
|
||||
<string name="connection_not_connected">منپیز نؽڌ</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">اشتراک وا مووفقیت زفت زابی</string>
|
||||
<string name="import_subscription_failure">اشتراک زفت نوابی</string>
|
||||
|
||||
@@ -321,6 +321,7 @@
|
||||
<string name="connection_test_error_status_code">کد خطا: #%d</string>
|
||||
<string name="connection_connected">متصل است، برای بررسی اتصال ضربه بزنید</string>
|
||||
<string name="connection_not_connected">متصل نیست</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">اشتراک با موفقیت ذخیره شد</string>
|
||||
<string name="import_subscription_failure">ذخیره اشتراک ناموفق بود</string>
|
||||
|
||||
@@ -323,6 +323,7 @@
|
||||
<string name="connection_test_error_status_code">Код ошибки: #%d</string>
|
||||
<string name="connection_connected">Подключено, нажмите для проверки</string>
|
||||
<string name="connection_not_connected">Не подключено</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">Подписка импортирована</string>
|
||||
<string name="import_subscription_failure">Невозможно импортировать подписку</string>
|
||||
|
||||
@@ -316,6 +316,7 @@
|
||||
<string name="connection_test_error_status_code">Mã lỗi: #%d</string>
|
||||
<string name="connection_connected">Đã kết nối, nhấn để kiểm tra kết nối mạng!</string>
|
||||
<string name="connection_not_connected">Chưa kết nối</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">Nhập gói đăng ký thành công!</string>
|
||||
<string name="import_subscription_failure">Nhập gói đăng ký không thành công!</string>
|
||||
|
||||
@@ -313,6 +313,7 @@
|
||||
<string name="connection_test_error_status_code">"状态码无效(#%d)"</string>
|
||||
<string name="connection_connected">"已连接,点击测试连接"</string>
|
||||
<string name="connection_not_connected">"未连接"</string>
|
||||
<string name="connection_runing_task_left">运行中的测试任务数:%s</string>
|
||||
|
||||
<string name="import_subscription_success">订阅导入成功</string>
|
||||
<string name="import_subscription_failure">导入订阅失败</string>
|
||||
|
||||
@@ -313,6 +313,7 @@
|
||||
<string name="connection_test_error_status_code">"錯誤碼:(#%d)"</string>
|
||||
<string name="connection_connected">"已連線,輕觸以檢查連線能力"</string>
|
||||
<string name="connection_not_connected">"未連線"</string>
|
||||
<string name="connection_runing_task_left">運行中的測試任務數:%s</string>
|
||||
|
||||
<string name="import_subscription_success">匯入訂閱成功</string>
|
||||
<string name="import_subscription_failure">匯入訂閱失敗</string>
|
||||
|
||||
@@ -327,6 +327,7 @@
|
||||
<string name="connection_test_error_status_code">Error code: #%d</string>
|
||||
<string name="connection_connected">Connected, tap to check connection</string>
|
||||
<string name="connection_not_connected">Not connected</string>
|
||||
<string name="connection_runing_task_left">Number of running test tasks: %s</string>
|
||||
|
||||
<string name="import_subscription_success">Subscription imported Successfully</string>
|
||||
<string name="import_subscription_failure">Import subscription failed</string>
|
||||
|
||||
Reference in new issue
Block a user