Merge changes Idd7d86f9,I73569744

* changes:
  Do not enable changes newer than the current sdk
  Add support for loading a static overrides file located in /product.
This commit is contained in:
Andrei-Valentin Onea
2021-03-12 13:28:50 +00:00
committed by Gerrit Code Review
10 changed files with 304 additions and 82 deletions

View File

@@ -31,4 +31,14 @@ public class AndroidBuildClassifier {
public boolean isFinalBuild() {
return "REL".equals(Build.VERSION.CODENAME);
}
/**
* The current platform SDK version.
*/
public int platformTargetSdk() {
if (isFinalBuild()) {
return Build.VERSION.SDK_INT;
}
return Build.VERSION_CODES.CUR_DEVELOPMENT;
}
}

View File

@@ -34,7 +34,8 @@ public final class OverrideAllowedState implements Parcelable {
DISABLED_NON_TARGET_SDK,
DISABLED_TARGET_SDK_TOO_HIGH,
DEFERRED_VERIFICATION,
LOGGING_ONLY_CHANGE
LOGGING_ONLY_CHANGE,
PLATFORM_TOO_OLD
})
@Retention(RetentionPolicy.SOURCE)
public @interface State {
@@ -65,6 +66,10 @@ public final class OverrideAllowedState implements Parcelable {
* Change is marked as logging only, and cannot be toggled.
*/
public static final int LOGGING_ONLY_CHANGE = 5;
/**
* Change is gated by a target sdk version newer than the current platform sdk version.
*/
public static final int PLATFORM_TOO_OLD = 6;
@State
public final int state;
@@ -123,6 +128,11 @@ public final class OverrideAllowedState implements Parcelable {
throw new SecurityException(String.format(
"Cannot override %1$d because it is marked as a logging-only change.",
changeId));
case PLATFORM_TOO_OLD:
throw new SecurityException(String.format(
"Cannot override %1$d for %2$s because the change's targetSdk threshold "
+ "(%3$d) is above the platform sdk.",
changeId, packageName, changeIdTargetSdk));
}
}
@@ -170,6 +180,8 @@ public final class OverrideAllowedState implements Parcelable {
return "DEFERRED_VERIFICATION";
case LOGGING_ONLY_CHANGE:
return "LOGGING_ONLY_CHANGE";
case PLATFORM_TOO_OLD:
return "PLATFORM_TOO_OLD";
}
return "UNKNOWN";
}