From 7d91e7b7b423ed5be7f694db73f19de12d845290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 19 Jul 2023 13:59:40 +0800 Subject: [PATCH] Display (Android): support detection in adb --- CMakeLists.txt | 2 +- .../displayserver/displayserver_android.c | 79 +++++++++++++++++++ src/modules/display/display.c | 5 -- 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 src/detection/displayserver/displayserver_android.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4450e6b28..542040f06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,7 +395,7 @@ elseif(ANDROID) src/detection/cursor/cursor_nosupport.c src/detection/cpuusage/cpuusage_linux.c src/detection/disk/disk_linux.c - src/detection/displayserver/displayserver_nosupport.c + src/detection/displayserver/displayserver_android.c src/detection/font/font_nosupport.c src/detection/gpu/gpu_nosupport.c src/detection/host/host_android.c diff --git a/src/detection/displayserver/displayserver_android.c b/src/detection/displayserver/displayserver_android.c new file mode 100644 index 000000000..24d874b4c --- /dev/null +++ b/src/detection/displayserver/displayserver_android.c @@ -0,0 +1,79 @@ +#include "displayserver.h" + +#include "common/processing.h" + +void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) +{ + ffStrbufInit(&ds->wmProcessName); + ffStrbufInit(&ds->wmPrettyName); + ffStrbufInit(&ds->wmProtocolName); + ffStrbufInit(&ds->deProcessName); + ffStrbufInit(&ds->dePrettyName); + ffStrbufInit(&ds->deVersion); + ffListInitA(&ds->displays, sizeof(FFDisplayResult), 0); + + FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); + if (ffProcessAppendStdOut(&buf, (char* []) { + "/system/bin/dumpsys", + "display", + NULL, + }) != NULL || buf.length == 0) + return; // Only works in `adb shell`, or when rooted + + uint32_t index = 0; + while ((index = ffStrbufNextIndexS(&buf, index, "DisplayDeviceInfo")) < buf.length) + { + index += strlen("DisplayDeviceInfo"); + uint32_t nextIndex = ffStrbufNextIndexC(&buf, index, '\n'); + buf.chars[nextIndex] = '\0'; + const char* info = buf.chars + index; + + // {"Builtin display": uniqueId="local:4630947134992368259", 1440 x 3200, modeId 2, defaultModeId 1, supportedModes [{id=1, width=1440, height=3200, fps=60.000004, alternativeRefreshRates=[24.000002, 30.000002, 40.0, 120.00001, 120.00001, 120.00001, 120.00001, 120.00001]}, + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateA(64); + unsigned width = 0, height = 0, modeId = 0; + double refreshRate = 0; + // {"Builtin display": uniqueId="local:4630947134992368259", 1440 x 3200, modeId 2 + int res = sscanf(info, "{\"%63[^\"]\":%*s%u x %u, modeId%u", name.chars, &width, &height, &modeId); + if (res >= 3) + { + if (res == 4) + { + ++info; // skip first '{' + while ((info = strchr(info, '{'))) + { + ++info; + + unsigned id; + double fps; + // id=1, width=1440, height=3200, fps=60.000004, + if (sscanf(info, "id=%u, %*s%*s fps=%lf", &id, &fps) >= 2) + { + if (id == modeId) + { + refreshRate = fps; + break; + } + } + else + break; + } + } + + ffStrbufRecalculateLength(&name); + ffdsAppendDisplay(ds, + (uint32_t)width, + (uint32_t)height, + refreshRate, + 0, + 0, + 0, + &name, + FF_DISPLAY_TYPE_UNKNOWN, + false, + 0 + ); + } + + index = nextIndex + 1; + } +} diff --git a/src/modules/display/display.c b/src/modules/display/display.c index abf233316..848936f61 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -8,11 +8,6 @@ void ffPrintDisplay(FFDisplayOptions* options) { - #ifdef __ANDROID__ - ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &instance.config.display.moduleArgs, "Display detection is not supported on Android"); - return; - #endif - const FFDisplayServerResult* dsResult = ffConnectDisplayServer(); if(dsResult->displays.length == 0)