diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java index 809f15b5a63..d0a9bc13c13 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java @@ -99,7 +99,7 @@ public CachedContentIndex(File cacheDir, byte[] secretKey, boolean encrypt) { if (secretKey != null) { Assertions.checkArgument(secretKey.length == 16); try { - cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); + cipher = getCipher(); secretKeySpec = new SecretKeySpec(secretKey, "AES"); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { throw new IllegalStateException(e); // Should never happen. @@ -354,6 +354,18 @@ private CachedContent addNew(String key, long length) { return cachedContent; } + private static Cipher getCipher() throws NoSuchPaddingException, NoSuchAlgorithmException { + // Workaround for https://issuetracker.google.com/issues/36976726 + if (Util.SDK_INT == 18) { + try { + return Cipher.getInstance("AES/CBC/PKCS5PADDING", "BC"); + } catch (Throwable ignored) { + // ignored + } + } + return Cipher.getInstance("AES/CBC/PKCS5PADDING"); + } + /** * Returns an id which isn't used in the given array. If the maximum id in the array is smaller * than {@link java.lang.Integer#MAX_VALUE} it just returns the next bigger integer. Otherwise it