[pm/metrics] add apk size in the log
Sum up all apk sizes in the code path and record in the log.
Test: atest android.content.pm.cts.PackageManagerShellCommandTest#testSplitsInstallStdIn
Test: out/host/linux-x86/bin/statsd_testdrive 263
event_metrics {
data {
elapsed_timestamp_nanos: 1543983836620
atom {
package_installer_v2_reported {
is_incremental: true
package_name: ""
duration_millis: 327
return_code: 1
size: 2512345
}
}
}
}
BUG: 152913040
Change-Id: Idde0adb6b639163627c092ed248631edfba2e952
Change-Id: I0eaf226513ee5a1b5f73726f4480c6ee73210b0d
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 13e7ac1..555d929 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -9327,6 +9327,8 @@
// Return_code 1 indicates success.
// For full list, see frameworks/base/core/java/android/content/pm/PackageManager.java
optional int32 return_code = 4;
+ // Total size of the APKs installed for this package
+ optional int64 apks_size_bytes = 5;
}
/**
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 77afc96..3f8a442 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -1812,7 +1812,33 @@
isIncrementalInstallation(),
packageNameToLog,
currentTimestamp - createdMillis,
- returnCode);
+ returnCode,
+ getApksSize());
+ }
+
+ private long getApksSize() {
+ final PackageSetting ps = mPm.getPackageSetting(mPackageName);
+ if (ps == null) {
+ return 0;
+ }
+ final File apkDirOrPath = ps.codePath;
+ if (apkDirOrPath == null) {
+ return 0;
+ }
+ if (apkDirOrPath.isFile() && apkDirOrPath.getName().toLowerCase().endsWith(".apk")) {
+ return apkDirOrPath.length();
+ }
+ if (!apkDirOrPath.isDirectory()) {
+ return 0;
+ }
+ final File[] files = apkDirOrPath.listFiles();
+ long apksSize = 0;
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].getName().toLowerCase().endsWith(".apk")) {
+ apksSize += files[i].length();
+ }
+ }
+ return apksSize;
}
/**