mirror of
https://github.com/samsonjs/media.git
synced 2026-04-06 11:25:46 +00:00
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 0a86790be2)
This commit is contained in:
parent
07ca741eb1
commit
7e30091196
3 changed files with 6 additions and 100 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue