From c76918b2b21c25d927dca8f8911349a15f22a1e2 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 21 Apr 2017 16:34:58 +0300 Subject: [PATCH] Use gdbserver command from a safe place Removed support for old QtCreator versions (pre 3.5) Change-Id: I5ec0e965c09c8a76810144b133af3395e32fddfa Reviewed-by: hjk Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../qt5/android/QtActivityDelegate.java | 57 +++++-------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index e0878f078f..26f877235f 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2014 BogDan Vatra +** Copyright (C) 2017 BogDan Vatra ** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2016 Olivier Goffart ** Contact: https://www.qt.io/licensing/ @@ -47,6 +47,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.AssetManager; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -708,58 +709,26 @@ public class QtActivityDelegate { // start application try { - // FIXME turn on debuggable check - // if the applications is debuggable and it has a native debug request + Bundle extras = m_activity.getIntent().getExtras(); if (extras != null) { - - if ( /*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 - &&*/ extras.containsKey("native_debug") - && extras.getString("native_debug").equals("true")) { - try { - String packagePath = - m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), - PackageManager.GET_CONFIGURATIONS).dataDir + "/"; - String gdbserverPath = - extras.containsKey("gdbserver_path") - ? extras.getString("gdbserver_path") - : packagePath+"lib/gdbserver "; - - String socket = - extras.containsKey("gdbserver_socket") - ? extras.getString("gdbserver_socket") - : "+debug-socket"; - - if (!(new File(gdbserverPath)).exists()) - gdbserverPath += ".so"; - - // start debugger - m_debuggerProcess = Runtime.getRuntime().exec(gdbserverPath - + socket - + " --attach " - + android.os.Process.myPid(), - null, - new File(packagePath)); - } catch (IOException ioe) { - Log.e(QtNative.QtTAG,"Can't start debugger" + ioe.getMessage()); - } catch (SecurityException se) { - Log.e(QtNative.QtTAG,"Can't start debugger" + se.getMessage()); - } catch (NameNotFoundException e) { - Log.e(QtNative.QtTAG,"Can't start debugger" + e.getMessage()); - } - } - - if ( /*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 &&*/ extras.containsKey("debug_ping") && extras.getString("debug_ping").equals("true")) { try { + final String dc = "--Added-by-androiddeployqt--/debugger.command"; + String debuggerCommand = + new BufferedReader(new InputStreamReader(m_activity.getAssets().open(dc))).readLine(); + String packagePath = + m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), + PackageManager.GET_CONFIGURATIONS).dataDir + "/"; + debugLog("extra parameters: " + extras); String packageName = m_activity.getPackageName(); String pingFile = extras.getString("ping_file"); String pongFile = extras.getString("pong_file"); String gdbserverSocket = extras.getString("gdbserver_socket"); - String gdbserverCommand = extras.getString("gdbserver_command"); + String gdbserverCommand = packagePath + debuggerCommand + gdbserverSocket; String pingSocket = extras.getString("ping_socket"); boolean usePing = pingFile != null; boolean usePong = pongFile != null; @@ -888,9 +857,9 @@ public class QtActivityDelegate } } catch (IOException ioe) { - Log.e(QtNative.QtTAG,"Can't start debugger" + ioe.getMessage()); + ioe.printStackTrace(); } catch (SecurityException se) { - Log.e(QtNative.QtTAG,"Can't start debugger" + se.getMessage()); + se.printStackTrace(); } }