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

Commit 6521c744 authored by Alex Buynytskyy's avatar Alex Buynytskyy Committed by Android (Google) Code Review
Browse files

Merge "APEX and system apps can't be installed in a streaming fashion."

parents 030536c8 ae3eabee
Loading
Loading
Loading
Loading
+35 −11
Original line number Original line Diff line number Diff line
@@ -558,12 +558,24 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        mStagedSessionErrorMessage =
        mStagedSessionErrorMessage =
                stagedSessionErrorMessage != null ? stagedSessionErrorMessage : "";
                stagedSessionErrorMessage != null ? stagedSessionErrorMessage : "";


        if (isStreamingInstallation()
        if (isDataLoaderInstallation()) {
                && this.params.dataLoaderParams.getComponentName().getPackageName()
            if (isApexInstallation()) {
                throw new IllegalArgumentException(
                        "DataLoader installation of APEX modules is not allowed.");
            }
        }

        if (isStreamingInstallation()) {
            if (!isIncrementalInstallationAllowed(mPackageName)) {
                throw new IllegalArgumentException(
                        "Incremental installation of this package is not allowed.");
            }
            if (this.params.dataLoaderParams.getComponentName().getPackageName()
                    == SYSTEM_DATA_LOADER_PACKAGE) {
                    == SYSTEM_DATA_LOADER_PACKAGE) {
                assertShellOrSystemCalling("System data loaders");
                assertShellOrSystemCalling("System data loaders");
            }
            }
        }
        }
    }


    public SessionInfo generateInfo() {
    public SessionInfo generateInfo() {
        return generateInfo(true);
        return generateInfo(true);
@@ -1173,6 +1185,19 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                == PackageManager.PERMISSION_GRANTED;
                == PackageManager.PERMISSION_GRANTED;
    }
    }


    /**
     * Checks if the package can be installed on IncFs.
     */
    private static boolean isIncrementalInstallationAllowed(String packageName) {
        final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
        final AndroidPackage existingPackage = pmi.getPackage(packageName);
        if (existingPackage == null) {
            return true;
        }

        return !PackageManagerService.isSystemApp(existingPackage);
    }

    /**
    /**
     * If this was not already called, the session will be sealed.
     * If this was not already called, the session will be sealed.
     *
     *
@@ -1362,14 +1387,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                    return false;
                    return false;
                }
                }


                final PackageInfo pkgInfo = mPm.getPackageInfo(
                        params.appPackageName, PackageManager.GET_SIGNATURES
                                | PackageManager.MATCH_STATIC_SHARED_LIBRARIES /*flags*/, userId);

                if (isApexInstallation()) {
                if (isApexInstallation()) {
                    validateApexInstallLocked();
                    validateApexInstallLocked();
                } else {
                } else {
                    validateApkInstallLocked(pkgInfo);
                    validateApkInstallLocked();
                }
                }
            }
            }


@@ -1786,8 +1807,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
     * {@link PackageManagerService}.
     * {@link PackageManagerService}.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private void validateApkInstallLocked(@Nullable PackageInfo pkgInfo)
    private void validateApkInstallLocked() throws PackageManagerException {
            throws PackageManagerException {
        ApkLite baseApk = null;
        ApkLite baseApk = null;
        mPackageName = null;
        mPackageName = null;
        mVersionCode = -1;
        mVersionCode = -1;
@@ -1797,6 +1817,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        mResolvedStagedFiles.clear();
        mResolvedStagedFiles.clear();
        mResolvedInheritedFiles.clear();
        mResolvedInheritedFiles.clear();


        final PackageInfo pkgInfo = mPm.getPackageInfo(
                params.appPackageName, PackageManager.GET_SIGNATURES
                        | PackageManager.MATCH_STATIC_SHARED_LIBRARIES /*flags*/, userId);

        // Partial installs must be consistent with existing install
        // Partial installs must be consistent with existing install
        if (params.mode == SessionParams.MODE_INHERIT_EXISTING
        if (params.mode == SessionParams.MODE_INHERIT_EXISTING
                && (pkgInfo == null || pkgInfo.applicationInfo == null)) {
                && (pkgInfo == null || pkgInfo.applicationInfo == null)) {