mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 09:27:41 +08:00
优化:利用BatteryReceiver守护自启动的Frpc (试验) #254
This commit is contained in:
parent
6ef83f131e
commit
b20a7f2391
@ -7,21 +7,31 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.IBinder
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.workDataOf
|
||||
import com.google.gson.Gson
|
||||
import com.idormy.sms.forwarder.App
|
||||
import com.idormy.sms.forwarder.R
|
||||
import com.idormy.sms.forwarder.core.Core
|
||||
import com.idormy.sms.forwarder.database.AppDatabase
|
||||
import com.idormy.sms.forwarder.entity.MsgInfo
|
||||
import com.idormy.sms.forwarder.utils.BatteryUtils
|
||||
import com.idormy.sms.forwarder.utils.SettingUtils
|
||||
import com.idormy.sms.forwarder.utils.Worker
|
||||
import com.idormy.sms.forwarder.workers.SendWorker
|
||||
import com.xuexiang.xutil.file.FileUtils
|
||||
import frpclib.Frpclib
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
import java.util.*
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Suppress("DEPRECATION", "DeferredResultUnused")
|
||||
class BatteryService : Service() {
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
@ -67,6 +77,27 @@ class BatteryService : Service() {
|
||||
Core.msg.deleteTimeAgo(cal.timeInMillis)
|
||||
}
|
||||
|
||||
//守护自启动的Frpc
|
||||
if (FileUtils.isFileExists(filesDir.absolutePath + "/libs/libgojni.so")) {
|
||||
GlobalScope.async(Dispatchers.IO) {
|
||||
val frpcList = AppDatabase.getInstance(App.context).frpcDao().getAutorun()
|
||||
|
||||
if (frpcList.isEmpty()) {
|
||||
Log.d(TAG, "没有自启动的Frpc")
|
||||
return@async
|
||||
}
|
||||
|
||||
for (frpc in frpcList) {
|
||||
if (!Frpclib.isRunning(frpc.uid)) {
|
||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
||||
if (!TextUtils.isEmpty(error)) {
|
||||
Log.e(TAG, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//电量发生变化
|
||||
val levelCur: Int = intent.getIntExtra("level", 0)
|
||||
val levelPre: Int = SettingUtils.batteryLevelCurrent
|
||||
|
@ -28,7 +28,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
|
||||
@Suppress("PrivatePropertyName", "DeferredResultUnused", "OPT_IN_USAGE")
|
||||
@Suppress("PrivatePropertyName", "DeferredResultUnused", "OPT_IN_USAGE", "DEPRECATION")
|
||||
class ForegroundService : Service() {
|
||||
private val TAG: String = "ForegroundService"
|
||||
private val compositeDisposable = CompositeDisposable()
|
||||
|
Loading…
x
Reference in New Issue
Block a user