assets: allow to use default uid, gid, groups, capabilities and context
This commit is contained in:
@@ -18,6 +18,11 @@ object Natives {
|
|||||||
// 11071: Fix the issue of failing to set a custom SELinux type.
|
// 11071: Fix the issue of failing to set a custom SELinux type.
|
||||||
const val MINIMAL_SUPPORTED_KERNEL = 11071
|
const val MINIMAL_SUPPORTED_KERNEL = 11071
|
||||||
|
|
||||||
|
const val KERNEL_SU_DOMAIN = "u:r:su:s0"
|
||||||
|
|
||||||
|
const val ROOT_UID = 0
|
||||||
|
const val ROOT_GID = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
System.loadLibrary("kernelsu")
|
System.loadLibrary("kernelsu")
|
||||||
}
|
}
|
||||||
@@ -84,11 +89,11 @@ object Natives {
|
|||||||
// these are used for root profile
|
// these are used for root profile
|
||||||
val rootUseDefault: Boolean = true,
|
val rootUseDefault: Boolean = true,
|
||||||
val rootTemplate: String? = null,
|
val rootTemplate: String? = null,
|
||||||
val uid: Int = 0,
|
val uid: Int = ROOT_UID,
|
||||||
val gid: Int = 0,
|
val gid: Int = ROOT_GID,
|
||||||
val groups: List<Int> = mutableListOf(),
|
val groups: List<Int> = mutableListOf(),
|
||||||
val capabilities: List<Int> = mutableListOf(),
|
val capabilities: List<Int> = mutableListOf(),
|
||||||
val context: String = "u:r:su:s0",
|
val context: String = KERNEL_SU_DOMAIN,
|
||||||
val namespace: Int = Namespace.INHERITED.ordinal,
|
val namespace: Int = Namespace.INHERITED.ordinal,
|
||||||
|
|
||||||
val nonRootUseDefault: Boolean = true,
|
val nonRootUseDefault: Boolean = true,
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ class TemplateViewModel : ViewModel() {
|
|||||||
val local: Boolean = true,
|
val local: Boolean = true,
|
||||||
|
|
||||||
val namespace: Int = Natives.Profile.Namespace.INHERITED.ordinal,
|
val namespace: Int = Natives.Profile.Namespace.INHERITED.ordinal,
|
||||||
val uid: Int = 0,
|
val uid: Int = Natives.ROOT_UID,
|
||||||
val gid: Int = 0,
|
val gid: Int = Natives.ROOT_GID,
|
||||||
val groups: List<Int> = mutableListOf(),
|
val groups: List<Int> = mutableListOf(),
|
||||||
val capabilities: List<Int> = mutableListOf(),
|
val capabilities: List<Int> = mutableListOf(),
|
||||||
val context: String = "u:r:su:s0",
|
val context: String = Natives.KERNEL_SU_DOMAIN,
|
||||||
val rules: List<String> = mutableListOf(),
|
val rules: List<String> = mutableListOf(),
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
@@ -140,13 +140,13 @@ private fun <T, R> JSONArray.mapCatching(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T : Enum<T>> getEnumOrdinals(
|
private inline fun <reified T : Enum<T>> getEnumOrdinals(
|
||||||
jsonArray: JSONArray, enumClass: Class<T>
|
jsonArray: JSONArray?, enumClass: Class<T>
|
||||||
): List<T> {
|
): List<T> {
|
||||||
return jsonArray.mapCatching<String, T>({ name ->
|
return jsonArray?.mapCatching<String, T>({ name ->
|
||||||
enumValueOf(name.uppercase())
|
enumValueOf(name.uppercase())
|
||||||
}, {
|
}, {
|
||||||
Log.e(TAG, "ignore invalid enum ${enumClass.simpleName}: $it", it)
|
Log.e(TAG, "ignore invalid enum ${enumClass.simpleName}: $it", it)
|
||||||
})
|
}).orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTemplateInfoById(id: String): TemplateViewModel.TemplateInfo? {
|
fun getTemplateInfoById(id: String): TemplateViewModel.TemplateInfo? {
|
||||||
@@ -171,8 +171,13 @@ private fun getLocaleString(json: JSONObject, key: String): String {
|
|||||||
|
|
||||||
private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo? {
|
private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo? {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
val groupsJsonArray = templateJson.getJSONArray("groups")
|
val groupsJsonArray = templateJson.optJSONArray("groups")
|
||||||
val capabilitiesJsonArray = templateJson.getJSONArray("capabilities")
|
val capabilitiesJsonArray = templateJson.optJSONArray("capabilities")
|
||||||
|
val context = templateJson.optString("context").takeIf { it.isNotEmpty() }
|
||||||
|
?: Natives.KERNEL_SU_DOMAIN;
|
||||||
|
val namespace = templateJson.optString("namespace").takeIf { it.isNotEmpty() }
|
||||||
|
?: Natives.Profile.Namespace.INHERITED.name
|
||||||
|
|
||||||
val rulesJsonArray = templateJson.optJSONArray("rules")
|
val rulesJsonArray = templateJson.optJSONArray("rules")
|
||||||
val templateInfo = TemplateViewModel.TemplateInfo(
|
val templateInfo = TemplateViewModel.TemplateInfo(
|
||||||
id = templateJson.getString("id"),
|
id = templateJson.getString("id"),
|
||||||
@@ -181,15 +186,15 @@ private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo?
|
|||||||
author = templateJson.optString("author"),
|
author = templateJson.optString("author"),
|
||||||
local = templateJson.optBoolean("local"),
|
local = templateJson.optBoolean("local"),
|
||||||
namespace = Natives.Profile.Namespace.valueOf(
|
namespace = Natives.Profile.Namespace.valueOf(
|
||||||
templateJson.getString("namespace").uppercase()
|
namespace.uppercase()
|
||||||
).ordinal,
|
).ordinal,
|
||||||
uid = templateJson.getInt("uid"),
|
uid = templateJson.optInt("uid", Natives.ROOT_UID),
|
||||||
gid = templateJson.getInt("gid"),
|
gid = templateJson.optInt("gid", Natives.ROOT_GID),
|
||||||
groups = getEnumOrdinals(groupsJsonArray, Groups::class.java).map { it.gid },
|
groups = getEnumOrdinals(groupsJsonArray, Groups::class.java).map { it.gid },
|
||||||
capabilities = getEnumOrdinals(
|
capabilities = getEnumOrdinals(
|
||||||
capabilitiesJsonArray, Capabilities::class.java
|
capabilitiesJsonArray, Capabilities::class.java
|
||||||
).map { it.cap },
|
).map { it.cap },
|
||||||
context = templateJson.getString("context"),
|
context = context,
|
||||||
rules = rulesJsonArray?.mapCatching<String, String>({ it }, {
|
rules = rulesJsonArray?.mapCatching<String, String>({ it }, {
|
||||||
Log.e(TAG, "ignore invalid rule: $it", it)
|
Log.e(TAG, "ignore invalid rule: $it", it)
|
||||||
}).orEmpty()
|
}).orEmpty()
|
||||||
|
|||||||
Reference in New Issue
Block a user