Merge "Fix some @hide usage in Tethering(Cont.)"
This commit is contained in:
commit
6a95399667
@ -619,6 +619,7 @@ filegroup {
|
||||
"core/java/com/android/internal/util/Preconditions.java",
|
||||
"core/java/com/android/internal/util/State.java",
|
||||
"core/java/com/android/internal/util/StateMachine.java",
|
||||
"core/java/com/android/internal/util/TrafficStatsConstants.java",
|
||||
"core/java/android/net/shared/Inet4AddressUtils.java",
|
||||
],
|
||||
}
|
||||
|
@ -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.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.TrafficStatsConstants* com.android.networkstack.tethering.util.TrafficStatsConstants@1
|
||||
|
||||
rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1
|
||||
|
||||
|
@ -668,7 +668,7 @@ public class RouterAdvertisementDaemon {
|
||||
}
|
||||
|
||||
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.
|
||||
// If the RS is larger than IPV6_MIN_MTU the packets are truncated.
|
||||
// This is fine since currently only byte 0 is examined anyway.
|
||||
|
@ -71,7 +71,6 @@ import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.TetherStatesParcel;
|
||||
import android.net.TetheringConfigurationParcel;
|
||||
import android.net.ip.IpServer;
|
||||
@ -291,13 +290,6 @@ public class Tethering {
|
||||
filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
||||
filter.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED);
|
||||
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 {
|
||||
@ -1384,12 +1376,17 @@ public class Tethering {
|
||||
|
||||
protected void setDnsForwarders(final Network network, final LinkProperties lp) {
|
||||
// TODO: Set v4 and/or v6 DNS per available connectivity.
|
||||
String[] dnsServers = mConfig.defaultIPv4DNS;
|
||||
final Collection<InetAddress> dnses = lp.getDnsServers();
|
||||
// TODO: Properly support the absence of DNS servers.
|
||||
final String[] dnsServers;
|
||||
if (dnses != null && !dnses.isEmpty()) {
|
||||
// TODO: remove this invocation of NetworkUtils.makeStrings().
|
||||
dnsServers = NetworkUtils.makeStrings(dnses);
|
||||
dnsServers = new String[dnses.size()];
|
||||
int i = 0;
|
||||
for (InetAddress dns : dnses) {
|
||||
dnsServers[i++] = dns.getHostAddress();
|
||||
}
|
||||
} else {
|
||||
dnsServers = mConfig.defaultIPv4DNS;
|
||||
}
|
||||
final int netId = (network != null) ? network.netId : NETID_UNSET;
|
||||
try {
|
||||
|
@ -37,7 +37,6 @@ import static com.android.internal.R.string.config_mobile_hotspot_provision_app_
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.TetheringConfigurationParcel;
|
||||
import android.net.util.SharedLog;
|
||||
import android.provider.Settings;
|
||||
@ -179,8 +178,8 @@ public class TetheringConfiguration {
|
||||
|
||||
pw.print("chooseUpstreamAutomatically: ");
|
||||
pw.println(chooseUpstreamAutomatically);
|
||||
dumpStringArray(pw, "preferredUpstreamIfaceTypes",
|
||||
preferredUpstreamNames(preferredUpstreamIfaceTypes));
|
||||
pw.print("legacyPreredUpstreamIfaceTypes: ");
|
||||
pw.println(Arrays.toString(toIntArray(preferredUpstreamIfaceTypes)));
|
||||
|
||||
dumpStringArray(pw, "legacyDhcpRanges", legacyDhcpRanges);
|
||||
dumpStringArray(pw, "defaultIPv4DNS", defaultIPv4DNS);
|
||||
@ -205,7 +204,7 @@ public class TetheringConfiguration {
|
||||
sj.add(String.format("isDunRequired:%s", isDunRequired));
|
||||
sj.add(String.format("chooseUpstreamAutomatically:%s", chooseUpstreamAutomatically));
|
||||
sj.add(String.format("preferredUpstreamIfaceTypes:%s",
|
||||
makeString(preferredUpstreamNames(preferredUpstreamIfaceTypes))));
|
||||
toIntArray(preferredUpstreamIfaceTypes)));
|
||||
sj.add(String.format("provisioningApp:%s", makeString(provisioningApp)));
|
||||
sj.add(String.format("provisioningAppNoUi:%s", provisioningAppNoUi));
|
||||
sj.add(String.format("enableLegacyDhcpServer:%s", enableLegacyDhcpServer));
|
||||
@ -234,21 +233,6 @@ public class TetheringConfiguration {
|
||||
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. */
|
||||
public static boolean checkDunRequired(Context ctx) {
|
||||
final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE);
|
||||
@ -388,6 +372,15 @@ public class TetheringConfiguration {
|
||||
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.
|
||||
*/
|
||||
@ -400,12 +393,7 @@ public class TetheringConfiguration {
|
||||
parcel.isDunRequired = isDunRequired;
|
||||
parcel.chooseUpstreamAutomatically = chooseUpstreamAutomatically;
|
||||
|
||||
int[] preferredTypes = new int[preferredUpstreamIfaceTypes.size()];
|
||||
int index = 0;
|
||||
for (Integer type : preferredUpstreamIfaceTypes) {
|
||||
preferredTypes[index++] = type;
|
||||
}
|
||||
parcel.preferredUpstreamIfaceTypes = preferredTypes;
|
||||
parcel.preferredUpstreamIfaceTypes = toIntArray(preferredUpstreamIfaceTypes);
|
||||
|
||||
parcel.legacyDhcpRanges = legacyDhcpRanges;
|
||||
parcel.defaultIPv4DNS = defaultIPv4DNS;
|
||||
|
@ -22,14 +22,17 @@ import android.net.NetworkCapabilities;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.util.InterfaceSet;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
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.
|
||||
* @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 String if4 = getInterfaceForDestination(lp, Inet4Address.ANY);
|
||||
final String if4 = getInterfaceForDestination(lp, INADDR_ANY);
|
||||
final String if6 = getIPv6Interface(ns);
|
||||
|
||||
return (if4 == null && if6 == null) ? null : new InterfaceSet(if4, if6);
|
||||
@ -76,7 +79,7 @@ public final class TetheringInterfaceUtils {
|
||||
&& ns.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||
|
||||
return canTether
|
||||
? getInterfaceForDestination(ns.linkProperties, Inet6Address.ANY)
|
||||
? getInterfaceForDestination(ns.linkProperties, IN6ADDR_ANY)
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -86,4 +89,12 @@ public final class TetheringInterfaceUtils {
|
||||
: 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ import static android.net.dhcp.IDhcpServer.STATUS_UNKNOWN_ERROR;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.IIntResultListener;
|
||||
import android.net.INetworkStackConnector;
|
||||
import android.net.ITetheringConnector;
|
||||
import android.net.ITetheringEventCallback;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.dhcp.DhcpServerCallbacks;
|
||||
import android.net.dhcp.DhcpServingParamsParcel;
|
||||
@ -307,9 +307,15 @@ public class TetheringService extends Service {
|
||||
mDeps = new TetheringDependencies() {
|
||||
@Override
|
||||
public NetworkRequest getDefaultNetworkRequest() {
|
||||
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getDefaultRequest();
|
||||
// TODO: b/147280869, add a proper system API to replace this.
|
||||
final NetworkRequest trackDefaultRequest = new NetworkRequest.Builder()
|
||||
.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
|
||||
|
@ -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_HIPRI;
|
||||
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_NOT_VPN;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
@ -35,7 +34,6 @@ import android.net.NetworkRequest;
|
||||
import android.net.util.PrefixUtils;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
@ -130,15 +128,15 @@ public class UpstreamNetworkMonitor {
|
||||
*/
|
||||
public void startTrackDefaultNetwork(NetworkRequest defaultNetworkRequest,
|
||||
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
|
||||
// as the ConnectivityService default request, and thus 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.
|
||||
|
||||
// defaultNetworkRequest 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 should be the same request as the ConnectivityService default request, and thus
|
||||
// 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) {
|
||||
final NetworkRequest trackDefaultRequest = new NetworkRequest(defaultNetworkRequest);
|
||||
mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_DEFAULT_INTERNET);
|
||||
cm().requestNetwork(trackDefaultRequest, mDefaultNetworkCallback, mHandler);
|
||||
cm().requestNetwork(defaultNetworkRequest, mDefaultNetworkCallback, mHandler);
|
||||
}
|
||||
if (mEntitlementMgr == null) {
|
||||
mEntitlementMgr = entitle;
|
||||
@ -239,7 +237,7 @@ public class UpstreamNetworkMonitor {
|
||||
final TypeStatePair typeStatePair = findFirstAvailableUpstreamByType(
|
||||
mNetworkMap.values(), preferredTypes, isCellularUpstreamPermitted());
|
||||
|
||||
mLog.log("preferred upstream type: " + getNetworkTypeName(typeStatePair.type));
|
||||
mLog.log("preferred upstream type: " + typeStatePair.type);
|
||||
|
||||
switch (typeStatePair.type) {
|
||||
case TYPE_MOBILE_DUN:
|
||||
@ -514,16 +512,13 @@ public class UpstreamNetworkMonitor {
|
||||
try {
|
||||
nc = ConnectivityManager.networkCapabilitiesForType(type);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
Log.e(TAG, "No NetworkCapabilities mapping for legacy type: "
|
||||
+ ConnectivityManager.getNetworkTypeName(type));
|
||||
Log.e(TAG, "No NetworkCapabilities mapping for legacy type: " + type);
|
||||
continue;
|
||||
}
|
||||
if (!isCellularUpstreamPermitted && isCellular(nc)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nc.setSingleUid(Process.myUid());
|
||||
|
||||
for (UpstreamNetworkState value : netStates) {
|
||||
if (!nc.satisfiedByNetworkCapabilities(value.networkCapabilities)) {
|
||||
continue;
|
||||
|
@ -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.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.TrafficStatsConstants* com.android.networkstack.tethering.util.TrafficStatsConstants@1
|
||||
|
||||
rule android.net.LocalLog* com.android.networkstack.tethering.LocalLog@1
|
||||
|
Loading…
x
Reference in New Issue
Block a user