From 7e30091196e578cf3eca2b56acabe83e14268736 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 15 May 2023 10:41:09 +0100 Subject: [PATCH] Remove two deprecated `SimpleCache` constructors Use a non-deprecated constructor that takes a `DatabaseProvider` instead for better performance. #minor-release PiperOrigin-RevId: 532046598 (cherry picked from commit 0a86790be25527c45b0070cd0d4a1089b2069108) --- RELEASENOTES.md | 4 ++ .../media3/datasource/cache/SimpleCache.java | 40 +----------- .../datasource/cache/SimpleCacheTest.java | 62 ------------------- 3 files changed, 6 insertions(+), 100 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5ff4de3f60..ac3dc63cf9 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,10 @@ implement playback resumption with media button events sent by, for example, a Bluetooth headset ([#167](https://github.com/androidx/media/issues/167)). +* Remove deprecated symbols: + * Remove two deprecated `SimpleCache` constructors, use a non-deprecated + constructor that takes a `DatabaseProvider` instead for better + performance. ### 1.1.0-alpha01 (2023-05-10) diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/cache/SimpleCache.java b/libraries/datasource/src/main/java/androidx/media3/datasource/cache/SimpleCache.java index 5bb81d239b..a6268598a1 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/cache/SimpleCache.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/cache/SimpleCache.java @@ -138,48 +138,12 @@ public final class SimpleCache implements Cache { @Deprecated @SuppressWarnings("deprecation") public SimpleCache(File cacheDir, CacheEvictor evictor) { - this(cacheDir, evictor, null, false); - } - - /** - * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence - * the directory cannot be used to store other files. - * - * @param cacheDir A dedicated cache directory. - * @param evictor The evictor to be used. For download use cases where cache eviction should not - * occur, use {@link NoOpCacheEvictor}. - * @param secretKey If not null, cache keys will be stored encrypted on filesystem using AES/CBC. - * The key must be 16 bytes long. - * @deprecated Use a constructor that takes a {@link DatabaseProvider} for improved performance. - */ - @Deprecated - @SuppressWarnings("deprecation") - public SimpleCache(File cacheDir, CacheEvictor evictor, @Nullable byte[] secretKey) { - this(cacheDir, evictor, secretKey, secretKey != null); - } - - /** - * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence - * the directory cannot be used to store other files. - * - * @param cacheDir A dedicated cache directory. - * @param evictor The evictor to be used. For download use cases where cache eviction should not - * occur, use {@link NoOpCacheEvictor}. - * @param secretKey If not null, cache keys will be stored encrypted on filesystem using AES/CBC. - * The key must be 16 bytes long. - * @param encrypt Whether the index will be encrypted when written. Must be false if {@code - * secretKey} is null. - * @deprecated Use a constructor that takes a {@link DatabaseProvider} for improved performance. - */ - @Deprecated - public SimpleCache( - File cacheDir, CacheEvictor evictor, @Nullable byte[] secretKey, boolean encrypt) { this( cacheDir, evictor, /* databaseProvider= */ null, - secretKey, - encrypt, + /* legacyIndexSecretKey= */ null, + /* legacyIndexEncrypt= */ false, /* preferLegacyIndex= */ true); } diff --git a/libraries/datasource/src/test/java/androidx/media3/datasource/cache/SimpleCacheTest.java b/libraries/datasource/src/test/java/androidx/media3/datasource/cache/SimpleCacheTest.java index 8d384d7e56..758921e2d3 100644 --- a/libraries/datasource/src/test/java/androidx/media3/datasource/cache/SimpleCacheTest.java +++ b/libraries/datasource/src/test/java/androidx/media3/datasource/cache/SimpleCacheTest.java @@ -44,7 +44,6 @@ import org.mockito.Mockito; @RunWith(AndroidJUnit4.class) public class SimpleCacheTest { - private static final byte[] ENCRYPTED_INDEX_KEY = Util.getUtf8Bytes("Bar12345Bar12345"); private static final String KEY_1 = "key1"; private static final String KEY_2 = "key2"; @@ -204,61 +203,6 @@ public class SimpleCacheTest { assertThat(simpleCache.getCachedSpans(KEY_1)).isEmpty(); } - @Test - @SuppressWarnings("deprecation") // Encrypted index is deprecated - public void newInstance_withEncryptedIndex() throws Exception { - SimpleCache simpleCache = getEncryptedSimpleCache(ENCRYPTED_INDEX_KEY); - CacheSpan holeSpan = simpleCache.startReadWrite(KEY_1, 0, LENGTH_UNSET); - addCache(simpleCache, KEY_1, 0, 15); - simpleCache.releaseHoleSpan(holeSpan); - simpleCache.release(); - - // Create a new instance pointing to the same directory. - simpleCache = getEncryptedSimpleCache(ENCRYPTED_INDEX_KEY); - - // Read the cached data back. - CacheSpan fileSpan = simpleCache.startReadWrite(KEY_1, 0, LENGTH_UNSET); - assertCachedDataReadCorrect(fileSpan); - } - - @Test - @SuppressWarnings("deprecation") // Encrypted index is deprecated - public void newInstance_withEncryptedIndexAndWrongKey_clearsCache() throws Exception { - SimpleCache simpleCache = getEncryptedSimpleCache(ENCRYPTED_INDEX_KEY); - - // Write data. - CacheSpan holeSpan = simpleCache.startReadWrite(KEY_1, 0, LENGTH_UNSET); - addCache(simpleCache, KEY_1, 0, 15); - simpleCache.releaseHoleSpan(holeSpan); - simpleCache.release(); - - // Create a new instance pointing to the same directory, with a different key. - simpleCache = getEncryptedSimpleCache(Util.getUtf8Bytes("Foo12345Foo12345")); - - // Cache should be cleared. - assertThat(simpleCache.getKeys()).isEmpty(); - assertNoCacheFiles(cacheDir); - } - - @Test - @SuppressWarnings("deprecation") // Encrypted index is deprecated - public void newInstance_withEncryptedIndexAndNoKey_clearsCache() throws Exception { - SimpleCache simpleCache = getEncryptedSimpleCache(ENCRYPTED_INDEX_KEY); - - // Write data. - CacheSpan holeSpan = simpleCache.startReadWrite(KEY_1, 0, LENGTH_UNSET); - addCache(simpleCache, KEY_1, 0, 15); - simpleCache.releaseHoleSpan(holeSpan); - simpleCache.release(); - - // Create a new instance pointing to the same directory, with no key. - simpleCache = getSimpleCache(); - - // Cache should be cleared. - assertThat(simpleCache.getKeys()).isEmpty(); - assertNoCacheFiles(cacheDir); - } - @Test public void write_oneLock_oneFile_thenRead() throws Exception { SimpleCache simpleCache = getSimpleCache(); @@ -689,12 +633,6 @@ public class SimpleCacheTest { return new SimpleCache(cacheDir, new NoOpCacheEvictor(), databaseProvider); } - @Deprecated - @SuppressWarnings("deprecation") // Testing deprecated behaviour. - private SimpleCache getEncryptedSimpleCache(byte[] secretKey) { - return new SimpleCache(cacheDir, new NoOpCacheEvictor(), secretKey); - } - private static void addCache(SimpleCache simpleCache, String key, int position, int length) throws IOException { File file = simpleCache.startFile(key, position, length);