Skip to content

Commit 4f295c0

Browse files
author
geyifeng
committed
优化代码
1 parent e42287a commit 4f295c0

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cactus/src/main/java/com/gyf/cactus/Cactus.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ class Cactus private constructor() {
4343
* 运行时回调广播ACTION
4444
*/
4545
@JvmField
46-
val CACTUS_WORK = "work".fieldByPid
46+
val CACTUS_WORK = "work".fieldById
4747
/**
4848
* 停止时回调广播ACTION
4949
*/
5050
@JvmField
51-
val CACTUS_STOP = "stop".fieldByPid
51+
val CACTUS_STOP = "stop".fieldById
5252
/**
5353
* 后台回调广播ACTION
5454
*/
5555
@JvmField
56-
val CACTUS_BACKGROUND = "background".fieldByPid
56+
val CACTUS_BACKGROUND = "background".fieldById
5757
/**
5858
* 前台后调广播ACTION
5959
*/
6060
@JvmField
61-
val CACTUS_FOREGROUND = "foreground".fieldByPid
61+
val CACTUS_FOREGROUND = "foreground".fieldById
6262
/**
6363
* key,通过广播形式获取启动次数
6464
*/

cactus/src/main/java/com/gyf/cactus/ext/CactusExt.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,14 @@ internal val Context.isCactusRunning
377377
}
378378

379379
/**
380-
* 获得带pid值的字段值
380+
* 获得带id值的字段值
381381
*/
382-
internal val String.fieldByPid get() = "${Constant.CACTUS_PACKAGE}.${this}.${Process.myPid()}"
382+
internal val String.fieldById get() = "${Constant.CACTUS_PACKAGE}.${this}.$id"
383+
384+
/**
385+
* 获取id
386+
*/
387+
internal val id get() = if (Process.myUid() <= 0) Process.myPid() else Process.myUid()
383388

384389
/**
385390
* 解除DeathRecipient绑定

cactus/src/main/java/com/gyf/cactus/service/CactusJobService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.content.ComponentName
99
import android.content.Context
1010
import android.content.Intent
1111
import android.os.Build
12-
import android.os.Process
1312
import androidx.annotation.RequiresApi
1413
import com.gyf.cactus.entity.CactusConfig
1514
import com.gyf.cactus.entity.Constant
@@ -84,7 +83,7 @@ class CactusJobService : JobService() {
8483
if (mJobId != -1) {
8584
mJobScheduler.cancel(mJobId)
8685
}
87-
mJobId = Process.myPid()
86+
mJobId = id
8887
saveJobId(mJobId)
8988
val builder = JobInfo.Builder(
9089
mJobId,

0 commit comments

Comments
 (0)