From c8d1457898b649432a35a0337052f137452ce6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Thu, 27 Jul 2017 17:20:19 +0200 Subject: [PATCH] Fix Android debug/run - Prefix all __adb__ commands with device specification to avoid errors when multiple devices connected. - Include Android release in device data collection. - Force system user:. - Ability to enable/disable. - Apply only if OS release >= 17 (when multiuser was introduced. - Fix argument passing. - Rename local variable `port` to `dbg_port` to better match its partner `fs_port`. - Fix typo in error message. --- platform/android/export/export.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 97f239c4da8..a722cd1b8c6 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -2050,6 +2050,7 @@ class EditorExportAndroid : public EditorExportPlatform { String id; String name; String description; + int release; }; struct APKExportData { @@ -2123,6 +2124,7 @@ class EditorExportAndroid : public EditorExportPlatform { if (ea->devices[j].id == ldevices[i]) { d.description = ea->devices[j].description; d.name = ea->devices[j].name; + d.release = ea->devices[j].release; } } @@ -2143,6 +2145,7 @@ class EditorExportAndroid : public EditorExportPlatform { String vendor; String device; d.description + "Device ID: " + d.id + "\n"; + d.release = 0; for (int j = 0; j < props.size(); j++) { String p = props[j]; @@ -2153,7 +2156,9 @@ class EditorExportAndroid : public EditorExportPlatform { } else if (p.begins_with("ro.build.display.id=")) { d.description += "Build: " + p.get_slice("=", 1).strip_edges() + "\n"; } else if (p.begins_with("ro.build.version.release=")) { - d.description += "Release: " + p.get_slice("=", 1).strip_edges() + "\n"; + const String release_str = p.get_slice("=", 1).strip_edges(); + d.description += "Release: " + release_str + "\n"; + d.release = release_str.to_int(); } else if (p.begins_with("ro.product.cpu.abi=")) { d.description += "CPU: " + p.get_slice("=", 1).strip_edges() + "\n"; } else if (p.begins_with("ro.product.manufacturer=")) { @@ -3005,15 +3010,19 @@ public: if (use_adb_over_usb) { args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); args.push_back("--remove-all"); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); - int port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + int dbg_port = EditorSettings::get_singleton()->get("network/debug/remote_port"); args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); - args.push_back("tcp:" + itos(port)); - args.push_back("tcp:" + itos(port)); + args.push_back("tcp:" + itos(dbg_port)); + args.push_back("tcp:" + itos(dbg_port)); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); print_line("Reverse result: " + itos(rv)); @@ -3021,6 +3030,8 @@ public: int fs_port = EditorSettings::get_singleton()->get("filesystem/file_server/port"); args.clear(); + args.push_back("-s"); + args.push_back(devices[p_device].id); args.push_back("reverse"); args.push_back("tcp:" + itos(fs_port)); args.push_back("tcp:" + itos(fs_port)); @@ -3036,7 +3047,10 @@ public: args.push_back("shell"); args.push_back("am"); args.push_back("start"); - args.push_back("--user 0"); + if ((bool)EditorSettings::get_singleton()->get("export/android/force_system_user") && devices[p_device].release >= 17) { // Multi-user introduced in Android 17 + args.push_back("--user"); + args.push_back("0"); + } args.push_back("-a"); args.push_back("android.intent.action.MAIN"); args.push_back("-n"); @@ -3044,7 +3058,7 @@ public: err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { - EditorNode::add_io_error("Could not execute ondevice."); + EditorNode::add_io_error("Could not execute on device."); device_lock->unlock(); return ERR_CANT_CREATE; } @@ -3586,6 +3600,7 @@ void register_android_exporter() { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/debug_keystore", PROPERTY_HINT_GLOBAL_FILE, "keystore")); EDITOR_DEF("export/android/debug_keystore_user", "androiddebugkey"); EDITOR_DEF("export/android/debug_keystore_pass", "android"); + EDITOR_DEF("export/android/force_system_user", false); EDITOR_DEF("export/android/timestamping_authority_url", ""); EDITOR_DEF("export/android/use_remote_debug_over_adb", false);