Refine relocate heuristics
This commit is contained in:
2
mobile/proguard-rules.pro
vendored
2
mobile/proguard-rules.pro
vendored
@@ -22,7 +22,7 @@
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-if public class be.mygod.librootkotlinx.RootServer {
|
||||
private void doInit(android.content.Context, java.lang.String, boolean);
|
||||
private void doInit(android.content.Context, boolean, java.lang.String);
|
||||
}
|
||||
-keep class be.mygod.librootkotlinx.RootServer {
|
||||
public static void main(java.lang.String[]);
|
||||
|
||||
@@ -71,6 +71,13 @@ object AppProcess {
|
||||
"/system/bin/app_process"
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to guess whether enabling relocation would work best.
|
||||
* It seems some Android 5-7 devices give random permission denials without relocation.
|
||||
* See also VPNHotspot#173.
|
||||
*/
|
||||
val shouldRelocateHeuristics get() = Build.VERSION.SDK_INT < 26 || myExeCanonical.startsWith("/data/")
|
||||
|
||||
/**
|
||||
* To workaround Samsung's stupid kernel patch that prevents exec, we need to relocate exe outside of /data.
|
||||
* See also: https://github.com/Chainfire/librootjava/issues/19
|
||||
|
||||
@@ -131,7 +131,7 @@ class RootServer {
|
||||
Logger.me.w(line)
|
||||
}
|
||||
}
|
||||
private fun doInit(context: Context, niceName: String, shouldRelocate: Boolean = false) {
|
||||
private fun doInit(context: Context, shouldRelocate: Boolean, niceName: String) {
|
||||
try {
|
||||
val (reader, writer) = try {
|
||||
process = ProcessBuilder("su").start()
|
||||
@@ -207,22 +207,12 @@ class RootServer {
|
||||
* Initialize a RootServer synchronously, can throw a lot of exceptions.
|
||||
*
|
||||
* @param context Any [Context] from the app.
|
||||
* @param shouldRelocate Whether app process should be copied first. See also [AppProcess.shouldRelocateHeuristics].
|
||||
* @param niceName Name to call the rooted Java process.
|
||||
*/
|
||||
suspend fun init(context: Context, niceName: String = "${context.packageName}:root") {
|
||||
withContext(Dispatchers.IO) {
|
||||
if (AppProcess.myExeCanonical.startsWith("/data/")) doInit(context, niceName, true) else try { // #173
|
||||
doInit(context, niceName)
|
||||
} catch (e: LaunchException) {
|
||||
try {
|
||||
doInit(context, niceName, true)
|
||||
} catch (e2: LaunchException) {
|
||||
e2.addSuppressed(e)
|
||||
throw e2
|
||||
}
|
||||
Logger.me.w("Root without relocation has failed", RuntimeException(e))
|
||||
}
|
||||
}
|
||||
suspend fun init(context: Context, shouldRelocate: Boolean = false,
|
||||
niceName: String = "${context.packageName}:root") {
|
||||
withContext(Dispatchers.IO) { doInit(context, shouldRelocate, niceName) }
|
||||
callbackListenerExit = GlobalScope.async(Dispatchers.IO) {
|
||||
val errorReader = async(Dispatchers.IO) {
|
||||
try {
|
||||
|
||||
@@ -8,6 +8,7 @@ import be.mygod.librootkotlinx.*
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.util.Services
|
||||
import be.mygod.vpnhotspot.util.UnblockCentral
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import timber.log.Timber
|
||||
|
||||
@@ -45,7 +46,10 @@ object RootManager : RootSession(), Logger {
|
||||
|
||||
override suspend fun initServer(server: RootServer) {
|
||||
Logger.me = this
|
||||
server.init(app.deviceStorage)
|
||||
AppProcess.shouldRelocateHeuristics.let {
|
||||
FirebaseCrashlytics.getInstance().setCustomKey("RootManager.relocateEnabled", it)
|
||||
server.init(app.deviceStorage, it)
|
||||
}
|
||||
server.execute(RootInit())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user