diff --git a/app/src/full/java/org/fdroid/fdroid/localrepo/peers/BonjourPeer.java b/app/src/full/java/org/fdroid/fdroid/localrepo/peers/BonjourPeer.java index 3c25169a9..cc836efa9 100644 --- a/app/src/full/java/org/fdroid/fdroid/localrepo/peers/BonjourPeer.java +++ b/app/src/full/java/org/fdroid/fdroid/localrepo/peers/BonjourPeer.java @@ -28,15 +28,6 @@ public class BonjourPeer extends WifiPeer { return serviceInfo.getName(); } - @Override - public boolean equals(Object peer) { - if (peer instanceof BonjourPeer) { - BonjourPeer that = (BonjourPeer) peer; - return TextUtils.equals(this.getFingerprint(), that.getFingerprint()); - } - return false; - } - @Override public int hashCode() { String fingerprint = getFingerprint(); diff --git a/app/src/full/java/org/fdroid/fdroid/localrepo/peers/WifiPeer.java b/app/src/full/java/org/fdroid/fdroid/localrepo/peers/WifiPeer.java index 161e2fbd0..03d913bab 100644 --- a/app/src/full/java/org/fdroid/fdroid/localrepo/peers/WifiPeer.java +++ b/app/src/full/java/org/fdroid/fdroid/localrepo/peers/WifiPeer.java @@ -2,7 +2,7 @@ package org.fdroid.fdroid.localrepo.peers; import android.net.Uri; import android.os.Parcel; - +import android.text.TextUtils; import org.fdroid.fdroid.R; import org.fdroid.fdroid.data.NewRepoConfig; @@ -26,6 +26,35 @@ public class WifiPeer implements Peer { this.shouldPromptForSwapBack = shouldPromptForSwapBack; } + /** + * Return if this instance points to the same device as that instance, even + * if some of the configuration details are not the same, like whether one + * instance supplies the fingerprint and the other does not, then use IP + * address and port number. + */ + @Override + public boolean equals(Object peer) { + if (peer instanceof BluetoothPeer) { + return false; + } + String fingerprint = getFingerprint(); + if (this instanceof BonjourPeer && peer instanceof BonjourPeer) { + BonjourPeer that = (BonjourPeer) peer; + return TextUtils.equals(this.getFingerprint(), that.getFingerprint()); + } else { + WifiPeer that = (WifiPeer) peer; + if (!TextUtils.isEmpty(fingerprint) && TextUtils.equals(this.getFingerprint(), that.getFingerprint())) { + return true; + } + return TextUtils.equals(this.getRepoAddress(), that.getRepoAddress()); + } + } + + @Override + public int hashCode() { + return (uri.getHost() + uri.getPort()).hashCode(); + } + @Override public String getName() { return name;