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

Commit d7acf52e authored by Songchun Fan's avatar Songchun Fan Committed by Song Chun Fan
Browse files

[pm] handle installExistingPackageAsUser in PackageMetrics

Logging installExistingPackageAsUser in PackageMetrics, including uid, installerUid, version, apk size and is_system.

FIXES: 298203341
Test: manual with "statsd_testdrive 524" command

Change-Id: Ic3ce714ecc8b9c526bb58624713c7b6f8f9786eb
parent c7bf4dc4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -747,7 +747,7 @@ final class InstallPackageHelper {
                                onInstallComplete(PackageManager.INSTALL_SUCCEEDED, mContext,
                                        onCompleteSender);
                            }
                        });
                        }, pkgSetting.getAppId(), callingUid, pkgSetting.isSystem());
                restoreAndPostInstall(request);
            }
        } finally {
+8 −2
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ final class InstallRequest {
    @Nullable
    private DomainSet mPreVerifiedDomains;

    private int mInstallerUidForInstallExisting = INVALID_UID;

    // New install
    InstallRequest(InstallingSession params) {
        mUserId = params.getUser().getIdentifier();
@@ -180,7 +182,7 @@ final class InstallRequest {

    // Install existing package as user
    InstallRequest(int userId, int returnCode, AndroidPackage pkg, int[] newUsers,
            Runnable runnable) {
            Runnable runnable, int appId, int installerUid, boolean isSystem) {
        mUserId = userId;
        mInstallArgs = null;
        mReturnCode = returnCode;
@@ -191,6 +193,9 @@ final class InstallRequest {
        mIsInstallForUsers = true;
        mSessionId = -1;
        mRequireUserAction = USER_ACTION_UNSPECIFIED;
        mAppId = appId;
        mInstallerUidForInstallExisting = installerUid;
        mSystem = isSystem;
    }

    // addForInit
@@ -381,7 +386,8 @@ final class InstallRequest {

    public int getInstallerPackageUid() {
        return (mInstallArgs != null && mInstallArgs.mInstallSource != null)
                ? mInstallArgs.mInstallSource.mInstallerPackageUid : INVALID_UID;
                ? mInstallArgs.mInstallSource.mInstallerPackageUid
                : mInstallerUidForInstallExisting;
    }

    public int getDataLoaderType() {
+10 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.SparseArray;

import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;
import com.android.server.pm.pkg.AndroidPackage;

import java.io.File;
import java.io.IOException;
@@ -111,17 +112,20 @@ final class PackageMetrics {

        long versionCode = 0, apksSize = 0;
        if (success) {
            // TODO: Remove temp try-catch to avoid IllegalStateException. The reason is because
            //  the scan result is null for installExistingPackageAsUser(). Because it's installing
            //  a package that's already existing, there's no scanning or parsing involved
            try {
            if (mInstallRequest.isInstallForUsers()) {
                // In case of installExistingPackageAsUser, there's no scanned PackageSetting
                // in the request but the pkg object should be readily available
                AndroidPackage pkg = mInstallRequest.getPkg();
                if (pkg != null) {
                    versionCode = pkg.getLongVersionCode();
                    apksSize = getApksSize(new File(pkg.getPath()));
                }
            } else {
                final PackageSetting ps = mInstallRequest.getScannedPackageSetting();
                if (ps != null) {
                    versionCode = ps.getVersionCode();
                    apksSize = getApksSize(ps.getPath());
                }
            } catch (IllegalStateException | NullPointerException e) {
                // no-op
            }
        }