Commit f6051654 by olly Committed by Oliver Woodman

Add database module

PiperOrigin-RevId: 405626096
parent a7aa674a
Showing with 118 additions and 13 deletions
......@@ -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'
......
......@@ -19,7 +19,7 @@ import android.content.Context;
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;
......@@ -194,7 +194,7 @@ public final class DemoUtil {
private static synchronized DatabaseProvider getDatabaseProvider(Context context) {
if (databaseProvider == null) {
databaseProvider = new ExoDatabaseProvider(context);
databaseProvider = new StandaloneDatabaseProvider(context);
}
return databaseProvider;
}
......
......@@ -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(
......
......@@ -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')
......
......@@ -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
......
......@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
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;
......@@ -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);
}
......
......@@ -29,7 +29,7 @@ import androidx.annotation.Nullable;
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;
......@@ -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);
}
......@@ -222,7 +222,7 @@ public class DefaultDownloadIndexTest {
@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"));
}
......@@ -251,7 +251,7 @@ public class DefaultDownloadIndexTest {
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);
......
# 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
// 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'
<?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>
......@@ -20,6 +20,7 @@ import android.database.Cursor;
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;
......@@ -31,6 +32,10 @@ import java.lang.annotation.RetentionPolicy;
*/
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. */
......
<?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>
......@@ -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
......
......@@ -21,7 +21,7 @@ import android.net.Uri;
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;
......@@ -72,7 +72,9 @@ public final class DashDownloadTest {
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment