diff options
author | Chris "Koying" Browet <cbro@semperpax.com> | 2018-01-07 13:25:30 +0100 |
---|---|---|
committer | Chris "Koying" Browet <cbro@semperpax.com> | 2018-01-09 19:40:27 +0100 |
commit | b1425bb2b6606f189c0db3bd9d3054434371d7fd (patch) | |
tree | 476de89ee686fc46e791fb41cdcc397d5d80cd9d /tools/android | |
parent | d139c83822cd1eec51b8db4cff135a1897337e5c (diff) |
CHG: [droid] use jni to read files
Diffstat (limited to 'tools/android')
3 files changed, 124 insertions, 37 deletions
diff --git a/tools/android/packaging/xbmc/src/XBMCFile.java.in b/tools/android/packaging/xbmc/src/XBMCFile.java.in new file mode 100644 index 0000000000..b99fb92773 --- /dev/null +++ b/tools/android/packaging/xbmc/src/XBMCFile.java.in @@ -0,0 +1,99 @@ +package @APP_PACKAGE@; + +import android.util.Log; + +/** + * Created by koyin on 07/01/2018. + */ + +public class XBMCFile +{ + native boolean _open(String path); + native void _close(); + native byte[] _read(); + native boolean _eof(); + + private static String TAG = "@APP_NAME@file"; + + public XBMCFile() + { + + } + + public boolean Open(String path) + { + try + { + return _open(path); + } + catch (Exception e) + { + e.printStackTrace(); + Log.e(TAG, "Open: Exception"); + return false; + } + catch (UnsatisfiedLinkError e) + { + Log.e(TAG, "Open: Not available"); + return false; + } + } + + public void Close() + { + try + { + _close(); + } + catch (Exception e) + { + e.printStackTrace(); + Log.e(TAG, "Close: Exception"); + return; + } + catch (UnsatisfiedLinkError e) + { + Log.e(TAG, "Close: Not available"); + return; + } + } + + public byte[] Read() + { + try + { + return _read(); + } + catch (Exception e) + { + e.printStackTrace(); + Log.e(TAG, "Read: Exception"); + return new byte[0]; + } + catch (UnsatisfiedLinkError e) + { + Log.e(TAG, "Read: Not available"); + return new byte[0]; + } + } + + public boolean Eof() + { + try + { + return _eof(); + } + catch (Exception e) + { + e.printStackTrace(); + Log.e(TAG, "Eof: Exception"); + return false; + } + catch (UnsatisfiedLinkError e) + { + Log.e(TAG, "Eof: Not available"); + return false; + } + } + +} diff --git a/tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in b/tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in index 35c61465d9..3268eebff6 100644 --- a/tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in +++ b/tools/android/packaging/xbmc/src/XBMCJsonRPC.java.in @@ -147,6 +147,11 @@ public class XBMCJsonRPC e.printStackTrace(); return null; } + catch (UnsatisfiedLinkError e) + { + Log.e(TAG, "_requestJSON: Not available"); + return null; + } } public JsonObject request_object(String jsonRequest) @@ -222,22 +227,7 @@ public class XBMCJsonRPC public String getDownloadUrl(String src) { - try - { - JsonObject req = request_object("{\"jsonrpc\": \"2.0\", \"method\": \"Files.PrepareDownload\", \"params\": { \"path\": \"" - + src + "\"}, \"id\": \"1\"}"); - if (req == null || !req.has("result")) - return null; - - JsonObject result = req.getAsJsonObject("result"); - String surl = result.getAsJsonObject("details").get("path").getAsString(); - - return (m_xbmc_web_url + "/" + surl); - } catch (Exception e) - { - e.printStackTrace(); - return ""; - } + return src; } public boolean Ping() diff --git a/tools/android/packaging/xbmc/src/content/XBMCImageContentProvider.java.in b/tools/android/packaging/xbmc/src/content/XBMCImageContentProvider.java.in index aef96a09b1..37f4303269 100644 --- a/tools/android/packaging/xbmc/src/content/XBMCImageContentProvider.java.in +++ b/tools/android/packaging/xbmc/src/content/XBMCImageContentProvider.java.in @@ -12,6 +12,7 @@ import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; +import @APP_PACKAGE@.XBMCFile; import @APP_PACKAGE@.XBMCProperties; /** @@ -76,20 +77,11 @@ public class XBMCImageContentProvider extends XBMCContentProvider String decodedUrl = uri.getFragment(); // Log.d(TAG, " decodedUrl: " + decodedUrl); if (decodedUrl == null) - { return null; - } - pipe = ParcelFileDescriptor.createPipe(); - URL url = new URL(decodedUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - String auth = XBMCProperties.getJsonAuthorization(); - if (!auth.isEmpty()) - connection.setRequestProperty("Authorization", auth); - connection.setDoInput(true); - connection.connect(); + pipe = ParcelFileDescriptor.createPipe(); - new TransferThread(connection.getInputStream(), + new TransferThread(decodedUrl, new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])).start(); } catch (IOException e) @@ -136,33 +128,39 @@ public class XBMCImageContentProvider extends XBMCContentProvider static class TransferThread extends Thread { - InputStream in; + String path; OutputStream out; - TransferThread(InputStream in, OutputStream out) + TransferThread(String path, OutputStream out) { - this.in = in; + this.path = path; this.out = out; } @Override public void run() { - byte[] buf = new byte[8192]; - int len; - try { - while ((len = in.read(buf)) >= 0) + XBMCFile in = new XBMCFile(); + if (!in.Open(path)) + { + out.flush(); + out.close(); + return; + } + + while (!in.Eof()) { - out.write(buf, 0, len); + byte[] buf = in.Read(); + out.write(buf, 0, buf.length); } - in.close(); + in.Close(); out.flush(); out.close(); } - catch (IOException e) + catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception transferring file", e); } |