-
-
Save reactormonk/45892c2ba8dcc7b0e5f9d583029e5827 to your computer and use it in GitHub Desktop.
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
class HDMIActivity : ComponentActivity() { | |
@SuppressLint("SoonBlockedPrivateApi", "WrongConstant") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val hdmiService = baseContext.getSystemService("hdmi_control") as HdmiControlManager | |
val sup = HdmiSupport(hdmiService) | |
val client = hdmiService.playbackClient | |
val resultsFlow = MutableSharedFlow<HdmiResult>() | |
val results: Flow<List<HdmiResult>> = (merge(resultsFlow, )) | |
.runningFold(listOf()) { list: List<HdmiResult>, v: HdmiResult -> list + listOf(v) } | |
fun addItem(item: HdmiResult) { | |
resultsFlow.tryEmit(item) | |
} | |
setContent { | |
LaunchedEffect(true) { | |
addItem(HdmiResult("Playback Client: $client")) | |
addItem(HdmiResult("Active Source: ${client.activeSource}")) | |
addItem(HdmiResult("Device Type: ${client.deviceType}")) | |
val field = hdmiService.javaClass.getDeclaredField("mService") | |
field.isAccessible = true | |
val service = field.get(hdmiService) as IHdmiControlService | |
Log.d("HdmiDebug", "Starting oneTouchPlay") | |
client.oneTouchPlay { | |
Log.d("HdmiDebug", "OneTouchPlay: $it") | |
} | |
addItem(HdmiResult("Device List: ${service.deviceList}")) | |
addItem(HdmiResult("Port Info: ${service.portInfo}")) | |
addItem(HdmiResult("Active Source: ${service.activeSource}")) | |
addItem(HdmiResult("Input Devices: ${service.inputDevices}")) | |
addItem(HdmiResult("Supported Device Types (4 is playback): ${service.supportedTypes.asList()}")) | |
addItem(HdmiResult("Can change system audio mode: ${service.canChangeSystemAudioMode()}")) | |
val log = service.activeSource.logicalAddress | |
val status = sup.queryDisplayStatus() | |
addItem(HdmiResult("Display Status: $status")) | |
sup.hotPlugEvents().collect { | |
addItem(HdmiResult("Port: ${it.port}")) | |
addItem(HdmiResult("Connected: ${it.isConnected}")) | |
} | |
} | |
val lazyListState = rememberLazyListState() | |
val resultsState by results.collectAsState(listOf(HdmiResult("Nothing here yet"))) | |
TopAppBar { | |
Button(onClick = { | |
// val command = "0x${log}0 0x9D 0x${Integer.toHexString(service.physicalAddress).slice(0..1)} 0x${Integer.toHexString(service.physicalAddress).slice(2..3)}" | |
// Runtime.getRuntime().exec(arrayOf("su", "-c", "echo $command > /sys/class/cec/cmd")) | |
}) { | |
Text("Inactivate source") | |
} | |
Button(onClick = { sup.toggleMute()}) { | |
Text("Toggle Mute") | |
} | |
Button(onClick = {sup.volumeUp()}) { | |
Text("Volume Up") | |
} | |
Button(onClick = {sup.volumeDown()}) { | |
Text("Volume Down") | |
} | |
Button(onClick = {client.sendStandby()}) { | |
Text("Standby") | |
} | |
} | |
LazyColumn(state = lazyListState, modifier = Modifier.fillMaxWidth()) { | |
items(resultsState) { result -> | |
Text(result.value) | |
} | |
} | |
LaunchedEffect(lazyListState) { | |
snapshotFlow { | |
lazyListState.layoutInfo.totalItemsCount | |
}.collect { | |
lazyListState.animateScrollToItem(it) | |
} | |
} | |
} | |
} | |
} | |
data class HdmiResult(val value: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment