Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6516d8e0 authored by Songchun Fan's avatar Songchun Fan Committed by Automerger Merge Worker
Browse files

Merge changes from topics "v2_metrics_add_size",...

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

Change-Id: I6e379f6e6e60471ec8de5f9410b02a355b602ef6
parents c3167a1b ec60726c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;
}

/**
+27 −1
Original line number Diff line number Diff line
@@ -1858,7 +1858,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;
    }

    /**