Commit cdb6ac40 by Oliver Woodman

Added a isLocalFileUrlOrPath(Uri) method to remove manual checks

Also replaced the manual checks with a call to this method
parent c667feca
......@@ -293,15 +293,12 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
}
}
private boolean uriIsLocalFile(Uri uri) {
return URI_FILE_SCHEME.equals(uri.getScheme()) || TextUtils.isEmpty(uri.getScheme());
}
@TargetApi(23)
private boolean requiresPermission(Uri uri) {
return Util.SDK_INT >= 23 && uriIsLocalFile(uri)
return Util.SDK_INT >= 23
&& Util.isLocalFileUri(uri)
&& checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED;
!= PackageManager.PERMISSION_GRANTED;
}
// Internal methods
......
......@@ -16,9 +16,9 @@
package com.google.android.exoplayer.upstream;
import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Util;
import android.content.Context;
import android.text.TextUtils;
import java.io.IOException;
......@@ -36,7 +36,6 @@ import java.io.IOException;
*/
public final class DefaultUriDataSource implements UriDataSource {
private static final String SCHEME_FILE = "file";
private static final String SCHEME_ASSET = "asset";
private static final String SCHEME_CONTENT = "content";
......@@ -119,7 +118,7 @@ public final class DefaultUriDataSource implements UriDataSource {
Assertions.checkState(dataSource == null);
// Choose the correct source for the scheme.
String scheme = dataSpec.uri.getScheme();
if (SCHEME_FILE.equals(scheme) || TextUtils.isEmpty(scheme)) {
if (Util.isLocalFileUri(dataSpec.uri)) {
if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
dataSource = assetDataSource;
} else {
......
......@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
......@@ -106,12 +107,13 @@ public final class Util {
}
/**
* Returns true if the URL points to a file on the local device
* Returns true if the URI is a path to a local file or a reference to a local file.
*
* @param url The URL to test
* @param uri The uri to test.
*/
public static boolean isUrlLocalFile(URL url) {
return url.getProtocol().equals("file");
public static boolean isLocalFileUri(Uri uri) {
String scheme = uri.getScheme();
return TextUtils.isEmpty(scheme) || scheme.equals("file");
}
/**
......
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