Merge changes from topics "v2_metrics_add_size", "v2_metrics_optional_package_name" into rvc-dev

* changes:
  [pm/metrics] add apk size in the log
  [pm/metrics] do not log package name for adb installations
This commit is contained in:
Songchun Fan
2020-05-01 22:27:59 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 4 deletions

View File

@@ -9344,6 +9344,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;
}
/**

View File

@@ -1847,13 +1847,44 @@ 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);
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;
}
/**
@@ -2879,7 +2910,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
mCallback.onSessionFinished(this, success);
if (isDataLoaderInstallation()) {
logDataLoaderInstallationSession(returnCode, msg);
logDataLoaderInstallationSession(returnCode);
}
}