Add database module
PiperOrigin-RevId: 405626096
This commit is contained in:
parent
a7aa674a29
commit
f605165430
@ -51,6 +51,9 @@ project(modulePrefix + 'library-ui').projectDir = new File(rootDir, 'library/ui'
|
|||||||
include modulePrefix + 'extension-leanback'
|
include modulePrefix + 'extension-leanback'
|
||||||
project(modulePrefix + 'extension-leanback').projectDir = new File(rootDir, 'extensions/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'
|
include modulePrefix + 'library-datasource'
|
||||||
project(modulePrefix + 'library-datasource').projectDir = new File(rootDir, 'library/datasource')
|
project(modulePrefix + 'library-datasource').projectDir = new File(rootDir, 'library/datasource')
|
||||||
include modulePrefix + 'extension-cronet'
|
include modulePrefix + 'extension-cronet'
|
||||||
|
@ -19,7 +19,7 @@ import android.content.Context;
|
|||||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||||
import com.google.android.exoplayer2.RenderersFactory;
|
import com.google.android.exoplayer2.RenderersFactory;
|
||||||
import com.google.android.exoplayer2.database.DatabaseProvider;
|
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.CronetDataSource;
|
||||||
import com.google.android.exoplayer2.ext.cronet.CronetUtil;
|
import com.google.android.exoplayer2.ext.cronet.CronetUtil;
|
||||||
import com.google.android.exoplayer2.offline.ActionFileUpgradeUtil;
|
import com.google.android.exoplayer2.offline.ActionFileUpgradeUtil;
|
||||||
@ -194,7 +194,7 @@ public final class DemoUtil {
|
|||||||
|
|
||||||
private static synchronized DatabaseProvider getDatabaseProvider(Context context) {
|
private static synchronized DatabaseProvider getDatabaseProvider(Context context) {
|
||||||
if (databaseProvider == null) {
|
if (databaseProvider == null) {
|
||||||
databaseProvider = new ExoDatabaseProvider(context);
|
databaseProvider = new StandaloneDatabaseProvider(context);
|
||||||
}
|
}
|
||||||
return databaseProvider;
|
return databaseProvider;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ which can be returned by `getDownloadManager()` in your `DownloadService`:
|
|||||||
|
|
||||||
~~~
|
~~~
|
||||||
// Note: This should be a singleton in your app.
|
// 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.
|
// A download cache should not evict media, so should use a NoopCacheEvictor.
|
||||||
downloadCache = new SimpleCache(
|
downloadCache = new SimpleCache(
|
||||||
|
@ -15,6 +15,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(modulePrefix + 'library-common')
|
api project(modulePrefix + 'library-common')
|
||||||
|
api project(modulePrefix + 'library-database')
|
||||||
api project(modulePrefix + 'library-datasource')
|
api project(modulePrefix + 'library-datasource')
|
||||||
api project(modulePrefix + 'library-decoder')
|
api project(modulePrefix + 'library-decoder')
|
||||||
api project(modulePrefix + 'library-extractor')
|
api project(modulePrefix + 'library-extractor')
|
||||||
|
@ -40,6 +40,7 @@ dependencies {
|
|||||||
api project(modulePrefix + 'library-datasource')
|
api project(modulePrefix + 'library-datasource')
|
||||||
api project(modulePrefix + 'library-decoder')
|
api project(modulePrefix + 'library-decoder')
|
||||||
api project(modulePrefix + 'library-extractor')
|
api project(modulePrefix + 'library-extractor')
|
||||||
|
api project(modulePrefix + 'library-database')
|
||||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||||
implementation 'androidx.core:core:' + androidxCoreVersion
|
implementation 'androidx.core:core:' + androidxCoreVersion
|
||||||
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
||||||
|
@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
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.testutil.TestUtil;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
@ -40,13 +40,13 @@ public class ActionFileUpgradeUtilTest {
|
|||||||
private static final long NOW_MS = 1234;
|
private static final long NOW_MS = 1234;
|
||||||
|
|
||||||
private File tempFile;
|
private File tempFile;
|
||||||
private ExoDatabaseProvider databaseProvider;
|
private StandaloneDatabaseProvider databaseProvider;
|
||||||
private DefaultDownloadIndex downloadIndex;
|
private DefaultDownloadIndex downloadIndex;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
|
tempFile = Util.createTempFile(ApplicationProvider.getApplicationContext(), "ExoPlayerTest");
|
||||||
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
|
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
|
||||||
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.database.DatabaseIOException;
|
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.database.VersionTable;
|
||||||
import com.google.android.exoplayer2.testutil.DownloadBuilder;
|
import com.google.android.exoplayer2.testutil.DownloadBuilder;
|
||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
@ -51,12 +51,12 @@ public class DefaultDownloadIndexTest {
|
|||||||
|
|
||||||
private static final String EMPTY_NAME = "";
|
private static final String EMPTY_NAME = "";
|
||||||
|
|
||||||
private ExoDatabaseProvider databaseProvider;
|
private StandaloneDatabaseProvider databaseProvider;
|
||||||
private DefaultDownloadIndex downloadIndex;
|
private DefaultDownloadIndex downloadIndex;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
databaseProvider = new ExoDatabaseProvider(ApplicationProvider.getApplicationContext());
|
databaseProvider = new StandaloneDatabaseProvider(ApplicationProvider.getApplicationContext());
|
||||||
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ public class DefaultDownloadIndexTest {
|
|||||||
@Test
|
@Test
|
||||||
public void downloadIndex_upgradesFromVersion2() throws IOException {
|
public void downloadIndex_upgradesFromVersion2() throws IOException {
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
File databaseFile = context.getDatabasePath(ExoDatabaseProvider.DATABASE_NAME);
|
File databaseFile = context.getDatabasePath(StandaloneDatabaseProvider.DATABASE_NAME);
|
||||||
try (FileOutputStream output = new FileOutputStream(databaseFile)) {
|
try (FileOutputStream output = new FileOutputStream(databaseFile)) {
|
||||||
output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
|
output.write(TestUtil.getByteArray(context, "media/offline/exoplayer_internal_v2.db"));
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ public class DefaultDownloadIndexTest {
|
|||||||
ImmutableList.of(),
|
ImmutableList.of(),
|
||||||
/* customCacheKey= */ "customCacheKey");
|
/* customCacheKey= */ "customCacheKey");
|
||||||
|
|
||||||
databaseProvider = new ExoDatabaseProvider(context);
|
databaseProvider = new StandaloneDatabaseProvider(context);
|
||||||
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
downloadIndex = new DefaultDownloadIndex(databaseProvider);
|
||||||
|
|
||||||
assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
|
assertEqual(downloadIndex.getDownload("http://www.test.com/manifest.mpd"), dashDownload);
|
||||||
|
10
library/database/README.md
Normal file
10
library/database/README.md
Normal file
@ -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
library/database/build.gradle
Normal file
44
library/database/build.gradle
Normal file
@ -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
library/database/src/main/AndroidManifest.xml
Normal file
19
library/database/src/main/AndroidManifest.xml
Normal file
@ -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>
|
@ -20,6 +20,7 @@ import android.database.Cursor;
|
|||||||
import android.database.SQLException;
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -31,6 +32,10 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
*/
|
*/
|
||||||
public final class VersionTable {
|
public final class VersionTable {
|
||||||
|
|
||||||
|
static {
|
||||||
|
ExoPlayerLibraryInfo.registerModule("goog.exo.database");
|
||||||
|
}
|
||||||
|
|
||||||
/** Returned by {@link #getVersion(SQLiteDatabase, int, String)} if the version is unset. */
|
/** Returned by {@link #getVersion(SQLiteDatabase, int, String)} if the version is unset. */
|
||||||
public static final int VERSION_UNSET = -1;
|
public static final int VERSION_UNSET = -1;
|
||||||
/** Version of tables used for offline functionality. */
|
/** Version of tables used for offline functionality. */
|
19
library/database/src/test/AndroidManifest.xml
Normal file
19
library/database/src/test/AndroidManifest.xml
Normal file
@ -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>
|
@ -32,6 +32,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(modulePrefix + 'library-common')
|
implementation project(modulePrefix + 'library-common')
|
||||||
|
implementation project(modulePrefix + 'library-database')
|
||||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||||
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
||||||
compileOnly 'com.google.errorprone:error_prone_annotations:' + errorProneVersion
|
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.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.rule.ActivityTestRule;
|
import androidx.test.rule.ActivityTestRule;
|
||||||
import com.google.android.exoplayer2.MediaItem;
|
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.offline.StreamKey;
|
||||||
import com.google.android.exoplayer2.source.dash.DashUtil;
|
import com.google.android.exoplayer2.source.dash.DashUtil;
|
||||||
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
|
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
|
||||||
@ -72,7 +72,9 @@ public final class DashDownloadTest {
|
|||||||
tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
|
tempFolder = Util.createTempDirectory(testRule.getActivity(), "ExoPlayerTest");
|
||||||
cache =
|
cache =
|
||||||
new SimpleCache(
|
new SimpleCache(
|
||||||
tempFolder, new NoOpCacheEvictor(), new ExoDatabaseProvider(testRule.getActivity()));
|
tempFolder,
|
||||||
|
new NoOpCacheEvictor(),
|
||||||
|
new StandaloneDatabaseProvider(testRule.getActivity()));
|
||||||
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
|
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
|
||||||
offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
|
offlineDataSourceFactory = new CacheDataSource.Factory().setCache(cache);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user