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

Commit ad7e2706 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Add .apex suffix to apex files during validation

Previously, the apex file being installed was moved into the staging
directory as same name provided during installation, due to which, when
the source apex file of installation did not have .apex suffix in its
file name, it failed validation in apexd. Now, if an apex file does not
have proper suffix, it will be concatenated during validation in
PackageInstallerSession.

Bug: 124837227
Test: atest CtsStagedInstallHostTestCases
Test: atest StagedInstallTest#testInstallStagedApexWithoutApexSuffix
Change-Id: Ice41f601dc42736ca0cdf2bad0817f0c00f50648
parent 26f2c379
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -254,6 +254,8 @@ public class PackageParser {


    /** @hide */
    /** @hide */
    public static final String APK_FILE_EXTENSION = ".apk";
    public static final String APK_FILE_EXTENSION = ".apk";
    /** @hide */
    public static final String APEX_FILE_EXTENSION = ".apex";


    /** @hide */
    /** @hide */
    public static class NewPermissionInfo {
    public static class NewPermissionInfo {
+24 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_INSUFFICIENT_STOR
import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SPLIT;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SPLIT;
import static android.content.pm.PackageParser.APEX_FILE_EXTENSION;
import static android.content.pm.PackageParser.APK_FILE_EXTENSION;
import static android.content.pm.PackageParser.APK_FILE_EXTENSION;
import static android.system.OsConstants.O_CREAT;
import static android.system.OsConstants.O_CREAT;
import static android.system.OsConstants.O_RDONLY;
import static android.system.OsConstants.O_RDONLY;
@@ -1484,7 +1485,29 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                    "Too many files for apex install");
                    "Too many files for apex install");
        }
        }


        mResolvedBaseFile = addedFiles[0];
        try {
            resolveStageDirLocked();
        } catch (IOException e) {
            throw new PackageManagerException(INSTALL_FAILED_CONTAINER_ERROR,
                    "Failed to resolve stage location", e);
        }

        File addedFile = addedFiles[0]; // there is only one file

        // Ensure file name has proper suffix
        final String sourceName = addedFile.getName();
        final String targetName = sourceName.endsWith(APEX_FILE_EXTENSION)
                ? sourceName
                : sourceName + APEX_FILE_EXTENSION;
        if (!FileUtils.isValidExtFilename(targetName)) {
            throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                    "Invalid filename: " + targetName);
        }

        final File targetFile = new File(mResolvedStageDir, targetName);
        resolveAndStageFile(addedFile, targetFile);

        mResolvedBaseFile = targetFile;
    }
    }


    /**
    /**