Add abstract getValue() for class SvcParam
The return type of getValue() in each child class of SvcParam is
checked at compilation time.
Bug: 240259333
Test: atest ConnectivityCoverageTests
Change-Id: Ia677f31a32f40512793cf16a94f64da499594b1f
diff --git a/staticlibs/framework/com/android/net/module/util/DnsSvcbRecord.java b/staticlibs/framework/com/android/net/module/util/DnsSvcbRecord.java
index 669725c..935cdf6 100644
--- a/staticlibs/framework/com/android/net/module/util/DnsSvcbRecord.java
+++ b/staticlibs/framework/com/android/net/module/util/DnsSvcbRecord.java
@@ -230,7 +230,7 @@
/**
* The base class for all SvcParam.
*/
- private abstract static class SvcParam {
+ private abstract static class SvcParam<T> {
private final int mKey;
SvcParam(int key) {
@@ -240,9 +240,11 @@
int getKey() {
return mKey;
}
+
+ abstract T getValue();
}
- private static class SvcParamMandatory extends SvcParam {
+ private static class SvcParamMandatory extends SvcParam<short[]> {
private final short[] mValue;
private SvcParamMandatory(@NonNull ByteBuffer buf) throws BufferUnderflowException,
@@ -258,6 +260,12 @@
}
@Override
+ short[] getValue() {
+ /* Not yet implemented */
+ return null;
+ }
+
+ @Override
public String toString() {
final StringJoiner valueJoiner = new StringJoiner(",");
for (short key : mValue) {
@@ -267,7 +275,7 @@
}
}
- private static class SvcParamAlpn extends SvcParam {
+ private static class SvcParamAlpn extends SvcParam<List<String>> {
private final List<String> mValue;
SvcParamAlpn(@NonNull ByteBuffer buf) throws BufferUnderflowException, ParseException {
@@ -281,6 +289,7 @@
}
}
+ @Override
List<String> getValue() {
return Collections.unmodifiableList(mValue);
}
@@ -291,7 +300,7 @@
}
}
- private static class SvcParamNoDefaultAlpn extends SvcParam {
+ private static class SvcParamNoDefaultAlpn extends SvcParam<Void> {
SvcParamNoDefaultAlpn(@NonNull ByteBuffer buf) throws BufferUnderflowException,
ParseException {
super(KEY_NO_DEFAULT_ALPN);
@@ -303,12 +312,17 @@
}
@Override
+ Void getValue() {
+ return null;
+ }
+
+ @Override
public String toString() {
return toKeyName(getKey());
}
}
- private static class SvcParamPort extends SvcParam {
+ private static class SvcParamPort extends SvcParam<Integer> {
private final int mValue;
SvcParamPort(@NonNull ByteBuffer buf) throws BufferUnderflowException, ParseException {
@@ -321,7 +335,8 @@
mValue = Short.toUnsignedInt(buf.getShort());
}
- int getValue() {
+ @Override
+ Integer getValue() {
return mValue;
}
@@ -331,7 +346,7 @@
}
}
- private static class SvcParamIpHint extends SvcParam {
+ private static class SvcParamIpHint extends SvcParam<List<InetAddress>> {
private final List<InetAddress> mValue;
private SvcParamIpHint(int key, @NonNull ByteBuffer buf, int addrLen) throws
@@ -346,6 +361,7 @@
}
}
+ @Override
List<InetAddress> getValue() {
return Collections.unmodifiableList(mValue);
}
@@ -378,7 +394,7 @@
}
}
- private static class SvcParamDohPath extends SvcParam {
+ private static class SvcParamDohPath extends SvcParam<String> {
private final String mValue;
SvcParamDohPath(@NonNull ByteBuffer buf) throws BufferUnderflowException, ParseException {
@@ -390,6 +406,7 @@
mValue = new String(value, StandardCharsets.UTF_8);
}
+ @Override
String getValue() {
return mValue;
}
@@ -401,7 +418,7 @@
}
// For other unrecognized and unimplemented SvcParams, they are stored as SvcParamGeneric.
- private static class SvcParamGeneric extends SvcParam {
+ private static class SvcParamGeneric extends SvcParam<byte[]> {
private final byte[] mValue;
SvcParamGeneric(int key, @NonNull ByteBuffer buf) throws BufferUnderflowException,
@@ -414,6 +431,12 @@
}
@Override
+ byte[] getValue() {
+ /* Not yet implemented */
+ return null;
+ }
+
+ @Override
public String toString() {
final StringBuilder out = new StringBuilder();
out.append(toKeyName(getKey()));