Merge "DO NOT MERGE - Merge Android 10 into master"
This commit is contained in:
@@ -78,7 +78,7 @@ public class CaptivePortal implements Parcelable {
|
|||||||
out.writeStrongBinder(mBinder);
|
out.writeStrongBinder(mBinder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<CaptivePortal> CREATOR
|
public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR
|
||||||
= new Parcelable.Creator<CaptivePortal>() {
|
= new Parcelable.Creator<CaptivePortal>() {
|
||||||
@Override
|
@Override
|
||||||
public CaptivePortal createFromParcel(Parcel in) {
|
public CaptivePortal createFromParcel(Parcel in) {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public final class ConnectionInfo implements Parcelable {
|
|||||||
out.writeInt(remote.getPort());
|
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) {
|
public ConnectionInfo createFromParcel(Parcel in) {
|
||||||
int protocol = in.readInt();
|
int protocol = in.readInt();
|
||||||
InetAddress localAddress;
|
InetAddress localAddress;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class DhcpInfo implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the Parcelable interface {@hide} */
|
/** Implement the Parcelable interface {@hide} */
|
||||||
public static final Creator<DhcpInfo> CREATOR =
|
public static final @android.annotation.NonNull Creator<DhcpInfo> CREATOR =
|
||||||
new Creator<DhcpInfo>() {
|
new Creator<DhcpInfo>() {
|
||||||
public DhcpInfo createFromParcel(Parcel in) {
|
public DhcpInfo createFromParcel(Parcel in) {
|
||||||
DhcpInfo info = new DhcpInfo();
|
DhcpInfo info = new DhcpInfo();
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public class IpConfiguration implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the Parcelable interface */
|
/** Implement the Parcelable interface */
|
||||||
public static final Creator<IpConfiguration> CREATOR =
|
public static final @android.annotation.NonNull Creator<IpConfiguration> CREATOR =
|
||||||
new Creator<IpConfiguration>() {
|
new Creator<IpConfiguration>() {
|
||||||
public IpConfiguration createFromParcel(Parcel in) {
|
public IpConfiguration createFromParcel(Parcel in) {
|
||||||
IpConfiguration config = new IpConfiguration();
|
IpConfiguration config = new IpConfiguration();
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ public final class IpPrefix implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
*/
|
*/
|
||||||
public static final Creator<IpPrefix> CREATOR =
|
public static final @android.annotation.NonNull Creator<IpPrefix> CREATOR =
|
||||||
new Creator<IpPrefix>() {
|
new Creator<IpPrefix>() {
|
||||||
public IpPrefix createFromParcel(Parcel in) {
|
public IpPrefix createFromParcel(Parcel in) {
|
||||||
byte[] address = in.createByteArray();
|
byte[] address = in.createByteArray();
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class KeepalivePacketData implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Parcelable Creator */
|
/** Parcelable Creator */
|
||||||
public static final Parcelable.Creator<KeepalivePacketData> CREATOR =
|
public static final @android.annotation.NonNull Parcelable.Creator<KeepalivePacketData> CREATOR =
|
||||||
new Parcelable.Creator<KeepalivePacketData>() {
|
new Parcelable.Creator<KeepalivePacketData>() {
|
||||||
public KeepalivePacketData createFromParcel(Parcel in) {
|
public KeepalivePacketData createFromParcel(Parcel in) {
|
||||||
return new KeepalivePacketData(in);
|
return new KeepalivePacketData(in);
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ public class LinkAddress implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
*/
|
*/
|
||||||
public static final Creator<LinkAddress> CREATOR =
|
public static final @android.annotation.NonNull Creator<LinkAddress> CREATOR =
|
||||||
new Creator<LinkAddress>() {
|
new Creator<LinkAddress>() {
|
||||||
public LinkAddress createFromParcel(Parcel in) {
|
public LinkAddress createFromParcel(Parcel in) {
|
||||||
InetAddress address = null;
|
InetAddress address = null;
|
||||||
|
|||||||
@@ -1627,7 +1627,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
*/
|
*/
|
||||||
public static final Creator<LinkProperties> CREATOR =
|
public static final @android.annotation.NonNull Creator<LinkProperties> CREATOR =
|
||||||
new Creator<LinkProperties>() {
|
new Creator<LinkProperties>() {
|
||||||
public LinkProperties createFromParcel(Parcel in) {
|
public LinkProperties createFromParcel(Parcel in) {
|
||||||
LinkProperties netProp = new LinkProperties();
|
LinkProperties netProp = new LinkProperties();
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public final class MacAddress implements Parcelable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<MacAddress> CREATOR =
|
public static final @android.annotation.NonNull Parcelable.Creator<MacAddress> CREATOR =
|
||||||
new Parcelable.Creator<MacAddress>() {
|
new Parcelable.Creator<MacAddress>() {
|
||||||
public MacAddress createFromParcel(Parcel in) {
|
public MacAddress createFromParcel(Parcel in) {
|
||||||
return new MacAddress(in.readLong());
|
return new MacAddress(in.readLong());
|
||||||
@@ -410,6 +410,21 @@ public final class MacAddress implements Parcelable {
|
|||||||
return out;
|
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
|
* 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
|
* to an EUI-64 MAC address per RFC 4291. The resulting EUI-64 is used to construct a link-local
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ public class Network implements Parcelable {
|
|||||||
dest.writeInt(netId);
|
dest.writeInt(netId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<Network> CREATOR =
|
public static final @android.annotation.NonNull Creator<Network> CREATOR =
|
||||||
new Creator<Network>() {
|
new Creator<Network>() {
|
||||||
public Network createFromParcel(Parcel in) {
|
public Network createFromParcel(Parcel in) {
|
||||||
int netId = in.readInt();
|
int netId = in.readInt();
|
||||||
|
|||||||
@@ -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) {
|
protected void stopSocketKeepalive(Message msg) {
|
||||||
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
|
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
|
||||||
|
|||||||
@@ -1481,7 +1481,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
dest.writeString(mSSID);
|
dest.writeString(mSSID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<NetworkCapabilities> CREATOR =
|
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
|
||||||
new Creator<NetworkCapabilities>() {
|
new Creator<NetworkCapabilities>() {
|
||||||
@Override
|
@Override
|
||||||
public NetworkCapabilities createFromParcel(Parcel in) {
|
public NetworkCapabilities createFromParcel(Parcel in) {
|
||||||
|
|||||||
@@ -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
|
@Override
|
||||||
public NetworkInfo createFromParcel(Parcel in) {
|
public NetworkInfo createFromParcel(Parcel in) {
|
||||||
int netType = in.readInt();
|
int netType = in.readInt();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class NetworkMisc implements Parcelable {
|
|||||||
out.writeInt(skip464xlat ? 1 : 0);
|
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
|
@Override
|
||||||
public NetworkMisc createFromParcel(Parcel in) {
|
public NetworkMisc createFromParcel(Parcel in) {
|
||||||
NetworkMisc networkMisc = new NetworkMisc();
|
NetworkMisc networkMisc = new NetworkMisc();
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
dest.writeInt(requestId);
|
dest.writeInt(requestId);
|
||||||
dest.writeString(type.name());
|
dest.writeString(type.name());
|
||||||
}
|
}
|
||||||
public static final Creator<NetworkRequest> CREATOR =
|
public static final @android.annotation.NonNull Creator<NetworkRequest> CREATOR =
|
||||||
new Creator<NetworkRequest>() {
|
new Creator<NetworkRequest>() {
|
||||||
public NetworkRequest createFromParcel(Parcel in) {
|
public NetworkRequest createFromParcel(Parcel in) {
|
||||||
NetworkCapabilities nc = NetworkCapabilities.CREATOR.createFromParcel(in);
|
NetworkCapabilities nc = NetworkCapabilities.CREATOR.createFromParcel(in);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class NetworkState implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
|
public static final @android.annotation.NonNull Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
|
||||||
@Override
|
@Override
|
||||||
public NetworkState createFromParcel(Parcel in) {
|
public NetworkState createFromParcel(Parcel in) {
|
||||||
return new NetworkState(in);
|
return new NetworkState(in);
|
||||||
|
|||||||
@@ -16,10 +16,15 @@
|
|||||||
|
|
||||||
package android.net;
|
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.annotation.UnsupportedAppUsage;
|
||||||
import android.net.shared.Inet4AddressUtils;
|
import android.net.shared.Inet4AddressUtils;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
|
import android.system.Os;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -454,4 +459,30 @@ public class NetworkUtils {
|
|||||||
}
|
}
|
||||||
return routedIPCount;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ public class ProxyInfo implements Parcelable {
|
|||||||
dest.writeStringArray(mParsedExclusionList);
|
dest.writeStringArray(mParsedExclusionList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<ProxyInfo> CREATOR =
|
public static final @android.annotation.NonNull Creator<ProxyInfo> CREATOR =
|
||||||
new Creator<ProxyInfo>() {
|
new Creator<ProxyInfo>() {
|
||||||
public ProxyInfo createFromParcel(Parcel in) {
|
public ProxyInfo createFromParcel(Parcel in) {
|
||||||
String host = null;
|
String host = null;
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
*/
|
*/
|
||||||
public static final Creator<RouteInfo> CREATOR =
|
public static final @android.annotation.NonNull Creator<RouteInfo> CREATOR =
|
||||||
new Creator<RouteInfo>() {
|
new Creator<RouteInfo>() {
|
||||||
public RouteInfo createFromParcel(Parcel in) {
|
public RouteInfo createFromParcel(Parcel in) {
|
||||||
IpPrefix dest = in.readParcelable(null);
|
IpPrefix dest = in.readParcelable(null);
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ public final class StaticIpConfiguration implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the Parcelable interface */
|
/** Implement the Parcelable interface */
|
||||||
public static final Creator<StaticIpConfiguration> CREATOR =
|
public static final @android.annotation.NonNull Creator<StaticIpConfiguration> CREATOR =
|
||||||
new Creator<StaticIpConfiguration>() {
|
new Creator<StaticIpConfiguration>() {
|
||||||
public StaticIpConfiguration createFromParcel(Parcel in) {
|
public StaticIpConfiguration createFromParcel(Parcel in) {
|
||||||
return readFromParcel(in);
|
return readFromParcel(in);
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public final class UidRange implements Parcelable {
|
|||||||
dest.writeInt(stop);
|
dest.writeInt(stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<UidRange> CREATOR =
|
public static final @android.annotation.NonNull Creator<UidRange> CREATOR =
|
||||||
new Creator<UidRange>() {
|
new Creator<UidRange>() {
|
||||||
@Override
|
@Override
|
||||||
public UidRange createFromParcel(Parcel in) {
|
public UidRange createFromParcel(Parcel in) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
|
|||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
import static android.net.ConnectivityManager.NETID_UNSET;
|
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_ETHERNET;
|
||||||
import static android.net.ConnectivityManager.TYPE_NONE;
|
import static android.net.ConnectivityManager.TYPE_NONE;
|
||||||
import static android.net.ConnectivityManager.TYPE_VPN;
|
import static android.net.ConnectivityManager.TYPE_VPN;
|
||||||
@@ -2810,7 +2811,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
case android.net.NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
|
case NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
|
||||||
handleReleaseNetworkRequest((NetworkRequest) msg.obj, msg.sendingUid,
|
handleReleaseNetworkRequest((NetworkRequest) msg.obj, msg.sendingUid,
|
||||||
/* callOnUnavailable */ true);
|
/* callOnUnavailable */ true);
|
||||||
break;
|
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.putString(mContext.getContentResolver(),
|
||||||
Settings.Global.NETWORK_AVOID_BAD_WIFI, null);
|
Settings.Global.NETWORK_AVOID_BAD_WIFI, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* Tests that link-local address generation from MAC is valid.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3423,7 +3423,7 @@ public class ConnectivityServiceTest {
|
|||||||
testFactory.setScoreFilter(40);
|
testFactory.setScoreFilter(40);
|
||||||
|
|
||||||
// Register the factory and expect it to receive the default request.
|
// 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();
|
testFactory.register();
|
||||||
SparseArray<NetworkRequest> requests = testFactory.waitForNetworkRequests(1);
|
SparseArray<NetworkRequest> requests = testFactory.waitForNetworkRequests(1);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.IpSecAlgorithm;
|
import android.net.IpSecAlgorithm;
|
||||||
import android.net.IpSecConfig;
|
import android.net.IpSecConfig;
|
||||||
@@ -57,6 +58,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -118,6 +120,11 @@ public class IpSecServiceParameterizedTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PackageManager getPackageManager() {
|
||||||
|
return mMockPkgMgr;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enforceCallingOrSelfPermission(String permission, String message) {
|
public void enforceCallingOrSelfPermission(String permission, String message) {
|
||||||
if (permission == android.Manifest.permission.MANAGE_IPSEC_TUNNELS) {
|
if (permission == android.Manifest.permission.MANAGE_IPSEC_TUNNELS) {
|
||||||
@@ -128,6 +135,7 @@ public class IpSecServiceParameterizedTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
INetd mMockNetd;
|
INetd mMockNetd;
|
||||||
|
PackageManager mMockPkgMgr;
|
||||||
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
||||||
IpSecService mIpSecService;
|
IpSecService mIpSecService;
|
||||||
Network fakeNetwork = new Network(0xAB);
|
Network fakeNetwork = new Network(0xAB);
|
||||||
@@ -152,11 +160,16 @@ public class IpSecServiceParameterizedTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mMockNetd = mock(INetd.class);
|
mMockNetd = mock(INetd.class);
|
||||||
|
mMockPkgMgr = mock(PackageManager.class);
|
||||||
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
||||||
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
|
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
|
||||||
|
|
||||||
// Injecting mock netd
|
// Injecting mock netd
|
||||||
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
|
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.
|
// A package granted the AppOp for MANAGE_IPSEC_TUNNELS will be MODE_ALLOWED.
|
||||||
when(mMockAppOps.noteOp(anyInt(), anyInt(), eq("blessedPackage")))
|
when(mMockAppOps.noteOp(anyInt(), anyInt(), eq("blessedPackage")))
|
||||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||||
@@ -709,4 +722,18 @@ public class IpSecServiceParameterizedTest {
|
|||||||
} catch (SecurityException expected) {
|
} 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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user