refactor: use better identifiers

This commit is contained in:
oSumAtrIX 2023-08-24 15:59:44 +02:00
parent 11c3a6cfd4
commit a536c9f815
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 38 additions and 38 deletions

View File

@ -1,18 +1,18 @@
package app.revanced.utils.adb package app.revanced.utils.adb
import app.revanced.utils.adb.AdbManager.Apk import app.revanced.utils.adb.AdbManager.Apk
import app.revanced.utils.adb.Constants.COMMAND_CREATE_DIR import app.revanced.utils.adb.Constants.CREATE_DIR
import app.revanced.utils.adb.Constants.COMMAND_DELETE import app.revanced.utils.adb.Constants.DELETE
import app.revanced.utils.adb.Constants.COMMAND_INSTALL_MOUNT import app.revanced.utils.adb.Constants.INSTALLATION_PATH
import app.revanced.utils.adb.Constants.COMMAND_PREPARE_MOUNT_APK import app.revanced.utils.adb.Constants.INSTALL_MOUNT
import app.revanced.utils.adb.Constants.COMMAND_RESTART import app.revanced.utils.adb.Constants.INSTALL_PATCHED_APK
import app.revanced.utils.adb.Constants.COMMAND_UMOUNT import app.revanced.utils.adb.Constants.MOUNT_PATH
import app.revanced.utils.adb.Constants.CONTENT_MOUNT_SCRIPT import app.revanced.utils.adb.Constants.MOUNT_SCRIPT
import app.revanced.utils.adb.Constants.PATH_INIT_PUSH import app.revanced.utils.adb.Constants.PATCHED_APK_PATH
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.PLACEHOLDER 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.JadbConnection
import se.vidstige.jadb.managers.Package import se.vidstige.jadb.managers.Package
import se.vidstige.jadb.managers.PackageManager 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") 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("$CREATE_DIR $INSTALLATION_PATH")
device.run(COMMAND_PREPARE_MOUNT_APK.applyReplacement()) 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(INSTALL_MOUNT.applyReplacement())
device.run(COMMAND_UMOUNT.applyReplacement()) // Sanity check. device.run(UMOUNT.applyReplacement()) // Sanity check.
device.run(PATH_MOUNT.applyReplacement()) device.run(MOUNT_PATH.applyReplacement())
device.run(COMMAND_RESTART.applyReplacement()) device.run(RESTART.applyReplacement())
super.install(apk) super.install(apk)
} }
@ -92,9 +92,9 @@ internal sealed class AdbManager(deviceSerial: String? = null) : Closeable {
val applyReplacement = getPlaceholderReplacement(packageName) val applyReplacement = getPlaceholderReplacement(packageName)
device.run(COMMAND_UMOUNT.applyReplacement(packageName)) device.run(UMOUNT.applyReplacement(packageName))
device.run(COMMAND_DELETE.applyReplacement(PATH_PATCHED_APK).applyReplacement()) device.run(DELETE.applyReplacement(PATCHED_APK_PATH).applyReplacement())
device.run(COMMAND_DELETE.applyReplacement(PATH_MOUNT).applyReplacement()) device.run(DELETE.applyReplacement(MOUNT_PATH).applyReplacement())
super.uninstall(packageName) super.uninstall(packageName)
} }

View File

@ -18,8 +18,8 @@ internal fun JadbDevice.run(command: String, su: Boolean = false) = with(this.st
internal fun JadbDevice.hasSu() = internal fun JadbDevice.hasSu() =
this.startCommand("su -h", false).waitFor() == 0 this.startCommand("su -h", false).waitFor() == 0
internal fun JadbDevice.copyFile(file: File, targetFile: String) = internal fun JadbDevice.push(file: File, targetFilePath: String) =
push(file, RemoteFile(targetFile)) push(file, RemoteFile(targetFilePath))
internal fun JadbDevice.createFile(targetFile: String, content: String) = internal fun JadbDevice.createFile(targetFile: String, content: String) =
push(content.byteInputStream(), System.currentTimeMillis(), 644, RemoteFile(targetFile)) push(content.byteInputStream(), System.currentTimeMillis(), 644, RemoteFile(targetFile))

View File

@ -1,37 +1,37 @@
package app.revanced.utils.adb package app.revanced.utils.adb
internal object Constants { 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 TMP_PATH = "/data/local/tmp/revanced.tmp"
internal const val PATH_INSTALLATION = "/data/adb/revanced/" internal const val INSTALLATION_PATH = "/data/adb/revanced/"
internal const val PATH_PATCHED_APK = "$PATH_INSTALLATION$PLACEHOLDER.apk" internal const val PATCHED_APK_PATH = "$INSTALLATION_PATH$PLACEHOLDER.apk"
internal const val PATH_MOUNT = "/data/adb/service.d/mount_revanced_$PLACEHOLDER.sh" internal const val MOUNT_PATH = "/data/adb/service.d/mount_revanced_$PLACEHOLDER.sh"
internal const val COMMAND_DELETE = "rm -rf $PLACEHOLDER" internal const val DELETE = "rm -rf $PLACEHOLDER"
internal const val COMMAND_CREATE_DIR = "mkdir -p" internal const val CREATE_DIR = "mkdir -p"
internal const val COMMAND_RESTART = "pm resolve-activity --brief $PLACEHOLDER | tail -n 1 | " + internal const val RESTART = "pm resolve-activity --brief $PLACEHOLDER | tail -n 1 | " +
"xargs am start -n && kill ${'$'}(pidof -s $PLACEHOLDER)" "xargs am start -n && kill ${'$'}(pidof -s $PLACEHOLDER)"
internal const val COMMAND_PREPARE_MOUNT_APK = "base_path=\"$PATH_PATCHED_APK\" && " + internal const val INSTALL_PATCHED_APK = "base_path=\"$PATCHED_APK_PATH\" && " +
"mv $PATH_INIT_PUSH ${'$'}base_path && " + "mv $TMP_PATH ${'$'}base_path && " +
"chmod 644 ${'$'}base_path && " + "chmod 644 ${'$'}base_path && " +
"chown system:system ${'$'}base_path && " + "chown system:system ${'$'}base_path && " +
"chcon u:object_r:apk_data_file:s0 ${'$'}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" "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 #!/system/bin/sh
MAGISKTMP="${'$'}(magisk --path)" || MAGISKTMP=/sbin MAGISKTMP="${'$'}(magisk --path)" || MAGISKTMP=/sbin
MIRROR="${'$'}MAGISKTMP/.magisk/mirror" MIRROR="${'$'}MAGISKTMP/.magisk/mirror"
while [ "${'$'}(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done 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' ) stock_path=${'$'}( pm path $PLACEHOLDER | grep base | sed 's/package://g' )
chcon u:object_r:apk_data_file:s0 ${'$'}base_path chcon u:object_r:apk_data_file:s0 ${'$'}base_path