-
-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathInstallCommand.kt
More file actions
85 lines (74 loc) · 2.69 KB
/
Copy pathInstallCommand.kt
File metadata and controls
85 lines (74 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package app.revanced.cli.command.utility
import app.revanced.library.installation.installer.*
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import picocli.CommandLine
import picocli.CommandLine.*
import java.io.File
import picocli.CommandLine.ParameterException
import java.util.logging.Logger
@Command(
name = "install",
description = ["Install an APK file."],
)
internal object InstallCommand : Runnable {
private val logger = Logger.getLogger(this::class.java.name)
@Parameters(
description = ["Serial of ADB devices. If not supplied, the first connected device will be used."],
arity = "0..*",
)
private var deviceSerials: Array<String>? = null
@Option(
names = ["-a", "--apk"],
description = ["APK file to be installed."],
required = true,
)
private lateinit var apk: File
@Option(
names = ["-m", "--mount"],
description = ["Mount the supplied APK file over the app with the supplied package name."],
)
private var packageName: String? = null
@Option(
names = ["--splits"],
description = ["Paths to split APK files, keyed by split name (e.g. --splits split_config.arm64_v8a=split_arm64.apk)."],
)
@Suppress("unused")
private fun setSplitApkFiles(splitApkFiles: Map<String, File>) {
splitApkFiles.forEach { (splitName, splitFile) ->
if (!splitFile.exists()) {
throw ParameterException(
CommandLine(this),
"Split APK file for $splitName does not exist: ${splitFile.path}",
)
}
}
this.splitApkFiles = splitApkFiles.toMutableMap()
}
private var splitApkFiles = mutableMapOf<String, File>()
override fun run() {
suspend fun install(deviceSerial: String? = null) {
val result = try {
if (packageName != null) {
AdbRootInstaller(deviceSerial)
} else {
AdbInstaller(deviceSerial)
}.install(Installer.Apk(apk, packageName, splitApkFiles))
} catch (e: Exception) {
logger.severe(e.toString())
}
when (result) {
RootInstallerResult.FAILURE ->
logger.severe("Failed to mount the APK file")
is AdbInstallerResult.Failure ->
logger.severe(result.exception.toString())
else ->
logger.info("Installed the APK file")
}
}
runBlocking {
deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install()
}
}
}