Merge "Add new overridable annotation to platform compat" am: 458515e464

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1540124

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Icdb84460fab8ec12e185a6f78afa0efd8de2d3b5
This commit is contained in:
Benjamin Franz
2021-01-12 16:22:18 +00:00
committed by Automerger Merge Worker
6 changed files with 64 additions and 39 deletions

View File

@@ -32,6 +32,7 @@ public class CompatibilityChangeInfo implements Parcelable {
private final boolean mDisabled; private final boolean mDisabled;
private final boolean mLoggingOnly; private final boolean mLoggingOnly;
private final @Nullable String mDescription; private final @Nullable String mDescription;
private final boolean mOverridable;
public long getId() { public long getId() {
return mChangeId; return mChangeId;
@@ -58,9 +59,13 @@ public class CompatibilityChangeInfo implements Parcelable {
return mDescription; return mDescription;
} }
public boolean getOverridable() {
return mOverridable;
}
public CompatibilityChangeInfo( public CompatibilityChangeInfo(
Long changeId, String name, int enableAfterTargetSdk, int enableSinceTargetSdk, Long changeId, String name, int enableAfterTargetSdk, int enableSinceTargetSdk,
boolean disabled, boolean loggingOnly, String description) { boolean disabled, boolean loggingOnly, String description, boolean overridable) {
this.mChangeId = changeId; this.mChangeId = changeId;
this.mName = name; this.mName = name;
if (enableAfterTargetSdk > 0) { if (enableAfterTargetSdk > 0) {
@@ -75,6 +80,7 @@ public class CompatibilityChangeInfo implements Parcelable {
this.mDisabled = disabled; this.mDisabled = disabled;
this.mLoggingOnly = loggingOnly; this.mLoggingOnly = loggingOnly;
this.mDescription = description; this.mDescription = description;
this.mOverridable = overridable;
} }
public CompatibilityChangeInfo(CompatibilityChangeInfo other) { public CompatibilityChangeInfo(CompatibilityChangeInfo other) {
@@ -84,6 +90,7 @@ public class CompatibilityChangeInfo implements Parcelable {
this.mDisabled = other.mDisabled; this.mDisabled = other.mDisabled;
this.mLoggingOnly = other.mLoggingOnly; this.mLoggingOnly = other.mLoggingOnly;
this.mDescription = other.mDescription; this.mDescription = other.mDescription;
this.mOverridable = other.mOverridable;
} }
private CompatibilityChangeInfo(Parcel in) { private CompatibilityChangeInfo(Parcel in) {
@@ -93,6 +100,7 @@ public class CompatibilityChangeInfo implements Parcelable {
mDisabled = in.readBoolean(); mDisabled = in.readBoolean();
mLoggingOnly = in.readBoolean(); mLoggingOnly = in.readBoolean();
mDescription = in.readString(); mDescription = in.readString();
mOverridable = in.readBoolean();
} }
@Override @Override
@@ -108,6 +116,7 @@ public class CompatibilityChangeInfo implements Parcelable {
dest.writeBoolean(mDisabled); dest.writeBoolean(mDisabled);
dest.writeBoolean(mLoggingOnly); dest.writeBoolean(mLoggingOnly);
dest.writeString(mDescription); dest.writeString(mDescription);
dest.writeBoolean(mOverridable);
} }
@Override @Override
@@ -126,6 +135,9 @@ public class CompatibilityChangeInfo implements Parcelable {
if (getLoggingOnly()) { if (getLoggingOnly()) {
sb.append("; loggingOnly"); sb.append("; loggingOnly");
} }
if (getOverridable()) {
sb.append("; overridable");
}
return sb.append(")").toString(); return sb.append(")").toString();
} }
@@ -143,8 +155,8 @@ public class CompatibilityChangeInfo implements Parcelable {
&& this.mEnableSinceTargetSdk == that.mEnableSinceTargetSdk && this.mEnableSinceTargetSdk == that.mEnableSinceTargetSdk
&& this.mDisabled == that.mDisabled && this.mDisabled == that.mDisabled
&& this.mLoggingOnly == that.mLoggingOnly && this.mLoggingOnly == that.mLoggingOnly
&& this.mDescription.equals(that.mDescription); && this.mDescription.equals(that.mDescription)
&& this.mOverridable == that.mOverridable;
} }
public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR = public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR =

View File

@@ -64,7 +64,7 @@ public final class CompatChange extends CompatibilityChangeInfo {
private Map<String, Boolean> mDeferredOverrides; private Map<String, Boolean> mDeferredOverrides;
public CompatChange(long changeId) { public CompatChange(long changeId) {
this(changeId, null, -1, -1, false, false, null); this(changeId, null, -1, -1, false, false, null, false);
} }
/** /**
@@ -77,9 +77,10 @@ public final class CompatChange extends CompatibilityChangeInfo {
* @param disabled If {@code true}, overrides any {@code enableAfterTargetSdk} set. * @param disabled If {@code true}, overrides any {@code enableAfterTargetSdk} set.
*/ */
public CompatChange(long changeId, @Nullable String name, int enableAfterTargetSdk, public CompatChange(long changeId, @Nullable String name, int enableAfterTargetSdk,
int enableSinceTargetSdk, boolean disabled, boolean loggingOnly, String description) { int enableSinceTargetSdk, boolean disabled, boolean loggingOnly, String description,
boolean overridable) {
super(changeId, name, enableAfterTargetSdk, enableSinceTargetSdk, disabled, loggingOnly, super(changeId, name, enableAfterTargetSdk, enableSinceTargetSdk, disabled, loggingOnly,
description); description, overridable);
} }
/** /**
@@ -88,7 +89,7 @@ public final class CompatChange extends CompatibilityChangeInfo {
public CompatChange(Change change) { public CompatChange(Change change) {
super(change.getId(), change.getName(), change.getEnableAfterTargetSdk(), super(change.getId(), change.getName(), change.getEnableAfterTargetSdk(),
change.getEnableSinceTargetSdk(), change.getDisabled(), change.getLoggingOnly(), change.getEnableSinceTargetSdk(), change.getDisabled(), change.getLoggingOnly(),
change.getDescription()); change.getDescription(), change.getOverridable());
} }
void registerListener(ChangeListener listener) { void registerListener(ChangeListener listener) {
@@ -274,6 +275,9 @@ public final class CompatChange extends CompatibilityChangeInfo {
if (mDeferredOverrides != null && mDeferredOverrides.size() > 0) { if (mDeferredOverrides != null && mDeferredOverrides.size() > 0) {
sb.append("; deferredOverrides=").append(mDeferredOverrides); sb.append("; deferredOverrides=").append(mDeferredOverrides);
} }
if (getOverridable()) {
sb.append("; overridable");
}
return sb.append(")").toString(); return sb.append(")").toString();
} }

View File

@@ -31,6 +31,7 @@
<xs:attribute type="xs:int" name="enableAfterTargetSdk"/> <xs:attribute type="xs:int" name="enableAfterTargetSdk"/>
<xs:attribute type="xs:int" name="enableSinceTargetSdk"/> <xs:attribute type="xs:int" name="enableSinceTargetSdk"/>
<xs:attribute type="xs:string" name="description"/> <xs:attribute type="xs:string" name="description"/>
<xs:attribute type="xs:boolean" name="overridable"/>
</xs:extension> </xs:extension>
</xs:simpleContent> </xs:simpleContent>
</xs:complexType> </xs:complexType>
@@ -48,7 +49,3 @@
</xs:unique> </xs:unique>
</xs:element> </xs:element>
</xs:schema> </xs:schema>

View File

@@ -10,6 +10,7 @@ package com.android.server.compat.config {
method public long getId(); method public long getId();
method public boolean getLoggingOnly(); method public boolean getLoggingOnly();
method public String getName(); method public String getName();
method public boolean getOverridable();
method public String getValue(); method public String getValue();
method public void setDescription(String); method public void setDescription(String);
method public void setDisabled(boolean); method public void setDisabled(boolean);
@@ -18,6 +19,7 @@ package com.android.server.compat.config {
method public void setId(long); method public void setId(long);
method public void setLoggingOnly(boolean); method public void setLoggingOnly(boolean);
method public void setName(String); method public void setName(String);
method public void setOverridable(boolean);
method public void setValue(String); method public void setValue(String);
} }

View File

@@ -40,78 +40,83 @@ class CompatConfigBuilder {
} }
CompatConfigBuilder addEnableAfterSdkChangeWithId(int sdk, long id) { CompatConfigBuilder addEnableAfterSdkChangeWithId(int sdk, long id) {
mChanges.add(new CompatChange(id, "", sdk, -1, false, false, "")); mChanges.add(new CompatChange(id, "", sdk, -1, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableAfterSdkChangeWithIdAndName(int sdk, long id, String name) { CompatConfigBuilder addEnableAfterSdkChangeWithIdAndName(int sdk, long id, String name) {
mChanges.add(new CompatChange(id, name, sdk, -1, false, false, "")); mChanges.add(new CompatChange(id, name, sdk, -1, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableAfterSdkChangeWithIdDefaultDisabled(int sdk, long id) { CompatConfigBuilder addEnableAfterSdkChangeWithIdDefaultDisabled(int sdk, long id) {
mChanges.add(new CompatChange(id, "", sdk, -1, true, false, "")); mChanges.add(new CompatChange(id, "", sdk, -1, true, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableAfterSdkChangeWithIdAndDescription(int sdk, long id, CompatConfigBuilder addEnableAfterSdkChangeWithIdAndDescription(int sdk, long id,
String description) { String description) {
mChanges.add(new CompatChange(id, "", sdk, -1, false, false, description)); mChanges.add(new CompatChange(id, "", sdk, -1, false, false, description, false));
return this; return this;
} }
CompatConfigBuilder addEnableSinceSdkChangeWithId(int sdk, long id) { CompatConfigBuilder addEnableSinceSdkChangeWithId(int sdk, long id) {
mChanges.add(new CompatChange(id, "", -1, sdk, false, false, "")); mChanges.add(new CompatChange(id, "", -1, sdk, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableSinceSdkChangeWithIdAndName(int sdk, long id, String name) { CompatConfigBuilder addEnableSinceSdkChangeWithIdAndName(int sdk, long id, String name) {
mChanges.add(new CompatChange(id, name, -1, sdk, false, false, "")); mChanges.add(new CompatChange(id, name, -1, sdk, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableSinceSdkChangeWithIdDefaultDisabled(int sdk, long id) { CompatConfigBuilder addEnableSinceSdkChangeWithIdDefaultDisabled(int sdk, long id) {
mChanges.add(new CompatChange(id, "", -1, sdk, true, false, "")); mChanges.add(new CompatChange(id, "", -1, sdk, true, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnableSinceSdkChangeWithIdAndDescription(int sdk, long id, CompatConfigBuilder addEnableSinceSdkChangeWithIdAndDescription(int sdk, long id,
String description) { String description) {
mChanges.add(new CompatChange(id, "", -1, sdk, false, false, description)); mChanges.add(new CompatChange(id, "", -1, sdk, false, false, description, false));
return this; return this;
} }
CompatConfigBuilder addEnabledChangeWithId(long id) { CompatConfigBuilder addEnabledChangeWithId(long id) {
mChanges.add(new CompatChange(id, "", -1, -1, false, false, "")); mChanges.add(new CompatChange(id, "", -1, -1, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnabledChangeWithIdAndName(long id, String name) { CompatConfigBuilder addEnabledChangeWithIdAndName(long id, String name) {
mChanges.add(new CompatChange(id, name, -1, -1, false, false, "")); mChanges.add(new CompatChange(id, name, -1, -1, false, false, "", false));
return this; return this;
} }
CompatConfigBuilder addEnabledChangeWithIdAndDescription(long id, String description) { CompatConfigBuilder addEnabledChangeWithIdAndDescription(long id, String description) {
mChanges.add(new CompatChange(id, "", -1, -1, false, false, description)); mChanges.add(new CompatChange(id, "", -1, -1, false, false, description, false));
return this; return this;
} }
CompatConfigBuilder addDisabledChangeWithId(long id) { CompatConfigBuilder addDisabledChangeWithId(long id) {
mChanges.add(new CompatChange(id, "", -1, -1, true, false, "")); mChanges.add(new CompatChange(id, "", -1, -1, true, false, "", false));
return this; return this;
} }
CompatConfigBuilder addDisabledChangeWithIdAndName(long id, String name) { CompatConfigBuilder addDisabledChangeWithIdAndName(long id, String name) {
mChanges.add(new CompatChange(id, name, -1, -1, true, false, "")); mChanges.add(new CompatChange(id, name, -1, -1, true, false, "", false));
return this; return this;
} }
CompatConfigBuilder addDisabledChangeWithIdAndDescription(long id, String description) { CompatConfigBuilder addDisabledChangeWithIdAndDescription(long id, String description) {
mChanges.add(new CompatChange(id, "", -1, -1, true, false, description)); mChanges.add(new CompatChange(id, "", -1, -1, true, false, description, false));
return this; return this;
} }
CompatConfigBuilder addLoggingOnlyChangeWithId(long id) { CompatConfigBuilder addLoggingOnlyChangeWithId(long id) {
mChanges.add(new CompatChange(id, "", -1, -1, false, true, "")); mChanges.add(new CompatChange(id, "", -1, -1, false, true, "", false));
return this;
}
CompatConfigBuilder addOverridableChangeWithId(long id) {
mChanges.add(new CompatChange(id, "", -1, -1, false, true, "", true));
return this; return this;
} }

View File

@@ -97,17 +97,22 @@ public class PlatformCompatTest {
.addEnableAfterSdkChangeWithId(Build.VERSION_CODES.Q, 5L) .addEnableAfterSdkChangeWithId(Build.VERSION_CODES.Q, 5L)
.addEnableAfterSdkChangeWithId(Build.VERSION_CODES.R, 6L) .addEnableAfterSdkChangeWithId(Build.VERSION_CODES.R, 6L)
.addLoggingOnlyChangeWithId(7L) .addLoggingOnlyChangeWithId(7L)
.addOverridableChangeWithId(8L)
.build(); .build();
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig); mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
assertThat(mPlatformCompat.listAllChanges()).asList().containsExactly( assertThat(mPlatformCompat.listAllChanges()).asList().containsExactly(
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, ""), new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, ""), new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
new CompatibilityChangeInfo(3L, "", Build.VERSION_CODES.O, -1, false, false, new CompatibilityChangeInfo(3L, "", Build.VERSION_CODES.O, -1, false, false,
"desc"), "desc", false),
new CompatibilityChangeInfo(4L, "", Build.VERSION_CODES.P, -1, false, false, ""), new CompatibilityChangeInfo(
new CompatibilityChangeInfo(5L, "", Build.VERSION_CODES.Q, -1, false, false, ""), 4L, "", Build.VERSION_CODES.P, -1, false, false, "", false),
new CompatibilityChangeInfo(6L, "", Build.VERSION_CODES.R, -1, false, false, ""), new CompatibilityChangeInfo(
new CompatibilityChangeInfo(7L, "", -1, -1, false, true, "")); 5L, "", Build.VERSION_CODES.Q, -1, false, false, "", false),
new CompatibilityChangeInfo(
6L, "", Build.VERSION_CODES.R, -1, false, false, "", false),
new CompatibilityChangeInfo(7L, "", -1, -1, false, true, "", false),
new CompatibilityChangeInfo(8L, "", -1, -1, false, true, "", true));
} }
@Test @Test
@@ -123,12 +128,12 @@ public class PlatformCompatTest {
.build(); .build();
mPlatformCompat = new PlatformCompat(mContext, mCompatConfig); mPlatformCompat = new PlatformCompat(mContext, mCompatConfig);
assertThat(mPlatformCompat.listUIChanges()).asList().containsExactly( assertThat(mPlatformCompat.listUIChanges()).asList().containsExactly(
new CompatibilityChangeInfo(1L, "", -1, -1, false, false, ""), new CompatibilityChangeInfo(1L, "", -1, -1, false, false, "", false),
new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, ""), new CompatibilityChangeInfo(2L, "change2", -1, -1, true, false, "", false),
new CompatibilityChangeInfo(5L, "", /*enableAfter*/ -1, new CompatibilityChangeInfo(
/*enableSince*/ Build.VERSION_CODES.Q, false, false, ""), 5L, "", Build.VERSION_CODES.P, -1, false, false, "", false),
new CompatibilityChangeInfo(6L, "", /*enableAfter*/ -1, new CompatibilityChangeInfo(
/*enableSince*/ Build.VERSION_CODES.R, false, false, "")); 6L, "", Build.VERSION_CODES.Q, -1, false, false, "", false));
} }
@Test @Test