diff --git a/app/build.gradle b/app/build.gradle index 4d8bf27..32ef84c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,8 @@ android { applicationId "com.dtmilano.android.culebratester2" minSdk 26 targetSdk 33 - versionCode 20068 - versionName "2.0.68-alpha" + versionCode 20069 + versionName "2.0.69-alpha" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/dtmilano/android/culebratester2/location/Am.kt b/app/src/main/java/com/dtmilano/android/culebratester2/location/Am.kt new file mode 100644 index 0000000..3b8e6e8 --- /dev/null +++ b/app/src/main/java/com/dtmilano/android/culebratester2/location/Am.kt @@ -0,0 +1,46 @@ +package com.dtmilano.android.culebratester2.location + +import io.ktor.locations.KtorExperimentalLocationsAPI +import io.ktor.locations.Location +import io.swagger.server.models.StatusResponse +import org.apache.commons.io.IOUtils +import java.util.concurrent.TimeUnit + +/** + * See https://github.com/ktorio/ktor/issues/1660 for the reason why we need the extra parameter + * in nested classes: + * + * "One of the problematic features is nested location classes and nested location objects. + * + * What we are thinking of to change: + * + * a nested location class should always have a property of the outer class or object + * nested objects in objects are not allowed + * The motivation for the first point is the fact that a location class nested to another, makes no + * sense without the ability to refer to the outer class." + */ +@KtorExperimentalLocationsAPI +@Location("/am") +class Am { + + @Location("/forceStop") + class ForceStop( + private val pkg: String, + private val parent: Am = Am()) { + fun response(): io.swagger.server.models.StatusResponse { + val command = listOf("am", "force-stop", pkg) + println("Executing $command") + val pb = ProcessBuilder(command) + val p = pb.start() + val stdOut = IOUtils.toString(p.inputStream, Charsets.UTF_8) + val stdErr = IOUtils.toString(p.errorStream, Charsets.UTF_8) + val exitStatus = p.waitFor(30, TimeUnit.SECONDS) + println("$command: exit status: $exitStatus") + return if (exitStatus) { + StatusResponse(StatusResponse.Status.OK) + } else { + StatusResponse(StatusResponse.Status.ERROR, errorMessage = stdErr) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/dtmilano/android/culebratester2/location/UiObject.kt b/app/src/main/java/com/dtmilano/android/culebratester2/location/UiObject.kt index 182c54d..132c528 100644 --- a/app/src/main/java/com/dtmilano/android/culebratester2/location/UiObject.kt +++ b/app/src/main/java/com/dtmilano/android/culebratester2/location/UiObject.kt @@ -27,7 +27,7 @@ import io.swagger.server.models.StringResponse import java.math.BigDecimal import javax.inject.Inject -private const val TAG = "UiObject2" +private const val TAG = "UiObject" /** * See https://github.com/ktorio/ktor/issues/1660 for the reason why we need the extra parameter @@ -158,7 +158,7 @@ class UiObject { @Location("/{oid}/exists") /*inner*/ class Exists( val oid: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -184,7 +184,7 @@ class UiObject { @Location("/{oid}/getBounds") /*inner*/ class GetBounds( val oid: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -212,7 +212,7 @@ class UiObject { /*inner*/ class GetChild( val oid: Int, private val uiSelector: String? = null, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -247,7 +247,7 @@ class UiObject { @Location("/{oid}/getChildCount") /*inner*/ class GetChildCount( val oid: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -273,7 +273,7 @@ class UiObject { @Location("/{oid}/getClassName") /*inner*/ class GetClassName( val oid: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -300,7 +300,7 @@ class UiObject { @Location("/{oid}/getContentDescription") /*inner*/ class GetContentDescription( val oid: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -368,7 +368,7 @@ class UiObject { val oid: Int, private val percentage: Int, private val steps: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -399,7 +399,7 @@ class UiObject { val oid: Int, private val percentage: Int, private val steps: Int, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -429,7 +429,7 @@ class UiObject { /*inner*/ class WaitForExists( val oid: Int, private val timeout: Long, - private val parent: UiObject2 = UiObject2() + private val parent: UiObject = UiObject() ) { private var holder: Holder @@ -474,4 +474,4 @@ class UiObject { return HttpException(HttpStatusCode.NotFound, "⚠️ UiObject matching $bsb not found") } } -} \ No newline at end of file +} diff --git a/openapi.yaml b/openapi.yaml index d29713f..b11105f 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -9,7 +9,7 @@ info: - the server should have been started using `./culebratester2 start-server` then you will be able to invoke the API and see the responses. - version: 2.0.68 + version: 2.0.69 servers: - url: http://localhost:9987/v2 paths: