From f3dbb746134b0eb2d56b7fdb721d9f5e810e2707 Mon Sep 17 00:00:00 2001 From: eguven Date: Thu, 1 Dec 2016 03:55:01 -0800 Subject: [PATCH] Fix unnecessary rewrite of cache index file after CachedContentIndex.readFile() Prevented readFile() setting "changed" boolean to true every time. It's set only if encryption key is set but the index file isn't encrypted. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140714173 --- .../upstream/cache/CachedContentIndex.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java index a4a97b4332..3180c2ad2d 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CachedContentIndex.java @@ -235,13 +235,17 @@ import javax.crypto.spec.SecretKeySpec; throw new IllegalStateException(e); } input = new DataInputStream(new CipherInputStream(inputStream, cipher)); + } else { + if (cipher != null) { + changed = true; // Force index to be rewritten encrypted after read. + } } int count = input.readInt(); int hashCode = 0; for (int i = 0; i < count; i++) { CachedContent cachedContent = new CachedContent(input); - addNew(cachedContent); + add(cachedContent); hashCode += cachedContent.headerHashCode(); } if (input.readInt() != hashCode) { @@ -302,10 +306,14 @@ import javax.crypto.spec.SecretKeySpec; } } - /** Adds the given CachedContent to the index. */ - /*package*/ void addNew(CachedContent cachedContent) { + private void add(CachedContent cachedContent) { keyToContent.put(cachedContent.key, cachedContent); idToKey.put(cachedContent.id, cachedContent.key); + } + + /** Adds the given CachedContent to the index. */ + /*package*/ void addNew(CachedContent cachedContent) { + add(cachedContent); changed = true; }