Skip to content

Commit

Permalink
[androiddebugbridge] Broken hdmi status on Fire TV Cube (#582)
Browse files Browse the repository at this point in the history
* fixed: missing Content-Length header (BodyPublisher.ofByteArrays JDK 17 issue)

Signed-off-by: Tom Blum <[email protected]>
  • Loading branch information
Trinitus01 authored Oct 10, 2024
1 parent b7f0bca commit 97ea751
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -258,42 +257,19 @@ public boolean isAwake() throws InterruptedException, AndroidDebugBridgeDeviceEx

public boolean isScreenOn() throws InterruptedException, AndroidDebugBridgeDeviceException,
AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException {
String result = runAdbShell("dumpsys", "power", "|", "grep", "'Display Power'");
String[] splitResult = result.split("=");
if (splitResult.length >= 2) {
return "ON".equals(splitResult[1]);
String result = runAdbShell("dumpsys", "display", "|", "grep", "mScreenState");
if (result.contains("mScreenState=")) {
return result.contains("mScreenState=ON");
}
throw new AndroidDebugBridgeDeviceReadException(SCREEN_STATE_CHANNEL, result);
}

public Optional<Boolean> isHDMIOn() throws InterruptedException, AndroidDebugBridgeDeviceException,
public boolean isHdmiOn() throws InterruptedException, AndroidDebugBridgeDeviceException,
AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException {
if (channelFallbackMap.get(HDMI_STATE_CHANNEL) == FallbackModes.LOGCAT) {
return isHDMIOnWithLogcat();
}
String result = runAdbShell("cat", "/sys/devices/virtual/switch/hdmi/state");
if ("0".equals(result) || "1".equals(result)) {
return Optional.of("1".equals(result));
} else {
LOGGER.debug("set fallback {} for {}", FallbackModes.LOGCAT, HDMI_STATE_CHANNEL);
channelFallbackMap.put(HDMI_STATE_CHANNEL, FallbackModes.LOGCAT);
return isHDMIOnWithLogcat();
String result = runAdbShell("dumpsys", "hdmi_control", "|", "grep", "mPowerStatus");
if (result.contains("mPowerStatus:")) {
return result.contains("mPowerStatus: 0");
}
}

private Optional<Boolean> isHDMIOnWithLogcat() throws InterruptedException, AndroidDebugBridgeDeviceException,
AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException {
String result = runAdbShell("logcat", "-d", "|", "grep", "hdmi", "|", "grep", "SWITCH_STATE=", "|", "tail",
"-1");
if (result.contains("SWITCH_STATE=")) {
return Optional.of(result.contains("SWITCH_STATE=1"));
} else if (result.isEmpty()) {
// IF THE DEVICE DO NOT SUPPORT THIS VALUE IN LOGCAT THE USER WILL NEVER KNOW THE CHANNEL WON'T WORK
// FIND A BETTER SOLUTION
return Optional.empty();
}
LOGGER.debug("remove fallback for {}", HDMI_STATE_CHANNEL);
channelFallbackMap.remove(HDMI_STATE_CHANNEL);
throw new AndroidDebugBridgeDeviceReadException(HDMI_STATE_CHANNEL, result);
}

Expand Down Expand Up @@ -548,7 +524,6 @@ public static class VolumeInfo {
private enum FallbackModes {
MONKEY,
MONKEY_LEANBACK_LAUNCHER,
DUMPSYS_ACTIVITY_RECENTS,
LOGCAT,
DUMPSYS_ACTIVITY_RECENTS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,12 @@ private void handleCommandInternal(ChannelUID channelUID, Command command)
break;
case HDMI_STATE_CHANNEL:
if (command instanceof RefreshType) {
adbConnection.isHDMIOn().ifPresent(hdmiState -> {
boolean lastHDMIState = (boolean) channelLastStateMap.getOrDefault(HDMI_STATE_CHANNEL, false);
if (hdmiState.equals(lastHDMIState)) {
updateState(channelUID, OnOffType.from(hdmiState));
}
channelLastStateMap.put(HDMI_STATE_CHANNEL, hdmiState);
});
boolean hdmiState = adbConnection.isHdmiOn();
boolean lastHdmiState = (boolean) channelLastStateMap.getOrDefault(HDMI_STATE_CHANNEL, false);
if (hdmiState == lastHdmiState) {
updateState(channelUID, OnOffType.from(hdmiState));
}
channelLastStateMap.put(HDMI_STATE_CHANNEL, hdmiState);
}
break;
}
Expand Down

0 comments on commit 97ea751

Please sign in to comment.