From 125ae0a1734a2626e666ea897bd6a6a3a873fa64 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 12 May 2019 18:34:28 +0200 Subject: [PATCH] Fixed conditions in sql queries --- app/src/main/java/com/topjohnwu/magisk/Constants.kt | 2 +- .../java/com/topjohnwu/magisk/data/database/PolicyDao.kt | 6 +++--- .../magisk/data/database/base/MagiskQueryBuilder.kt | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/Constants.kt b/app/src/main/java/com/topjohnwu/magisk/Constants.kt index c23f3422a..5db50e2ea 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Constants.kt +++ b/app/src/main/java/com/topjohnwu/magisk/Constants.kt @@ -8,7 +8,7 @@ object Constants { val MAGISK_PATH = "/sbin/.magisk/img" val MAGISK_LOG = "/cache/magisk.log" - val USER_ID = Process.myUid() / 100000 + val USER_ID get() = Process.myUid() / 100000 const val SNET_REVISION = "b66b1a914978e5f4c4bbfd74a59f4ad371bac107" const val BOOTCTL_REVISION = "9c5dfc1b8245c0b5b524901ef0ff0f8335757b77" diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt index 2298f228e..e8ef9ddf2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt @@ -36,13 +36,13 @@ class PolicyDao( fun delete(uid: Int) = query { condition { - equals("uid", uid.toString()) + equals("uid", uid) } }.ignoreElement() fun fetch(uid: Int) = query { condition { - equals("uid/100000", Constants.USER_ID.toString()) + equals("uid/100000", Constants.USER_ID) } }.flattenAsFlowable { it } .map { it.toPolicy(context.packageManager) } diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt index e78e25232..788113b51 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt @@ -107,8 +107,11 @@ class Condition { private val conditionWord = "WHERE %s" private var condition: String = "" - fun equals(field: String, value: String) { - condition = "$field=\"$value\"" + fun equals(field: String, value: Any) { + condition = when (value) { + is String -> "$field=\"$value\"" + else -> "$field=$value" + } } fun greaterThan(field: String, value: String) {