Fix service resolve on tethering downstreams
Tethering downstreams do not have NetworkAgents, and although they have
a netid of 99, Networks with netId 99 are not usable by apps for most
connectivity APIs.
Recent refactoring in NsdService adds the Network of a found service
into its NsdServiceInfo, and uses that network to resolve the service.
In that case the Network has netId 99 and resolving the service fails.
Avoid that problem by:
- Keeping the Network field null when a service is found on a tethering
downstream; this avoids giving apps a confusing and unusable Network
with netId 99
- Using the interface index found during discovery to resolve the
service, if the app uses the NsdServiceInfo that was obtained from
discovery to resolve. If not, all interfaces will be used to resolve,
as per legacy APIs.
Bug: 233979892
Test: atest NsdServiceTest
Also manual test with 2 devices connected via hotspot
Change-Id: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a
(cherry picked from commit 1a8ee102d3)
Merged-In: Idd176153b67ccbd1d4f1b1fd66dafaa2f3a9e27a
This commit is contained in:
committed by
Cherrypicker Worker
parent
d3cd66e224
commit
0102c9440a
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user