Skip to content

Commit

Permalink
fix: global rule match priority (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed May 10, 2024
1 parent 2e47b99 commit 51e8362
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ class GlobalRule(
override val type = "global"

private val excludeAppIds = apps.filter { e -> !e.value.enable }.keys
private val enableApps = apps.filter { e -> e.value.enable }

/**
* 内置禁用>用户配置>规则自带
* 范围越精确优先级越高
*/
override fun matchActivity(appId: String, activityId: String?): Boolean {
// 规则自带禁用
if (excludeAppIds.contains(appId)) {
return false
}

// 用户自定义禁用
if (excludeData.excludeAppIds.contains(appId)) {
return false
Expand All @@ -69,22 +76,25 @@ class GlobalRule(
}
if (excludeData.includeAppIds.contains(appId)) {
activityId ?: return true
val app = apps[appId] ?: return true
val app = enableApps[appId] ?: return true
// 规则自带页面的禁用
return !app.excludeActivityIds.any { e -> e.startsWith(activityId) }
}
if (!matchLauncher && appId == launcherAppId) {
return false
}
if (!matchSystemApp && systemAppsFlow.value.contains(appId)) {
return false
}
val app = apps[appId] ?: return matchAnyApp
activityId ?: return true
if (app.excludeActivityIds.any { e -> e.startsWith(activityId) }) {
return false

// 范围比较
val app = enableApps[appId]
if (app != null) { // 规则自定义启用
activityId ?: return true
return app.activityIds.isEmpty() || app.activityIds.any { e -> e.startsWith(activityId) }
} else {
if (!matchLauncher && appId == launcherAppId) {
return false
}
if (!matchSystemApp && systemAppsFlow.value.contains(appId)) {
return false
}
return matchAnyApp
}
return app.activityIds.isEmpty() || app.activityIds.any { e -> e.startsWith(activityId) }
}

}

0 comments on commit 51e8362

Please sign in to comment.