mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Use different authorities for AssetContentProvider
Otherwise it's impossible to install the androidTest apk of both lib-datasource and lib-exoplayer on the same device #cherrypick PiperOrigin-RevId: 727867871 (cherry picked from commit 527e1d52aedbff53e3ba670d2b6a3cf0b0a84abb)
This commit is contained in:
parent
57bbb6c5c6
commit
88e7636ae0
@ -27,7 +27,7 @@
|
|||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
||||||
<provider
|
<provider
|
||||||
android:authorities="androidx.media3.test.utils.AssetContentProvider"
|
android:authorities="androidx.media3.datasource.test.AssetContentProvider"
|
||||||
android:name="androidx.media3.test.utils.AssetContentProvider"/>
|
android:name="androidx.media3.test.utils.AssetContentProvider"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public final class ContentDataSourceContractTest extends DataSourceContractTest {
|
public final class ContentDataSourceContractTest extends DataSourceContractTest {
|
||||||
|
|
||||||
|
private static final String AUTHORITY = "androidx.media3.datasource.test.AssetContentProvider";
|
||||||
private static final String DATA_PATH = "media/mp3/1024_incrementing_bytes.mp3";
|
private static final String DATA_PATH = "media/mp3/1024_incrementing_bytes.mp3";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,18 +43,18 @@ public final class ContentDataSourceContractTest extends DataSourceContractTest
|
|||||||
return ImmutableList.of(
|
return ImmutableList.of(
|
||||||
new TestResource.Builder()
|
new TestResource.Builder()
|
||||||
.setName("simple (pipe=false)")
|
.setName("simple (pipe=false)")
|
||||||
.setUri(AssetContentProvider.buildUri(DATA_PATH, /* pipeMode= */ false))
|
.setUri(AssetContentProvider.buildUri(AUTHORITY, DATA_PATH, /* pipeMode= */ false))
|
||||||
.setExpectedBytes(completeData)
|
.setExpectedBytes(completeData)
|
||||||
.build(),
|
.build(),
|
||||||
new TestResource.Builder()
|
new TestResource.Builder()
|
||||||
.setName("simple (pipe=true)")
|
.setName("simple (pipe=true)")
|
||||||
.setUri(AssetContentProvider.buildUri(DATA_PATH, /* pipeMode= */ true))
|
.setUri(AssetContentProvider.buildUri(AUTHORITY, DATA_PATH, /* pipeMode= */ true))
|
||||||
.setExpectedBytes(completeData)
|
.setExpectedBytes(completeData)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Uri getNotFoundUri() {
|
protected Uri getNotFoundUri() {
|
||||||
return AssetContentProvider.buildUri("not/a/real/path", /* pipeMode= */ false);
|
return AssetContentProvider.buildUri(AUTHORITY, "not/a/real/path", /* pipeMode= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public final class ContentDataSourceTest {
|
public final class ContentDataSourceTest {
|
||||||
|
|
||||||
|
private static final String AUTHORITY = "androidx.media3.datasource.test.AssetContentProvider";
|
||||||
private static final String DATA_PATH = "media/mp3/1024_incrementing_bytes.mp3";
|
private static final String DATA_PATH = "media/mp3/1024_incrementing_bytes.mp3";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -70,7 +71,7 @@ public final class ContentDataSourceTest {
|
|||||||
public void readInvalidUri() throws Exception {
|
public void readInvalidUri() throws Exception {
|
||||||
ContentDataSource dataSource =
|
ContentDataSource dataSource =
|
||||||
new ContentDataSource(ApplicationProvider.getApplicationContext());
|
new ContentDataSource(ApplicationProvider.getApplicationContext());
|
||||||
Uri contentUri = AssetContentProvider.buildUri("does/not.exist", false);
|
Uri contentUri = AssetContentProvider.buildUri(AUTHORITY, "does/not.exist", false);
|
||||||
DataSpec dataSpec = new DataSpec(contentUri);
|
DataSpec dataSpec = new DataSpec(contentUri);
|
||||||
try {
|
try {
|
||||||
dataSource.open(dataSpec);
|
dataSource.open(dataSpec);
|
||||||
@ -84,7 +85,7 @@ public final class ContentDataSourceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void assertData(int offset, int length, boolean pipeMode) throws IOException {
|
private static void assertData(int offset, int length, boolean pipeMode) throws IOException {
|
||||||
Uri contentUri = AssetContentProvider.buildUri(DATA_PATH, pipeMode);
|
Uri contentUri = AssetContentProvider.buildUri(AUTHORITY, DATA_PATH, pipeMode);
|
||||||
ContentDataSource dataSource =
|
ContentDataSource dataSource =
|
||||||
new ContentDataSource(ApplicationProvider.getApplicationContext());
|
new ContentDataSource(ApplicationProvider.getApplicationContext());
|
||||||
try {
|
try {
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
|
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true">
|
||||||
<provider
|
<provider
|
||||||
android:authorities="androidx.media3.test.utils.AssetContentProvider"
|
android:authorities="androidx.media3.exoplayer.test.AssetContentProvider"
|
||||||
android:name="androidx.media3.test.utils.AssetContentProvider"/>
|
android:name="androidx.media3.test.utils.AssetContentProvider"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
@ -72,6 +72,8 @@ import org.junit.runners.Parameterized.Parameters;
|
|||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class MediaExtractorContractTest {
|
public class MediaExtractorContractTest {
|
||||||
|
|
||||||
|
private static final String AUTHORITY = "androidx.media3.exoplayer.test.AssetContentProvider";
|
||||||
|
|
||||||
@Parameters(name = "{0}")
|
@Parameters(name = "{0}")
|
||||||
public static ImmutableList<Function<Context, MediaExtractorProxy>>
|
public static ImmutableList<Function<Context, MediaExtractorProxy>>
|
||||||
mediaExtractorProxyFactories() {
|
mediaExtractorProxyFactories() {
|
||||||
@ -226,7 +228,8 @@ public class MediaExtractorContractTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setDataSource_withContentUri_returnsCorrectTrackCount() throws IOException {
|
public void setDataSource_withContentUri_returnsCorrectTrackCount() throws IOException {
|
||||||
Uri contentUri = AssetContentProvider.buildUri("media/mp4/sample.mp4", /* pipeMode= */ false);
|
Uri contentUri =
|
||||||
|
AssetContentProvider.buildUri(AUTHORITY, "media/mp4/sample.mp4", /* pipeMode= */ false);
|
||||||
|
|
||||||
mediaExtractorProxy.setDataSource(context, contentUri, /* headers= */ null);
|
mediaExtractorProxy.setDataSource(context, contentUri, /* headers= */ null);
|
||||||
|
|
||||||
|
@ -21,8 +21,5 @@
|
|||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
||||||
<provider
|
|
||||||
android:authorities="androidx.media3.test.utils.AssetContentProvider"
|
|
||||||
android:name="androidx.media3.test.utils.AssetContentProvider"/>
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -38,14 +38,13 @@ import java.io.IOException;
|
|||||||
public final class AssetContentProvider extends ContentProvider
|
public final class AssetContentProvider extends ContentProvider
|
||||||
implements ContentProvider.PipeDataWriter<Object> {
|
implements ContentProvider.PipeDataWriter<Object> {
|
||||||
|
|
||||||
private static final String AUTHORITY = "androidx.media3.test.utils.AssetContentProvider";
|
|
||||||
private static final String PARAM_PIPE_MODE = "pipe-mode";
|
private static final String PARAM_PIPE_MODE = "pipe-mode";
|
||||||
|
|
||||||
public static Uri buildUri(String filePath, boolean pipeMode) {
|
public static Uri buildUri(String authority, String filePath, boolean pipeMode) {
|
||||||
Uri.Builder builder =
|
Uri.Builder builder =
|
||||||
new Uri.Builder()
|
new Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
.authority(AUTHORITY)
|
.authority(authority)
|
||||||
.path(filePath);
|
.path(filePath);
|
||||||
if (pipeMode) {
|
if (pipeMode) {
|
||||||
builder.appendQueryParameter(PARAM_PIPE_MODE, "1");
|
builder.appendQueryParameter(PARAM_PIPE_MODE, "1");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user