Skip to content

Commit b28203c

Browse files
authored
fix(AdbControlUnit): 兼容部分 vivo 和较新 Android 设备上 Viewport INTERNAL 格式的输出 (#1381)
1 parent 9b81b9f commit b28203c

1 file changed

Lines changed: 83 additions & 5 deletions

File tree

source/MaaToolkit/AdbDevice/AdbDeviceFinder.cpp

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "MaaControlUnit/ControlUnitAPI.h"
99
#include "MaaUtils/IOStream/BoostIO.hpp"
1010
#include "MaaUtils/Logger.h"
11+
#include "MaaUtils/StringMisc.hpp"
1112

1213
MAA_TOOLKIT_NS_BEGIN
1314

@@ -123,6 +124,10 @@ bool request_waydroid_config(std::shared_ptr<MAA_CTRL_UNIT_NS::AdbControlUnitAPI
123124
if (!ret) {
124125
return false;
125126
}
127+
128+
string_trim_(output);
129+
tolowers_(output);
130+
126131
if (output.find("waydroid") == std::string::npos) {
127132
return false;
128133
}
@@ -152,10 +157,9 @@ bool request_androws_config(std::shared_ptr<MAA_CTRL_UNIT_NS::AdbControlUnitAPI>
152157
if (!ret) {
153158
return false;
154159
}
155-
// Trim whitespace/newlines
156-
while (!output.empty() && (output.back() == '\n' || output.back() == '\r' || output.back() == ' ')) {
157-
output.pop_back();
158-
}
160+
161+
string_trim_(output);
162+
159163
if (output.empty()) {
160164
return false;
161165
}
@@ -184,7 +188,11 @@ bool request_avd_config(std::shared_ptr<MAA_CTRL_UNIT_NS::AdbControlUnitAPI> con
184188
if (!control_unit->shell("getprop ro.product.model", output)) {
185189
return false;
186190
}
187-
if (!output.starts_with("Android SDK") && !output.starts_with("sdk_")) {
191+
192+
string_trim_(output);
193+
tolowers_(output);
194+
195+
if (!output.starts_with("android sdk") && !output.starts_with("sdk_")) {
188196
return false;
189197
}
190198

@@ -194,6 +202,74 @@ bool request_avd_config(std::shared_ptr<MAA_CTRL_UNIT_NS::AdbControlUnitAPI> con
194202
return true;
195203
}
196204

205+
bool request_vivo_orientation_config(std::shared_ptr<MAA_CTRL_UNIT_NS::AdbControlUnitAPI> control_unit, AdbDevice& device)
206+
{
207+
if (!control_unit) {
208+
return false;
209+
}
210+
211+
std::string brand;
212+
if (!control_unit->shell("getprop ro.product.brand", brand)) {
213+
return false;
214+
}
215+
216+
string_trim_(brand);
217+
tolowers_(brand);
218+
219+
std::string manufacturer;
220+
if (control_unit->shell("getprop ro.product.manufacturer", manufacturer)) {
221+
string_trim_(manufacturer);
222+
tolowers_(manufacturer);
223+
}
224+
225+
std::string model;
226+
if (control_unit->shell("getprop ro.product.model", model)) {
227+
string_trim_(model);
228+
tolowers_(model);
229+
}
230+
231+
const bool is_vivo_device = brand.find("vivo") != std::string::npos || manufacturer.find("vivo") != std::string::npos
232+
|| model.find("vivo") != std::string::npos || model.find("iqoo") != std::string::npos;
233+
234+
if (!is_vivo_device) {
235+
return false;
236+
}
237+
238+
// If SurfaceOrientation exists, the default Orientation command should still work.
239+
// In this case, do not override the default command to minimize the impact scope.
240+
std::string surface_orientation;
241+
if (control_unit->shell("dumpsys input | grep -m 1 SurfaceOrientation", surface_orientation)) {
242+
string_trim_(surface_orientation);
243+
if (!surface_orientation.empty()) {
244+
return false;
245+
}
246+
}
247+
248+
// Some vivo / iQOO devices do not have SurfaceOrientation in dumpsys input,
249+
// but Viewport INTERNAL contains orientation=0/1/2/3.
250+
std::string viewport;
251+
if (!control_unit->shell("dumpsys input | grep -m 1 'Viewport INTERNAL'", viewport)) {
252+
return false;
253+
}
254+
255+
if (viewport.find("orientation=") == std::string::npos) {
256+
return false;
257+
}
258+
259+
auto& command = device.config["command"];
260+
261+
command["Orientation"] = json::array {
262+
"{ADB}",
263+
"-s",
264+
"{ADB_SERIAL}",
265+
"shell",
266+
"dumpsys input | sed -n 's/.*Viewport INTERNAL.*orientation=\\([0-3]\\).*/\\1/p' | tail -n 1",
267+
};
268+
269+
LogInfo << "vivo orientation config enabled" << VAR(device);
270+
return true;
271+
}
272+
197273
std::optional<AdbDevice>
198274
AdbDeviceFinder::try_device(const std::filesystem::path& adb_path, const std::string& serial, const Emulator& emulator) const
199275
{
@@ -232,6 +308,8 @@ std::optional<AdbDevice>
232308
}
233309
else if (request_avd_config(control_unit, device)) {
234310
}
311+
else if (request_vivo_orientation_config(control_unit, device)) {
312+
}
235313
// else if (request_xxx_config(control_unit, device)) {
236314
// }
237315
else {

0 commit comments

Comments
 (0)