소스 검색

1.4.2 optimize:保活优化

xwh 1 주 전
부모
커밋
89d6287e0f
2개의 변경된 파일42개의 추가작업 그리고 33개의 파일을 삭제
  1. 1 0
      app/src/main/AndroidManifest.xml
  2. 41 33
      app/src/main/java/com/hh/hhomc/keeplive/MyJobService.kt

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -111,6 +111,7 @@
             android:process=":remote" />
         <service
             android:name=".keeplive.MyJobService"
+            android:process=":jobremote"
             android:permission="android.permission.BIND_JOB_SERVICE" />
 
 

+ 41 - 33
app/src/main/java/com/hh/hhomc/keeplive/MyJobService.kt

@@ -10,6 +10,7 @@ import android.content.Intent
 import android.os.Build
 import android.util.Log
 import androidx.annotation.RequiresApi
+import com.common.lib_base.common.async.ThreadPoolManager
 import com.common.lib_base.utils.log.AppLogUtils
 import com.hh.hhomc.keeplive.LocalService
 import com.hh.hhomc.keeplive.RemoteService
@@ -53,45 +54,52 @@ class MyJobService :JobService(){
 
     override fun onStartJob(params: JobParameters?): Boolean {
         AppLogUtils.i("开启job")
+        ThreadPoolManager.getInstance().executeIOTask {
+            try {
 
-        //如果7.0以上 轮训
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            StartJob(this)
-        }
-        val isLocalRun: Boolean = Utils.isRunningService(
-            this,
-            LocalService::class.java.name
-        )
-        val isRemoteRun: Boolean = Utils.isRunningService(
-            this,
-            RemoteService::class.java.name
-        )
-
-        val isBackgroundServiceRun: Boolean = Utils.isRunningService(
-                this,
-                BackgroundService::class.java.name
-        )
-
-        //只有其中任何一个服务被干掉了,则进行start
-        if (!isLocalRun || !isRemoteRun || !isBackgroundServiceRun) {
-
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                // 8.0
-                startForegroundService(Intent(this, LocalService::class.java));
-                startForegroundService(Intent(this, RemoteService::class.java));
-                startForegroundService(Intent(this, BackgroundService::class.java));
-            }else{
-                startService(Intent(this, LocalService::class.java))
-                startService(Intent(this, RemoteService::class.java))
-
-                startService(Intent(this, BackgroundService::class.java))
-            }
+                val isLocalRun: Boolean = Utils.isRunningService(
+                    this,
+                    LocalService::class.java.name
+                )
+                val isRemoteRun: Boolean = Utils.isRunningService(
+                    this,
+                    RemoteService::class.java.name
+                )
 
+                val isBackgroundServiceRun: Boolean = Utils.isRunningService(
+                    this,
+                    BackgroundService::class.java.name
+                )
 
+                //只有其中任何一个服务被干掉了,则进行start
+                if (!isLocalRun || !isRemoteRun || !isBackgroundServiceRun) {
 
-        }
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                        // 8.0
+                        startForegroundService(Intent(this, LocalService::class.java));
+                        startForegroundService(Intent(this, RemoteService::class.java));
+                        startForegroundService(Intent(this, BackgroundService::class.java));
+                    } else {
+                        startService(Intent(this, LocalService::class.java))
+                        startService(Intent(this, RemoteService::class.java))
+
+                        startService(Intent(this, BackgroundService::class.java))
+                    }
 
 
+                }
+
+
+            } catch (e: java.lang.Exception) {
+
+            } finally {
+                //如果7.0以上 轮训
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                    StartJob(this)
+                }
+            }
+        }
+
 
 
         return false