More MagidkDB fixes

This commit is contained in:
topjohnwu 2019-06-07 01:05:54 -07:00
parent 3123cc1059
commit cec017b7bf
3 changed files with 10 additions and 35 deletions

View File

@ -75,7 +75,11 @@ open class Insert : MagiskQueryBuilder {
private val keys get() = _values.keys.joinToString(",") private val keys get() = _values.keys.joinToString(",")
private val values get() = _values.values.joinToString(",") { private val values get() = _values.values.joinToString(",") {
if (it is String) "\"$it\"" else it.toString() when (it) {
is Boolean -> if (it) "1" else "0"
is Number -> it.toString()
else -> "\"$it\""
}
} }
private var _values: Map<String, Any> = mapOf() private var _values: Map<String, Any> = mapOf()

View File

@ -38,7 +38,6 @@ fun Map<String, String>.toLog(): MagiskLog {
fun Long.toDate() = Date(this) fun Long.toDate() = Date(this)
fun MagiskLog.toMap() = mapOf( fun MagiskLog.toMap() = mapOf(
"from_uid" to fromUid, "from_uid" to fromUid,
"to_uid" to toUid, "to_uid" to toUid,
@ -47,8 +46,8 @@ fun MagiskLog.toMap() = mapOf(
"app_name" to appName, "app_name" to appName,
"command" to command, "command" to command,
"action" to action, "action" to action,
"time" to date "time" to date.time
).mapValues { it.toString() } )
fun MagiskPolicy.toLog( fun MagiskPolicy.toLog(
toUid: Int, toUid: Int,

View File

@ -24,42 +24,14 @@ data class MagiskPolicy(
} }
/*@Throws(PackageManager.NameNotFoundException::class)
fun ContentValues.toPolicy(pm: PackageManager): MagiskPolicy {
val uid = getAsInteger("uid")
val packageName = getAsString("package_name")
val info = pm.getApplicationInfo(packageName, 0)
if (info.uid != uid)
throw PackageManager.NameNotFoundException()
return MagiskPolicy(
uid = uid,
packageName = packageName,
policy = getAsInteger("policy"),
until = getAsInteger("until").toLong(),
logging = getAsInteger("logging") != 0,
notification = getAsInteger("notification") != 0,
applicationInfo = info,
appName = info.loadLabel(pm).toString()
)
}
fun MagiskPolicy.toContentValues() = ContentValues().apply {
put("uid", uid)
put("uid", uid)
put("package_name", packageName)
put("policy", policy)
put("until", until)
put("logging", if (logging) 1 else 0)
put("notification", if (notification) 1 else 0)
}*/
fun MagiskPolicy.toMap() = mapOf( fun MagiskPolicy.toMap() = mapOf(
"uid" to uid, "uid" to uid,
"package_name" to packageName, "package_name" to packageName,
"policy" to policy, "policy" to policy,
"until" to until, "until" to until,
"logging" to if (logging) 1 else 0, "logging" to logging,
"notification" to if (notification) 1 else 0 "notification" to notification
).mapValues { it.value.toString() } )
@Throws(PackageManager.NameNotFoundException::class) @Throws(PackageManager.NameNotFoundException::class)
fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy { fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {