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) {
List<File> files = new ArrayList();
List<File> files = new ArrayList<>();
File[] listed = dir.listFiles();
if (listed != null)
for (File file : listed)
@ -876,25 +876,45 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
try {
Log.i("Update usage");
Runtime rt = Runtime.getRuntime();
long hused = rt.totalMemory() - rt.freeMemory();
long hmax = rt.maxMemory();
long nheap = Debug.getNativeHeapAllocatedSize();
tvMemoryUsage.setText(getString(R.string.title_advanced_memory_usage,
Helper.humanReadableByteCount(hused),
Helper.humanReadableByteCount(hmax),
Helper.humanReadableByteCount(nheap)));
new SimpleTask<StorageData>() {
@Override
protected StorageData onExecute(Context context, Bundle args) throws Throwable {
StorageData data = new StorageData();
Runtime rt = Runtime.getRuntime();
data.hused = rt.totalMemory() - rt.freeMemory();
data.hmax = rt.maxMemory();
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,
Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()),
Helper.humanReadableByteCount(Helper.getTotalStorageSpace())));
@Override
protected void onExecuted(Bundle args, StorageData data) {
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
public void run() {
updateUsage();
protected void onException(Bundle args, Throwable ex) {
Log.e(ex);
}
}, 2500);
}.execute(this, null, "usage");
} catch (Throwable ex) {
Log.e(ex);
}
@ -906,4 +926,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
getString(R.string.title_advanced_last_cleanup,
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();
}
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) {
// https://issuetracker.google.com/issues/72053350
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",
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.getTotalStorageSpace())));
Helper.humanReadableByteCount(Helper.getTotalStorageSpace()),
Helper.humanReadableByteCount(Helper.getSize(context.getFilesDir()))));
Runtime rt = Runtime.getRuntime();
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_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_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_ciphers" translatable="false">Ciphers</string>
<string name="title_advanced_files" translatable="false">Files &gt;%1$s</string>

Loading…
Cancel
Save