Reimplement getErrorCodeFromPlatformDiagnosticsInfo to save the pattern

PiperOrigin-RevId: 382494191
This commit is contained in:
aquilescanta 2021-07-01 12:25:06 +01:00 committed by kim-vde
parent 91cb54b84e
commit a24bbbdd5e

View File

@ -145,9 +145,6 @@ public final class Util {
+ "(T(([0-9]*)H)?(([0-9]*)M)?(([0-9.]*)S)?)?$"); + "(T(([0-9]*)H)?(([0-9]*)M)?(([0-9.]*)S)?)?$");
private static final Pattern ESCAPED_CHARACTER_PATTERN = Pattern.compile("%([A-Fa-f0-9]{2})"); private static final Pattern ESCAPED_CHARACTER_PATTERN = Pattern.compile("%([A-Fa-f0-9]{2})");
/** Pattern to extract error code from platform diagnostics info. */
private static final Pattern DIAGNOSTIC_INFO_CODE_PATTERN = Pattern.compile(".*?_(neg_|)(\\d+)");
// https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-content-overview#URLs. // https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-content-overview#URLs.
private static final Pattern ISM_URL_PATTERN = Pattern.compile(".*\\.isml?(?:/(manifest(.*))?)?"); private static final Pattern ISM_URL_PATTERN = Pattern.compile(".*\\.isml?(?:/(manifest(.*))?)?");
private static final String ISM_HLS_FORMAT_EXTENSION = "format=m3u8-aapl"; private static final String ISM_HLS_FORMAT_EXTENSION = "format=m3u8-aapl";
@ -2382,19 +2379,27 @@ public final class Util {
/** /**
* Attempts to parse an error code from a diagnostic string found in framework media exceptions. * Attempts to parse an error code from a diagnostic string found in framework media exceptions.
* For example: android.media.MediaCodec.error_1 or android.media.MediaDrm.error_neg_2. *
* <p>For example: android.media.MediaCodec.error_1 or android.media.MediaDrm.error_neg_2.
*
* @param diagnosticsInfo A string from which to parse the error code.
* @return The parser error code, or 0 if an error code could not be parsed.
*/ */
public static int getErrorCodeFromPlatformDiagnosticsInfo(@Nullable String diagnosticsInfo) { public static int getErrorCodeFromPlatformDiagnosticsInfo(@Nullable String diagnosticsInfo) {
// TODO (internal b/192337376): Change 0 for ERROR_UNKNOWN once available.
if (diagnosticsInfo == null) { if (diagnosticsInfo == null) {
return 0; return 0;
} }
Matcher matcher = DIAGNOSTIC_INFO_CODE_PATTERN.matcher(diagnosticsInfo); String[] strings = split(diagnosticsInfo, "_");
if (!matcher.matches()) { int length = strings.length;
if (length < 2) {
return 0; return 0;
} }
String digitsSection = strings[length - 1];
boolean isNegative = length >= 3 && "neg".equals(strings[length - 2]);
try { try {
int errorCode = Integer.parseInt(Assertions.checkNotNull(matcher.group(2))); int errorCode = Integer.parseInt(Assertions.checkNotNull(digitsSection));
return Assertions.checkNotNull(matcher.group(1)).isEmpty() ? errorCode : -errorCode; return isNegative ? -errorCode : errorCode;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return 0; return 0;
} }