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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user