Show app storage space

pull/192/head
M66B 4 years ago
parent 551e37c009
commit c89717a5e6

@ -627,7 +627,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
private List<File> getFiles(File dir, long minSize) { private List<File> getFiles(File dir, long minSize) {
List<File> files = new ArrayList(); List<File> files = new ArrayList<>();
File[] listed = dir.listFiles(); File[] listed = dir.listFiles();
if (listed != null) if (listed != null)
for (File file : listed) for (File file : listed)
@ -876,25 +876,45 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
try { try {
Log.i("Update usage"); Log.i("Update usage");
Runtime rt = Runtime.getRuntime(); new SimpleTask<StorageData>() {
long hused = rt.totalMemory() - rt.freeMemory(); @Override
long hmax = rt.maxMemory(); protected StorageData onExecute(Context context, Bundle args) throws Throwable {
long nheap = Debug.getNativeHeapAllocatedSize(); StorageData data = new StorageData();
tvMemoryUsage.setText(getString(R.string.title_advanced_memory_usage, Runtime rt = Runtime.getRuntime();
Helper.humanReadableByteCount(hused), data.hused = rt.totalMemory() - rt.freeMemory();
Helper.humanReadableByteCount(hmax), data.hmax = rt.maxMemory();
Helper.humanReadableByteCount(nheap))); data.nheap = Debug.getNativeHeapAllocatedSize();
data.available = Helper.getAvailableStorageSpace();
data.total = Helper.getTotalStorageSpace();
data.used = Helper.getSize(context.getFilesDir());
return data;
}
tvStorageUsage.setText(getString(R.string.title_advanced_storage_usage, @Override
Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()), protected void onExecuted(Bundle args, StorageData data) {
Helper.humanReadableByteCount(Helper.getTotalStorageSpace()))); tvMemoryUsage.setText(getString(R.string.title_advanced_memory_usage,
Helper.humanReadableByteCount(data.hused),
Helper.humanReadableByteCount(data.hmax),
Helper.humanReadableByteCount(data.nheap)));
tvStorageUsage.setText(getString(R.string.title_advanced_storage_usage,
Helper.humanReadableByteCount(data.available),
Helper.humanReadableByteCount(data.total),
Helper.humanReadableByteCount(data.used)));
getView().postDelayed(new Runnable() {
@Override
public void run() {
updateUsage();
}
}, 2500);
}
getView().postDelayed(new Runnable() {
@Override @Override
public void run() { protected void onException(Bundle args, Throwable ex) {
updateUsage(); Log.e(ex);
} }
}, 2500); }.execute(this, null, "usage");
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} }
@ -906,4 +926,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
getString(R.string.title_advanced_last_cleanup, getString(R.string.title_advanced_last_cleanup,
time < 0 ? "-" : DTF.format(time))); time < 0 ? "-" : DTF.format(time)));
} }
private static class StorageData {
private long hused;
private long hmax;
private long nheap;
private long available;
private long total;
private long used;
}
} }

@ -1218,6 +1218,18 @@ public class Helper {
return stats.getTotalBytes(); return stats.getTotalBytes();
} }
static long getSize(File dir) {
long size = 0;
File[] listed = dir.listFiles();
if (listed != null)
for (File file : listed)
if (file.isDirectory())
size += getSize(file);
else
size += file.length();
return size;
}
static void openAdvanced(Intent intent) { static void openAdvanced(Intent intent) {
// https://issuetracker.google.com/issues/72053350 // https://issuetracker.google.com/issues/72053350
intent.putExtra("android.content.extra.SHOW_ADVANCED", true); intent.putExtra("android.content.extra.SHOW_ADVANCED", true);

@ -1382,9 +1382,10 @@ public class Log {
sb.append(String.format("Memory class: %d MB/%s\r\n", sb.append(String.format("Memory class: %d MB/%s\r\n",
am.getMemoryClass(), Helper.humanReadableByteCount(mi.totalMem))); am.getMemoryClass(), Helper.humanReadableByteCount(mi.totalMem)));
sb.append(String.format("Storage space: %s/%s\r\n", sb.append(String.format("Storage space: %s/%s App: %s\r\n",
Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()), Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()),
Helper.humanReadableByteCount(Helper.getTotalStorageSpace()))); Helper.humanReadableByteCount(Helper.getTotalStorageSpace()),
Helper.humanReadableByteCount(Helper.getSize(context.getFilesDir()))));
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
long hused = (rt.totalMemory() - rt.freeMemory()) / 1024L; long hused = (rt.totalMemory() - rt.freeMemory()) / 1024L;

@ -545,7 +545,7 @@
<string name="title_advanced_processors" translatable="false">Processors: %1$d</string> <string name="title_advanced_processors" translatable="false">Processors: %1$d</string>
<string name="title_advanced_memory_class" translatable="false">Memory class: %1$s/%2$s Total: %3$s</string> <string name="title_advanced_memory_class" translatable="false">Memory class: %1$s/%2$s Total: %3$s</string>
<string name="title_advanced_memory_usage" translatable="false">Memory usage: %1$s/%2$s Native: %3$s</string> <string name="title_advanced_memory_usage" translatable="false">Memory usage: %1$s/%2$s Native: %3$s</string>
<string name="title_advanced_storage_usage" translatable="false">Storage space: %1$s/%2$s</string> <string name="title_advanced_storage_usage" translatable="false">Storage space: %1$s/%2$s App: %3$s</string>
<string name="title_advanced_charsets" translatable="false">Charsets</string> <string name="title_advanced_charsets" translatable="false">Charsets</string>
<string name="title_advanced_ciphers" translatable="false">Ciphers</string> <string name="title_advanced_ciphers" translatable="false">Ciphers</string>
<string name="title_advanced_files" translatable="false">Files &gt;%1$s</string> <string name="title_advanced_files" translatable="false">Files &gt;%1$s</string>

Loading…
Cancel
Save