Merge "Fix some @hide usage in Tethering(Cont.)"

This commit is contained in:
Mark Chien
2020-01-09 08:47:07 +00:00
committed by Gerrit Code Review
8 changed files with 58 additions and 59 deletions

View File

@@ -11,6 +11,7 @@ rule com.android.internal.util.MessageUtils* com.android.networkstack.tethering.
rule com.android.internal.util.Preconditions* com.android.networkstack.tethering.util.Preconditions@1 rule com.android.internal.util.Preconditions* com.android.networkstack.tethering.util.Preconditions@1
rule com.android.internal.util.State* com.android.networkstack.tethering.util.State@1 rule com.android.internal.util.State* com.android.networkstack.tethering.util.State@1
rule com.android.internal.util.StateMachine* com.android.networkstack.tethering.util.StateMachine@1 rule com.android.internal.util.StateMachine* com.android.networkstack.tethering.util.StateMachine@1
rule com.android.internal.util.TrafficStatsConstants* com.android.networkstack.tethering.util.TrafficStatsConstants@1
rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1 rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1

View File

@@ -668,7 +668,7 @@ public class RouterAdvertisementDaemon {
} }
private final class UnicastResponder extends Thread { private final class UnicastResponder extends Thread {
private final InetSocketAddress mSolicitor = new InetSocketAddress(); private final InetSocketAddress mSolicitor = new InetSocketAddress(0);
// The recycled buffer for receiving Router Solicitations from clients. // The recycled buffer for receiving Router Solicitations from clients.
// If the RS is larger than IPV6_MIN_MTU the packets are truncated. // If the RS is larger than IPV6_MIN_MTU the packets are truncated.
// This is fine since currently only byte 0 is examined anyway. // This is fine since currently only byte 0 is examined anyway.

View File

@@ -71,7 +71,6 @@ import android.net.LinkAddress;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.Network; import android.net.Network;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkUtils;
import android.net.TetherStatesParcel; import android.net.TetherStatesParcel;
import android.net.TetheringConfigurationParcel; import android.net.TetheringConfigurationParcel;
import android.net.ip.IpServer; import android.net.ip.IpServer;
@@ -291,13 +290,6 @@ public class Tethering {
filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
filter.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED); filter.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED);
mContext.registerReceiver(mStateReceiver, filter, null, handler); mContext.registerReceiver(mStateReceiver, filter, null, handler);
filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_SHARED);
filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
filter.addDataScheme("file");
mContext.registerReceiver(mStateReceiver, filter, null, handler);
} }
private class TetheringThreadExecutor implements Executor { private class TetheringThreadExecutor implements Executor {
@@ -1384,12 +1376,17 @@ public class Tethering {
protected void setDnsForwarders(final Network network, final LinkProperties lp) { protected void setDnsForwarders(final Network network, final LinkProperties lp) {
// TODO: Set v4 and/or v6 DNS per available connectivity. // TODO: Set v4 and/or v6 DNS per available connectivity.
String[] dnsServers = mConfig.defaultIPv4DNS;
final Collection<InetAddress> dnses = lp.getDnsServers(); final Collection<InetAddress> dnses = lp.getDnsServers();
// TODO: Properly support the absence of DNS servers. // TODO: Properly support the absence of DNS servers.
final String[] dnsServers;
if (dnses != null && !dnses.isEmpty()) { if (dnses != null && !dnses.isEmpty()) {
// TODO: remove this invocation of NetworkUtils.makeStrings(). dnsServers = new String[dnses.size()];
dnsServers = NetworkUtils.makeStrings(dnses); int i = 0;
for (InetAddress dns : dnses) {
dnsServers[i++] = dns.getHostAddress();
}
} else {
dnsServers = mConfig.defaultIPv4DNS;
} }
final int netId = (network != null) ? network.netId : NETID_UNSET; final int netId = (network != null) ? network.netId : NETID_UNSET;
try { try {

View File

@@ -37,7 +37,6 @@ import static com.android.internal.R.string.config_mobile_hotspot_provision_app_
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.TetheringConfigurationParcel; import android.net.TetheringConfigurationParcel;
import android.net.util.SharedLog; import android.net.util.SharedLog;
import android.provider.Settings; import android.provider.Settings;
@@ -179,8 +178,8 @@ public class TetheringConfiguration {
pw.print("chooseUpstreamAutomatically: "); pw.print("chooseUpstreamAutomatically: ");
pw.println(chooseUpstreamAutomatically); pw.println(chooseUpstreamAutomatically);
dumpStringArray(pw, "preferredUpstreamIfaceTypes", pw.print("legacyPreredUpstreamIfaceTypes: ");
preferredUpstreamNames(preferredUpstreamIfaceTypes)); pw.println(Arrays.toString(toIntArray(preferredUpstreamIfaceTypes)));
dumpStringArray(pw, "legacyDhcpRanges", legacyDhcpRanges); dumpStringArray(pw, "legacyDhcpRanges", legacyDhcpRanges);
dumpStringArray(pw, "defaultIPv4DNS", defaultIPv4DNS); dumpStringArray(pw, "defaultIPv4DNS", defaultIPv4DNS);
@@ -205,7 +204,7 @@ public class TetheringConfiguration {
sj.add(String.format("isDunRequired:%s", isDunRequired)); sj.add(String.format("isDunRequired:%s", isDunRequired));
sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically)); sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically));
sj.add(String.format("preferredUpstreamIfaceTypes:%s", sj.add(String.format("preferredUpstreamIfaceTypes:%s",
makeString(preferredUpstreamNames(preferredUpstreamIfaceTypes)))); toIntArray(preferredUpstreamIfaceTypes)));
sj.add(String.format("provisioningApp:%s", makeString(provisioningApp))); sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi)); sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer)); sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer));
@@ -234,21 +233,6 @@ public class TetheringConfiguration {
return sj.toString(); return sj.toString();
} }
private static String[] preferredUpstreamNames(Collection<Integer> upstreamTypes) {
String[] upstreamNames = null;
if (upstreamTypes != null) {
upstreamNames = new String[upstreamTypes.size()];
int i = 0;
for (Integer netType : upstreamTypes) {
upstreamNames[i] = ConnectivityManager.getNetworkTypeName(netType);
i++;
}
}
return upstreamNames;
}
/** Check whether dun is required. */ /** Check whether dun is required. */
public static boolean checkDunRequired(Context ctx) { public static boolean checkDunRequired(Context ctx) {
final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE); final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE);
@@ -388,6 +372,15 @@ public class TetheringConfiguration {
return false; return false;
} }
private static int[] toIntArray(Collection<Integer> values) {
final int[] result = new int[values.size()];
int index = 0;
for (Integer value : values) {
result[index++] = value;
}
return result;
}
/** /**
* Convert this TetheringConfiguration to a TetheringConfigurationParcel. * Convert this TetheringConfiguration to a TetheringConfigurationParcel.
*/ */
@@ -400,12 +393,7 @@ public class TetheringConfiguration {
parcel.isDunRequired = isDunRequired; parcel.isDunRequired = isDunRequired;
parcel.chooseUpstreamAutomatically = chooseUpstreamAutomatically; parcel.chooseUpstreamAutomatically = chooseUpstreamAutomatically;
int[] preferredTypes = new int[preferredUpstreamIfaceTypes.size()]; parcel.preferredUpstreamIfaceTypes = toIntArray(preferredUpstreamIfaceTypes);
int index = 0;
for (Integer type : preferredUpstreamIfaceTypes) {
preferredTypes[index++] = type;
}
parcel.preferredUpstreamIfaceTypes = preferredTypes;
parcel.legacyDhcpRanges = legacyDhcpRanges; parcel.legacyDhcpRanges = legacyDhcpRanges;
parcel.defaultIPv4DNS = defaultIPv4DNS; parcel.defaultIPv4DNS = defaultIPv4DNS;

View File

@@ -22,14 +22,17 @@ import android.net.NetworkCapabilities;
import android.net.RouteInfo; import android.net.RouteInfo;
import android.net.util.InterfaceSet; import android.net.util.InterfaceSet;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException;
/** /**
* @hide * @hide
*/ */
public final class TetheringInterfaceUtils { public final class TetheringInterfaceUtils {
private static final InetAddress IN6ADDR_ANY = getByAddress(
new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
private static final InetAddress INADDR_ANY = getByAddress(new byte[] {0, 0, 0, 0});
/** /**
* Get upstream interfaces for tethering based on default routes for IPv4/IPv6. * Get upstream interfaces for tethering based on default routes for IPv4/IPv6.
* @return null if there is no usable interface, or a set of at least one interface otherwise. * @return null if there is no usable interface, or a set of at least one interface otherwise.
@@ -40,7 +43,7 @@ public final class TetheringInterfaceUtils {
} }
final LinkProperties lp = ns.linkProperties; final LinkProperties lp = ns.linkProperties;
final String if4 = getInterfaceForDestination(lp, Inet4Address.ANY); final String if4 = getInterfaceForDestination(lp, INADDR_ANY);
final String if6 = getIPv6Interface(ns); final String if6 = getIPv6Interface(ns);
return (if4 == null && if6 == null) ? null : new InterfaceSet(if4, if6); return (if4 == null && if6 == null) ? null : new InterfaceSet(if4, if6);
@@ -76,7 +79,7 @@ public final class TetheringInterfaceUtils {
&& ns.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR); && ns.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
return canTether return canTether
? getInterfaceForDestination(ns.linkProperties, Inet6Address.ANY) ? getInterfaceForDestination(ns.linkProperties, IN6ADDR_ANY)
: null; : null;
} }
@@ -86,4 +89,12 @@ public final class TetheringInterfaceUtils {
: null; : null;
return (ri != null) ? ri.getInterface() : null; return (ri != null) ? ri.getInterface() : null;
} }
private static InetAddress getByAddress(final byte[] addr) {
try {
return InetAddress.getByAddress(null, addr);
} catch (UnknownHostException e) {
throw new AssertionError("illegal address length" + addr.length);
}
}
} }

View File

@@ -26,11 +26,11 @@ import static android.net.dhcp.IDhcpServer.STATUS_UNKNOWN_ERROR;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.IIntResultListener; import android.net.IIntResultListener;
import android.net.INetworkStackConnector; import android.net.INetworkStackConnector;
import android.net.ITetheringConnector; import android.net.ITetheringConnector;
import android.net.ITetheringEventCallback; import android.net.ITetheringEventCallback;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest; import android.net.NetworkRequest;
import android.net.dhcp.DhcpServerCallbacks; import android.net.dhcp.DhcpServerCallbacks;
import android.net.dhcp.DhcpServingParamsParcel; import android.net.dhcp.DhcpServingParamsParcel;
@@ -307,9 +307,15 @@ public class TetheringService extends Service {
mDeps = new TetheringDependencies() { mDeps = new TetheringDependencies() {
@Override @Override
public NetworkRequest getDefaultNetworkRequest() { public NetworkRequest getDefaultNetworkRequest() {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService( // TODO: b/147280869, add a proper system API to replace this.
Context.CONNECTIVITY_SERVICE); final NetworkRequest trackDefaultRequest = new NetworkRequest.Builder()
return cm.getDefaultRequest(); .clearCapabilities()
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build();
return trackDefaultRequest;
} }
@Override @Override

View File

@@ -19,7 +19,6 @@ package com.android.server.connectivity.tethering;
import static android.net.ConnectivityManager.TYPE_MOBILE_DUN; import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI; import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
import static android.net.ConnectivityManager.TYPE_NONE; import static android.net.ConnectivityManager.TYPE_NONE;
import static android.net.ConnectivityManager.getNetworkTypeName;
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN; import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
@@ -35,7 +34,6 @@ import android.net.NetworkRequest;
import android.net.util.PrefixUtils; import android.net.util.PrefixUtils;
import android.net.util.SharedLog; import android.net.util.SharedLog;
import android.os.Handler; import android.os.Handler;
import android.os.Process;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -130,15 +128,15 @@ public class UpstreamNetworkMonitor {
*/ */
public void startTrackDefaultNetwork(NetworkRequest defaultNetworkRequest, public void startTrackDefaultNetwork(NetworkRequest defaultNetworkRequest,
EntitlementManager entitle) { EntitlementManager entitle) {
// This is not really a "request", just a way of tracking the system default network.
// It's guaranteed not to actually bring up any networks because it's the same request // defaultNetworkRequest is not really a "request", just a way of tracking the system
// as the ConnectivityService default request, and thus shares fate with it. We can't // default network. It's guaranteed not to actually bring up any networks because it's
// use registerDefaultNetworkCallback because it will not track the system default // the should be the same request as the ConnectivityService default request, and thus
// network if there is a VPN that applies to our UID. // shares fate with it. We can't use registerDefaultNetworkCallback because it will not
// track the system default network if there is a VPN that applies to our UID.
if (mDefaultNetworkCallback == null) { if (mDefaultNetworkCallback == null) {
final NetworkRequest trackDefaultRequest = new NetworkRequest(defaultNetworkRequest);
mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_DEFAULT_INTERNET); mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_DEFAULT_INTERNET);
cm().requestNetwork(trackDefaultRequest, mDefaultNetworkCallback, mHandler); cm().requestNetwork(defaultNetworkRequest, mDefaultNetworkCallback, mHandler);
} }
if (mEntitlementMgr == null) { if (mEntitlementMgr == null) {
mEntitlementMgr = entitle; mEntitlementMgr = entitle;
@@ -239,7 +237,7 @@ public class UpstreamNetworkMonitor {
final TypeStatePair typeStatePair = findFirstAvailableUpstreamByType( final TypeStatePair typeStatePair = findFirstAvailableUpstreamByType(
mNetworkMap.values(), preferredTypes, isCellularUpstreamPermitted()); mNetworkMap.values(), preferredTypes, isCellularUpstreamPermitted());
mLog.log("preferred upstream type: " + getNetworkTypeName(typeStatePair.type)); mLog.log("preferred upstream type: " + typeStatePair.type);
switch (typeStatePair.type) { switch (typeStatePair.type) {
case TYPE_MOBILE_DUN: case TYPE_MOBILE_DUN:
@@ -514,16 +512,13 @@ public class UpstreamNetworkMonitor {
try { try {
nc = ConnectivityManager.networkCapabilitiesForType(type); nc = ConnectivityManager.networkCapabilitiesForType(type);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
Log.e(TAG, "No NetworkCapabilities mapping for legacy type: " Log.e(TAG, "No NetworkCapabilities mapping for legacy type: " + type);
+ ConnectivityManager.getNetworkTypeName(type));
continue; continue;
} }
if (!isCellularUpstreamPermitted && isCellular(nc)) { if (!isCellularUpstreamPermitted && isCellular(nc)) {
continue; continue;
} }
nc.setSingleUid(Process.myUid());
for (UpstreamNetworkState value : netStates) { for (UpstreamNetworkState value : netStates) {
if (!nc.satisfiedByNetworkCapabilities(value.networkCapabilities)) { if (!nc.satisfiedByNetworkCapabilities(value.networkCapabilities)) {
continue; continue;

View File

@@ -7,5 +7,6 @@ rule com.android.internal.util.MessageUtils* com.android.networkstack.tethering.
rule com.android.internal.util.Preconditions* com.android.networkstack.tethering.util.Preconditions@1 rule com.android.internal.util.Preconditions* com.android.networkstack.tethering.util.Preconditions@1
rule com.android.internal.util.State* com.android.networkstack.tethering.util.State@1 rule com.android.internal.util.State* com.android.networkstack.tethering.util.State@1
rule com.android.internal.util.StateMachine* com.android.networkstack.tethering.util.StateMachine@1 rule com.android.internal.util.StateMachine* com.android.networkstack.tethering.util.StateMachine@1
rule com.android.internal.util.TrafficStatsConstants* com.android.networkstack.tethering.util.TrafficStatsConstants@1
rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1 rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1