-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation of InvokeAndroidDevices
Fix InstallAndroidApps Update Example.kt
- Loading branch information
Showing
15 changed files
with
353 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 32 additions & 7 deletions
39
corellium/adapter/src/main/kotlin/flank/corellium/adapter/InstallAndroidApps.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,62 @@ | ||
package flank.corellium.adapter | ||
|
||
import flank.corellium.api.AndroidApps | ||
import flank.corellium.client.agent.disconnect | ||
import flank.corellium.client.agent.uploadFile | ||
import flank.corellium.client.console.close | ||
import flank.corellium.client.console.sendCommand | ||
import flank.corellium.client.core.connectAgent | ||
import flank.corellium.client.core.connectConsole | ||
import flank.corellium.client.core.getAllProjects | ||
import flank.corellium.client.core.getProjectInstancesList | ||
import java.io.File | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.flowOf | ||
|
||
private const val PATH_TO_UPLOAD = "/sdcard" | ||
|
||
class InstallAndroidApps( | ||
private val projectName: String | ||
) : AndroidApps.Install { | ||
|
||
override suspend fun List<AndroidApps>.invoke() { | ||
val corellium = corellium | ||
val projectId = corellium.getAllProjects().first { it.name == projectName }.id | ||
val instances = corellium.getProjectInstancesList(projectId).associateBy { it.id } | ||
override suspend fun List<AndroidApps>.invoke(): Unit = corellium.run { | ||
val projectId = getAllProjects().first { it.name == projectName }.id | ||
val instances = getProjectInstancesList(projectId).associateBy { it.id } | ||
|
||
forEach { apps -> | ||
val instance = instances.getValue(apps.instanceId) | ||
val agent = corellium.connectAgent(instance.agent!!.info) | ||
val console = corellium.connectConsole(instance.id) | ||
|
||
println("Connecting agent for ${apps.instanceId}") | ||
val agentInfo = requireNotNull(instance.agent?.info) { | ||
"Cannot connect to the agent, no agent info for instance ${instance.name} with id: ${instance.id}" | ||
} | ||
val agent = connectAgent(agentInfo) | ||
|
||
println("Connecting console for ${apps.instanceId}") | ||
val console = connectConsole(instance.id) | ||
|
||
// Disable system logging | ||
flowOf("su", "dmesg -n 1", "exit").collect(console::sendCommand) | ||
|
||
apps.paths.forEach { localPath -> | ||
val file = File(localPath) | ||
val remotePath = "$PATH_TO_UPLOAD/${file.name}" | ||
|
||
println("Uploading apk $localPath") | ||
agent.uploadFile(remotePath, file.readBytes()) | ||
console.sendCommand("pm install $remotePath") | ||
|
||
println("Installing apk $localPath") | ||
console.sendCommand( | ||
// Current solution is enough for the MVP. | ||
// Fixme: Find better solution for recognizing test apk. | ||
if (localPath.endsWith("androidTest.apk")) | ||
"pm install -t $remotePath" else | ||
"pm install $remotePath" | ||
) | ||
} | ||
|
||
console.close() | ||
agent.disconnect() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
corellium/adapter/src/test/kotlin/flank/corellium/adapter/AdaptersExample.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.