mirror of
https://github.com/revanced/revanced-cli.git
synced 2024-12-04 09:22:54 +01:00
refactor: use better identifiers
This commit is contained in:
parent
11c3a6cfd4
commit
a536c9f815
@ -1,18 +1,18 @@
|
||||
package app.revanced.utils.adb
|
||||
|
||||
import app.revanced.utils.adb.AdbManager.Apk
|
||||
import app.revanced.utils.adb.Constants.COMMAND_CREATE_DIR
|
||||
import app.revanced.utils.adb.Constants.COMMAND_DELETE
|
||||
import app.revanced.utils.adb.Constants.COMMAND_INSTALL_MOUNT
|
||||
import app.revanced.utils.adb.Constants.COMMAND_PREPARE_MOUNT_APK
|
||||
import app.revanced.utils.adb.Constants.COMMAND_RESTART
|
||||
import app.revanced.utils.adb.Constants.COMMAND_UMOUNT
|
||||
import app.revanced.utils.adb.Constants.CONTENT_MOUNT_SCRIPT
|
||||
import app.revanced.utils.adb.Constants.PATH_INIT_PUSH
|
||||
import app.revanced.utils.adb.Constants.PATH_INSTALLATION
|
||||
import app.revanced.utils.adb.Constants.PATH_MOUNT
|
||||
import app.revanced.utils.adb.Constants.PATH_PATCHED_APK
|
||||
import app.revanced.utils.adb.Constants.CREATE_DIR
|
||||
import app.revanced.utils.adb.Constants.DELETE
|
||||
import app.revanced.utils.adb.Constants.INSTALLATION_PATH
|
||||
import app.revanced.utils.adb.Constants.INSTALL_MOUNT
|
||||
import app.revanced.utils.adb.Constants.INSTALL_PATCHED_APK
|
||||
import app.revanced.utils.adb.Constants.MOUNT_PATH
|
||||
import app.revanced.utils.adb.Constants.MOUNT_SCRIPT
|
||||
import app.revanced.utils.adb.Constants.PATCHED_APK_PATH
|
||||
import app.revanced.utils.adb.Constants.PLACEHOLDER
|
||||
import app.revanced.utils.adb.Constants.RESTART
|
||||
import app.revanced.utils.adb.Constants.TMP_PATH
|
||||
import app.revanced.utils.adb.Constants.UMOUNT
|
||||
import se.vidstige.jadb.JadbConnection
|
||||
import se.vidstige.jadb.managers.Package
|
||||
import se.vidstige.jadb.managers.PackageManager
|
||||
@ -72,17 +72,17 @@ internal sealed class AdbManager(deviceSerial: String? = null) : Closeable {
|
||||
apk.packageName ?: throw IllegalArgumentException("Package name is required")
|
||||
)
|
||||
|
||||
device.copyFile(apk.file, PATH_INIT_PUSH)
|
||||
device.push(apk.file, TMP_PATH)
|
||||
|
||||
device.run("$COMMAND_CREATE_DIR $PATH_INSTALLATION")
|
||||
device.run(COMMAND_PREPARE_MOUNT_APK.applyReplacement())
|
||||
device.run("$CREATE_DIR $INSTALLATION_PATH")
|
||||
device.run(INSTALL_PATCHED_APK.applyReplacement())
|
||||
|
||||
device.createFile(PATH_INIT_PUSH, CONTENT_MOUNT_SCRIPT.applyReplacement())
|
||||
device.createFile(TMP_PATH, MOUNT_SCRIPT.applyReplacement())
|
||||
|
||||
device.run(COMMAND_INSTALL_MOUNT.applyReplacement())
|
||||
device.run(COMMAND_UMOUNT.applyReplacement()) // Sanity check.
|
||||
device.run(PATH_MOUNT.applyReplacement())
|
||||
device.run(COMMAND_RESTART.applyReplacement())
|
||||
device.run(INSTALL_MOUNT.applyReplacement())
|
||||
device.run(UMOUNT.applyReplacement()) // Sanity check.
|
||||
device.run(MOUNT_PATH.applyReplacement())
|
||||
device.run(RESTART.applyReplacement())
|
||||
|
||||
super.install(apk)
|
||||
}
|
||||
@ -92,9 +92,9 @@ internal sealed class AdbManager(deviceSerial: String? = null) : Closeable {
|
||||
|
||||
val applyReplacement = getPlaceholderReplacement(packageName)
|
||||
|
||||
device.run(COMMAND_UMOUNT.applyReplacement(packageName))
|
||||
device.run(COMMAND_DELETE.applyReplacement(PATH_PATCHED_APK).applyReplacement())
|
||||
device.run(COMMAND_DELETE.applyReplacement(PATH_MOUNT).applyReplacement())
|
||||
device.run(UMOUNT.applyReplacement(packageName))
|
||||
device.run(DELETE.applyReplacement(PATCHED_APK_PATH).applyReplacement())
|
||||
device.run(DELETE.applyReplacement(MOUNT_PATH).applyReplacement())
|
||||
|
||||
super.uninstall(packageName)
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ internal fun JadbDevice.run(command: String, su: Boolean = false) = with(this.st
|
||||
internal fun JadbDevice.hasSu() =
|
||||
this.startCommand("su -h", false).waitFor() == 0
|
||||
|
||||
internal fun JadbDevice.copyFile(file: File, targetFile: String) =
|
||||
push(file, RemoteFile(targetFile))
|
||||
internal fun JadbDevice.push(file: File, targetFilePath: String) =
|
||||
push(file, RemoteFile(targetFilePath))
|
||||
|
||||
internal fun JadbDevice.createFile(targetFile: String, content: String) =
|
||||
push(content.byteInputStream(), System.currentTimeMillis(), 644, RemoteFile(targetFile))
|
||||
|
@ -1,37 +1,37 @@
|
||||
package app.revanced.utils.adb
|
||||
|
||||
internal object Constants {
|
||||
internal const val PLACEHOLDER = "TEMPLATE_PACKAGE_NAME"
|
||||
internal const val PLACEHOLDER = "PLACEHOLDER"
|
||||
|
||||
internal const val PATH_INIT_PUSH = "/data/local/tmp/revanced.delete"
|
||||
internal const val PATH_INSTALLATION = "/data/adb/revanced/"
|
||||
internal const val PATH_PATCHED_APK = "$PATH_INSTALLATION$PLACEHOLDER.apk"
|
||||
internal const val PATH_MOUNT = "/data/adb/service.d/mount_revanced_$PLACEHOLDER.sh"
|
||||
internal const val TMP_PATH = "/data/local/tmp/revanced.tmp"
|
||||
internal const val INSTALLATION_PATH = "/data/adb/revanced/"
|
||||
internal const val PATCHED_APK_PATH = "$INSTALLATION_PATH$PLACEHOLDER.apk"
|
||||
internal const val MOUNT_PATH = "/data/adb/service.d/mount_revanced_$PLACEHOLDER.sh"
|
||||
|
||||
internal const val COMMAND_DELETE = "rm -rf $PLACEHOLDER"
|
||||
internal const val COMMAND_CREATE_DIR = "mkdir -p"
|
||||
internal const val COMMAND_RESTART = "pm resolve-activity --brief $PLACEHOLDER | tail -n 1 | " +
|
||||
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 | " +
|
||||
"xargs am start -n && kill ${'$'}(pidof -s $PLACEHOLDER)"
|
||||
|
||||
internal const val COMMAND_PREPARE_MOUNT_APK = "base_path=\"$PATH_PATCHED_APK\" && " +
|
||||
"mv $PATH_INIT_PUSH ${'$'}base_path && " +
|
||||
internal const val INSTALL_PATCHED_APK = "base_path=\"$PATCHED_APK_PATH\" && " +
|
||||
"mv $TMP_PATH ${'$'}base_path && " +
|
||||
"chmod 644 ${'$'}base_path && " +
|
||||
"chown system:system ${'$'}base_path && " +
|
||||
"chcon u:object_r:apk_data_file:s0 ${'$'}base_path"
|
||||
|
||||
internal const val COMMAND_UMOUNT =
|
||||
internal const val UMOUNT =
|
||||
"grep $PLACEHOLDER /proc/mounts | while read -r line; do echo ${'$'}line | cut -d \" \" -f 2 | sed 's/apk.*/apk/' | xargs -r umount -l; done"
|
||||
|
||||
internal const val COMMAND_INSTALL_MOUNT = "mv $PATH_INIT_PUSH $PATH_MOUNT && chmod +x $PATH_MOUNT"
|
||||
internal const val INSTALL_MOUNT = "mv $TMP_PATH $MOUNT_PATH && chmod +x $MOUNT_PATH"
|
||||
|
||||
internal const val CONTENT_MOUNT_SCRIPT =
|
||||
internal const val MOUNT_SCRIPT =
|
||||
"""
|
||||
#!/system/bin/sh
|
||||
MAGISKTMP="${'$'}(magisk --path)" || MAGISKTMP=/sbin
|
||||
MIRROR="${'$'}MAGISKTMP/.magisk/mirror"
|
||||
while [ "${'$'}(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done
|
||||
|
||||
base_path="$PATH_PATCHED_APK"
|
||||
base_path="$PATCHED_APK_PATH"
|
||||
stock_path=${'$'}( pm path $PLACEHOLDER | grep base | sed 's/package://g' )
|
||||
|
||||
chcon u:object_r:apk_data_file:s0 ${'$'}base_path
|
||||
|
Loading…
Reference in New Issue
Block a user