Merge "Add skip functionality to package parsing" into rvc-dev am: 2728af853a

Change-Id: I18807bec3194ba59bcf3b3895aed69d15cfb7e92
This commit is contained in:
Winson Chiu
2020-05-01 20:24:01 +00:00
committed by Automerger Merge Worker
6 changed files with 32 additions and 6 deletions

View File

@@ -1561,6 +1561,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,

View File

@@ -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;
}

View File

@@ -2347,14 +2347,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)

View File

@@ -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);

View File

@@ -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);

View File

@@ -23,6 +23,7 @@ import android.content.pm.ConfigurationInfo
import android.content.pm.FeatureInfo
import android.content.pm.InstrumentationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.PackageParser
import android.content.pm.PackageUserState
import android.content.pm.PermissionInfo
@@ -168,6 +169,11 @@ open class AndroidPackageParsingTestBase {
private fun <T> tryOrNull(block: () -> T) = try {
block()
} catch (e: PackageParser.PackageParserException) {
if (e.error != PackageManager.INSTALL_PARSE_FAILED_SKIPPED) {
thrownInSetUp.add(e)
}
null
} catch (t: Throwable) {
thrownInSetUp.add(t)
null