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

Commit 42592cc8 authored by Joanne Chung's avatar Joanne Chung
Browse files

Catch NPE when reportInstallationToSecurityLog

The scan result is null for installExistingPackageAsUser(), becuse
it is installing a package that already exists, there is no scanning
or parsing involved.

Like reportInstallationStats, we also catch the exception temporary
here. There is a follow up bug to handle it correctly.

Bug: 301397206
Test: manual.
Change-Id: Ie846264d2bc1cd300d67d5cf69e41b710716fa54
parent 0283bc86
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -310,6 +310,10 @@ final class PackageMetrics {
        if (!SecurityLog.isLoggingEnabled()) {
            return;
        }
        // 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 {
            final PackageSetting ps = mInstallRequest.getScannedPackageSetting();
            if (ps == null) {
                return;
@@ -323,6 +327,9 @@ final class PackageMetrics {
                SecurityLog.writeEvent(SecurityLog.TAG_PACKAGE_UPDATED, packageName, versionCode,
                        userId);
            }
        } catch (IllegalStateException | NullPointerException e) {
            // no-op
        }
    }

    private static void reportUninstallationToSecurityLog(String packageName, long versionCode,