Android: accept both spaces and tabs separators for env vars and args
The requirement for separating the app args by tabs only is not justified, since the the args are passed as a string to C++ where QProcess::splitCommand() is used to get a list of single args and that knows how to handle the parsing properly anyway. As for env vars, QtLoader currently expects env vars to be separated by tabs only, however, to account for different use cases, it should handle both tabs and spaces. Task-number: QTBUG-115016 Task-number: QTBUG-106478 Task-number: QTQAINFRA-5703 Change-Id: I58258861477776b82294a4c2603b230f178f16a6 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
parent
b044323c16
commit
ee874e7ca8
@ -21,7 +21,7 @@ import android.view.Window;
|
||||
|
||||
public class QtActivityBase extends Activity
|
||||
{
|
||||
private String m_applicationParams = null;
|
||||
private String m_applicationParams = "";
|
||||
private boolean m_isCustomThemeSet = false;
|
||||
private boolean m_retainNonConfigurationInstance = false;
|
||||
|
||||
@ -50,11 +50,16 @@ public class QtActivityBase extends Activity
|
||||
intent.putExtra(extraSourceInfoKey, sourceInformation);
|
||||
}
|
||||
|
||||
// Append any parameters to your application,
|
||||
// the parameters must be "\t" separated.
|
||||
// Append any parameters to your application.
|
||||
// Either a whitespace or a tab is accepted as a separator between parameters.
|
||||
/** @noinspection unused*/
|
||||
public void appendApplicationParameters(String params)
|
||||
{
|
||||
if (params == null || params.isEmpty())
|
||||
return;
|
||||
|
||||
if (!m_applicationParams.isEmpty())
|
||||
m_applicationParams += " ";
|
||||
m_applicationParams += params;
|
||||
}
|
||||
|
||||
@ -95,7 +100,7 @@ public class QtActivityBase extends Activity
|
||||
addReferrer(getIntent());
|
||||
|
||||
QtActivityLoader loader = new QtActivityLoader(this);
|
||||
loader.setApplicationParameters(m_applicationParams);
|
||||
loader.appendApplicationParameters(m_applicationParams);
|
||||
|
||||
loader.loadQtLibraries();
|
||||
m_delegate.startNativeApplication(loader.getApplicationParameters(),
|
||||
|
@ -114,7 +114,7 @@ class QtActivityDelegate
|
||||
}
|
||||
}
|
||||
|
||||
public void startNativeApplication(ArrayList<String> appParams, String mainLib)
|
||||
public void startNativeApplication(String appParams, String mainLib)
|
||||
{
|
||||
if (m_surfaces != null)
|
||||
return;
|
||||
|
@ -125,7 +125,7 @@ class QtActivityLoader extends QtLoader {
|
||||
|
||||
String intentArgs = intent.getStringExtra("applicationArguments");
|
||||
if (intentArgs != null)
|
||||
setApplicationParameters(intentArgs);
|
||||
appendApplicationParameters(intentArgs);
|
||||
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras == null) {
|
||||
@ -144,7 +144,7 @@ class QtActivityLoader extends QtLoader {
|
||||
|
||||
if (extras.containsKey("extraappparams")) {
|
||||
String extraAppParams = extras.getString("extraappparams");
|
||||
setApplicationParameters(getDecodedUtfString(extraAppParams));
|
||||
appendApplicationParameters(getDecodedUtfString(extraAppParams));
|
||||
}
|
||||
} else {
|
||||
Log.d(QtNative.QtTAG, "Not in debug mode! It is not allowed to use extra arguments " +
|
||||
|
@ -38,7 +38,7 @@ abstract class QtLoader {
|
||||
protected ComponentInfo m_contextInfo;
|
||||
|
||||
protected String m_mainLib;
|
||||
protected ArrayList<String> m_applicationParameters = new ArrayList<>();
|
||||
protected String m_applicationParameters = "";
|
||||
protected HashMap<String, String> m_environmentVariables = new HashMap<>();
|
||||
|
||||
/**
|
||||
@ -91,7 +91,7 @@ abstract class QtLoader {
|
||||
String backgroundRunning = getMetaData("android.app.background_running");
|
||||
setEnvironmentVariable("QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED", backgroundRunning);
|
||||
setEnvironmentVariable("QTRACE_LOCATION", getMetaData("android.app.trace_location"));
|
||||
setApplicationParameters(getMetaData("android.app.arguments"));
|
||||
appendApplicationParameters(getMetaData("android.app.arguments"));
|
||||
}
|
||||
|
||||
private ArrayList<String> preferredAbiLibs(String[] libs) {
|
||||
@ -164,31 +164,22 @@ abstract class QtLoader {
|
||||
* the main library's main() function. This is assembled from
|
||||
* a combination of static values and also metadata dependent values.
|
||||
**/
|
||||
public ArrayList<String> getApplicationParameters() {
|
||||
public String getApplicationParameters() {
|
||||
return m_applicationParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a parameter string to the internal array list of parameters.
|
||||
**/
|
||||
public void setApplicationParameter(String param)
|
||||
{
|
||||
if (param == null || param.isEmpty())
|
||||
return;
|
||||
m_applicationParameters.add(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of parameters to the internal array list of parameters.
|
||||
* This expects the parameters separated by '\t'.
|
||||
* Either a whitespace or a tab is accepted as a separator between parameters.
|
||||
**/
|
||||
public void setApplicationParameters(String params)
|
||||
public void appendApplicationParameters(String params)
|
||||
{
|
||||
if (params == null || params.isEmpty())
|
||||
return;
|
||||
|
||||
for (String param : params.split("\t"))
|
||||
setApplicationParameter(param);
|
||||
if (!m_applicationParameters.isEmpty())
|
||||
m_applicationParameters += " ";
|
||||
m_applicationParameters += params;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,15 +199,16 @@ abstract class QtLoader {
|
||||
/**
|
||||
* Sets a list of keys/values string to as environment variables.
|
||||
* This expects the key/value to be separated by '=', and parameters
|
||||
* to be separated by '\t'.
|
||||
* Ex: key1=val1\tkey2=val2\tkey3=val3
|
||||
* to be separated by tabs or space.
|
||||
**/
|
||||
public void setEnvironmentVariables(String environmentVariables)
|
||||
{
|
||||
if (environmentVariables == null || environmentVariables.isEmpty())
|
||||
return;
|
||||
|
||||
for (String variable : environmentVariables.split("\t")) {
|
||||
environmentVariables = environmentVariables.replaceAll("\t", " ");
|
||||
|
||||
for (String variable : environmentVariables.split(" ")) {
|
||||
String[] keyValue = variable.split("=", 2);
|
||||
if (keyValue.length < 2 || keyValue[0].isEmpty())
|
||||
continue;
|
||||
|
@ -278,11 +278,11 @@ class QtNative
|
||||
runAction(() -> view.setVisibility(visible ? View.VISIBLE : View.GONE));
|
||||
}
|
||||
|
||||
public static void startApplication(ArrayList<String> params, String mainLib)
|
||||
public static void startApplication(String params, String mainLib)
|
||||
{
|
||||
synchronized (m_mainActivityMutex) {
|
||||
m_qtThread.run(() -> {
|
||||
final String qtParams = mainLib + "\t" + String.join("\t", params);
|
||||
final String qtParams = mainLib + " " + params;
|
||||
if (!startQtAndroidPlugin(qtParams))
|
||||
Log.e(QtTAG, "An error occurred while starting the Qt Android plugin");
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user