Merge "Add support for "empty" server-side flag values"

This commit is contained in:
Neil Fuller
2022-06-10 13:45:05 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 4 deletions

View File

@@ -278,11 +278,19 @@ public final class ServerFlags {
*/
@NonNull
public Optional<String[]> getOptionalStringArray(@DeviceConfigKey String key) {
Optional<String> string = getOptionalString(key);
if (!string.isPresent()) {
Optional<String> optionalString = getOptionalString(key);
if (!optionalString.isPresent()) {
return Optional.empty();
}
return Optional.of(string.get().split(","));
// DeviceConfig appears to have no way to specify an empty string, so we use "_[]_" as a
// special value to mean a zero-length array.
String value = optionalString.get();
if ("_[]_".equals(value)) {
return Optional.of(new String[0]);
}
return Optional.of(value.split(","));
}
/**

View File

@@ -334,7 +334,7 @@ final class ServiceConfigAccessorImpl implements ServiceConfigAccessor {
}
int[] priorityInts = null;
if (priorityStrings != null && priorityStrings.length > 0) {
if (priorityStrings != null) {
priorityInts = new int[priorityStrings.length];
try {
for (int i = 0; i < priorityInts.length; i++) {