Add descriptions to compat changes.
Capture the comment above a definition of a compat change and make it
the description.
Next: make sure existing changes use supported format (only /**
comments, only above the annotations), and use in developer UI.
Bug: 144927670
Test: atest com.android.server.compat.CompatConfigTest
Change-Id: Ib23f341baa171599654c351693e4b0ddf4b2515c
diff --git a/core/java/com/android/internal/compat/CompatibilityChangeInfo.java b/core/java/com/android/internal/compat/CompatibilityChangeInfo.java
index e48e2df..16628d7 100644
--- a/core/java/com/android/internal/compat/CompatibilityChangeInfo.java
+++ b/core/java/com/android/internal/compat/CompatibilityChangeInfo.java
@@ -30,6 +30,7 @@
private final @Nullable String mName;
private final int mEnableAfterTargetSdk;
private final boolean mDisabled;
+ private final @Nullable String mDescription;
public long getId() {
return mChangeId;
@@ -48,12 +49,18 @@
return mDisabled;
}
+ public String getDescription() {
+ return mDescription;
+ }
+
public CompatibilityChangeInfo(
- Long changeId, String name, int enableAfterTargetSdk, boolean disabled) {
+ Long changeId, String name, int enableAfterTargetSdk, boolean disabled,
+ String description) {
this.mChangeId = changeId;
this.mName = name;
this.mEnableAfterTargetSdk = enableAfterTargetSdk;
this.mDisabled = disabled;
+ this.mDescription = description;
}
private CompatibilityChangeInfo(Parcel in) {
@@ -61,6 +68,7 @@
mName = in.readString();
mEnableAfterTargetSdk = in.readInt();
mDisabled = in.readBoolean();
+ mDescription = in.readString();
}
@Override
@@ -74,6 +82,7 @@
dest.writeString(mName);
dest.writeInt(mEnableAfterTargetSdk);
dest.writeBoolean(mDisabled);
+ dest.writeString(mDescription);
}
public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR =
diff --git a/services/core/java/com/android/server/compat/CompatChange.java b/services/core/java/com/android/server/compat/CompatChange.java
index 95582f7..2eec419 100644
--- a/services/core/java/com/android/server/compat/CompatChange.java
+++ b/services/core/java/com/android/server/compat/CompatChange.java
@@ -55,7 +55,7 @@
private Map<String, Boolean> mPackageOverrides;
public CompatChange(long changeId) {
- this(changeId, null, -1, false);
+ this(changeId, null, -1, false, null);
}
/**
@@ -66,8 +66,8 @@
* @param disabled If {@code true}, overrides any {@code enableAfterTargetSdk} set.
*/
public CompatChange(long changeId, @Nullable String name, int enableAfterTargetSdk,
- boolean disabled) {
- super(changeId, name, enableAfterTargetSdk, disabled);
+ boolean disabled, String description) {
+ super(changeId, name, enableAfterTargetSdk, disabled, description);
}
/**
@@ -75,7 +75,7 @@
*/
public CompatChange(Change change) {
super(change.getId(), change.getName(), change.getEnableAfterTargetSdk(),
- change.getDisabled());
+ change.getDisabled(), change.getDescription());
}
void registerListener(ChangeListener listener) {
diff --git a/services/core/java/com/android/server/compat/CompatConfig.java b/services/core/java/com/android/server/compat/CompatConfig.java
index 39c6e75..cf83dd6 100644
--- a/services/core/java/com/android/server/compat/CompatConfig.java
+++ b/services/core/java/com/android/server/compat/CompatConfig.java
@@ -319,7 +319,8 @@
changeInfos[i] = new CompatibilityChangeInfo(change.getId(),
change.getName(),
change.getEnableAfterTargetSdk(),
- change.getDisabled());
+ change.getDisabled(),
+ change.getDescription());
}
return changeInfos;
}
diff --git a/services/core/xsd/platform-compat-config.xsd b/services/core/xsd/platform-compat-config.xsd
index ee39e50..a70568f 100644
--- a/services/core/xsd/platform-compat-config.xsd
+++ b/services/core/xsd/platform-compat-config.xsd
@@ -28,6 +28,7 @@
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:boolean" name="disabled"/>
<xs:attribute type="xs:int" name="enableAfterTargetSdk"/>
+ <xs:attribute type="xs:string" name="description"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
diff --git a/services/core/xsd/platform-compat-schema/current.txt b/services/core/xsd/platform-compat-schema/current.txt
index 8456785..3a33f63 100644
--- a/services/core/xsd/platform-compat-schema/current.txt
+++ b/services/core/xsd/platform-compat-schema/current.txt
@@ -3,11 +3,13 @@
public class Change {
ctor public Change();
+ method public String getDescription();
method public boolean getDisabled();
method public int getEnableAfterTargetSdk();
method public long getId();
method public String getName();
method public String getValue();
+ method public void setDescription(String);
method public void setDisabled(boolean);
method public void setEnableAfterTargetSdk(int);
method public void setId(long);
diff --git a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
index f8c87fc..7267976 100644
--- a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
@@ -73,36 +73,36 @@
@Test
public void testDisabledChangeDisabled() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, ""));
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 1))).isFalse();
}
@Test
public void testTargetSdkChangeDisabled() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false, null));
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isFalse();
}
@Test
public void testTargetSdkChangeEnabled() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, false, ""));
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isTrue();
}
@Test
public void testDisabledOverrideTargetSdkChange() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true, null));
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 3))).isFalse();
}
@Test
public void testGetDisabledChanges() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true));
- pc.addChange(new CompatChange(2345L, "OTHER_CHANGE", -1, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, null));
+ pc.addChange(new CompatChange(2345L, "OTHER_CHANGE", -1, false, null));
assertThat(pc.getDisabledChanges(
makeAppInfo("com.some.package", 2))).asList().containsExactly(1234L);
}
@@ -110,9 +110,9 @@
@Test
public void testGetDisabledChangesSorted() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true));
- pc.addChange(new CompatChange(123L, "OTHER_CHANGE", 2, true));
- pc.addChange(new CompatChange(12L, "THIRD_CHANGE", 2, true));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", 2, true, null));
+ pc.addChange(new CompatChange(123L, "OTHER_CHANGE", 2, true, null));
+ pc.addChange(new CompatChange(12L, "THIRD_CHANGE", 2, true, null));
assertThat(pc.getDisabledChanges(
makeAppInfo("com.some.package", 2))).asList().containsExactly(12L, 123L, 1234L);
}
@@ -120,7 +120,7 @@
@Test
public void testPackageOverrideEnabled() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true)); // disabled
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, true, null)); // disabled
pc.addOverride(1234L, "com.some.package", true);
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isTrue();
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.other.package", 2))).isFalse();
@@ -129,7 +129,7 @@
@Test
public void testPackageOverrideDisabled() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
pc.addOverride(1234L, "com.some.package", false);
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isFalse();
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.other.package", 2))).isTrue();
@@ -152,7 +152,7 @@
@Test
public void testRemovePackageOverride() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
pc.addOverride(1234L, "com.some.package", false);
pc.removeOverride(1234L, "com.some.package");
assertThat(pc.isChangeEnabled(1234L, makeAppInfo("com.some.package", 2))).isTrue();
@@ -161,8 +161,8 @@
@Test
public void testLookupChangeId() {
CompatConfig pc = new CompatConfig();
- pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false));
- pc.addChange(new CompatChange(2345L, "ANOTHER_CHANGE", -1, false));
+ pc.addChange(new CompatChange(1234L, "MY_CHANGE", -1, false, null));
+ pc.addChange(new CompatChange(2345L, "ANOTHER_CHANGE", -1, false, null));
assertThat(pc.lookupChangeId("MY_CHANGE")).isEqualTo(1234L);
}
@@ -174,8 +174,9 @@
@Test
public void testReadConfig() {
- Change[] changes = {new Change(1234L, "MY_CHANGE1", false, 2), new Change(1235L,
- "MY_CHANGE2", true, null), new Change(1236L, "MY_CHANGE3", false, null)};
+ Change[] changes = {new Change(1234L, "MY_CHANGE1", false, 2, null), new Change(1235L,
+ "MY_CHANGE2", true, null, "description"), new Change(1236L, "MY_CHANGE3", false,
+ null, "")};
File dir = createTempDir();
writeChangesToFile(changes, new File(dir.getPath() + "/platform_compat_config.xml"));
@@ -191,9 +192,9 @@
@Test
public void testReadConfigMultipleFiles() {
- Change[] changes1 = {new Change(1234L, "MY_CHANGE1", false, 2)};
- Change[] changes2 = {new Change(1235L, "MY_CHANGE2", true, null), new Change(1236L,
- "MY_CHANGE3", false, null)};
+ Change[] changes1 = {new Change(1234L, "MY_CHANGE1", false, 2, null)};
+ Change[] changes2 = {new Change(1235L, "MY_CHANGE2", true, null, ""), new Change(1236L,
+ "MY_CHANGE3", false, null, null)};
File dir = createTempDir();
writeChangesToFile(changes1,