-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): reconnect lost devices
- Loading branch information
Showing
10 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
21 changes: 14 additions & 7 deletions
21
core/src/main/kotlin/com/malinskiy/marathon/device/DeviceProvider.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,20 +1,27 @@ | ||
package com.malinskiy.marathon.device | ||
|
||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.channels.ReceiveChannel | ||
|
||
interface DeviceProvider { | ||
sealed class DeviceEvent { | ||
class DeviceConnected(val device: Device) : DeviceEvent() | ||
class DeviceDisconnected(val device: Device) : DeviceEvent() | ||
class DeviceConnected( | ||
val device: Device, | ||
) : DeviceEvent() | ||
|
||
class DeviceDisconnected( | ||
val device: Device, | ||
) : DeviceEvent() | ||
} | ||
|
||
suspend fun initialize() | ||
|
||
/** | ||
* Remote test parsers require a temp device | ||
* This method should be called before reading from the [subscribe()] channel | ||
* Remote test parsers require a temp device This method should be called before reading from | ||
* the [subscribe()] channel | ||
*/ | ||
suspend fun borrow() : Device | ||
suspend fun borrow(): Device | ||
|
||
suspend fun terminate() | ||
fun subscribe(): Channel<DeviceEvent> | ||
|
||
fun subscribe(scheduler: ReceiveChannel<DeviceEvent>): ReceiveChannel<DeviceEvent> | ||
} |
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
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
26 changes: 26 additions & 0 deletions
26
...or-android/src/main/kotlin/com/malinskiy/marathon/android/adam/DisconnectDeviceRequest.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.malinskiy.marathon.android.adam | ||
|
||
import com.malinskiy.adam.extension.readProtocolString | ||
import com.malinskiy.adam.request.ComplexRequest | ||
import com.malinskiy.adam.request.HostTarget | ||
import com.malinskiy.adam.transport.Socket | ||
|
||
class DisconnectDeviceRequest( | ||
private val host: String? = null, | ||
private val port: Int? = 5555 | ||
) : ComplexRequest<String>(target = HostTarget) { | ||
|
||
override fun serialize() = createBaseRequest( | ||
"disconnect:${ | ||
if (host == null) { | ||
"" | ||
} else if (port != null) { | ||
"$host:$port" | ||
} else { | ||
"$host" | ||
} | ||
}" | ||
) | ||
|
||
override suspend fun readElement(socket: Socket) = socket.readProtocolString() | ||
} |
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