Skip to content

Commit

Permalink
CHG: [droid] replace image provider by file provider
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jan 7, 2018
1 parent 46da305 commit 3625a8a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 212 deletions.
1 change: 0 additions & 1 deletion project/cmake/scripts/android/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ set(package_files strings.xml
src/content/XBMCFileContentProvider.java
src/content/XBMCMediaContentProvider.java
src/content/XBMCContentProvider.java
src/content/XBMCImageContentProvider.java
src/content/XBMCYTDLContentProvider.java
src/XBMCSettingsContentObserver.java
src/XBMCMainView.java
Expand Down
4 changes: 0 additions & 4 deletions tools/android/packaging/xbmc/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@
</intent-filter>
</receiver>

<provider
android:name=".content.XBMCImageContentProvider"
android:authorities="@[email protected]"
android:exported="true" />
<provider
android:name=".content.XBMCMediaContentProvider"
android:authorities="@[email protected]"
Expand Down
53 changes: 24 additions & 29 deletions tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package @APP_PACKAGE@;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -39,7 +35,6 @@ import @[email protected];
import @[email protected];
import @[email protected];
import @[email protected];
import @[email protected];

public class XBMCJsonRPC
{
Expand Down Expand Up @@ -419,8 +414,8 @@ public class XBMCJsonRPC
movie.get("movieid").getAsString(),
movie.get("title").getAsString(),
movie.get("tagline").getAsString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(),
Intent.ACTION_GET_CONTENT,
Uri.parse("videodb://movies/titles/" + movie.get("movieid").getAsString() + "?showinfo=true"),
0,
Expand Down Expand Up @@ -467,8 +462,8 @@ public class XBMCJsonRPC
tvshow.get("tvshowid").getAsString(),
tvshow.get("title").getAsString(),
tvshow.get("plot").getAsString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(),
Intent.ACTION_GET_CONTENT,
Uri.parse("videodb://tvshows/titles/" + tvshow.get("tvshowid").getAsString() + "?showinfo=true"),
0,
Expand Down Expand Up @@ -505,8 +500,8 @@ public class XBMCJsonRPC
album.get("albumid").getAsString(),
album.get("title").getAsString(),
album.get("displayartist").getAsString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(),
Intent.ACTION_GET_CONTENT,
Uri.parse("musicdb://albums/" + album.get("albumid").getAsString() + "/"),
0,
Expand Down Expand Up @@ -541,8 +536,8 @@ public class XBMCJsonRPC
artist.get("artistid").getAsString(),
artist.get("artist").getAsString(),
artist.get("description").getAsString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(),
XBMCImageContentProvider.GetImageUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(),
XBMCFileContentProvider.buildUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(),
Intent.ACTION_GET_CONTENT,
Uri.parse("musicdb://artists/" + artist.get("artistid").getAsString() + "/"),
0,
Expand Down Expand Up @@ -595,7 +590,7 @@ public class XBMCJsonRPC

final XBMCRecommendationBuilder notificationBuilder = builder
.setBackground(
XBMCImageContentProvider.GetImageUri(
XBMCFileContentProvider.buildUri(
getDownloadUrl(movie.get("fanart").getAsString())).toString())
.setId(id).setPriority(MAX_RECOMMENDATIONS - count)
.setTitle(movie.get("title").getAsString())
Expand Down Expand Up @@ -637,7 +632,7 @@ public class XBMCJsonRPC

final XBMCRecommendationBuilder notificationBuilder = builder
.setBackground(
XBMCImageContentProvider.GetImageUri(
XBMCFileContentProvider.buildUri(
getDownloadUrl(tvshow.get("fanart").getAsString())).toString())
.setId(id).setPriority(MAX_RECOMMENDATIONS - count)
.setTitle(tvshow.get("title").getAsString())
Expand Down Expand Up @@ -680,7 +675,7 @@ public class XBMCJsonRPC

final XBMCRecommendationBuilder notificationBuilder = builder
.setBackground(
XBMCImageContentProvider.GetImageUri(
XBMCFileContentProvider.buildUri(
getDownloadUrl(album.get("fanart").getAsString())).toString())
.setId(id).setPriority(MAX_RECOMMENDATIONS - count)
.setTitle(album.get("title").getAsString())
Expand Down Expand Up @@ -806,14 +801,14 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("2:3");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setXbmcUrl("videodb://movies/titles/" + details.get("movieid").getAsString() + "?showinfo=true");

Expand Down Expand Up @@ -864,14 +859,14 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("2:3");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/");
med.setCategory(Media.MEDIA_TYPE_TVSHOW);
Expand All @@ -897,14 +892,14 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("16:9");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/" + details.get("episodeid").getAsInt() + "?showinfo=true");
/*
Expand Down Expand Up @@ -938,14 +933,14 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("1:1");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setXbmcUrl("musicdb://albums/" + details.get("albumid").getAsString() + "/");
med.setCategory(Media.MEDIA_TYPE_ALBUM);
Expand All @@ -971,14 +966,14 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("1:1");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}

String extension = "";
Expand Down Expand Up @@ -1024,21 +1019,21 @@ public class XBMCJsonRPC
{
String url = getDownloadUrl(details.get("thumbnail").getAsString());
if (url != null && !url.isEmpty())
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}
med.setCardImageAspectRatio("1:1");
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty())
{
String url = getDownloadUrl(details.get("fanart").getAsString());
if (url != null && !url.isEmpty())
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString());
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString());
}

med.setXbmcUrl("videodb://musicvideos/titles/" + details.get("musicvideoid").getAsInt());

String url = getDownloadUrl(details.get("file").getAsString());
if (url != null && !url.isEmpty())
med.setVideoUrl(url);
med.setVideoUrl(XBMCFileContentProvider.buildUri(url).toString());

med.setCategory(Media.MEDIA_TYPE_MUSICVIDEO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class SyncChannelJobService extends JobService
try (Cursor cursor =
mContext.getContentResolver()
.query(
XBMCFileContentProvider.buildUri("/playlists/video"),
XBMCFileContentProvider.buildUri("special://profile/playlists/video/"),
null,
null,
null,
Expand All @@ -115,7 +115,7 @@ public class SyncChannelJobService extends JobService
try (Cursor cursor =
mContext.getContentResolver()
.query(
XBMCFileContentProvider.buildUri("/playlists/mixed"),
XBMCFileContentProvider.buildUri("special://profile/playlists/mixed/"),
null,
null,
null,
Expand All @@ -130,7 +130,7 @@ public class SyncChannelJobService extends JobService
try (Cursor cursor =
mContext.getContentResolver()
.query(
XBMCFileContentProvider.buildUri("/playlists/music"),
XBMCFileContentProvider.buildUri("special://profile/playlists/music/"),
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;

import @[email protected];
import @[email protected];
import @[email protected];

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

public class XBMCFileContentProvider extends XBMCContentProvider
Expand All @@ -18,13 +24,21 @@ public class XBMCFileContentProvider extends XBMCContentProvider

private XBMCJsonRPC mJsonRPC = null;

public static Uri buildUri(String path)
public static Uri buildUri(String surl)
{
if (surl == null)
return null;
if (surl.isEmpty())
return null;

Uri.Builder builder = new Uri.Builder();
builder.scheme("content")
.authority(AUTHORITY)
.path(path);
return builder.build();
.fragment(surl);

Uri out = builder.build();
// Log.d(TAG, "GetImageUri: in:" + surl + " out:" + out.toString());
return out;
}

@Override
Expand Down Expand Up @@ -66,8 +80,7 @@ public class XBMCFileContentProvider extends XBMCContentProvider
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder)
{
String path = uri.getPath();
String xbmcURL = "special://profile" + path;
String xbmcURL = uri.getFragment();

List<File> files = mJsonRPC.getFiles(xbmcURL);
if (files.isEmpty())
Expand Down Expand Up @@ -96,4 +109,77 @@ public class XBMCFileContentProvider extends XBMCContentProvider
}
return mc;
}

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
throws FileNotFoundException
{
// Log.d(TAG, "openFile: " + uri.toString());

ParcelFileDescriptor[] pipe = null;

try
{
String decodedUrl = uri.getFragment();
// Log.d(TAG, " decodedUrl: " + decodedUrl);
if (decodedUrl == null)
return null;

pipe = ParcelFileDescriptor.createPipe();

new XBMCFileContentProvider.TransferThread(decodedUrl,
new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])).start();
}
catch (IOException e)
{
Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
throw new FileNotFoundException("Could not open pipe for: "
+ uri.toString());
}

return (pipe[0]);
}


static class TransferThread extends Thread
{
String path;
OutputStream out;

TransferThread(String path, OutputStream out)
{
this.path = path;
this.out = out;
}

@Override
public void run()
{
try
{
XBMCFile in = new XBMCFile();
if (!in.Open(path))
{
out.flush();
out.close();
return;
}

while (!in.Eof())
{
byte[] buf = in.Read();
out.write(buf, 0, buf.length);
}

in.Close();
out.flush();
out.close();
}
catch (Exception e)
{
Log.e(getClass().getSimpleName(), "Exception transferring file", e);
}
}
}

}
Loading

0 comments on commit 3625a8a

Please sign in to comment.