mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-18 14:07:39 +00:00
Fixed mapping generic pairs to policy crashing when no policy is found
The policy (app) is now deleted when found invalid (uninstalled)
This commit is contained in:
parent
4db41e2ac4
commit
ca156befbd
@ -8,6 +8,7 @@ import com.topjohnwu.magisk.model.entity.MagiskPolicy
|
|||||||
import com.topjohnwu.magisk.model.entity.toMap
|
import com.topjohnwu.magisk.model.entity.toMap
|
||||||
import com.topjohnwu.magisk.model.entity.toPolicy
|
import com.topjohnwu.magisk.model.entity.toPolicy
|
||||||
import com.topjohnwu.magisk.utils.now
|
import com.topjohnwu.magisk.utils.now
|
||||||
|
import timber.log.Timber
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
@ -47,12 +48,7 @@ class PolicyDao(
|
|||||||
condition {
|
condition {
|
||||||
equals("uid", uid)
|
equals("uid", uid)
|
||||||
}
|
}
|
||||||
}.map { it.firstOrNull()?.toPolicy(context.packageManager) }
|
}.map { it.first().toPolicySafe() }
|
||||||
.doOnError {
|
|
||||||
if (it is PackageManager.NameNotFoundException) {
|
|
||||||
delete(uid).subscribe()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun update(policy: MagiskPolicy) = query<Replace> {
|
fun update(policy: MagiskPolicy) = query<Replace> {
|
||||||
values(policy.toMap())
|
values(policy.toMap())
|
||||||
@ -62,8 +58,24 @@ class PolicyDao(
|
|||||||
condition {
|
condition {
|
||||||
equals("uid/100000", Const.USER_ID)
|
equals("uid/100000", Const.USER_ID)
|
||||||
}
|
}
|
||||||
}.flattenAsFlowable { it }
|
}.map { it.mapNotNull { it.toPolicySafe() } }
|
||||||
.map { it.toPolicy(context.packageManager) }
|
|
||||||
.toList()
|
|
||||||
|
private fun Map<String, String>.toPolicySafe(): MagiskPolicy? {
|
||||||
|
val taskResult = runCatching { toPolicy(context.packageManager) }
|
||||||
|
val result = taskResult.getOrNull()
|
||||||
|
val exception = taskResult.exceptionOrNull()
|
||||||
|
|
||||||
|
Timber.e(exception)
|
||||||
|
|
||||||
|
when (exception) {
|
||||||
|
is PackageManager.NameNotFoundException -> {
|
||||||
|
val uid = getOrElse("uid") { null } ?: return null
|
||||||
|
delete(uid).subscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user