Skip to content

Commit

Permalink
Add database module
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 405626096
  • Loading branch information
ojw28 committed Oct 26, 2021
1 parent a7aa674 commit f605165
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 13 deletions.
3 changes: 3 additions & 0 deletions core_settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ project(modulePrefix + 'library-ui').projectDir = new File(rootDir, 'library/ui'
include modulePrefix + 'extension-leanback'
project(modulePrefix + 'extension-leanback').projectDir = new File(rootDir, 'extensions/leanback')

include modulePrefix + 'library-database'
project(modulePrefix + 'library-database').projectDir = new File(rootDir, 'library/database')

include modulePrefix + 'library-datasource'
project(modulePrefix + 'library-datasource').projectDir = new File(rootDir, 'library/datasource')
include modulePrefix + 'extension-cronet'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.database.DatabaseProvider;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
import com.google.android.exoplayer2.ext.cronet.CronetDataSource;
import com.google.android.exoplayer2.ext.cronet.CronetUtil;
import com.google.android.exoplayer2.offline.ActionFileUpgradeUtil;
Expand Down Expand Up @@ -194,7 +194,7 @@ private static synchronized void upgradeActionFile(

private static synchronized DatabaseProvider getDatabaseProvider(Context context) {
if (databaseProvider == null) {
databaseProvider = new ExoDatabaseProvider(context);
databaseProvider = new StandaloneDatabaseProvider(context);
}
return databaseProvider;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/downloading-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ which can be returned by `getDownloadManager()` in your `DownloadService`:

~~~
// Note: This should be a singleton in your app.
databaseProvider = new ExoDatabaseProvider(context);
databaseProvider = new StandaloneDatabaseProvider(context);
// A download cache should not evict media, so should use a NoopCacheEvictor.
downloadCache = new SimpleCache(
Expand Down
1 change: 1 addition & 0 deletions library/all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"

dependencies {
api project(modulePrefix + 'library-common')
api project(modulePrefix + 'library-database')
api project(modulePrefix + 'library-datasource')
api project(modulePrefix + 'library-decoder')
api project(modulePrefix + 'library-extractor')
Expand Down
1 change: 1 addition & 0 deletions library/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
api project(modulePrefix + 'library-datasource')
api project(modulePrefix + 'library-decoder')
api project(modulePrefix + 'library-extractor')
api project(modulePrefix + 'library-database')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
implementation 'androidx.core:core:' + androidxCoreVersion
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
Expand All @@ -40,13 +40,13 @@ public class ActionFileUpgradeUtilTest {
private static final long NOW_MS = 1234;

private File tempFile;
private ExoDatabaseProvider databaseProvider;
private StandaloneDatabaseProvider databaseProvider;
private DefaultDownloadIndex downloadIndex;

@Before
public void setUp() throws Exception {
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
downloadIndex = new DefaultDownloadIndex(databaseProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.database.DatabaseIOException;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
import com.google.android.exoplayer2.database.VersionTable;
import com.google.android.exoplayer2.testutil.DownloadBuilder;
import com.google.android.exoplayer2.testutil.TestUtil;
Expand All @@ -51,12 +51,12 @@ public class DefaultDownloadIndexTest {

private static final String EMPTY_NAME = "";

private ExoDatabaseProvider databaseProvider;
private StandaloneDatabaseProvider databaseProvider;
private DefaultDownloadIndex downloadIndex;

@Before
public void setUp() {
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
downloadIndex = new DefaultDownloadIndex(databaseProvider);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ public void downloadIndex_versionDowngradeWipesData() throws DatabaseIOException
@Test
public void downloadIndex_upgradesFromVersion2() throws IOException {
Context context = ApplicationProvider.getApplicationContext();
File databaseFile = context.getDatabasePath(ExoDatabaseProvider.DATABASE_NAME);
File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
try (FileOutputStream output = new FileOutputStream(databaseFile)) {
output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public void downloadIndex_upgradesFromVersion2() throws IOException {
ImmutableList.of(),
/* customCacheKey= */ "customCacheKey");

databaseProvider = new ExoDatabaseProvider(context);
databaseProvider = new StandaloneDatabaseProvider(context);
downloadIndex = new DefaultDownloadIndex(databaseProvider);

assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
Expand Down
10 changes: 10 additions & 0 deletions library/database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Common module

Provides database functionality for use by other media modules. Application code
will not normally need to depend on this module directly.

## Links

* [Javadoc][]

[Javadoc]: https://exoplayer.dev/doc/reference/index.html
44 changes: 44 additions & 0 deletions library/database/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2021 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"

android {
buildTypes {
debug {
testCoverageEnabled = true
}
}
}

dependencies {
implementation project(modulePrefix + 'library-common')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
testImplementation 'androidx.test:core:' + androidxTestCoreVersion
testImplementation 'androidx.test.ext:junit:' + androidxTestJUnitVersion
testImplementation 'com.google.truth:truth:' + truthVersion
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
testImplementation project(modulePrefix + 'testutils')
}

ext {
javadocTitle = 'Database module'
}
apply from: '../../javadoc_library.gradle'

ext {
releaseArtifactId = 'exoplayer-database'
releaseDescription = 'The ExoPlayer database module.'
}
apply from: '../../publish.gradle'
19 changes: 19 additions & 0 deletions library/database/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<manifest package="com.google.android.exoplayer2.database">
<uses-sdk/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.IntDef;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
Expand All @@ -31,6 +32,10 @@
*/
public final class VersionTable {

static {
ExoPlayerLibraryInfo.registerModule("goog.exo.database");
}

/** Returned by {@link #getVersion(SQLiteDatabase, int, String)} if the version is unset. */
public static final int VERSION_UNSET = -1;
/** Version of tables used for offline functionality. */
Expand Down
19 changes: 19 additions & 0 deletions library/database/src/test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<manifest package="com.google.android.exoplayer2.database">
<uses-sdk/>
</manifest>
1 change: 1 addition & 0 deletions library/datasource/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ android {

dependencies {
implementation project(modulePrefix + 'library-common')
implementation project(modulePrefix + 'library-database')
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
compileOnly 'com.google.errorprone:error_prone_annotations:' + errorProneVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.source.dash.DashUtil;
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
Expand Down Expand Up @@ -72,7 +72,9 @@ public void setUp() throws Exception {
tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
cache =
new SimpleCache(
tempFolder, new NoOpCacheEvictor(), new ExoDatabaseProvider(testRule.getActivity()));
tempFolder,
new NoOpCacheEvictor(),
new StandaloneDatabaseProvider(testRule.getActivity()));
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
}
Expand Down

0 comments on commit f605165

Please sign in to comment.