Skip to content

Commit

Permalink
Merge pull request #33 from DeviceFarmer/support_display_id
Browse files Browse the repository at this point in the history
Add secondary display selection (apk only)
  • Loading branch information
koral-- authored Jan 5, 2022
2 parents 48cbb97 + 5d1ce2b commit 5be2c02
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
13 changes: 9 additions & 4 deletions experimental/app/src/main/java/io/devicefarmer/minicap/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Main {
Pair(p, elem)
} else {
when (lastKey) {
"-d" -> p.displayId(elem.toInt())
"-n" -> p.socket(elem)
"-P" -> p.projection(elem)
"-Q" -> p.quality(elem.toInt())
Expand All @@ -55,10 +56,11 @@ class Main {
}.first.build()

provider = if (params.projection == null) {
SurfaceProvider()
SurfaceProvider(params.displayId)
} else {
params.projection.forceAspectRatio()
SurfaceProvider(
params.displayId,
Size(
params.projection.targetSize.width,
params.projection.targetSize.height
Expand Down Expand Up @@ -138,15 +140,17 @@ class Parameters private constructor(
val socket: String,
val quality: Int,
val displayInfo: Boolean,
val frameRate: Float
val frameRate: Float,
val displayId: Int
) {
data class Builder(
var projection: Projection? = null,
var screenshot: Boolean = false,
var socket: String = "minicap",
var quality: Int = 100,
var displayInfo: Boolean = false,
var frameRate: Float = Float.MAX_VALUE
var frameRate: Float = Float.MAX_VALUE,
var displayId: Int = 0
) {
//TODO make something more robust
fun projection(p: String) = apply {
Expand All @@ -165,6 +169,7 @@ class Parameters private constructor(
fun quality(value: Int) = apply { this.quality = value }
fun displayInfo(enabled: Boolean) = apply { this.displayInfo = enabled }
fun frameRate(value: Float) = apply { this.frameRate = value }
fun build() = Parameters(projection, screenshot, socket, quality, displayInfo, frameRate)
fun displayId(value: Int) = apply { this.displayId = value }
fun build() = Parameters(projection, screenshot, socket, quality, displayInfo, frameRate, displayId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.util.Size
import io.devicefarmer.minicap.output.DisplayOutput
import io.devicefarmer.minicap.output.MinicapClientOutput
import io.devicefarmer.minicap.SimpleServer
import io.devicefarmer.minicap.utils.DisplayManagerGlobal
import org.slf4j.LoggerFactory
import java.io.OutputStream
import java.io.PrintStream
Expand All @@ -36,7 +37,7 @@ import java.nio.ByteBuffer
* and sends the results to an output (could be a file for screenshot, or a minicap client receiving the
* jpeg stream)
*/
abstract class BaseProvider(private val targetSize: Size, val rotation: Int) : SimpleServer.Listener,
abstract class BaseProvider(private val displayId: Int, private val targetSize: Size, val rotation: Int) : SimpleServer.Listener,
ImageReader.OnImageAvailableListener {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import kotlin.system.exitProcess
* Provides screen images using [SurfaceControl]. This is pretty similar to the native version
* of minicap but here it is done at a higher level making things a bit easier.
*/
class SurfaceProvider(targetSize: Size, orientation: Int) : BaseProvider(targetSize, orientation) {
constructor() : this(currentScreenSize(), currentRotation())
class SurfaceProvider(displayId: Int, targetSize: Size, orientation: Int) : BaseProvider(displayId, targetSize, orientation) {
constructor(display: Int) : this(display, currentScreenSize(), currentRotation())

companion object {
private fun currentScreenSize(): Size {
Expand All @@ -54,7 +54,7 @@ class SurfaceProvider(targetSize: Size, orientation: Int) : BaseProvider(targetS
private val handler: Handler = Handler(Looper.getMainLooper())
private var display: IBinder? = null

val displayInfo: DisplayInfo = currentDisplayInfo()
val displayInfo: DisplayInfo = DisplayManagerGlobal.getDisplayInfo(displayId)

override fun getScreenSize(): Size = displayInfo.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ object DisplayManagerGlobal {
throw AssertionError(e)
}
}

fun getDisplayIds(): IntArray {
return try {
displayManager!!.javaClass.getMethod("getDisplayIds")
.invoke(displayManager) as IntArray
} catch (e: Exception) {
throw AssertionError(e)
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devicefarmer/minicap-prebuilt",
"version": "2.7.0",
"version": "2.7.1",
"description": "Prebuilt binaries of minicap.",
"keywords": [
"minicap"
Expand Down

0 comments on commit 5be2c02

Please sign in to comment.