hare0815
(Harald)
February 23, 2021, 6:43pm
1
Platform information:
Hardware: VirtualBox
OS: Ubuntu 20.04 LTS
Java Runtime Environment: Zulu 11
openHAB version: 3.1.0-SNAPSHOT (#2220 )
I configured my smartphone (Xiaomi Mi A1 with LineageOS 17.1) to test the binding.
The status of the thing is Online.
The binding does a test for ‘adb awake state’ with a command
adb shell:dumpsys activity | grep mWakefulness
, which fails.
If i do the same command manually in a shell, it also fails.
If I correct the command to
adb shell dumpsys activity | grep mWakefulness
(without colon after shell
) it is executed without errors.
openhab.log (with TRACE on):
19:01:00.898 [DEBUG] [dge.internal.AndroidDebugBridgeDevice] - 192.168.nnn.nn - shell:dumpsys activity | grep mWakefulness
19:01:05.907 [WARN ] [ge.internal.AndroidDebugBridgeHandler] - Unable to refresh awake state: Timeout
19:01:15.257 [DEBUG] [dge.internal.AndroidDebugBridgeDevice] - 192.168.nnn.nn - shell:input keyevent KEYCODE_POWER
19:01:20.260 [WARN ] [ge.internal.AndroidDebugBridgeHandler] - 192.168.nnn.nn - timeout error
19:01:35.910 [DEBUG] [ge.internal.AndroidDebugBridgeHandler] - Refresh device 192.168.nnn.nn status
19:01:35.911 [DEBUG] [dge.internal.AndroidDebugBridgeDevice] - 192.168.nnn.nn - shell:dumpsys activity | grep mWakefulness
19:01:40.912 [WARN ] [ge.internal.AndroidDebugBridgeHandler] - Unable to refresh awake state: Timeout
Can anyone reproduce or confirm my problem?
Does anyone have a solution suggestion for me?
Thanks.
Wolfgang_S
(Wolfgang_S)
February 23, 2021, 7:16pm
2
Could it be that the colon between shell and dumpsys is just debug output ?
The source code of the binding in line125 does not show a colon:
var targetLine = Arrays.stream(out.split("\n")).findFirst().orElse(""); var lineParts = targetLine.split(" "); if (lineParts.length >= 2) { var packageActivityName = lineParts[lineParts.length - 2]; if (packageActivityName.contains("/")) return packageActivityName.split("/")[0]; } 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 {
hare0815
(Harald)
February 24, 2021, 8:47am
3
I thought the logger command is from inside the function runAdbShell
(at line 278).
In line 280 the command AdbStream stream = adb.open("shell:" + cmd);
is build.
I do not know a lot about java, but could it be, that this is the problematic line?
private String runAdbShell(String... args) throws InterruptedException, AndroidDebugBridgeDeviceException, TimeoutException, ExecutionException { var adb = connection; if (adb == null) { throw new AndroidDebugBridgeDeviceException("Device not connected"); } var commandFuture = scheduler.submit(() -> { var byteArrayOutputStream = new ByteArrayOutputStream(); String cmd = String.join(" ", args); logger.debug("{} - shell:{}", ip, cmd); try { AdbStream stream = adb.open("shell:" + cmd); do { byteArrayOutputStream.writeBytes(stream.read()); } while (!stream.isClosed()); } catch (IOException e) { String message = e.getMessage(); if (message != null && !message.equals("Stream closed")) { throw e; }
Wolfgang_S
(Wolfgang_S)
February 24, 2021, 12:55pm
4
That is the line that is responsible for the output of the logging information.
Two rows below ( AdbStream stream = … ) is the command that is being executed then.
hare0815
(Harald)
February 26, 2021, 1:29pm
5
I must have misunderstood something. Basically, the binding works.
It was my mistake, the target device was running a firewall that did not allow wifi debugging.