Merge "Fix service resolve on tethering downstreams"

This commit is contained in:
Remi NGUYEN VAN
2022-06-01 05:31:14 +00:00
committed by Gerrit Code Review
6 changed files with 211 additions and 22 deletions

View File

@@ -53,6 +53,8 @@ public final class NsdServiceInfo implements Parcelable {
@Nullable
private Network mNetwork;
private int mInterfaceIndex;
public NsdServiceInfo() {
}
@@ -312,8 +314,11 @@ public final class NsdServiceInfo implements Parcelable {
/**
* Get the network where the service can be found.
*
* This is never null if this {@link NsdServiceInfo} was obtained from
* {@link NsdManager#discoverServices} or {@link NsdManager#resolveService}.
* This is set if this {@link NsdServiceInfo} was obtained from
* {@link NsdManager#discoverServices} or {@link NsdManager#resolveService}, unless the service
* was found on a network interface that does not have a {@link Network} (such as a tethering
* downstream, where services are advertised from devices connected to this device via
* tethering).
*/
@Nullable
public Network getNetwork() {
@@ -329,6 +334,26 @@ public final class NsdServiceInfo implements Parcelable {
mNetwork = network;
}
/**
* Get the index of the network interface where the service was found.
*
* This is only set when the service was found on an interface that does not have a usable
* Network, in which case {@link #getNetwork()} returns null.
* @return The interface index as per {@link java.net.NetworkInterface#getIndex}, or 0 if unset.
* @hide
*/
public int getInterfaceIndex() {
return mInterfaceIndex;
}
/**
* Set the index of the network interface where the service was found.
* @hide
*/
public void setInterfaceIndex(int interfaceIndex) {
mInterfaceIndex = interfaceIndex;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -375,6 +400,7 @@ public final class NsdServiceInfo implements Parcelable {
}
dest.writeParcelable(mNetwork, 0);
dest.writeInt(mInterfaceIndex);
}
/** Implement the Parcelable interface */
@@ -405,6 +431,7 @@ public final class NsdServiceInfo implements Parcelable {
info.mTxtRecord.put(in.readString(), valueArray);
}
info.mNetwork = in.readParcelable(null, Network.class);
info.mInterfaceIndex = in.readInt();
return info;
}