diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java
index 27470676..7f783f93 100644
--- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java
+++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java
@@ -119,6 +119,7 @@ public class SettingsActivity extends SyncthingActivity {
private static final String KEY_ST_RESET_DELTAS = "st_reset_deltas";
// Settings/About
private static final String KEY_SYNCTHING_API_KEY = "syncthing_api_key";
+ private static final String KEY_SYNCTHING_DATABASE_SIZE = "syncthing_database_size";
@Inject NotificationHandler mNotificationHandler;
@Inject SharedPreferences mPreferences;
@@ -157,6 +158,7 @@ public class SettingsActivity extends SyncthingActivity {
private Preference mSyncthingVersion;
private Preference mSyncthingApiKey;
+ private Context mContext;
private SyncthingService mSyncthingService;
private RestApi mRestApi;
@@ -184,6 +186,7 @@ public class SettingsActivity extends SyncthingActivity {
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
+ mContext = getActivity().getApplicationContext();
super.onActivityCreated(savedInstanceState);
addPreferencesFromResource(R.xml.app_settings);
@@ -310,6 +313,7 @@ public class SettingsActivity extends SyncthingActivity {
Log.d(TAG, "Failed to get app version name");
}
mSyncthingApiKey.setOnPreferenceClickListener(this);
+ screen.findPreference(KEY_SYNCTHING_DATABASE_SIZE).setSummary(getDatabaseSize());
openSubPrefScreen(screen);
}
@@ -639,7 +643,7 @@ public class SettingsActivity extends SyncthingActivity {
return true;
case KEY_SYNCTHING_API_KEY:
// Copy syncthing's API key to clipboard.
- ClipboardManager clipboard = (ClipboardManager) getActivity().getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.syncthing_api_key), mSyncthingApiKey.getSummary());
clipboard.setPrimaryClip(clip);
Toast.makeText(getActivity(), R.string.api_key_copied_to_clipboard, Toast.LENGTH_SHORT)
@@ -819,5 +823,21 @@ public class SettingsActivity extends SyncthingActivity {
return false;
}
}
+
+ /**
+ * Calculates the size of the syncthing database on disk.
+ */
+ private String getDatabaseSize() {
+ String dbPath = mContext.getFilesDir() + "/" + Constants.INDEX_DB_FOLDER;
+ String result = Util.runShellCommandGetOutput("/system/bin/du -sh " + dbPath, false);
+ if (TextUtils.isEmpty(result)) {
+ return "N/A";
+ }
+ String resultParts[] = result.split("\\s+");
+ if (resultParts.length == 0) {
+ return "N/A";
+ }
+ return resultParts[0];
+ }
}
}
diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java
index 39260c8c..c42a139e 100644
--- a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java
+++ b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java
@@ -146,7 +146,7 @@ public class Constants {
/**
* Name of the folder containing the index database.
*/
- static final String INDEX_DB_FOLDER = "index-v0.14.0.db";
+ public static final String INDEX_DB_FOLDER = "index-v0.14.0.db";
/**
* Name of the public HTTPS CA file in the data directory.
diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java
index 35c2e75e..cf0df241 100644
--- a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java
+++ b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java
@@ -12,12 +12,16 @@ import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
+import com.google.common.base.Charsets;
+
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.service.Constants;
+import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;
@@ -195,7 +199,7 @@ public class Util {
shellOut.close();
}
} catch (IOException e) {
- Log.w(TAG, "Failed to close shell stream", e);
+ Log.w(TAG, "runShellCommand: Failed to close stream", e);
}
if (shellProc != null) {
shellProc.destroy();
@@ -204,6 +208,55 @@ public class Util {
return exitCode;
}
+ public static String runShellCommandGetOutput(String cmd, Boolean useRoot) {
+ int exitCode = 255;
+ String capturedStdOut = "";
+ Process shellProc = null;
+ DataOutputStream shellOut = null;
+ try {
+ shellProc = Runtime.getRuntime().exec((useRoot) ? "su" : "sh");
+ shellOut = new DataOutputStream(shellProc.getOutputStream());
+ BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(shellOut));
+ Log.d(TAG, "runShellCommandGetOutput: " + cmd);
+ bufferedWriter.write(cmd);
+ bufferedWriter.flush();
+ shellOut.close();
+ shellOut = null;
+ BufferedReader bufferedReader = null;
+ try {
+ bufferedReader = new BufferedReader(new InputStreamReader(shellProc.getInputStream(), Charsets.UTF_8));
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ // Log.i(TAG, "runShellCommandGetOutput: " + line);
+ capturedStdOut = capturedStdOut + line + "\n";
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "runShellCommandGetOutput: Failed to read output", e);
+ } finally {
+ if (bufferedReader != null)
+ bufferedReader.close();
+ }
+ exitCode = shellProc.waitFor();
+ Log.i(TAG, "runShellCommandGetOutput: Exited with code " + exitCode);
+ } catch (IOException | InterruptedException e) {
+ Log.w(TAG, "runShellCommandGetOutput: Exception", e);
+ } finally {
+ try {
+ if (shellOut != null) {
+ shellOut.close();
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "runShellCommandGetOutput: Failed to close shell stream", e);
+ }
+ if (shellProc != null) {
+ shellProc.destroy();
+ }
+ }
+
+ // Return captured command line output.
+ return capturedStdOut;
+ }
+
/**
* Make sure that dialog is showing and activity is valid before dismissing dialog, to prevent
* various crashes.
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index fae21020..0508c283 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -569,6 +569,9 @@ Bitte melden Sie auftretende Probleme via GitHub.
Syncthing API Key in die Zwischenablage kopiert
+
+ Syncthing Datenbankgröße
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8392a5a7..1b03ae10 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -577,6 +577,9 @@ Please report any problems you encounter via Github.
Syncthing API key copied to clipboard
+
+ Syncthing Database Size
+
diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml
index 1dd18292..f274e828 100644
--- a/app/src/main/res/xml/app_settings.xml
+++ b/app/src/main/res/xml/app_settings.xml
@@ -298,6 +298,12 @@
android:key="syncthing_api_key"
android:title="@string/syncthing_api_key" />
+
+