Skip to content

Commit f605165

Browse files
committed
Add database module
PiperOrigin-RevId: 405626096
1 parent a7aa674 commit f605165

File tree

21 files changed

+118
-13
lines changed

21 files changed

+118
-13
lines changed

core_settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ project(modulePrefix + 'library-ui').projectDir = new File(rootDir, 'library/ui'
5151
include modulePrefix + 'extension-leanback'
5252
project(modulePrefix + 'extension-leanback').projectDir = new File(rootDir, 'extensions/leanback')
5353

54+
include modulePrefix + 'library-database'
55+
project(modulePrefix + 'library-database').projectDir = new File(rootDir, 'library/database')
56+
5457
include modulePrefix + 'library-datasource'
5558
project(modulePrefix + 'library-datasource').projectDir = new File(rootDir, 'library/datasource')
5659
include modulePrefix + 'extension-cronet'

demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.google.android.exoplayer2.DefaultRenderersFactory;
2020
import com.google.android.exoplayer2.RenderersFactory;
2121
import com.google.android.exoplayer2.database.DatabaseProvider;
22-
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
22+
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
2323
import com.google.android.exoplayer2.ext.cronet.CronetDataSource;
2424
import com.google.android.exoplayer2.ext.cronet.CronetUtil;
2525
import com.google.android.exoplayer2.offline.ActionFileUpgradeUtil;
@@ -194,7 +194,7 @@ private static synchronized void upgradeActionFile(
194194

195195
private static synchronized DatabaseProvider getDatabaseProvider(Context context) {
196196
if (databaseProvider == null) {
197-
databaseProvider = new ExoDatabaseProvider(context);
197+
databaseProvider = new StandaloneDatabaseProvider(context);
198198
}
199199
return databaseProvider;
200200
}

docs/downloading-media.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ which can be returned by `getDownloadManager()` in your `DownloadService`:
6363

6464
~~~
6565
// Note: This should be a singleton in your app.
66-
databaseProvider = new ExoDatabaseProvider(context);
66+
databaseProvider = new StandaloneDatabaseProvider(context);
6767
6868
// A download cache should not evict media, so should use a NoopCacheEvictor.
6969
downloadCache = new SimpleCache(

library/all/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"
1515

1616
dependencies {
1717
api project(modulePrefix + 'library-common')
18+
api project(modulePrefix + 'library-database')
1819
api project(modulePrefix + 'library-datasource')
1920
api project(modulePrefix + 'library-decoder')
2021
api project(modulePrefix + 'library-extractor')

library/core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies {
4040
api project(modulePrefix + 'library-datasource')
4141
api project(modulePrefix + 'library-decoder')
4242
api project(modulePrefix + 'library-extractor')
43+
api project(modulePrefix + 'library-database')
4344
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
4445
implementation 'androidx.core:core:' + androidxCoreVersion
4546
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version

library/core/src/test/java/com/google/android/exoplayer2/offline/ActionFileUpgradeUtilTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import android.net.Uri;
2121
import androidx.test.core.app.ApplicationProvider;
2222
import androidx.test.ext.junit.runners.AndroidJUnit4;
23-
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
23+
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
2424
import com.google.android.exoplayer2.testutil.TestUtil;
2525
import com.google.android.exoplayer2.util.MimeTypes;
2626
import com.google.android.exoplayer2.util.Util;
@@ -40,13 +40,13 @@ public class ActionFileUpgradeUtilTest {
4040
private static final long NOW_MS = 1234;
4141

4242
private File tempFile;
43-
private ExoDatabaseProvider databaseProvider;
43+
private StandaloneDatabaseProvider databaseProvider;
4444
private DefaultDownloadIndex downloadIndex;
4545

4646
@Before
4747
public void setUp() throws Exception {
4848
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
49-
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
49+
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
5050
downloadIndex = new DefaultDownloadIndex(databaseProvider);
5151
}
5252

library/core/src/test/java/com/google/android/exoplayer2/offline/DefaultDownloadIndexTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import androidx.test.core.app.ApplicationProvider;
3030
import androidx.test.ext.junit.runners.AndroidJUnit4;
3131
import com.google.android.exoplayer2.database.DatabaseIOException;
32-
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
32+
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
3333
import com.google.android.exoplayer2.database.VersionTable;
3434
import com.google.android.exoplayer2.testutil.DownloadBuilder;
3535
import com.google.android.exoplayer2.testutil.TestUtil;
@@ -51,12 +51,12 @@ public class DefaultDownloadIndexTest {
5151

5252
private static final String EMPTY_NAME = "";
5353

54-
private ExoDatabaseProvider databaseProvider;
54+
private StandaloneDatabaseProvider databaseProvider;
5555
private DefaultDownloadIndex downloadIndex;
5656

5757
@Before
5858
public void setUp() {
59-
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
59+
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
6060
downloadIndex = new DefaultDownloadIndex(databaseProvider);
6161
}
6262

@@ -222,7 +222,7 @@ public void downloadIndex_versionDowngradeWipesData() throws DatabaseIOException
222222
@Test
223223
public void downloadIndex_upgradesFromVersion2() throws IOException {
224224
Context context = ApplicationProvider.getApplicationContext();
225-
File databaseFile = context.getDatabasePath(ExoDatabaseProvider.DATABASE_NAME);
225+
File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
226226
try (FileOutputStream output = new FileOutputStream(databaseFile)) {
227227
output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
228228
}
@@ -251,7 +251,7 @@ public void downloadIndex_upgradesFromVersion2() throws IOException {
251251
ImmutableList.of(),
252252
/* customCacheKey= */ "customCacheKey");
253253

254-
databaseProvider = new ExoDatabaseProvider(context);
254+
databaseProvider = new StandaloneDatabaseProvider(context);
255255
downloadIndex = new DefaultDownloadIndex(databaseProvider);
256256

257257
assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);

library/database/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Common module
2+
3+
Provides database functionality for use by other media modules. Application code
4+
will not normally need to depend on this module directly.
5+
6+
## Links
7+
8+
* [Javadoc][]
9+
10+
[Javadoc]: https://exoplayer.dev/doc/reference/index.html

library/database/build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (C) 2021 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"
15+
16+
android {
17+
buildTypes {
18+
debug {
19+
testCoverageEnabled = true
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
implementation project(modulePrefix + 'library-common')
26+
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
27+
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
28+
testImplementation 'androidx.test:core:' + androidxTestCoreVersion
29+
testImplementation 'androidx.test.ext:junit:' + androidxTestJUnitVersion
30+
testImplementation 'com.google.truth:truth:' + truthVersion
31+
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
32+
testImplementation project(modulePrefix + 'testutils')
33+
}
34+
35+
ext {
36+
javadocTitle = 'Database module'
37+
}
38+
apply from: '../../javadoc_library.gradle'
39+
40+
ext {
41+
releaseArtifactId = 'exoplayer-database'
42+
releaseDescription = 'The ExoPlayer database module.'
43+
}
44+
apply from: '../../publish.gradle'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
xml version="1.0" encoding="utf-8"?>
2+
16+
17+
<manifest package="com.google.android.exoplayer2.database">
18+
<uses-sdk/>
19+
manifest>

library/common/src/main/java/com/google/android/exoplayer2/database/VersionTable.java renamed to library/database/src/main/java/com/google/android/exoplayer2/database/VersionTable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.database.SQLException;
2121
import android.database.sqlite.SQLiteDatabase;
2222
import androidx.annotation.IntDef;
23+
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
2324
import com.google.android.exoplayer2.util.Util;
2425
import java.lang.annotation.Documented;
2526
import java.lang.annotation.Retention;
@@ -31,6 +32,10 @@
3132
*/
3233
public final class VersionTable {
3334

35+
static {
36+
ExoPlayerLibraryInfo.registerModule("goog.exo.database");
37+
}
38+
3439
/** Returned by {@link #getVersion(SQLiteDatabase, int, String)} if the version is unset. */
3540
public static final int VERSION_UNSET = -1;
3641
/** Version of tables used for offline functionality. */
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
xml version="1.0" encoding="utf-8"?>
2+
16+
17+
<manifest package="com.google.android.exoplayer2.database">
18+
<uses-sdk/>
19+
manifest>

library/datasource/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ android {
3232

3333
dependencies {
3434
implementation project(modulePrefix + 'library-common')
35+
implementation project(modulePrefix + 'library-database')
3536
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
3637
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
3738
compileOnly 'com.google.errorprone:error_prone_annotations:' + errorProneVersion

playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import androidx.test.ext.junit.runners.AndroidJUnit4;
2222
import androidx.test.rule.ActivityTestRule;
2323
import com.google.android.exoplayer2.MediaItem;
24-
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
24+
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
2525
import com.google.android.exoplayer2.offline.StreamKey;
2626
import com.google.android.exoplayer2.source.dash.DashUtil;
2727
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
@@ -72,7 +72,9 @@ public void setUp() throws Exception {
7272
tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
7373
cache =
7474
new SimpleCache(
75-
tempFolder, new NoOpCacheEvictor(), new ExoDatabaseProvider(testRule.getActivity()));
75+
tempFolder,
76+
new NoOpCacheEvictor(),
77+
new StandaloneDatabaseProvider(testRule.getActivity()));
7678
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
7779
offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
7880
}

0 commit comments

Comments
 (0)