Skip to content

Commit

Permalink
Filter out empty lines, properly handle installation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Dyatlov committed Jul 5, 2024
1 parent 9858db7 commit cc689ae
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ class AndroidAppInstaller(
val usedStorageThresholdInPercents = androidConfiguration.usedStorageThresholdInPercents
if (storageUsedPercentage > usedStorageThresholdInPercents) {
logger.warn { "On ${device.serialNumber} used more than $usedStorageThresholdInPercents% of storage" }
val appsToClean = device.safeExecuteShellCommand(INSTALLED_TEST_APPS_SCRIPT).lines()
val appsToClean = device.safeExecuteShellCommand(INSTALLED_TEST_APPS_SCRIPT).lines().filter { it.isNotEmpty() }
logger.info { "Removing ${appsToClean.size} apps on ${device.serialNumber}" }
appsToClean.forEach {
try {
val result = device.safeUninstallPackage(it)
if (result == "Success") {
logger.info { "Uninstalled $it - $result" }
installedApps[device.serialNumber]?.remove(it)
val error = device.safeUninstallPackage(it)
if (error != null) {
logger.error { "Error while uninstalling $it on ${device.serialNumber} : $error" }
} else {
logger.error { "Error while uninstalling $it on ${device.serialNumber} : $result" }
logger.info { "Uninstalled $it" }
installedApps[device.serialNumber]?.remove(it)
}
} catch (ignored: Throwable) {
logger.error(ignored) { "Error while uninstalling $it on ${device.serialNumber}" }
} catch (error: Throwable) {
logger.error(error) { "Error while uninstalling $it on ${device.serialNumber}" }
}
}
}
Expand Down

0 comments on commit cc689ae

Please sign in to comment.