1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-10 20:15:54 +00:00

Allow setting arbitary environment variables (fixes #788)

This commit is contained in:
Felix Ableitner 2017-08-25 20:12:14 +09:00
parent 31721af0c3
commit f2071be81c
4 changed files with 37 additions and 3 deletions

View file

@ -131,6 +131,7 @@ public class SettingsActivity extends SyncthingActivity {
Preference importConfig = findPreference("import_config");
Preference stTrace = findPreference("sttrace");
Preference environmentVariables = findPreference("environment_variables");
Preference stReset = findPreference("streset");
mUseRoot = (CheckBoxPreference) findPreference(SyncthingService.PREF_USE_ROOT);
@ -151,6 +152,7 @@ public class SettingsActivity extends SyncthingActivity {
importConfig.setOnPreferenceClickListener(this);
stTrace.setOnPreferenceChangeListener(this);
environmentVariables.setOnPreferenceChangeListener(this);
stReset.setOnPreferenceClickListener(this);
mUseRoot.setOnPreferenceChangeListener(this);
@ -298,6 +300,16 @@ public class SettingsActivity extends SyncthingActivity {
return false;
}
break;
case "environment_variables":
if (((String) o).matches("^(\\w+=[\\w:/\\.]+)?( \\w+=[\\w:/\\.]+)*$")) {
mSyncthingService.getApi().showRestartDialog(getActivity());
}
else {
Toast.makeText(getActivity(), R.string.toast_invalid_environment_variables, Toast.LENGTH_SHORT)
.show();
return false;
}
break;
}
return true;

View file

@ -142,6 +142,7 @@ public class SyncthingRunnable implements Runnable {
}
if (sp.getBoolean("use_legacy_hashing", false))
env.put("STHASHING", "standard");
putCustomEnvironmentVariables(env, sp);
process = pb.start();
mSyncthing.set(process);
@ -200,6 +201,17 @@ public class SyncthingRunnable implements Runnable {
}
}
private void putCustomEnvironmentVariables(Map<String, String> environment, SharedPreferences sp) {
String customEnvironment = sp.getString("environment_variables", null);
if (TextUtils.isEmpty(customEnvironment))
return;
for (String e : customEnvironment.split(" ")) {
String[] e2 = e.split("=");
environment.put(e2[0], e2[1]);
}
}
/**
* Returns true if root is available and enabled in settings.
*/

View file

@ -347,9 +347,13 @@ Please report any problems you encounter via Github.</string>
<!-- Title for the preference to set STTRACE parameters -->
<string name="sttrace_title">Debug Options</string>
<string name="environment_variables">Environment variables</string>
<!-- Toast after entering invalid STTRACE params -->
<string name="toast_invalid_sttrace">Only 0-9, a-z and \',\' are allowed in STTRACE options</string>
<string name="toast_invalid_environment_variables">Value is not a valid environment variable string</string>
<!-- Title for the preference to reset Syncthing indexes -->
<string name="streset_title">Reset Database</string>

View file

@ -159,6 +159,12 @@
android:singleLine="true"
android:inputType="textNoSuggestions"/>
<EditTextPreference
android:key="environment_variables"
android:title="@string/environment_variables"
android:singleLine="true"
android:inputType="textNoSuggestions"/>
<Preference
android:key="streset"
android:title="@string/streset_title"