throw new AndroidDebugBridgeDeviceReadException("can read package name");
}
+ public boolean isAwake()
+ throws InterruptedException, AndroidDebugBridgeDeviceException, TimeoutException, ExecutionException {
+ String devicesResp = runAdbShell("dumpsys", "activity", "|", "grep", "mWakefulness");
+ return devicesResp.contains("mWakefulness=Awake");
+ }
+
public boolean isScreenOn() throws InterruptedException, AndroidDebugBridgeDeviceException,
AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException {
String devicesResp = runAdbShell("dumpsys", "power", "|", "grep", "'Display Power'");
if (devicesResp.contains("=")) {
try {
- return devicesResp.split("=")[1].equals("ON");
+ var state = devicesResp.split("=")[1].trim();
+ return state.equals("ON");
} catch (NumberFormatException e) {
logger.debug("Unable to parse device wake lock: {}", e.getMessage());
}
private AndroidDebugBridgeConfiguration config = new AndroidDebugBridgeConfiguration();
private @Nullable ScheduledFuture<?> connectionCheckerSchedule;
private AndroidDebugBridgeMediaStatePackageConfig @Nullable [] packageConfigs = null;
+ private boolean deviceAwake = false;
public AndroidDebugBridgeHandler(Thing thing) {
super(thing);
updateState(channelUID, new DecimalType(lock));
}
break;
+ case AWAKE_STATE_CHANNEL:
+ if (command instanceof RefreshType) {
+ boolean awakeState = adbConnection.isAwake();
+ updateState(channelUID, OnOffType.from(awakeState));
+ }
+ break;
case SCREEN_STATE_CHANNEL:
if (command instanceof RefreshType) {
boolean screenState = adbConnection.isScreenOn();
} catch (AndroidDebugBridgeDeviceException e) {
logger.debug("Error connecting to device; [{}]: {}", e.getClass().getCanonicalName(),
e.getMessage());
+ adbConnection.disconnect();
updateStatus(ThingStatus.OFFLINE);
return;
}
}
private void refreshStatus() throws InterruptedException, AndroidDebugBridgeDeviceException, ExecutionException {
+ boolean awakeState;
+ boolean prevDeviceAwake = deviceAwake;
+ try {
+ awakeState = adbConnection.isAwake();
+ deviceAwake = awakeState;
+ } catch (TimeoutException e) {
+ logger.warn("Unable to refresh awake state: Timeout");
+ return;
+ }
+ var awakeStateChannelUID = new ChannelUID(this.thing.getUID(), AWAKE_STATE_CHANNEL);
+ if (isLinked(awakeStateChannelUID)) {
+ updateState(awakeStateChannelUID, OnOffType.from(awakeState));
+ }
+ if (!awakeState && !prevDeviceAwake) {
+ logger.debug("device {} is sleeping", config.ip);
+ return;
+ }
try {
handleCommandInternal(new ChannelUID(this.thing.getUID(), MEDIA_VOLUME_CHANNEL), RefreshType.REFRESH);
} catch (AndroidDebugBridgeDeviceReadException e) {
<channel id="current-package" typeId="current-package-channel"/>
<channel id="wake-lock" typeId="wake-lock-channel"/>
<channel id="screen-state" typeId="screen-state-channel"/>
+ <channel id="awake-state" typeId="awake-state-channel"/>
</channels>
<representation-property>serial</representation-property>
<config-description>
<state readOnly="true"/>
</channel-type>
+ <channel-type id="awake-state-channel" advanced="true">
+ <item-type>Switch</item-type>
+ <label>Awake State</label>
+ <description>Awake State</description>
+ <state readOnly="true"/>
+ </channel-type>
+
<channel-type id="screen-state-channel" advanced="true">
<item-type>Switch</item-type>
<label>Screen State</label>