From cf463af83f3cc56b1e20950bf60f1cf54e66e271 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Wed, 29 Apr 2020 12:43:53 -0700 Subject: [PATCH 1/2] [pm/metrics] do not log package name for adb installations Per privacy requirements, we will not log package name if the installation is initiated from adb. Test: manual with adb install Test: $ ./out/host/linux-x86/bin/statsd_testdrive 263 event_metrics { data { elapsed_timestamp_nanos: 630320497997 atom { package_installer_v2_reported { is_incremental: true package_name: "" duration_millis: 567 return_code: 1 } } } } BUG: 152913040 Change-Id: I147358e59bf6a43fc76b6721ec1a415167b305d7 --- .../android/server/pm/PackageInstallerSession.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 6b1ef3acdf610..77afc960f897a 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -1801,11 +1801,16 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } - private void logDataLoaderInstallationSession(int returnCode, String extraMessage) { + private void logDataLoaderInstallationSession(int returnCode) { + // Skip logging the side-loaded app installations, as those are private and aren't reported + // anywhere; app stores already have a record of the installation and that's why reporting + // it here is fine + final String packageNameToLog = + (params.installFlags & PackageManager.INSTALL_FROM_ADB) == 0 ? mPackageName : ""; final long currentTimestamp = System.currentTimeMillis(); FrameworkStatsLog.write(FrameworkStatsLog.PACKAGE_INSTALLER_V2_REPORTED, isIncrementalInstallation(), - mPackageName, + packageNameToLog, currentTimestamp - createdMillis, returnCode); } @@ -2812,7 +2817,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mCallback.onSessionFinished(this, success); if (isDataLoaderInstallation()) { - logDataLoaderInstallationSession(returnCode, msg); + logDataLoaderInstallationSession(returnCode); } } From aff0dce1723bae9e68079328ef3243f682bacce9 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Wed, 29 Apr 2020 15:23:40 -0700 Subject: [PATCH 2/2] [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 --- cmds/statsd/src/atoms.proto | 2 ++ .../server/pm/PackageInstallerSession.java | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 13e7ac1fd4a09..555d92949a3cc 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -9327,6 +9327,8 @@ message PackageInstallerV2Reported { // 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 77afc960f897a..3f8a442b296dd 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 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { 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; } /**