use mDNS TXT records to detect FDroid repos, path, etc.
FDroid repos are advertised via Bonjour as plain HTTP or HTTPS services, since they are browseable with a standard Web Browser. The "Find Local Repos" browser in FDroid should only show FDroid repos, not any website, so that is detected using a "type" TXT record in the FDroid broadcasts.
This commit is contained in:
parent
30ecc1c9f6
commit
8ebce69d5d
@ -8,6 +8,7 @@ import android.net.wifi.WifiManager.MulticastLock;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -20,6 +21,7 @@ import org.fdroid.fdroid.R;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jmdns.*;
|
||||
@ -44,18 +46,6 @@ public class MDnsHelper implements ServiceListener {
|
||||
mMulticastLock.setReferenceCounted(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceAdded(ServiceEvent event) {
|
||||
// a ListView Adapter can only be updated on the UI thread
|
||||
final ServiceInfo serviceInfo = event.getInfo();
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter.addItem(serviceInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceRemoved(ServiceEvent event) {
|
||||
// a ListView Adapter can only be updated on the UI thread
|
||||
@ -68,16 +58,27 @@ public class MDnsHelper implements ServiceListener {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceAdded(ServiceEvent event) {
|
||||
addFDroidService(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceResolved(ServiceEvent event) {
|
||||
addFDroidService(event);
|
||||
}
|
||||
|
||||
private void addFDroidService(ServiceEvent event) {
|
||||
// a ListView Adapter can only be updated on the UI thread
|
||||
final ServiceInfo serviceInfo = event.getInfo();
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter.addItem(serviceInfo);
|
||||
}
|
||||
});
|
||||
String type = serviceInfo.getPropertyString("type");
|
||||
if (type.startsWith("fdroidrepo"))
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter.addItem(serviceInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void discoverServices() {
|
||||
|
@ -14,6 +14,7 @@ import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
@ -263,15 +264,15 @@ public class RepoListFragment extends ListFragment
|
||||
(DiscoveredRepo) parent.getItemAtPosition(position);
|
||||
|
||||
final ServiceInfo serviceInfo = discoveredService.getServiceInfo();
|
||||
|
||||
String serviceType = serviceInfo.getType();
|
||||
// TODO get repo type from TXT record
|
||||
String protocol = serviceType.contains("fdroidrepos") ? "https:/" : "http:/";
|
||||
|
||||
String serviceAddress = protocol + serviceInfo.getInetAddresses()[0]
|
||||
+ ":" + serviceInfo.getPort() + "/fdroid/repo";
|
||||
// TODO get path from TXT record
|
||||
showAddRepo(serviceAddress, "");
|
||||
String type = serviceInfo.getPropertyString("type");
|
||||
String protocol = type.contains("fdroidrepos") ? "https:/" : "http:/";
|
||||
String path = serviceInfo.getPropertyString("path");
|
||||
if (TextUtils.isEmpty(path))
|
||||
path = "/fdroid/repo";
|
||||
String serviceUrl = protocol + serviceInfo.getInetAddresses()[0]
|
||||
+ ":" + serviceInfo.getPort() + path;
|
||||
// TODO get fingerprint from TXT record
|
||||
showAddRepo(serviceUrl, "");
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user