summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2018-08-14 12:26:45 -0700
committerMakoto Onuki <omakoto@google.com>2018-08-14 12:30:06 -0700
commit016dc59fef6309afba9dd31f425ddb5c286a085a (patch)
tree71f7507bcac0f4df69dbc0bbcacc966759b03485 /core/java
parent88ee680e4c8cd8f66d6117f74caf5324244cc316 (diff)
Print DB file sizes in "dumpsys dbinfo"
- This will be included in bugreports, but only for running processes. Bug: 111939259 Test: dumpsys dbinfo (when device locked and unlocked) Change-Id: If743b2c3340eac7e6bc873ac655ac352a46fb7dc
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/ActivityThread.java61
1 files changed, 58 insertions, 3 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 2a3fc04b2451..66524ed76aba 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -1355,14 +1355,69 @@ public final class ActivityThread extends ClientTransactionHandler {
IoUtils.closeQuietly(pfd);
}
- private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args) {
+ private File getDatabasesDir(Context context) {
+ // There's no simple way to get the databases/ path, so do it this way.
+ return context.getDatabasePath("a").getParentFile();
+ }
+
+ private void dumpDatabaseInfo(ParcelFileDescriptor pfd, String[] args, boolean isSystem) {
PrintWriter pw = new FastPrintWriter(
new FileOutputStream(pfd.getFileDescriptor()));
PrintWriterPrinter printer = new PrintWriterPrinter(pw);
SQLiteDebug.dump(printer, args);
+
+ if (isSystem) {
+ dumpDatabaseFileSizes(pw, Environment.getDataSystemDirectory(), true);
+ dumpDatabaseFileSizes(pw, Environment.getDataSystemDeDirectory(), true);
+ dumpDatabaseFileSizes(pw, Environment.getDataSystemCeDirectory(), true);
+ } else {
+ Context context = getApplication();
+ if (context != null) {
+ dumpDatabaseFileSizes(pw,
+ getDatabasesDir(context.createDeviceProtectedStorageContext()),
+ false);
+ dumpDatabaseFileSizes(pw,
+ getDatabasesDir(context.createCredentialProtectedStorageContext()),
+ false);
+ }
+ }
pw.flush();
}
+ private void dumpDatabaseFileSizes(PrintWriter pw, File dir, boolean isSystem) {
+ final File[] files = dir.listFiles();
+ if (files == null || files.length == 0) {
+ return;
+ }
+ Arrays.sort(files, (a, b) -> a.getName().compareTo(b.getName()));
+
+ boolean needHeader = true;
+ for (File f : files) {
+ if (isSystem) {
+ // If it's the system server, the directory contains other files too, so
+ // filter by file extensions.
+ // (If it's an app, just print all files because they may not use *.db
+ // extension.)
+ final String name = f.getName();
+ if (!(name.endsWith(".db") || name.endsWith(".db-wal")
+ || name.endsWith(".db-journal"))) {
+ continue;
+ }
+ }
+ if (needHeader) {
+ pw.println();
+ pw.println("Database files in " + dir.getAbsolutePath() + ":");
+ needHeader = false;
+ }
+
+ pw.print(" ");
+ pw.print(f.getName());
+ pw.print(" ");
+ pw.print(f.length());
+ pw.println(" bytes");
+ }
+ }
+
@Override
public void dumpDbInfo(final ParcelFileDescriptor pfd, final String[] args) {
if (mSystemThread) {
@@ -1383,14 +1438,14 @@ public final class ActivityThread extends ClientTransactionHandler {
@Override
public void run() {
try {
- dumpDatabaseInfo(dup, args);
+ dumpDatabaseInfo(dup, args, true);
} finally {
IoUtils.closeQuietly(dup);
}
}
});
} else {
- dumpDatabaseInfo(pfd, args);
+ dumpDatabaseInfo(pfd, args, false);
IoUtils.closeQuietly(pfd);
}
}