Using ADB in a java application to monitor android device status every three seconds. Height adb commands are used :
adb shell settings get global airplane_mode_on
adb shell settings get system system_locales
adb shell dumpsys telephony.registry
adb shell "dumpsys content | grep ^Account | grep @ | grep com.google"
adb shell getprop gsm.network.type adb shell getprop gsm.operator.alpha
adb shell settings get system screen_off_timeout
adb shell settings get global wifi_on
Except for the dumpsys commands, the replies are one line values and take 200 msec each for readline() execution to complete.
"dumpsys telephony.registry" returns about 5000 lines and takes 500 msec.
"dumpsys content | grep ^Account .." returns three or four lines and takes 300 msec.
I have no problem with the delays, but server CPU is severely impacted during that time. Sending those height commands increased CPU by 30%. The application is required to monitor up to height different devices simultaneously and it causes 100% CPU peaks with as little as two devices connected.
The java application is not the issue because I do reproduce the CPU impact while sending the ADB commands from DOS prompt.
Things I tried with no benefit observed :
- Send commands separately
- Send one multiple commands line :
adb shell command1 && adb shell command2 && adb shell command3 .." - Put delays between commands (10, 100, 200, 500 msec)
- Use ADB connection over Wifi instead of USB
- Compared different Android device models and vendors (Samsung, Google, ..)
- Installed latest Android SDK platform-tools :
>adb version
Android Debug Bridge version 1.0.41
Version 35.0.2-12147458
Installed as C:\Windows\SysWOW64\platform-tools\adb.exe
Running on Windows 10.0.19045
Edit : Comment from Robert and answer from Martin Zeitler suggest to include all commands in one single ADB session. I tried it like this :
tResult = adb_shell_method("command1 && echo WWW && command2 && echo WWW && ..");
resultArray = tResult.split("WWW");
Collecting the height commands like this takes ~320 msec and hits CPU by less than 5%.
Now I understand that each "adb shell" execution is more complex than I thought. Therefore, it would be best to create one adb session with the device for and use it as long as it is connected. Collecting data from the UE with a method like
String executeADBCommand(String command, <adb session class> ADBSession);