From f3fdfefa09eeaecfec763801c655ee10397c06e5 Mon Sep 17 00:00:00 2001 From: Robbie Cooper Date: Mon, 14 Oct 2019 03:07:46 -0400 Subject: [PATCH 1/2] Detect adb connection type and debug over Wi-Fi if needed Avoid using adb reverse if deploying with adb tcpip. This still can fail if the user is attempting to debug over usb and has connected their device over BOTH usb and tcpip. I'm not sure how we would detect that problem in advance though. --- platform/android/export/export.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index a43f195b848..1460c336e84 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -220,6 +220,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { String name; String description; int api_level; + bool usb; }; struct APKExportData { @@ -246,17 +247,20 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { String devices; List args; args.push_back("devices"); + args.push_back("-l"); int ec; OS::get_singleton()->execute(adb, args, true, NULL, &devices, &ec); Vector ds = devices.split("\n"); Vector ldevices; + Vector ldevices_usbconnection; for (int i = 1; i < ds.size(); i++) { String d = ds[i]; - int dpos = d.find("device"); + int dpos = d.find(" device "); if (dpos == -1) continue; + ldevices_usbconnection.push_back(d.find(" usb:") != -1); d = d.substr(0, dpos).strip_edges(); ldevices.push_back(d); } @@ -287,6 +291,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { Device d; d.id = ldevices[i]; + d.usb = ldevices_usbconnection[i]; for (int j = 0; j < ea->devices.size(); j++) { if (ea->devices[j].id == ldevices[i]) { d.description = ea->devices[j].description; @@ -1404,7 +1409,9 @@ public: } const bool use_remote = (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) || (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT); - const bool use_reverse = devices[p_device].api_level >= 21; + const bool use_reverse = devices[p_device].api_level >= 21 && devices[p_device].usb; + // Note: Reverse can still fail if device is connected by both usb and network + // Ideally we'd know for sure whether adb reverse would work before we build the APK if (use_reverse) p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST; @@ -1509,7 +1516,7 @@ public: } } else { - static const char *const msg = "--- Device API < 21; debugging over Wi-Fi ---"; + static const char *const msg = "--- Device API < 21 or no USB connection; debugging over Wi-Fi ---"; EditorNode::get_singleton()->get_log()->add_message(msg, EditorLog::MSG_TYPE_EDITOR); print_line(String(msg).to_upper()); } From 37e6a8f901d83a959fb30607ffb7f9ee03cf2882 Mon Sep 17 00:00:00 2001 From: Robbie Cooper Date: Mon, 14 Oct 2019 03:12:01 -0400 Subject: [PATCH 2/2] Add connection information and serial number to device description The description appears when hovering over the one-click-deploy button (top-right). This information helps the user distinguish between their devices if multiple are connected or if the same device is connected by both usb and tcpip (two entries in the list for the same device). --- platform/android/export/export.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 1460c336e84..ecf7cad8ba5 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -346,9 +346,17 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { } else if (p.begins_with("ro.opengles.version=")) { uint32_t opengl = p.get_slice("=", 1).to_int(); d.description += "OpenGL: " + itos(opengl >> 16) + "." + itos((opengl >> 8) & 0xFF) + "." + itos((opengl)&0xFF) + "\n"; + } else if (p.begins_with("ro.boot.serialno=")) { + d.description += "Serial: " + p.get_slice("=", 1).strip_edges() + "\n"; } } + if (d.usb) { + d.description += "Connection: USB\n"; + } else { + d.description += "Connection: " + d.id + "\n"; + } + d.name = vendor + " " + device; if (device == String()) continue; }