Symlink pre API 21

This commit is contained in:
topjohnwu 2021-01-30 01:12:49 -08:00
parent 8794141b7f
commit 52e1b84d41

View File

@ -56,22 +56,24 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.lang.reflect.Method
import java.lang.reflect.Array as JArray import java.lang.reflect.Array as JArray
val packageName: String get() = get<Context>().packageName val packageName: String get() = get<Context>().packageName
private lateinit var osSymlink: Method
private lateinit var os: Any
fun symlink(oldPath: String, newPath: String) { fun symlink(oldPath: String, newPath: String) {
if (SDK_INT >= 21) { if (SDK_INT >= 21) {
Os.symlink(oldPath, newPath) Os.symlink(oldPath, newPath)
} else { } else {
// Just copy the files pre 5.0 if (!::osSymlink.isInitialized) {
val old = File(oldPath) os = Class.forName("libcore.io.Libcore").getField("os").get(null)!!
val newFile = File(newPath) osSymlink = os.javaClass.getMethod("symlink", String::class.java, String::class.java)
old.copyTo(newFile) }
if (old.canExecute()) osSymlink.invoke(os, oldPath, newPath)
newFile.setExecutable(true)
} }
} }
val ServiceInfo.isIsolated get() = (flags and FLAG_ISOLATED_PROCESS) != 0 val ServiceInfo.isIsolated get() = (flags and FLAG_ISOLATED_PROCESS) != 0