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

Commit b58595b7 authored by Winson's avatar Winson
Browse files

Add skip functionality to package parsing

There are specific cases where a package should be ignored by
whoever is parsing it, either because the device was configured to
ignore it, or the device doesn't support it.

While mostly used for testing, this adds a skip method to
ParseInput and a matching install error code to explicitly express
this case during parsing.

Bug: 155420149

Test: atest com.android.server.pm.parsing

Change-Id: I7eff53544341e21108d9d027f3afe75a1e845f40
parent 094e5ddb
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1560,6 +1560,14 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_PARSE_FAILED_RESOURCES_ARSC_COMPRESSED = -124;

    /**
     * Installation failed return code: the package was skipped and should be ignored.
     *
     * The reason for the skip is undefined.
     * @hide
     */
    public static final int INSTALL_PARSE_FAILED_SKIPPED = -125;

    /** @hide */
    @IntDef(flag = true, prefix = { "DELETE_" }, value = {
            DELETE_KEEP_DATA,
+1 −0
Original line number Diff line number Diff line
@@ -2001,6 +2001,7 @@ public class PackageParser {
                    Slog.i(TAG, "Skipping target and overlay pair " + pkg.mOverlayTarget + " and "
                        + pkg.baseCodePath+ ": overlay ignored due to required system property: "
                        + propName + " with value: " + propValue);
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_SKIPPED;
                    return null;
                }

+4 −6
Original line number Diff line number Diff line
@@ -2348,14 +2348,12 @@ public class ParsingPackageUtils {
            String propValue = sa.getString(
                    R.styleable.AndroidManifestResourceOverlay_requiredSystemPropertyValue);
            if (!PackageParser.checkRequiredSystemProperties(propName, propValue)) {
                Slog.i(TAG, "Skipping target and overlay pair " + target + " and "
                String message = "Skipping target and overlay pair " + target + " and "
                        + pkg.getBaseCodePath()
                        + ": overlay ignored due to required system property: "
                        + propName + " with value: " + propValue);
                return input.error("Skipping target and overlay pair " + target + " and "
                        + pkg.getBaseCodePath()
                        + ": overlay ignored due to required system property: "
                        + propName + " with value: " + propValue);
                        + propName + " with value: " + propValue;
                Slog.i(TAG, message);
                return input.skip(message);
            }

            return input.success(pkg.setOverlay(true)
+8 −0
Original line number Diff line number Diff line
@@ -88,6 +88,14 @@ public interface ParseInput {
     */
    ParseResult<?> enableDeferredError(String packageName, int targetSdkVersion);

    /**
     * This will assign errorCode to {@link PackageManager#INSTALL_PARSE_FAILED_SKIPPED, used for
     * packages which should be ignored by the caller.
     *
     * @see #error(int, String, Exception)
     */
    <ResultType> ParseResult<ResultType> skip(@NonNull String parseError);

    /** @see #error(int, String, Exception) */
    <ResultType> ParseResult<ResultType> error(int parseError);

+5 −0
Original line number Diff line number Diff line
@@ -146,6 +146,11 @@ public class ParseTypeImpl implements ParseInput, ParseResult<Object> {
        return success(null);
    }

    @Override
    public <ResultType> ParseResult<ResultType> skip(@NonNull String parseError) {
        return error(PackageManager.INSTALL_PARSE_FAILED_SKIPPED, parseError);
    }

    @Override
    public <ResultType> ParseResult<ResultType> error(int parseError) {
        return error(parseError, null);
Loading