Skip to content

Commit

Permalink
use fallback for getHintText whenapi level 25 or lower.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Knee committed Oct 23, 2023
1 parent 116a96d commit 1d47a58
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ object AccessibilityNodeInfoExt {
* Retrieves the hint text associated with this [android.view.accessibility.AccessibilityNodeInfo].
*
* If the device API level is below 26 (Oreo), this function provides a fallback
* by returning an empty CharSequence instead. If both hint text and content description
* are unavailable, it returns an empty string.
* by returning an empty CharSequence instead.
*
* @return [CharSequence] representing the hint text or its fallback.
*/
Expand Down
23 changes: 19 additions & 4 deletions maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ class AndroidDriver(

private fun startInstrumentationSession() {
val startTime = System.currentTimeMillis()
val instrumentationCommand = "am instrument -w -m -e debug false " +
"-e class 'dev.mobile.maestro.MaestroDriverService#grpcServer' " +
"dev.mobile.maestro.test/androidx.test.runner.AndroidJUnitRunner &\n"
val apiLevel = getDeviceApiLevel()

val instrumentationCommand = buildString {
append("am instrument -w ")
if (apiLevel >= 26) append("-m ")
append("-e debug false ")
append("-e class 'dev.mobile.maestro.MaestroDriverService#grpcServer' ")
append("dev.mobile.maestro.test/androidx.test.runner.AndroidJUnitRunner &\n")
}

while (System.currentTimeMillis() - startTime < getStartupTimeout()) {
instrumentationSession = dadb.openShell(instrumentationCommand)
Expand All @@ -99,6 +105,15 @@ class AndroidDriver(
throw TimeoutException("Maestro instrumentation could not be initialized")
}

private fun getDeviceApiLevel(): Int {
val response = dadb.openShell("getprop ro.build.version.sdk").readAll()
if (response.exitCode != 0) {
throw IOException("Failed to get device API level: ${response.errorOutput}")
}
return response.output.trim().toIntOrNull() ?: throw IOException("Invalid API level: ${response.output}")
}


private fun allocateForwarder() {
PORT_TO_FORWARDER[hostPort]?.close()
PORT_TO_ALLOCATION_POINT[hostPort]?.let {
Expand Down Expand Up @@ -378,7 +393,7 @@ class AndroidDriver(
} catch (e: IOException) {
throw IOException(
"Failed to capture screen recording on the device. Note that some Android emulators do not support screen recording. " +
"Try using a different Android emulator (eg. Pixel 5 / API 30)",
"Try using a different Android emulator (eg. Pixel 5 / API 30)",
e,
)
}
Expand Down

0 comments on commit 1d47a58

Please sign in to comment.