fix: Check, if mounting is possible

This commit is contained in:
oSumAtrIX 2023-09-19 04:53:22 +02:00
parent db50cee12c
commit 3e13fb5d56
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 24 additions and 4 deletions

View File

@ -47,6 +47,12 @@ public final class app/revanced/lib/adb/AdbManager$Companion {
public final class app/revanced/lib/adb/AdbManager$DeviceNotFoundException : java/lang/Exception {
}
public final class app/revanced/lib/adb/AdbManager$FailedToFindInstalledPackageException : java/lang/Exception {
}
public final class app/revanced/lib/adb/AdbManager$PackageNameRequiredException : java/lang/Exception {
}
public final class app/revanced/lib/adb/AdbManager$RootAdbManager : app/revanced/lib/adb/AdbManager {
public static final field Utils Lapp/revanced/lib/adb/AdbManager$RootAdbManager$Utils;
public fun install (Lapp/revanced/lib/adb/AdbManager$Apk;)V

View File

@ -10,6 +10,7 @@ import app.revanced.lib.adb.Constants.MOUNT_PATH
import app.revanced.lib.adb.Constants.MOUNT_SCRIPT
import app.revanced.lib.adb.Constants.PATCHED_APK_PATH
import app.revanced.lib.adb.Constants.PLACEHOLDER
import app.revanced.lib.adb.Constants.RESOLVE_ACTIVITY
import app.revanced.lib.adb.Constants.RESTART
import app.revanced.lib.adb.Constants.TMP_PATH
import app.revanced.lib.adb.Constants.UMOUNT
@ -74,9 +75,14 @@ sealed class AdbManager private constructor(deviceSerial: String? = null) {
logger.info("Installing by mounting")
val applyReplacement = getPlaceholderReplacement(
apk.packageName ?: throw IllegalArgumentException("Package name is required")
apk.packageName ?: throw PackageNameRequiredException()
)
device.run(RESOLVE_ACTIVITY.applyReplacement()).inputStream.bufferedReader().readLine().let { line ->
if (line != "No activity found") return@let
throw throw FailedToFindInstalledPackageException(apk.packageName)
}
device.push(apk.file, TMP_PATH)
device.run("$CREATE_DIR $INSTALLATION_PATH")
@ -142,4 +148,10 @@ sealed class AdbManager private constructor(deviceSerial: String? = null) {
Exception(deviceSerial?.let {
"The device with the ADB device serial \"$deviceSerial\" can not be found"
} ?: "No ADB device found")
class FailedToFindInstalledPackageException internal constructor(packageName: String) :
Exception("Failed to find installed package \"$packageName\" because no activity was found")
class PackageNameRequiredException internal constructor() :
Exception("Package name is required")
}

View File

@ -2,6 +2,7 @@ package app.revanced.lib.adb
import se.vidstige.jadb.JadbDevice
import se.vidstige.jadb.RemoteFile
import se.vidstige.jadb.ShellProcess
import se.vidstige.jadb.ShellProcessBuilder
import java.io.File
@ -15,8 +16,8 @@ internal fun JadbDevice.buildCommand(command: String, su: Boolean = true): Shell
return shellProcessBuilder(cmd, *args.toTypedArray())
}
internal fun JadbDevice.run(command: String, su: Boolean = true): Int {
return this.buildCommand(command, su).start().waitFor()
internal fun JadbDevice.run(command: String, su: Boolean = true): ShellProcess {
return this.buildCommand(command, su).start()!!
}
internal fun JadbDevice.hasSu() =

View File

@ -10,7 +10,8 @@ internal object Constants {
internal const val DELETE = "rm -rf $PLACEHOLDER"
internal const val CREATE_DIR = "mkdir -p"
internal const val RESTART = "pm resolve-activity --brief $PLACEHOLDER | tail -n 1 | " +
internal const val RESOLVE_ACTIVITY = "pm resolve-activity --brief $PLACEHOLDER"
internal const val RESTART = "$RESOLVE_ACTIVITY | tail -n 1 | " +
"xargs am start -n && kill ${'$'}(pidof -s $PLACEHOLDER)"
internal const val INSTALL_PATCHED_APK = "base_path=\"$PATCHED_APK_PATH\" && " +