From 3d2291c5511c9f6b3b4797a9eb4af87c75bedc43 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 30 Apr 2022 22:05:28 +0200 Subject: [PATCH] Debug: cache size --- .../java/eu/faircode/email/FragmentOptionsMisc.java | 8 ++++++-- app/src/main/java/eu/faircode/email/Helper.java | 13 +++++++++++++ app/src/main/java/eu/faircode/email/Log.java | 6 ++++-- app/src/main/res/values/strings.xml | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index d3f49a49e3..d39320b1b2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -40,6 +40,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.Environment; +import android.os.storage.StorageManager; import android.provider.Settings; import android.text.SpannableStringBuilder; import android.text.Spanned; @@ -1811,7 +1812,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc new SimpleTask() { @Override - protected StorageData onExecute(Context context, Bundle args) throws Throwable { + protected StorageData onExecute(Context context, Bundle args) { StorageData data = new StorageData(); Runtime rt = Runtime.getRuntime(); data.hused = rt.totalMemory() - rt.freeMemory(); @@ -1820,6 +1821,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc data.available = Helper.getAvailableStorageSpace(); data.total = Helper.getTotalStorageSpace(); data.used = Helper.getSize(context.getFilesDir()); + data.cache = Helper.getCacheSize(context); return data; } @@ -1833,7 +1835,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc tvStorageUsage.setText(getString(R.string.title_advanced_storage_usage, Helper.humanReadableByteCount(data.total - data.available), Helper.humanReadableByteCount(data.total), - Helper.humanReadableByteCount(data.used))); + Helper.humanReadableByteCount(data.used), + data.cache > 0 ? Helper.humanReadableByteCount(data.cache) : "-")); getView().postDelayed(new Runnable() { @Override @@ -1989,5 +1992,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private long available; private long total; private long used; + private long cache; } } diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 909f7ad059..e22e881a0e 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -54,6 +54,7 @@ import android.os.LocaleList; import android.os.Parcel; import android.os.PowerManager; import android.os.StatFs; +import android.os.storage.StorageManager; import android.provider.Settings; import android.security.KeyChain; import android.security.KeyChainAliasCallback; @@ -2018,6 +2019,18 @@ public class Helper { return stats.getTotalBytes(); } + static long getCacheSize(Context context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + try { + StorageManager sm = Helper.getSystemService(context, StorageManager.class); + File cache = context.getCacheDir(); + return sm.getCacheQuotaBytes(sm.getUuidForPath(cache)); + } catch (IOException ex) { + Log.w(ex); + } + return -1; + } + static long getSize(File dir) { long size = 0; File[] listed = dir.listFiles(); diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 848c19b615..bf9409a531 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -1886,10 +1886,12 @@ public class Log { long storage_available = Helper.getAvailableStorageSpace(); long storage_total = Helper.getTotalStorageSpace(); long storage_used = Helper.getSize(context.getFilesDir()); - sb.append(String.format("Storage space: %s/%s App: %s\r\n", + long cache = Helper.getCacheSize(context); + sb.append(String.format("Storage space: %s/%s App: %s cache: %s\r\n", Helper.humanReadableByteCount(storage_total - storage_available), Helper.humanReadableByteCount(storage_total), - Helper.humanReadableByteCount(storage_used))); + Helper.humanReadableByteCount(storage_used), + cache > 0 ? Helper.humanReadableByteCount(cache) : "-")); Runtime rt = Runtime.getRuntime(); long hused = (rt.totalMemory() - rt.freeMemory()) / 1024L / 1024L; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b2921ef25..e4751222bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -754,7 +754,8 @@ Processors: %1$d Memory class: %1$s/%2$s Total: %3$s Memory usage: %1$s/%2$s Native: %3$s - Storage space: %1$s/%2$s App: %3$s + Storage space: %1$s/%2$s App: %3$s Cache: %4$s + Cache size: %1$s Cursor window size: %1$s Contact lookup: %1$d cached: %2$d Public suffix list: %1$d