Skip to content

Commit

Permalink
Launch cleanup device script when 80% of space
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Dyatlov committed Jul 1, 2024
1 parent 07b6e19 commit fa060ca
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AndroidAppInstaller(

@Suppress("TooGenericExceptionThrown")
private suspend fun ensureInstalled(device: AndroidDevice, appPackage: String, appApk: File) {
withRetry(attempts = MAX_RETIRES, delayTime = 1000) {
withRetry(attempts = MAX_RETIRES, delayTime = 5000) {
try {
val checkStarted = Instant.now()
val fileHash = fileHasher.getHash(appApk)
Expand All @@ -61,16 +61,22 @@ class AndroidAppInstaller(
installedApps
.getOrPut(device.serialNumber) { hashMapOf() }
.put(appPackage, fileHash)
val amountLeft = device
.safeExecuteShellCommand("df /storage/emulated -h | grep '/storage/emulated' | awk '{print \\\$5}'")
.dropLast(1)
.toInt()
logger.info { "Left $amountLeft% of storage" }
val storageLimit = 80
if (amountLeft < storageLimit) {
logger.warn { "Not enough space left" }
androidConfiguration.cleanupDeviceScript?.let {
logger.info { "Less than $storageLimit% left\nLaunching cleanup shell script `$it`" }
device.safeExecuteShellCommand(it).let { logger.info { it } }
}
}
}
} catch (e: InstallException) {
logger.error(e) { "Error while installing $appPackage, ${appApk.absolutePath} on ${device.serialNumber}" }
if (e.stackTrace.toString().contains("not enough space")) {
logger.error { "Not enough space" }
androidConfiguration.cleanupDeviceScript?.let {
logger.info { "Launch shell script `$it`" }
device.safeExecuteShellCommand(it).let { logger.info { it } }
}
}
throw RuntimeException("Error while installing $appPackage on ${device.serialNumber}", e)
}
}
Expand Down

0 comments on commit fa060ca

Please sign in to comment.