Skip to content

Commit

Permalink
Merge pull request #136 from tobexyz/feat/issue133
Browse files Browse the repository at this point in the history
issue #133 added configurable filter for interfaces used by content d…
  • Loading branch information
tobexyz authored Dec 21, 2024
2 parents 572d474 + b9189c5 commit 6737d67
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion yaacc/src/main/java/de/yaacc/upnp/UpnpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ public PlayableItem createPlayableItem(Uri uri) {
item.setUri(uri);
if (this.getPreferences().getBoolean(getContext().getString(R.string.settings_local_server_proxy_chkbx), false)) {
String contentKey = sha256(uriString);
String proxyUrl = "http://" + YaaccUpnpServerService.getIpAddress() + ":" + YaaccUpnpServerService.PORT + "/" + YaaccUpnpServerService.PROXY_PATH + "/" + contentKey;
String proxyUrl = "http://" + YaaccUpnpServerService.getIpAddress(getContext()) + ":" + YaaccUpnpServerService.PORT + "/" + YaaccUpnpServerService.PROXY_PATH + "/" + contentKey;
this.getPreferences().edit().putString(YaaccUpnpServerService.PROXY_LINK_KEY_PREFIX + contentKey, uriString).commit();
this.getPreferences().edit().putString(YaaccUpnpServerService.PROXY_LINK_MIME_TYPE_KEY_PREFIX + contentKey, item.getMimeType()).commit();
item.setUri(Uri.parse(proxyUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.MenuItem;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;
Expand Down Expand Up @@ -62,6 +63,9 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d(getClass().getName(), "providerActive: " + providerActive);
CheckBox providerCheckBox = findViewById(R.id.providerEnabled);
providerCheckBox.setChecked(providerActive);
TextView localServerControlInterface = findViewById(R.id.localServerControlInterface);
String[] ipConfig = YaaccUpnpServerService.getIfAndIpAddress(this);
localServerControlInterface.setText(ipConfig[1] + "@" + ipConfig[0]);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.util.TimerTask;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import de.yaacc.R;
import de.yaacc.Yaacc;
Expand Down Expand Up @@ -308,7 +309,7 @@ public void execute(Exception ex) {
}

})
.setCanonicalHostName(getIpAddress())
.setCanonicalHostName(getIpAddress(getApplicationContext()))
.register("*", new YaaccUpnpServerServiceHttpHandler(getApplicationContext()))
.create();

Expand Down Expand Up @@ -416,7 +417,7 @@ private LocalDevice createMediaServerDevice() {
DeviceDetails yaaccDetails = new DeviceDetails(
"YAACC - MediaServer(" + getLocalServerName() + ")", new ManufacturerDetails("yaacc.de",
"http://www.yaacc.de"), new ModelDetails(getLocalServerName() + "-MediaServer", "Free Android UPnP AV MediaServer, GNU GPL",
versionName), URI.create("http://" + getIpAddress() + ":" + PORT));
versionName), URI.create("http://" + getIpAddress(getApplicationContext()) + ":" + PORT));


DeviceIdentity identity = new DeviceIdentity(new UDN(mediaServerUuid));
Expand Down Expand Up @@ -500,7 +501,7 @@ protected int getLockTimeoutMillis() {

@Override
protected YaaccContentDirectory createServiceInstance() {
return new YaaccContentDirectory(getApplicationContext(), getIpAddress());
return new YaaccContentDirectory(getApplicationContext(), getIpAddress(getApplicationContext()));
}
});
return contentDirectoryService;
Expand Down Expand Up @@ -844,27 +845,28 @@ private void setUpnpClient(UpnpClient upnpClient) {
// return false;
// }

/**
* @return the initialized
*/
public boolean isInitialized() {
return initialized;
}

/**
* get the ip address of the device
*
* @return the address or null if anything went wrong
*/
public static String getIpAddress() {
public static String getIpAddress(Context context) {
return getIfAndIpAddress(context)[0];
}

public static String[] getIfAndIpAddress(Context context) {
String hostAddress = null;
String[] result = new String[2];
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
List<String> interfaces = List.of(preferences.getString(context.getString(R.string.settings_local_server_if_filter_key), "").split(","));
try {
for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces(); networkInterfaces
.hasMoreElements(); ) {
NetworkInterface networkInterface = networkInterfaces
.nextElement();
if (!networkInterface.getName().startsWith("rmnet")) {
if (interfaces.stream().filter(i -> networkInterface.getName().startsWith(i)).collect(Collectors.toList()).isEmpty()) {
for (Enumeration<InetAddress> inetAddresses = networkInterface
.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
InetAddress inetAddress = inetAddresses.nextElement();
Expand All @@ -874,6 +876,7 @@ public static String getIpAddress() {
.getHostAddress()).matches()) {

hostAddress = inetAddress.getHostAddress();
result[1] = networkInterface.getName();
}

}
Expand All @@ -885,7 +888,8 @@ public static String getIpAddress() {
}
// maybe wifi is off we have to use the loopback device
hostAddress = hostAddress == null ? "0.0.0.0" : hostAddress;
return hostAddress;
result[0] = hostAddress;
return result;
}

public class YaaccUpnpServerServiceBinder extends Binder {
Expand Down
24 changes: 16 additions & 8 deletions yaacc/src/main/res/layout/activity_yaacc_upnp_server_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".upnp.server.YaaccUpnpServerControlActivity" >
tools:context=".upnp.server.YaaccUpnpServerControlActivity">

<CheckBox
android:id="@+id/providerEnabled"
<TextView
android:id="@+id/localServerControlInterface"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="26dp"
android:layout_marginLeft="5dp"
android:text="@string/all"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textColor="?android:attr/colorForeground" />

<CheckBox
android:id="@+id/providerEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/localServerControlInterface"
android:layout_alignParentLeft="true"
android:enabled="false"
android:text="@string/settings_local_server_provider_on" />

<CheckBox
android:id="@+id/receiverEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/providerEnabled"
android:enabled="false"
android:text="@string/settings_local_server_receiver_on" />



<Button
android:id="@+id/stopServer"
android:layout_width="wrap_content"
Expand All @@ -38,14 +46,14 @@
android:layout_marginLeft="19dp"
android:layout_marginStart="19dp"
android:text="@string/yaacc_upnp_server_stop_server" />

<Space
android:id="@+id/Separator"
android:layout_alignBaseline="@+id/stopServer"
android:layout_toRightOf="@+id/stopServer"
android:layout_toEndOf="@+id/stopServer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />

<Button
android:id="@+id/startServer"
Expand Down
3 changes: 3 additions & 0 deletions yaacc/src/main/res/values-de/setting_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@
<string name="settings_browse_swipe_off">Tabwechsel nur mit Touch</string>
<string name="settings_browse_swipe_on">Tabwechsel mit Swipe und Touch</string>
<string name="settings_browse_swipe_title">"Swipe-Verhalten "</string>
<string name="settings_local_server_if_filter_key">settings_local_server_if_filter_key</string>
<string name="settings_local_server_if_filter_names">Ignorierte Interfaces für die IP-Ermittlung</string>

</resources>
3 changes: 2 additions & 1 deletion yaacc/src/main/res/values/setting_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@
<string name="settings_browse_swipe_off">Change tabs on touch</string>
<string name="settings_browse_swipe_on">Change tabs on swipe and touch</string>
<string name="settings_browse_swipe_title">"Swipe on browse "</string>

<string name="settings_local_server_if_filter_key">settings_local_server_if_filter_key</string>
<string name="settings_local_server_if_filter_names">black listed interfaces for ip adress retrieval</string>
</resources>
4 changes: 4 additions & 0 deletions yaacc/src/main/res/xml/preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
<EditTextPreference
android:key="@string/settings_local_server_name_key"
android:title="@string/settings_local_server_name" />
<EditTextPreference
android:key="@string/settings_local_server_if_filter_key"
android:title="@string/settings_local_server_if_filter_names"
android:defaultValue="rmnet,ccmni"/>
<EditTextPreference
android:enabled="false"
app:isPreferenceVisible="false"
Expand Down

0 comments on commit 6737d67

Please sign in to comment.