From 947f1e5adc8beffcc79cfc54a1ccc997dfd9aefe Mon Sep 17 00:00:00 2001 From: bju Date: Mon, 23 Jul 2018 00:51:34 +0200 Subject: Feature #2557: Added support for IPv6 --- .../de/bjusystems/vdrmanager/data/Preferences.java | 5 +- .../java/de/bjusystems/vdrmanager/data/Vdr.java | 54 +++-------- .../de/bjusystems/vdrmanager/data/db/DBAccess.java | 6 +- .../vdrmanager/utils/svdrp/SvdrpClient.java | 100 ++++++++++++++++----- .../vdrmanager/utils/wakeup/AsyncWakeupTask.java | 2 - .../src/main/res/values-de/strings.xml | 2 + .../src/main/res/values/arrays.xml | 8 +- .../src/main/res/values/strings.xml | 9 ++ .../src/main/res/xml/vdr_prefs.xml | 9 ++ 9 files changed, 125 insertions(+), 70 deletions(-) (limited to 'vdrmanager') diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java index 4d19d0e..6904402 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Preferences.java @@ -10,7 +10,6 @@ import android.text.TextUtils; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.StringUtils; -import de.bjusystems.vdrmanager.app.VdrManagerApp; import de.bjusystems.vdrmanager.data.db.DBAccess; /** @@ -162,6 +161,10 @@ public class Preferences { return getCurrentVdr().getStreamingPassword(); } + public String getIp46Mode() { + return getCurrentVdr().getIp46Mode(); + } + /** * Properties singleton */ diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java index 619bb9e..ad53fd5 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/Vdr.java @@ -201,6 +201,9 @@ public class Vdr { @DatabaseField(columnName="enableRemote") private boolean enableRemote = true; + + @DatabaseField(columnName="ip46Mode") + private String ip46Mode = "ip4"; public String getServerTimeZone() { return serverTimeZone; @@ -498,6 +501,14 @@ public class Vdr { this.timeout = timeout; } + public String getIp46Mode() { + return ip46Mode; + } + + public void setIp46Mode(final String ip46Mode) { + this.ip46Mode = ip46Mode; + } + private static T get(Map map, String key) { return get(map, key, null); } @@ -566,6 +577,7 @@ public class Vdr { map.put("vdr_port", port); map.put("vdr_password", password); map.put("vdr_secure", secure); + map.put("vdr_ip46_mode", ip46Mode); map.put("limit_channels", filterChannels); map.put("last_channel", channelFilter); @@ -611,47 +623,6 @@ public class Vdr { public void set(Map map) { init(map); -/* - name = get(map, "vdr_name"); - host = get(map, "vdr_host"); - port = getInteger(map, "vdr_port"); - password = get(map, "vdr_password"); - secure = getBoolean(map, "vdr_secure"); - - filterChannels = getBoolean(map, "limit_channels"); - channelFilter = get(map, "last_channel"); - - wakeupEnabled = getBoolean(map, "key_wakeup_enabled"); - wakeupUrl = get(map, "key_wakeup_url"); - wakeupUser = get(map, "key_wakeup_user"); - wakeupPassword = get(map, "key_wakeup_password"); - wakeupMethod = get(map, "key_wakeup_method"); - wolCustomBroadcast = get(map, "key_wol_custom_broadcast"); - mac = get(map, "key_wakeup_wol_mac"); - - connectionTimeout = getInteger(map, "key_conntimeout_key"); - readTimeout = getInteger(map, "key_vdr_readtimeout"); - timeout = getInteger(map, "key_vdr_timeout"); - - timerPreMargin = getInteger(map, "timer_pre_start_buffer" - ); - timerPostMargin = getInteger(map, "timer_post_end_buffer"); - timerDefaultPriority = getInteger(map, "timer_default_priority"); - timerDefaultLifetime = getInteger(map, "timer_default_lifetime"); - - streamPort = getInteger(map, "streamingport"); - streamingPassword = get(map, "key_streaming_password"); - streamingUsername = get(map, "key_streaming_username"); - encoding = get(map, "key_vdr_encoding"); - streamFormat = get(map, "livetv_streamformat"); - remuxCommand = get(map, "remux_command"); - remuxParameter = get(map, "remux_parameter"); - enableRemux = getBoolean(map, "remux_enable"); - - enableRecStreaming = getBoolean(map, "key_rec_stream_enable"); - livePort = getInteger(map, "key_live_port"); - recStreamMethod = get(map, "key_recstream_method"); - */ } public void init(Map map) { @@ -660,6 +631,7 @@ public class Vdr { port = getInteger(map, "vdr_port", 6420); password = get(map, "vdr_password", ""); secure = getBoolean(map, "vdr_secure"); + ip46Mode = get(map, "vdr_ip46_mode"); filterChannels = getBoolean(map, "limit_channels", true); channelFilter = get(map, "last_channel", ""); diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java index 0e529dc..a8305d9 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/data/db/DBAccess.java @@ -32,7 +32,7 @@ public class DBAccess extends OrmLiteSqliteOpenHelper { // any time you make changes to your database objects, you may have to // increase the database version // Version 3 since 0.6 - private static final int DATABASE_VERSION = 6; + private static final int DATABASE_VERSION = 7; private RuntimeExceptionDao vdrDAO = null; @@ -130,6 +130,10 @@ public class DBAccess extends OrmLiteSqliteOpenHelper { getVdrDAO().executeRaw("ALTER TABLE `vdr` ADD COLUMN svdrpHost varchar"); } + if (oldVersion < 7) { + getVdrDAO().executeRaw("ALTER TABLE `vdr` ADD COLUMN ip46Mode varchar"); + } + } catch (SQLException e) { Log.e(DBAccess.class.getName(), "Can't drop databases", e); throw new RuntimeException(e); diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index 31fa0f4..f415d3a 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -1,13 +1,17 @@ package de.bjusystems.vdrmanager.utils.svdrp; +import android.util.Log; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; -import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -16,9 +20,6 @@ import java.util.TimerTask; import java.util.zip.GZIPInputStream; import java.util.zip.InflaterInputStream; -import android.content.Context; -import android.sax.StartElementListener; -import android.util.Log; import de.bjusystems.vdrmanager.app.C; import de.bjusystems.vdrmanager.data.Preferences; @@ -224,20 +225,69 @@ public abstract class SvdrpClient { // connect informListener(SvdrpEvent.CONNECTING); - if (prefs.isSecure()) { - socket = new MySSLSocketFactory(false, - certificateProblemListener).createSocket(); - } else { - socket = new Socket(); + InetAddress ip4address = null; + InetAddress ip6address = null; + + final InetAddress[] addresses = InetAddress.getAllByName(prefs.getHost()); + for (final InetAddress address : addresses) { + if (address instanceof Inet4Address) { + ip4address = address; + } else if (address instanceof Inet6Address) { + ip6address = address; + } } - socket.connect( - new InetSocketAddress(prefs.getHost(), prefs - .getPort()), - prefs.getConnectionTimeout() * 1000);// 8 secs for connect - if (abort) { - informListener(SvdrpEvent.ABORTED); + List addressToTry = new ArrayList<>(); + + switch (prefs.getIp46Mode()) { + case "ip4": + addressToTry.add(ip4address); + break; + case "ip6": + addressToTry.add(ip6address); + break; + case "ip46": + addressToTry.add(ip4address); + addressToTry.add(ip6address); + break; + case "ip64": + addressToTry.add(ip6address); + addressToTry.add(ip4address); + break; } + + Exception exception = null; + for (final InetAddress inetAddress : addressToTry) { + if (inetAddress == null) { + continue; + } + if (abort) { + break; + } + + try { + initSocket(prefs); + socket.connect(new InetSocketAddress( + inetAddress, + prefs.getPort()), + prefs.getConnectionTimeout() * 1000); + break; + } catch (Exception e) { + socket.close(); + Log.w(TAG, "Couldn't connect to " + inetAddress.getHostAddress()); + exception = e; + } + } + + if (!socket.isConnected()) { + if (abort) { + informListener(SvdrpEvent.ABORTED); + } else { + informListener(SvdrpEvent.CONNECT_ERROR); + } + return false; + } + // socket.setSoTimeout(prefs.getReadTimeout() * 1000);// 15 sec for // each read @@ -261,14 +311,6 @@ public abstract class SvdrpClient { outputStream = socket.getOutputStream(); inputStream = socket.getInputStream(); - } catch (final SocketTimeoutException sote) { - Log.w(TAG, sote); - if (abort) { - informListener(SvdrpEvent.ABORTED); - } else { - informListener(SvdrpEvent.CONNECTION_TIMEOUT); - } - return false; } catch (final Exception e) { Log.w(TAG, e); @@ -293,6 +335,18 @@ public abstract class SvdrpClient { return true; } + private void initSocket(final Preferences prefs) throws Exception { + if (socket != null) { + socket.close(); + } + if (prefs.isSecure()) { + socket = new MySSLSocketFactory(false, + certificateProblemListener).createSocket(); + } else { + socket = new Socket(); + } + } + /** * Disconnect from SVDRP if connected * diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java index 0b99b04..12a1f3e 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/java/de/bjusystems/vdrmanager/utils/wakeup/AsyncWakeupTask.java @@ -6,8 +6,6 @@ import android.os.AsyncTask; import android.util.Log; import android.widget.Toast; -import java.io.IOException; - import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.utils.http.HttpHelper; diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml index 0ae6b80..7a7d365 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values-de/strings.xml @@ -137,6 +137,8 @@ herrlado<herrlado@gmail.com> Passwort für das VDR Plugin Sichere Verbindung Verwende SSL für Verbindungen (aktuell nicht implementiert) + IPv4/6 Auswahl + IPv4/6 Auswahl-Modus Kanaleinstellungen Begrenze Kanäle diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml index c0398bd..d53afcb 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/arrays.xml @@ -46,8 +46,12 @@ has hls - - + + ip4 + ip6 + ip46 + ip64 + \ No newline at end of file diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml index 5176908..3a21c46 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/values/strings.xml @@ -148,6 +148,15 @@ Password for the VDR plugin Secure connect Use SSL for connections + IPv4/6 selection + IPv4/6 selection mode + + + Use only IPv4 + Use only IPv6 + Prefer IPv4 over IPv6 + Prefer IPv6 over IPv4 + Channel settings diff --git a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml index efd13f8..b221b3f 100644 --- a/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml +++ b/vdrmanager/de.bjusystems.vdrmanager/src/main/res/xml/vdr_prefs.xml @@ -32,6 +32,15 @@ android:enabled="true" android:summary="@string/vdr_ssl_summary" android:title="@string/vdr_ssl_title" /> + + +