Merge changes Idd7d86f9,I73569744 am: 420476e0cd am: 086acc1ba8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1532338 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Idec178eb39c014c9817db666fd3d5b5a39be52ba
This commit is contained in:
committed by
Automerger Merge Worker
commit
3fb101a052
@@ -31,4 +31,14 @@ public class AndroidBuildClassifier {
|
|||||||
public boolean isFinalBuild() {
|
public boolean isFinalBuild() {
|
||||||
return "REL".equals(Build.VERSION.CODENAME);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public final class OverrideAllowedState implements Parcelable {
|
|||||||
DISABLED_NON_TARGET_SDK,
|
DISABLED_NON_TARGET_SDK,
|
||||||
DISABLED_TARGET_SDK_TOO_HIGH,
|
DISABLED_TARGET_SDK_TOO_HIGH,
|
||||||
DEFERRED_VERIFICATION,
|
DEFERRED_VERIFICATION,
|
||||||
LOGGING_ONLY_CHANGE
|
LOGGING_ONLY_CHANGE,
|
||||||
|
PLATFORM_TOO_OLD
|
||||||
})
|
})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface State {
|
public @interface State {
|
||||||
@@ -65,6 +66,10 @@ public final class OverrideAllowedState implements Parcelable {
|
|||||||
* Change is marked as logging only, and cannot be toggled.
|
* Change is marked as logging only, and cannot be toggled.
|
||||||
*/
|
*/
|
||||||
public static final int LOGGING_ONLY_CHANGE = 5;
|
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
|
@State
|
||||||
public final int state;
|
public final int state;
|
||||||
@@ -123,6 +128,11 @@ public final class OverrideAllowedState implements Parcelable {
|
|||||||
throw new SecurityException(String.format(
|
throw new SecurityException(String.format(
|
||||||
"Cannot override %1$d because it is marked as a logging-only change.",
|
"Cannot override %1$d because it is marked as a logging-only change.",
|
||||||
changeId));
|
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";
|
return "DEFERRED_VERIFICATION";
|
||||||
case LOGGING_ONLY_CHANGE:
|
case LOGGING_ONLY_CHANGE:
|
||||||
return "LOGGING_ONLY_CHANGE";
|
return "LOGGING_ONLY_CHANGE";
|
||||||
|
case PLATFORM_TOO_OLD:
|
||||||
|
return "PLATFORM_TOO_OLD";
|
||||||
}
|
}
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
|
import com.android.internal.compat.AndroidBuildClassifier;
|
||||||
import com.android.internal.compat.CompatibilityChangeInfo;
|
import com.android.internal.compat.CompatibilityChangeInfo;
|
||||||
import com.android.internal.compat.OverrideAllowedState;
|
import com.android.internal.compat.OverrideAllowedState;
|
||||||
import com.android.server.compat.config.Change;
|
import com.android.server.compat.config.Change;
|
||||||
@@ -55,7 +56,7 @@ public final class CompatChange extends CompatibilityChangeInfo {
|
|||||||
* A change ID to be used only in the CTS test for this SystemApi
|
* A change ID to be used only in the CTS test for this SystemApi
|
||||||
*/
|
*/
|
||||||
@ChangeId
|
@ChangeId
|
||||||
@EnabledSince(targetSdkVersion = 1235) // Needs to be > test APK targetSdkVersion.
|
@EnabledSince(targetSdkVersion = 31) // Needs to be > test APK targetSdkVersion.
|
||||||
static final long CTS_SYSTEM_API_CHANGEID = 149391281; // This is a bug id.
|
static final long CTS_SYSTEM_API_CHANGEID = 149391281; // This is a bug id.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,7 +234,7 @@ public final class CompatChange extends CompatibilityChangeInfo {
|
|||||||
* @param app Info about the app in question
|
* @param app Info about the app in question
|
||||||
* @return {@code true} if the change should be enabled for the package.
|
* @return {@code true} if the change should be enabled for the package.
|
||||||
*/
|
*/
|
||||||
boolean isEnabled(ApplicationInfo app) {
|
boolean isEnabled(ApplicationInfo app, AndroidBuildClassifier buildClassifier) {
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
return defaultValue();
|
return defaultValue();
|
||||||
}
|
}
|
||||||
@@ -244,7 +245,13 @@ public final class CompatChange extends CompatibilityChangeInfo {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getEnableSinceTargetSdk() != -1) {
|
if (getEnableSinceTargetSdk() != -1) {
|
||||||
return app.targetSdkVersion >= getEnableSinceTargetSdk();
|
// If the change is gated by a platform version newer than the one currently installed
|
||||||
|
// on the device, disregard the app's target sdk version.
|
||||||
|
int compareSdk = Math.min(app.targetSdkVersion, buildClassifier.platformTargetSdk());
|
||||||
|
if (compareSdk != app.targetSdkVersion) {
|
||||||
|
compareSdk = app.targetSdkVersion;
|
||||||
|
}
|
||||||
|
return compareSdk >= getEnableSinceTargetSdk();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,12 +74,14 @@ final class CompatConfig {
|
|||||||
private final LongSparseArray<CompatChange> mChanges = new LongSparseArray<>();
|
private final LongSparseArray<CompatChange> mChanges = new LongSparseArray<>();
|
||||||
|
|
||||||
private final OverrideValidatorImpl mOverrideValidator;
|
private final OverrideValidatorImpl mOverrideValidator;
|
||||||
|
private final AndroidBuildClassifier mAndroidBuildClassifier;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private File mOverridesFile;
|
private File mOverridesFile;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
CompatConfig(AndroidBuildClassifier androidBuildClassifier, Context context) {
|
CompatConfig(AndroidBuildClassifier androidBuildClassifier, Context context) {
|
||||||
mOverrideValidator = new OverrideValidatorImpl(androidBuildClassifier, context, this);
|
mOverrideValidator = new OverrideValidatorImpl(androidBuildClassifier, context, this);
|
||||||
|
mAndroidBuildClassifier = androidBuildClassifier;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +135,7 @@ final class CompatConfig {
|
|||||||
synchronized (mChanges) {
|
synchronized (mChanges) {
|
||||||
for (int i = 0; i < mChanges.size(); ++i) {
|
for (int i = 0; i < mChanges.size(); ++i) {
|
||||||
CompatChange c = mChanges.valueAt(i);
|
CompatChange c = mChanges.valueAt(i);
|
||||||
if (!c.isEnabled(app)) {
|
if (!c.isEnabled(app, mAndroidBuildClassifier)) {
|
||||||
disabled.add(c.getId());
|
disabled.add(c.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +177,7 @@ final class CompatConfig {
|
|||||||
// we know nothing about this change: default behaviour is enabled.
|
// we know nothing about this change: default behaviour is enabled.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return c.isEnabled(app);
|
return c.isEnabled(app, mAndroidBuildClassifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +477,7 @@ final class CompatConfig {
|
|||||||
synchronized (mChanges) {
|
synchronized (mChanges) {
|
||||||
for (int i = 0; i < mChanges.size(); ++i) {
|
for (int i = 0; i < mChanges.size(); ++i) {
|
||||||
CompatChange c = mChanges.valueAt(i);
|
CompatChange c = mChanges.valueAt(i);
|
||||||
if (c.isEnabled(applicationInfo)) {
|
if (c.isEnabled(applicationInfo, mAndroidBuildClassifier)) {
|
||||||
enabled.add(c.getId());
|
enabled.add(c.getId());
|
||||||
} else {
|
} else {
|
||||||
disabled.add(c.getId());
|
disabled.add(c.getId());
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import static com.android.internal.compat.OverrideAllowedState.DISABLED_NON_TARG
|
|||||||
import static com.android.internal.compat.OverrideAllowedState.DISABLED_NOT_DEBUGGABLE;
|
import static com.android.internal.compat.OverrideAllowedState.DISABLED_NOT_DEBUGGABLE;
|
||||||
import static com.android.internal.compat.OverrideAllowedState.DISABLED_TARGET_SDK_TOO_HIGH;
|
import static com.android.internal.compat.OverrideAllowedState.DISABLED_TARGET_SDK_TOO_HIGH;
|
||||||
import static com.android.internal.compat.OverrideAllowedState.LOGGING_ONLY_CHANGE;
|
import static com.android.internal.compat.OverrideAllowedState.LOGGING_ONLY_CHANGE;
|
||||||
|
import static com.android.internal.compat.OverrideAllowedState.PLATFORM_TOO_OLD;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@@ -85,6 +86,9 @@ public class OverrideValidatorImpl extends IOverrideValidator.Stub {
|
|||||||
if (debuggableBuild) {
|
if (debuggableBuild) {
|
||||||
return new OverrideAllowedState(ALLOWED, -1, -1);
|
return new OverrideAllowedState(ALLOWED, -1, -1);
|
||||||
}
|
}
|
||||||
|
if (maxTargetSdk >= mAndroidBuildClassifier.platformTargetSdk()) {
|
||||||
|
return new OverrideAllowedState(PLATFORM_TOO_OLD, -1, maxTargetSdk);
|
||||||
|
}
|
||||||
PackageManager packageManager = mContext.getPackageManager();
|
PackageManager packageManager = mContext.getPackageManager();
|
||||||
if (packageManager == null) {
|
if (packageManager == null) {
|
||||||
throw new IllegalStateException("No PackageManager!");
|
throw new IllegalStateException("No PackageManager!");
|
||||||
|
|||||||
@@ -66,18 +66,22 @@ public class PlatformCompat extends IPlatformCompat.Stub {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ChangeReporter mChangeReporter;
|
private final ChangeReporter mChangeReporter;
|
||||||
private final CompatConfig mCompatConfig;
|
private final CompatConfig mCompatConfig;
|
||||||
|
private final AndroidBuildClassifier mBuildClassifier;
|
||||||
|
|
||||||
public PlatformCompat(Context context) {
|
public PlatformCompat(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_SYSTEM_SERVER);
|
mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_SYSTEM_SERVER);
|
||||||
mCompatConfig = CompatConfig.create(new AndroidBuildClassifier(), mContext);
|
mBuildClassifier = new AndroidBuildClassifier();
|
||||||
|
mCompatConfig = CompatConfig.create(mBuildClassifier, mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PlatformCompat(Context context, CompatConfig compatConfig) {
|
PlatformCompat(Context context, CompatConfig compatConfig,
|
||||||
|
AndroidBuildClassifier buildClassifier) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_SYSTEM_SERVER);
|
mChangeReporter = new ChangeReporter(ChangeReporter.SOURCE_SYSTEM_SERVER);
|
||||||
mCompatConfig = compatConfig;
|
mCompatConfig = compatConfig;
|
||||||
|
mBuildClassifier = buildClassifier;
|
||||||
|
|
||||||
registerPackageReceiver(context);
|
registerPackageReceiver(context);
|
||||||
}
|
}
|
||||||
@@ -392,7 +396,8 @@ public class PlatformCompat extends IPlatformCompat.Stub {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (change.getEnableSinceTargetSdk() > 0) {
|
if (change.getEnableSinceTargetSdk() > 0) {
|
||||||
return change.getEnableSinceTargetSdk() >= Build.VERSION_CODES.Q;
|
return change.getEnableSinceTargetSdk() >= Build.VERSION_CODES.Q
|
||||||
|
&& change.getEnableSinceTargetSdk() <= mBuildClassifier.platformTargetSdk();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ class CompatConfigBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompatConfigBuilder addEnabledSinceApexChangeWithId(int sdk, long id) {
|
||||||
|
mChanges.add(new CompatChange(id, "", -1, sdk, false, false, "", false));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
CompatConfig build() {
|
CompatConfig build() {
|
||||||
CompatConfig config = new CompatConfig(mBuildClassifier, mContext);
|
CompatConfig config = new CompatConfig(mBuildClassifier, mContext);
|
||||||
config.forceNonDebuggableFinalForTest(false);
|
config.forceNonDebuggableFinalForTest(false);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class CompatConfigTest {
|
|||||||
// Assume userdebug/eng non-final build
|
// Assume userdebug/eng non-final build
|
||||||
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
||||||
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
||||||
|
when(mBuildClassifier.platformTargetSdk()).thenReturn(30);
|
||||||
ChangeIdStateCache.disable();
|
ChangeIdStateCache.disable();
|
||||||
when(mPackageManager.getApplicationInfo(anyString(), anyInt()))
|
when(mPackageManager.getApplicationInfo(anyString(), anyInt()))
|
||||||
.thenThrow(new NameNotFoundException());
|
.thenThrow(new NameNotFoundException());
|
||||||
@@ -566,6 +567,34 @@ public class CompatConfigTest {
|
|||||||
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isTrue();
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadApexConfig() throws IOException {
|
||||||
|
String configXml = "<config>"
|
||||||
|
+ "<compat-change id=\"1234\" name=\"MY_CHANGE1\" enableAfterTargetSdk=\"2\" />"
|
||||||
|
+ "<compat-change id=\"1235\" name=\"MY_CHANGE2\" disabled=\"true\" />"
|
||||||
|
+ "<compat-change id=\"1236\" name=\"MY_CHANGE3\" />"
|
||||||
|
+ "<compat-change id=\"1237\" name=\"MY_CHANGE4\" enableSinceTargetSdk=\"31\" />"
|
||||||
|
+ "</config>";
|
||||||
|
|
||||||
|
File dir = createTempDir();
|
||||||
|
writeToFile(dir, "platform_compat_config.xml", configXml);
|
||||||
|
CompatConfig compatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
|
compatConfig.forceNonDebuggableFinalForTest(false);
|
||||||
|
|
||||||
|
compatConfig.initConfigFromLib(dir);
|
||||||
|
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1234L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(3).build())).isTrue();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1235L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(5).build())).isFalse();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1236L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(1).build())).isTrue();
|
||||||
|
assertThat(compatConfig.isChangeEnabled(1237L,
|
||||||
|
ApplicationInfoBuilder.create().withTargetSdk(31).build())).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadConfigMultipleFiles() throws IOException {
|
public void testReadConfigMultipleFiles() throws IOException {
|
||||||
String configXml1 = "<config>"
|
String configXml1 = "<config>"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import static com.android.internal.compat.OverrideAllowedState.DISABLED_NON_TARG
|
|||||||
import static com.android.internal.compat.OverrideAllowedState.DISABLED_NOT_DEBUGGABLE;
|
import static com.android.internal.compat.OverrideAllowedState.DISABLED_NOT_DEBUGGABLE;
|
||||||
import static com.android.internal.compat.OverrideAllowedState.DISABLED_TARGET_SDK_TOO_HIGH;
|
import static com.android.internal.compat.OverrideAllowedState.DISABLED_TARGET_SDK_TOO_HIGH;
|
||||||
import static com.android.internal.compat.OverrideAllowedState.LOGGING_ONLY_CHANGE;
|
import static com.android.internal.compat.OverrideAllowedState.LOGGING_ONLY_CHANGE;
|
||||||
|
import static com.android.internal.compat.OverrideAllowedState.PLATFORM_TOO_OLD;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ public class OverrideValidatorImplTest {
|
|||||||
private static final int TARGET_SDK = 10;
|
private static final int TARGET_SDK = 10;
|
||||||
private static final int TARGET_SDK_BEFORE = 9;
|
private static final int TARGET_SDK_BEFORE = 9;
|
||||||
private static final int TARGET_SDK_AFTER = 11;
|
private static final int TARGET_SDK_AFTER = 11;
|
||||||
|
private static final int PLATFORM_SDK_VERSION = 30;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@@ -61,6 +63,7 @@ public class OverrideValidatorImplTest {
|
|||||||
private AndroidBuildClassifier debuggableBuild() {
|
private AndroidBuildClassifier debuggableBuild() {
|
||||||
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
||||||
when(buildClassifier.isDebuggableBuild()).thenReturn(true);
|
when(buildClassifier.isDebuggableBuild()).thenReturn(true);
|
||||||
|
when(buildClassifier.platformTargetSdk()).thenReturn(PLATFORM_SDK_VERSION);
|
||||||
return buildClassifier;
|
return buildClassifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +71,7 @@ public class OverrideValidatorImplTest {
|
|||||||
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
||||||
when(buildClassifier.isDebuggableBuild()).thenReturn(false);
|
when(buildClassifier.isDebuggableBuild()).thenReturn(false);
|
||||||
when(buildClassifier.isFinalBuild()).thenReturn(false);
|
when(buildClassifier.isFinalBuild()).thenReturn(false);
|
||||||
|
when(buildClassifier.platformTargetSdk()).thenReturn(PLATFORM_SDK_VERSION);
|
||||||
return buildClassifier;
|
return buildClassifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ public class OverrideValidatorImplTest {
|
|||||||
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
AndroidBuildClassifier buildClassifier = mock(AndroidBuildClassifier.class);
|
||||||
when(buildClassifier.isDebuggableBuild()).thenReturn(false);
|
when(buildClassifier.isDebuggableBuild()).thenReturn(false);
|
||||||
when(buildClassifier.isFinalBuild()).thenReturn(true);
|
when(buildClassifier.isFinalBuild()).thenReturn(true);
|
||||||
|
when(buildClassifier.platformTargetSdk()).thenReturn(PLATFORM_SDK_VERSION);
|
||||||
return buildClassifier;
|
return buildClassifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,6 +337,26 @@ public class OverrideValidatorImplTest {
|
|||||||
TARGET_SDK_BEFORE));
|
TARGET_SDK_BEFORE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getOverrideAllowedState_targetSdkChangeGreaterThanOsVersion_rejectOverride()
|
||||||
|
throws Exception {
|
||||||
|
final AndroidBuildClassifier buildClassifier = finalBuild();
|
||||||
|
CompatConfig config = CompatConfigBuilder.create(finalBuild(), mContext)
|
||||||
|
.addEnabledSinceApexChangeWithId(PLATFORM_SDK_VERSION + 1, 1).build();
|
||||||
|
IOverrideValidator overrideValidator = config.getOverrideValidator();
|
||||||
|
when(mPackageManager.getApplicationInfo(eq(PACKAGE_NAME), anyInt()))
|
||||||
|
.thenReturn(ApplicationInfoBuilder.create()
|
||||||
|
.withPackageName(PACKAGE_NAME)
|
||||||
|
.debuggable()
|
||||||
|
.build());
|
||||||
|
|
||||||
|
OverrideAllowedState stateTargetSdkLessChange =
|
||||||
|
overrideValidator.getOverrideAllowedState(1, PACKAGE_NAME);
|
||||||
|
assertThat(stateTargetSdkLessChange).isEqualTo(
|
||||||
|
new OverrideAllowedState(PLATFORM_TOO_OLD, -1,
|
||||||
|
PLATFORM_SDK_VERSION));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOverrideAllowedState_finalBuildEnabledChangeDebugApp_rejectOverride()
|
public void getOverrideAllowedState_finalBuildEnabledChangeDebugApp_rejectOverride()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
@@ -78,11 +78,12 @@ public class PlatformCompatTest {
|
|||||||
when(mPackageManager.getApplicationInfo(eq(PACKAGE_NAME), anyInt()))
|
when(mPackageManager.getApplicationInfo(eq(PACKAGE_NAME), anyInt()))
|
||||||
.thenThrow(new PackageManager.NameNotFoundException());
|
.thenThrow(new PackageManager.NameNotFoundException());
|
||||||
mCompatConfig = new CompatConfig(mBuildClassifier, mContext);
|
mCompatConfig = new CompatConfig(mBuildClassifier, mContext);
|
||||||
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig, mBuildClassifier);
|
||||||
// Assume userdebug/eng non-final build
|
// Assume userdebug/eng non-final build
|
||||||
mCompatConfig.forceNonDebuggableFinalForTest(false);
|
mCompatConfig.forceNonDebuggableFinalForTest(false);
|
||||||
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
when(mBuildClassifier.isDebuggableBuild()).thenReturn(true);
|
||||||
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
when(mBuildClassifier.isFinalBuild()).thenReturn(false);
|
||||||
|
when(mBuildClassifier.platformTargetSdk()).thenReturn(30);
|
||||||
LocalServices.removeServiceForTest(PackageManagerInternal.class);
|
LocalServices.removeServiceForTest(PackageManagerInternal.class);
|
||||||
LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternal);
|
LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternal);
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,7 @@ public class PlatformCompatTest {
|
|||||||
.addLoggingOnlyChangeWithId(7L)
|
.addLoggingOnlyChangeWithId(7L)
|
||||||
.addOverridableChangeWithId(8L)
|
.addOverridableChangeWithId(8L)
|
||||||
.build();
|
.build();
|
||||||
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig, mBuildClassifier);
|
||||||
assertThat(mPlatformCompat.listAllChanges()).asList().containsExactly(
|
assertThat(mPlatformCompat.listAllChanges()).asList().containsExactly(
|
||||||
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
|
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
|
||||||
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
|
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
|
||||||
@@ -125,8 +126,9 @@ public class PlatformCompatTest {
|
|||||||
.addEnableSinceSdkChangeWithId(Build.VERSION_CODES.Q, 5L)
|
.addEnableSinceSdkChangeWithId(Build.VERSION_CODES.Q, 5L)
|
||||||
.addEnableSinceSdkChangeWithId(Build.VERSION_CODES.R, 6L)
|
.addEnableSinceSdkChangeWithId(Build.VERSION_CODES.R, 6L)
|
||||||
.addLoggingOnlyChangeWithId(7L)
|
.addLoggingOnlyChangeWithId(7L)
|
||||||
|
.addEnableSinceSdkChangeWithId(31, 8L)
|
||||||
.build();
|
.build();
|
||||||
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig, mBuildClassifier);
|
||||||
assertThat(mPlatformCompat.listUIChanges()).asList().containsExactly(
|
assertThat(mPlatformCompat.listUIChanges()).asList().containsExactly(
|
||||||
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
|
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
|
||||||
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
|
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
|
||||||
@@ -144,7 +146,7 @@ public class PlatformCompatTest {
|
|||||||
.addEnableAfterSdkChangeWithId(Build.VERSION_CODES.O, 3L)
|
.addEnableAfterSdkChangeWithId(Build.VERSION_CODES.O, 3L)
|
||||||
.build();
|
.build();
|
||||||
mCompatConfig.forceNonDebuggableFinalForTest(true);
|
mCompatConfig.forceNonDebuggableFinalForTest(true);
|
||||||
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
|
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig, mBuildClassifier);
|
||||||
|
|
||||||
// Before adding overrides.
|
// Before adding overrides.
|
||||||
assertThat(mPlatformCompat.isChangeEnabledByPackageName(1, PACKAGE_NAME, 0)).isTrue();
|
assertThat(mPlatformCompat.isChangeEnabledByPackageName(1, PACKAGE_NAME, 0)).isTrue();
|
||||||
|
|||||||
Reference in New Issue
Block a user