Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[androiddebugbridge] Broken hdmi status on Fire TV Cube #582

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this works for both cases we had before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is much more stable than the previous way(s).

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
Loading