1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-29 15:51:17 +00:00

Download Support Bundle (fixes #330) (#332)

* http/GetRequest: Add URI_DEBUG_SUPPORT

* Add ConfigXml#getGui

* Update model/Gui

* Add strings en-GB

* Add pref: webUIDebugging

* SettingsActivity: Add mWebUIDebugging, KEY_WEBUI_DEBUGGING

* Add pref button: downloadSupportBundle

* Add string: download_support_bundle_title

* Update string: webui_debugging_summary

* WIP

* WIP

* Use DownloadManager instead

* Revert "Use DownloadManager instead"

This reverts commit f2b24f5f295b27dd4d1aa2bed7bd2a08afce2159.

* Try sending auth to browser - unsafe

* Revert "Try sending auth to browser - unsafe"

This reverts commit 53523aad2e65147c99ee590cd0722c0e221fad8f.

* Add RestApi#downloadSupportBundle (fixes #330)

* Add SettingsActivity#onDownloadSupportBundleClick (fixes #330)

* FileUtils: Move getExternalStorageDownloadsDirectory code into separate function

* RestApi#downloadSupportBundle: Add callback for result UI

* SettingsActivity: Add UI to show if bundle download succeeded (fixes #330)

* Add strings for success, failure, in progress

* Add comment

* Imported de translation
This commit is contained in:
Catfriend1 2019-02-24 13:47:56 +01:00 committed by GitHub
parent 4ef5853b88
commit 0d50bca3d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 151 additions and 16 deletions

View file

@ -51,10 +51,12 @@ import com.nutomic.syncthingandroid.service.NotificationHandler;
import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder; import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
import com.nutomic.syncthingandroid.util.FileUtils;
import com.nutomic.syncthingandroid.util.Languages; import com.nutomic.syncthingandroid.util.Languages;
import com.nutomic.syncthingandroid.util.Util; import com.nutomic.syncthingandroid.util.Util;
import com.nutomic.syncthingandroid.views.WifiSsidPreference; import com.nutomic.syncthingandroid.views.WifiSsidPreference;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.HashSet; import java.util.HashSet;
@ -132,9 +134,11 @@ public class SettingsActivity extends SyncthingActivity {
Preference.OnPreferenceClickListener { Preference.OnPreferenceClickListener {
private static final String TAG = "SettingsFragment"; private static final String TAG = "SettingsFragment";
// Settings/Syncthing // Settings/Syncthing Options
private static final String KEY_WEBUI_TCP_PORT = "webUITcpPort"; private static final String KEY_WEBUI_TCP_PORT = "webUITcpPort";
private static final String KEY_WEBUI_REMOTE_ACCESS = "webUIRemoteAccess"; private static final String KEY_WEBUI_REMOTE_ACCESS = "webUIRemoteAccess";
private static final String KEY_WEBUI_DEBUGGING = "webUIDebugging";
private static final String KEY_DOWNLOAD_SUPPORT_BUNDLE = "downloadSupportBundle";
private static final String KEY_UNDO_IGNORED_DEVICES_FOLDERS = "undo_ignored_devices_folders"; private static final String KEY_UNDO_IGNORED_DEVICES_FOLDERS = "undo_ignored_devices_folders";
// Settings/Import and Export // Settings/Import and Export
private static final String KEY_EXPORT_CONFIG = "export_config"; private static final String KEY_EXPORT_CONFIG = "export_config";
@ -186,6 +190,8 @@ public class SettingsActivity extends SyncthingActivity {
private CheckBoxPreference mWebUIRemoteAccess; private CheckBoxPreference mWebUIRemoteAccess;
private CheckBoxPreference mRestartOnWakeup; private CheckBoxPreference mRestartOnWakeup;
private CheckBoxPreference mUrAccepted; private CheckBoxPreference mUrAccepted;
private CheckBoxPreference mWebUIDebugging;
private Preference mDownloadSupportBundle;
/* Experimental options */ /* Experimental options */
private CheckBoxPreference mUseWakelock; private CheckBoxPreference mUseWakelock;
@ -307,7 +313,7 @@ public class SettingsActivity extends SyncthingActivity {
} }
setPreferenceCategoryChangeListener(categoryBehaviour, this::onBehaviourPreferenceChange); setPreferenceCategoryChangeListener(categoryBehaviour, this::onBehaviourPreferenceChange);
/* Syncthing options */ /* Syncthing Options */
mDeviceName = (EditTextPreference) findPreference("deviceName"); mDeviceName = (EditTextPreference) findPreference("deviceName");
mListenAddresses = (EditTextPreference) findPreference("listenAddresses"); mListenAddresses = (EditTextPreference) findPreference("listenAddresses");
mMaxRecvKbps = (EditTextPreference) findPreference("maxRecvKbps"); mMaxRecvKbps = (EditTextPreference) findPreference("maxRecvKbps");
@ -322,11 +328,14 @@ public class SettingsActivity extends SyncthingActivity {
mSyncthingApiKey = findPreference(KEY_SYNCTHING_API_KEY); mSyncthingApiKey = findPreference(KEY_SYNCTHING_API_KEY);
mRestartOnWakeup = (CheckBoxPreference) findPreference("restartOnWakeup"); mRestartOnWakeup = (CheckBoxPreference) findPreference("restartOnWakeup");
mUrAccepted = (CheckBoxPreference) findPreference("urAccepted"); mUrAccepted = (CheckBoxPreference) findPreference("urAccepted");
mWebUIDebugging = (CheckBoxPreference) findPreference(KEY_WEBUI_DEBUGGING);
mDownloadSupportBundle = findPreference(KEY_DOWNLOAD_SUPPORT_BUNDLE);
Preference undoIgnoredDevicesFolders = findPreference(KEY_UNDO_IGNORED_DEVICES_FOLDERS); Preference undoIgnoredDevicesFolders = findPreference(KEY_UNDO_IGNORED_DEVICES_FOLDERS);
mCategorySyncthingOptions = findPreference("category_syncthing_options"); mCategorySyncthingOptions = findPreference("category_syncthing_options");
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange); setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
mSyncthingApiKey.setOnPreferenceClickListener(this); mSyncthingApiKey.setOnPreferenceClickListener(this);
mDownloadSupportBundle.setOnPreferenceClickListener(this);
undoIgnoredDevicesFolders.setOnPreferenceClickListener(this); undoIgnoredDevicesFolders.setOnPreferenceClickListener(this);
/* Import and Export */ /* Import and Export */
@ -503,17 +512,20 @@ public class SettingsActivity extends SyncthingActivity {
mSyncthingVersion.setSummary(mRestApi.getVersion()); mSyncthingVersion.setSummary(mRestApi.getVersion());
mSyncthingApiKey.setSummary(mRestApi.getApiKey()); mSyncthingApiKey.setSummary(mRestApi.getApiKey());
mOptions = mRestApi.getOptions(); mOptions = mRestApi.getOptions();
if (mOptions != null) {
Joiner joiner = Joiner.on(", "); Joiner joiner = Joiner.on(", ");
mDeviceName.setText(mRestApi.getLocalDevice().name); mDeviceName.setText(mRestApi.getLocalDevice().name);
mListenAddresses.setText(joiner.join(mOptions.listenAddresses)); mListenAddresses.setText(joiner.join(mOptions.listenAddresses));
mMaxRecvKbps.setText(Integer.toString(mOptions.maxRecvKbps)); mMaxRecvKbps.setText(Integer.toString(mOptions.maxRecvKbps));
mMaxSendKbps.setText(Integer.toString(mOptions.maxSendKbps)); mMaxSendKbps.setText(Integer.toString(mOptions.maxSendKbps));
mNatEnabled.setChecked(mOptions.natEnabled); mNatEnabled.setChecked(mOptions.natEnabled);
mLocalAnnounceEnabled.setChecked(mOptions.localAnnounceEnabled); mLocalAnnounceEnabled.setChecked(mOptions.localAnnounceEnabled);
mGlobalAnnounceEnabled.setChecked(mOptions.globalAnnounceEnabled); mGlobalAnnounceEnabled.setChecked(mOptions.globalAnnounceEnabled);
mRelaysEnabled.setChecked(mOptions.relaysEnabled); mRelaysEnabled.setChecked(mOptions.relaysEnabled);
mGlobalAnnounceServers.setText(joiner.join(mOptions.globalAnnounceServers)); mGlobalAnnounceServers.setText(joiner.join(mOptions.globalAnnounceServers));
mRestartOnWakeup.setChecked(mOptions.restartOnWakeup);
mUrAccepted.setChecked(mRestApi.isUsageReportingAccepted());
}
// Web GUI tcp port and bind ip address. // Web GUI tcp port and bind ip address.
mGui = mRestApi.getGui(); mGui = mRestApi.getGui();
@ -521,10 +533,9 @@ public class SettingsActivity extends SyncthingActivity {
mWebUITcpPort.setText(mGui.getBindPort()); mWebUITcpPort.setText(mGui.getBindPort());
mWebUITcpPort.setSummary(mGui.getBindPort()); mWebUITcpPort.setSummary(mGui.getBindPort());
mWebUIRemoteAccess.setChecked(!BIND_LOCALHOST.equals(mGui.getBindAddress())); mWebUIRemoteAccess.setChecked(!BIND_LOCALHOST.equals(mGui.getBindAddress()));
mWebUIDebugging.setChecked(mGui.debugging);
mDownloadSupportBundle.setEnabled(mGui.debugging);
} }
mRestartOnWakeup.setChecked(mOptions.restartOnWakeup);
mUrAccepted.setChecked(mRestApi.isUsageReportingAccepted());
} }
@Override @Override
@ -663,6 +674,17 @@ public class SettingsActivity extends SyncthingActivity {
mRestApi.setUsageReporting((boolean) o); mRestApi.setUsageReporting((boolean) o);
mOptions = mRestApi.getOptions(); mOptions = mRestApi.getOptions();
break; break;
case KEY_WEBUI_DEBUGGING:
mGui.debugging = (boolean) o;
// Immediately apply changes.
mRestApi.editSettings(mGui, mOptions);
if (mRestApi != null &&
mSyncthingService.getCurrentState() != SyncthingService.State.DISABLED) {
mRestApi.saveConfigAndRestart();
mPendingConfig = false;
}
return true;
default: throw new InvalidParameterException(); default: throw new InvalidParameterException();
} }
@ -793,6 +815,9 @@ public class SettingsActivity extends SyncthingActivity {
return true; return true;
default: default:
return false; return false;
case KEY_DOWNLOAD_SUPPORT_BUNDLE:
onDownloadSupportBundleClick();
return true;
case KEY_UNDO_IGNORED_DEVICES_FOLDERS: case KEY_UNDO_IGNORED_DEVICES_FOLDERS:
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setMessage(R.string.undo_ignored_devices_folders_question) .setMessage(R.string.undo_ignored_devices_folders_question)
@ -845,6 +870,30 @@ public class SettingsActivity extends SyncthingActivity {
} }
} }
private void onDownloadSupportBundleClick() {
if (mRestApi == null) {
Toast.makeText(mContext,
getString(R.string.generic_error) + getString(R.string.syncthing_disabled),
Toast.LENGTH_SHORT).show();
return;
}
mDownloadSupportBundle.setEnabled(false);
mDownloadSupportBundle.setSummary(R.string.download_support_bundle_in_progress);
String localDeviceName = mRestApi.getLocalDevice().getDisplayName();
String targetFileFullFN = FileUtils.getExternalStorageDownloadsDirectory() + "/" +
"syncthing-support-bundle_" + localDeviceName + ".zip";
File targetFile = new File(targetFileFullFN);
mRestApi.downloadSupportBundle(targetFile, failSuccess -> {
mDownloadSupportBundle.setEnabled(true);
if (!failSuccess) {
mDownloadSupportBundle.setSummary(R.string.download_support_bundle_failed);
return;
}
mDownloadSupportBundle.setSummary(getString(R.string.download_support_bundle_succeeded, targetFileFullFN));
});
}
/** /**
* Enables or disables {@link #mUseRoot} preference depending whether root is available. * Enables or disables {@link #mUseRoot} preference depending whether root is available.
*/ */

View file

@ -22,6 +22,7 @@ public class GetRequest extends ApiRequest {
public static final String URI_VERSION = "/rest/system/version"; public static final String URI_VERSION = "/rest/system/version";
public static final String URI_SYSTEM_STATUS = "/rest/system/status"; public static final String URI_SYSTEM_STATUS = "/rest/system/status";
public static final String URI_CONNECTIONS = "/rest/system/connections"; public static final String URI_CONNECTIONS = "/rest/system/connections";
public static final String URI_DEBUG_SUPPORT = "/rest/debug/support";
public static final String URI_DB_IGNORES = "/rest/db/ignores"; public static final String URI_DB_IGNORES = "/rest/db/ignores";
public static final String URI_DB_STATUS = "/rest/db/status"; public static final String URI_DB_STATUS = "/rest/db/status";
public static final String URI_DEVICEID = "/rest/svc/deviceid"; public static final String URI_DEVICEID = "/rest/svc/deviceid";

View file

@ -42,6 +42,9 @@ import com.nutomic.syncthingandroid.model.SystemStatus;
import com.nutomic.syncthingandroid.model.SystemVersion; import com.nutomic.syncthingandroid.model.SystemVersion;
import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.Constants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -838,6 +841,37 @@ public class RestApi {
} }
} }
public void downloadSupportBundle(File targetFile, final OnResultListener1<Boolean> listener) {
new GetRequest(mContext, mUrl, GetRequest.URI_DEBUG_SUPPORT, mApiKey, null, result -> {
Boolean failSuccess = true;
LogV("downloadSupportBundle: Writing '" + targetFile.getPath() + "' ...");
FileOutputStream fileOutputStream = null;
try {
if (!targetFile.exists()) {
targetFile.createNewFile();
}
fileOutputStream = new FileOutputStream(targetFile);
fileOutputStream.write(result.getBytes("ISO-8859-1")); // Do not use UTF-8 here because the ZIP would be corrupted.
fileOutputStream.flush();
} catch (IOException e) {
Log.w(TAG, "downloadSupportBundle: Failed to write '" + targetFile.getPath() + "' #1", e);
failSuccess = false;
} finally {
try {
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e) {
Log.e(TAG, "downloadSupportBundle: Failed to write '" + targetFile.getPath() + "' #2", e);
failSuccess = false;
}
}
if (listener != null) {
listener.onResult(failSuccess);
}
});
}
/** /**
* Event triggered by {@link RunConditionMonitor} routed here through {@link SyncthingService}. * Event triggered by {@link RunConditionMonitor} routed here through {@link SyncthingService}.
*/ */

View file

@ -501,6 +501,21 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="webui_remote_access_summary">Erlaubt es, von einem anderen Gerät aus auf die Weboberfläche zuzugreifen. Wenn aktiviert, kannst Du dich mit dem Benutzer \'syncthing\' und dem API Key als Passwort anmelden. Standard: Deaktiviert (am sichersten)</string> <string name="webui_remote_access_summary">Erlaubt es, von einem anderen Gerät aus auf die Weboberfläche zuzugreifen. Wenn aktiviert, kannst Du dich mit dem Benutzer \'syncthing\' und dem API Key als Passwort anmelden. Standard: Deaktiviert (am sichersten)</string>
<string name="webui_debugging_title">WebUI Fehlersuchmodus</string>
<string name="webui_debugging_summary">Ermögliche Profiling und das Herunterladen eines Supportpakets. Ändern dieser Option wird Syncthing sofort neu starten.</string>
<string name="download_support_bundle_title">Supportpaket herunterladen</string>
<!-- Summary shown when the user clicked the download support bundle button -->
<string name="download_support_bundle_in_progress">Bereite Supportpaket-Download vor ...</string>
<!-- Toast after successful download of the support bundle -->
<string name="download_support_bundle_succeeded">Supportpaket erfolgreich heruntergeladen: %s</string>
<!-- Toast after failed support bundle download -->
<string name="download_support_bundle_failed">Herunterladen des Supportpakets fehlgeschlagen. Prüfe die Logs.</string>
<!-- Titles for the preference to undo ignored devices and folders --> <!-- Titles for the preference to undo ignored devices and folders -->
<string name="undo_ignored_devices_folders_title">Mache Ignorieren von Geräten und Ordnern rückgängig</string> <string name="undo_ignored_devices_folders_title">Mache Ignorieren von Geräten und Ordnern rückgängig</string>
<string name="undo_ignored_devices_folders_question">Dies macht vorherige Entscheidungen, Geräte und Ordner zu ignorieren, rückgängig. Fortfahren?</string> <string name="undo_ignored_devices_folders_question">Dies macht vorherige Entscheidungen, Geräte und Ordner zu ignorieren, rückgängig. Fortfahren?</string>
@ -562,6 +577,10 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="config_imported_successful">Konfiguration importiert</string> <string name="config_imported_successful">Konfiguration importiert</string>
<string name="config_import_failed">Import fehlgeschlagen, Dateien werden in %1$s erwartet</string> <string name="config_import_failed">Import fehlgeschlagen, Dateien werden in %1$s erwartet</string>
<string name="dialog_settings_restart_app_title">Neustart erforderlich</string>
<string name="dialog_settings_restart_app_question">Das Ändern dieser Option erfordert einen sofortigen Neustart der App. Alle anderen Änderungen werden verworfen. Fortsetzen?</string>
<!-- Title for the preference to set STTRACE parameters --> <!-- Title for the preference to set STTRACE parameters -->
<string name="sttrace_title">STTRACE Optionen</string> <string name="sttrace_title">STTRACE Optionen</string>
@ -590,6 +609,10 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="category_about">Über</string> <string name="category_about">Über</string>
<string name="verbose_log_title">Ausführliches Log</string>
<string name="verbose_log_summary">Aktivieren dieser Option wird sehr detaillierte Logs zur Fehlersuche liefern.</string>
<!-- Settings item that opens the log activity --> <!-- Settings item that opens the log activity -->
<string name="open_log">Log öffnen</string> <string name="open_log">Log öffnen</string>

View file

@ -504,6 +504,21 @@ Please report any problems you encounter via Github.</string>
<string name="webui_remote_access_summary">Specify to permit accessing the Web UI from another device. If enabled, you are able to logon with user \'syncthing\' and API key as password. Default: disabled (most secure)</string> <string name="webui_remote_access_summary">Specify to permit accessing the Web UI from another device. If enabled, you are able to logon with user \'syncthing\' and API key as password. Default: disabled (most secure)</string>
<string name="webui_debugging_title">WebUI Debugging</string>
<string name="webui_debugging_summary">Enable to start profiling and to be able to download a support bundle. Changing this option will restart Syncthing immediately.</string>
<string name="download_support_bundle_title">Download Support Bundle</string>
<!-- Summary shown when the user clicked the download support bundle button -->
<string name="download_support_bundle_in_progress">Preparing Support Bundle download ...</string>
<!-- Toast after successful download of the support bundle -->
<string name="download_support_bundle_succeeded">Support Bundle successfully downloaded to %s.</string>
<!-- Toast after failed support bundle download -->
<string name="download_support_bundle_failed">Failed downloading Support Bundle. Check the logs.</string>
<!-- Titles for the preference to undo ignored devices and folders --> <!-- Titles for the preference to undo ignored devices and folders -->
<string name="undo_ignored_devices_folders_title">Undo ignoring devices and folders</string> <string name="undo_ignored_devices_folders_title">Undo ignoring devices and folders</string>
<string name="undo_ignored_devices_folders_question">This will undo previous decisions to ignore devices and folders. Continue?</string> <string name="undo_ignored_devices_folders_question">This will undo previous decisions to ignore devices and folders. Continue?</string>

View file

@ -193,9 +193,22 @@
android:title="@string/usage_reporting" android:title="@string/usage_reporting"
android:persistent="false" /> android:persistent="false" />
<CheckBoxPreference
android:key="webUIDebugging"
android:title="@string/webui_debugging_title"
android:summary="@string/webui_debugging_summary"
android:persistent="false" />
<Preference
android:key="downloadSupportBundle"
android:title="@string/download_support_bundle_title"
android:persistent="false"
android:singleLine="true" />
<Preference <Preference
android:key="undo_ignored_devices_folders" android:key="undo_ignored_devices_folders"
android:title="@string/undo_ignored_devices_folders_title" android:title="@string/undo_ignored_devices_folders_title"
android:persistent="false"
android:singleLine="true" /> android:singleLine="true" />
</PreferenceScreen> </PreferenceScreen>