Merge "DO NOT MERGE - Merge Android 10 into master"

This commit is contained in:
Xin Li
2019-09-05 16:53:23 +00:00
committed by Gerrit Code Review
25 changed files with 135 additions and 22 deletions

View File

@@ -78,7 +78,7 @@ public class CaptivePortal implements Parcelable {
out.writeStrongBinder(mBinder);
}
public static final Parcelable.Creator<CaptivePortal> CREATOR
public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR
= new Parcelable.Creator<CaptivePortal>() {
@Override
public CaptivePortal createFromParcel(Parcel in) {

View File

@@ -54,7 +54,7 @@ public final class ConnectionInfo implements Parcelable {
out.writeInt(remote.getPort());
}
public static final Creator<ConnectionInfo> CREATOR = new Creator<ConnectionInfo>() {
public static final @android.annotation.NonNull Creator<ConnectionInfo> CREATOR = new Creator<ConnectionInfo>() {
public ConnectionInfo createFromParcel(Parcel in) {
int protocol = in.readInt();
InetAddress localAddress;

View File

@@ -84,7 +84,7 @@ public class DhcpInfo implements Parcelable {
}
/** Implement the Parcelable interface {@hide} */
public static final Creator<DhcpInfo> CREATOR =
public static final @android.annotation.NonNull Creator<DhcpInfo> CREATOR =
new Creator<DhcpInfo>() {
public DhcpInfo createFromParcel(Parcel in) {
DhcpInfo info = new DhcpInfo();

View File

@@ -189,7 +189,7 @@ public class IpConfiguration implements Parcelable {
}
/** Implement the Parcelable interface */
public static final Creator<IpConfiguration> CREATOR =
public static final @android.annotation.NonNull Creator<IpConfiguration> CREATOR =
new Creator<IpConfiguration>() {
public IpConfiguration createFromParcel(Parcel in) {
IpConfiguration config = new IpConfiguration();

View File

@@ -288,7 +288,7 @@ public final class IpPrefix implements Parcelable {
/**
* Implement the Parcelable interface.
*/
public static final Creator<IpPrefix> CREATOR =
public static final @android.annotation.NonNull Creator<IpPrefix> CREATOR =
new Creator<IpPrefix>() {
public IpPrefix createFromParcel(Parcel in) {
byte[] address = in.createByteArray();

View File

@@ -105,7 +105,7 @@ public class KeepalivePacketData implements Parcelable {
}
/** Parcelable Creator */
public static final Parcelable.Creator<KeepalivePacketData> CREATOR =
public static final @android.annotation.NonNull Parcelable.Creator<KeepalivePacketData> CREATOR =
new Parcelable.Creator<KeepalivePacketData>() {
public KeepalivePacketData createFromParcel(Parcel in) {
return new KeepalivePacketData(in);

View File

@@ -378,7 +378,7 @@ public class LinkAddress implements Parcelable {
/**
* Implement the Parcelable interface.
*/
public static final Creator<LinkAddress> CREATOR =
public static final @android.annotation.NonNull Creator<LinkAddress> CREATOR =
new Creator<LinkAddress>() {
public LinkAddress createFromParcel(Parcel in) {
InetAddress address = null;

View File

@@ -1627,7 +1627,7 @@ public final class LinkProperties implements Parcelable {
/**
* Implement the Parcelable interface.
*/
public static final Creator<LinkProperties> CREATOR =
public static final @android.annotation.NonNull Creator<LinkProperties> CREATOR =
new Creator<LinkProperties>() {
public LinkProperties createFromParcel(Parcel in) {
LinkProperties netProp = new LinkProperties();

View File

@@ -168,7 +168,7 @@ public final class MacAddress implements Parcelable {
return 0;
}
public static final Parcelable.Creator<MacAddress> CREATOR =
public static final @android.annotation.NonNull Parcelable.Creator<MacAddress> CREATOR =
new Parcelable.Creator<MacAddress>() {
public MacAddress createFromParcel(Parcel in) {
return new MacAddress(in.readLong());
@@ -410,6 +410,21 @@ public final class MacAddress implements Parcelable {
return out;
}
/**
* Checks if this MAC Address matches the provided range.
*
* @param baseAddress MacAddress representing the base address to compare with.
* @param mask MacAddress representing the mask to use during comparison.
* @return true if this MAC Address matches the given range.
*
* @hide
*/
public boolean matches(@NonNull MacAddress baseAddress, @NonNull MacAddress mask) {
Preconditions.checkNotNull(baseAddress);
Preconditions.checkNotNull(mask);
return (mAddr & mask.mAddr) == (baseAddress.mAddr & mask.mAddr);
}
/**
* Create a link-local Inet6Address from the MAC address. The EUI-48 MAC address is converted
* to an EUI-64 MAC address per RFC 4291. The resulting EUI-64 is used to construct a link-local

View File

@@ -471,7 +471,7 @@ public class Network implements Parcelable {
dest.writeInt(netId);
}
public static final Creator<Network> CREATOR =
public static final @android.annotation.NonNull Creator<Network> CREATOR =
new Creator<Network>() {
public Network createFromParcel(Parcel in) {
int netId = in.readInt();

View File

@@ -516,7 +516,7 @@ public abstract class NetworkAgent extends Handler {
}
/**
* Requests that the network hardware stops sending keepalive packets.
* Requests that the network hardware send the specified packet at the specified interval.
*/
protected void stopSocketKeepalive(Message msg) {
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);

View File

@@ -1481,7 +1481,7 @@ public final class NetworkCapabilities implements Parcelable {
dest.writeString(mSSID);
}
public static final Creator<NetworkCapabilities> CREATOR =
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
new Creator<NetworkCapabilities>() {
@Override
public NetworkCapabilities createFromParcel(Parcel in) {

View File

@@ -560,7 +560,7 @@ public class NetworkInfo implements Parcelable {
}
}
public static final Creator<NetworkInfo> CREATOR = new Creator<NetworkInfo>() {
public static final @android.annotation.NonNull Creator<NetworkInfo> CREATOR = new Creator<NetworkInfo>() {
@Override
public NetworkInfo createFromParcel(Parcel in) {
int netType = in.readInt();

View File

@@ -106,7 +106,7 @@ public class NetworkMisc implements Parcelable {
out.writeInt(skip464xlat ? 1 : 0);
}
public static final Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
public static final @android.annotation.NonNull Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
@Override
public NetworkMisc createFromParcel(Parcel in) {
NetworkMisc networkMisc = new NetworkMisc();

View File

@@ -368,7 +368,7 @@ public class NetworkRequest implements Parcelable {
dest.writeInt(requestId);
dest.writeString(type.name());
}
public static final Creator<NetworkRequest> CREATOR =
public static final @android.annotation.NonNull Creator<NetworkRequest> CREATOR =
new Creator<NetworkRequest>() {
public NetworkRequest createFromParcel(Parcel in) {
NetworkCapabilities nc = NetworkCapabilities.CREATOR.createFromParcel(in);

View File

@@ -87,7 +87,7 @@ public class NetworkState implements Parcelable {
}
@UnsupportedAppUsage
public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
public static final @android.annotation.NonNull Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
@Override
public NetworkState createFromParcel(Parcel in) {
return new NetworkState(in);

View File

@@ -16,10 +16,15 @@
package android.net;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.net.shared.Inet4AddressUtils;
import android.os.Build;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
import android.util.Pair;
@@ -454,4 +459,30 @@ public class NetworkUtils {
}
return routedIPCount;
}
private static final int[] ADDRESS_FAMILIES = new int[] {AF_INET, AF_INET6};
/**
* Returns true if the hostname is weakly validated.
* @param hostname Name of host to validate.
* @return True if it's a valid-ish hostname.
*
* @hide
*/
public static boolean isWeaklyValidatedHostname(@NonNull String hostname) {
// TODO(b/34953048): Use a validation method that permits more accurate,
// but still inexpensive, checking of likely valid DNS hostnames.
final String weakHostnameRegex = "^[a-zA-Z0-9_.-]+$";
if (!hostname.matches(weakHostnameRegex)) {
return false;
}
for (int address_family : ADDRESS_FAMILIES) {
if (Os.inet_pton(address_family, hostname) != null) {
return false;
}
}
return true;
}
}

View File

@@ -342,7 +342,7 @@ public class ProxyInfo implements Parcelable {
dest.writeStringArray(mParsedExclusionList);
}
public static final Creator<ProxyInfo> CREATOR =
public static final @android.annotation.NonNull Creator<ProxyInfo> CREATOR =
new Creator<ProxyInfo>() {
public ProxyInfo createFromParcel(Parcel in) {
String host = null;

View File

@@ -527,7 +527,7 @@ public final class RouteInfo implements Parcelable {
/**
* Implement the Parcelable interface.
*/
public static final Creator<RouteInfo> CREATOR =
public static final @android.annotation.NonNull Creator<RouteInfo> CREATOR =
new Creator<RouteInfo>() {
public RouteInfo createFromParcel(Parcel in) {
IpPrefix dest = in.readParcelable(null);

View File

@@ -283,7 +283,7 @@ public final class StaticIpConfiguration implements Parcelable {
}
/** Implement the Parcelable interface */
public static final Creator<StaticIpConfiguration> CREATOR =
public static final @android.annotation.NonNull Creator<StaticIpConfiguration> CREATOR =
new Creator<StaticIpConfiguration>() {
public StaticIpConfiguration createFromParcel(Parcel in) {
return readFromParcel(in);

View File

@@ -111,7 +111,7 @@ public final class UidRange implements Parcelable {
dest.writeInt(stop);
}
public static final Creator<UidRange> CREATOR =
public static final @android.annotation.NonNull Creator<UidRange> CREATOR =
new Creator<UidRange>() {
@Override
public UidRange createFromParcel(Parcel in) {

View File

@@ -20,6 +20,7 @@ import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.NETID_UNSET;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_NONE;
import static android.net.ConnectivityManager.TYPE_VPN;
@@ -2810,7 +2811,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
switch (msg.what) {
default:
return false;
case android.net.NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
case NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
handleReleaseNetworkRequest((NetworkRequest) msg.obj, msg.sendingUid,
/* callOnUnavailable */ true);
break;
@@ -7015,6 +7016,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
// restore private DNS settings to default mode (opportunistic)
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_PRIVATE_DNS)) {
Settings.Global.putString(mContext.getContentResolver(),
Settings.Global.PRIVATE_DNS_MODE, PRIVATE_DNS_MODE_OPPORTUNISTIC);
}
Settings.Global.putString(mContext.getContentResolver(),
Settings.Global.NETWORK_AVOID_BAD_WIFI, null);
}

View File

@@ -254,6 +254,39 @@ public class MacAddressTest {
}
}
@Test
public void testMatches() {
// match 4 bytes prefix
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:00:00"),
MacAddress.fromString("ff:ff:ff:ff:00:00")));
// match bytes 0,1,2 and 5
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:00:00:11"),
MacAddress.fromString("ff:ff:ff:00:00:ff")));
// match 34 bit prefix
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:c0:00"),
MacAddress.fromString("ff:ff:ff:ff:c0:00")));
// fail to match 36 bit prefix
assertFalse(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:40:00"),
MacAddress.fromString("ff:ff:ff:ff:f0:00")));
// match all 6 bytes
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("aa:bb:cc:dd:ee:11"),
MacAddress.fromString("ff:ff:ff:ff:ff:ff")));
// match none of 6 bytes
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
MacAddress.fromString("00:00:00:00:00:00"),
MacAddress.fromString("00:00:00:00:00:00")));
}
/**
* Tests that link-local address generation from MAC is valid.
*/

View File

@@ -3423,7 +3423,7 @@ public class ConnectivityServiceTest {
testFactory.setScoreFilter(40);
// Register the factory and expect it to receive the default request.
testFactory.expectAddRequestsWithScores(0); // default request score is 0, not served yet
testFactory.expectAddRequestsWithScores(0);
testFactory.register();
SparseArray<NetworkRequest> requests = testFactory.waitForNetworkRequests(1);

View File

@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.INetd;
import android.net.IpSecAlgorithm;
import android.net.IpSecConfig;
@@ -57,6 +58,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.net.Inet4Address;
import java.net.Socket;
import java.util.Arrays;
import java.util.Collection;
@@ -118,6 +120,11 @@ public class IpSecServiceParameterizedTest {
}
}
@Override
public PackageManager getPackageManager() {
return mMockPkgMgr;
}
@Override
public void enforceCallingOrSelfPermission(String permission, String message) {
if (permission == android.Manifest.permission.MANAGE_IPSEC_TUNNELS) {
@@ -128,6 +135,7 @@ public class IpSecServiceParameterizedTest {
};
INetd mMockNetd;
PackageManager mMockPkgMgr;
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
IpSecService mIpSecService;
Network fakeNetwork = new Network(0xAB);
@@ -152,11 +160,16 @@ public class IpSecServiceParameterizedTest {
@Before
public void setUp() throws Exception {
mMockNetd = mock(INetd.class);
mMockPkgMgr = mock(PackageManager.class);
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
// Injecting mock netd
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);
// A package granted the AppOp for MANAGE_IPSEC_TUNNELS will be MODE_ALLOWED.
when(mMockAppOps.noteOp(anyInt(), anyInt(), eq("blessedPackage")))
.thenReturn(AppOpsManager.MODE_ALLOWED);
@@ -709,4 +722,18 @@ public class IpSecServiceParameterizedTest {
} catch (SecurityException expected) {
}
}
@Test
public void testFeatureFlagVerification() throws Exception {
when(mMockPkgMgr.hasSystemFeature(eq(PackageManager.FEATURE_IPSEC_TUNNELS)))
.thenReturn(false);
try {
String addr = Inet4Address.getLoopbackAddress().getHostAddress();
mIpSecService.createTunnelInterface(
addr, addr, new Network(0), new Binder(), "blessedPackage");
fail("Expected UnsupportedOperationException for disabled feature");
} catch (UnsupportedOperationException expected) {
}
}
}