Merge "Remove aidl wrappers for framework parcelables"

This commit is contained in:
Remi NGUYEN VAN
2019-03-18 01:30:01 +00:00
committed by Gerrit Code Review
22 changed files with 61 additions and 561 deletions

View File

@@ -832,14 +832,9 @@ aidl_interface {
"core/java/android/net/INetworkStackConnector.aidl",
"core/java/android/net/INetworkStackStatusCallback.aidl",
"core/java/android/net/InitialConfigurationParcelable.aidl",
"core/java/android/net/IpPrefixParcelable.aidl",
"core/java/android/net/LinkAddressParcelable.aidl",
"core/java/android/net/LinkPropertiesParcelable.aidl",
"core/java/android/net/NetworkParcelable.aidl",
"core/java/android/net/PrivateDnsConfigParcel.aidl",
"core/java/android/net/ProvisioningConfigurationParcelable.aidl",
"core/java/android/net/ProxyInfoParcelable.aidl",
"core/java/android/net/RouteInfoParcelable.aidl",
"core/java/android/net/StaticIpConfigurationParcelable.aidl",
"core/java/android/net/TcpKeepalivePacketDataParcelable.aidl",
"core/java/android/net/dhcp/DhcpServingParamsParcel.aidl",
@@ -848,6 +843,14 @@ aidl_interface {
"core/java/android/net/ip/IIpClient.aidl",
"core/java/android/net/ip/IIpClientCallbacks.aidl",
],
backend: {
ndk: {
enabled: false,
},
cpp: {
enabled: false,
},
},
api_dir: "aidl/networkstack",
}

View File

@@ -16,12 +16,12 @@
package android.net;
import android.net.IpPrefixParcelable;
import android.net.LinkAddressParcelable;
import android.net.IpPrefix;
import android.net.LinkAddress;
parcelable InitialConfigurationParcelable {
LinkAddressParcelable[] ipAddresses;
IpPrefixParcelable[] directlyConnectedRoutes;
LinkAddress[] ipAddresses;
IpPrefix[] directlyConnectedRoutes;
String[] dnsServers;
String gateway;
}

View File

@@ -17,4 +17,6 @@
package android.net;
parcelable IpPrefix cpp_header "binder/IpPrefix.h";
// @JavaOnlyStableParcelable only affects the parcelable when built as stable aidl (aidl_interface
// build rule). IpPrefix is also used in cpp but only as non-stable aidl.
@JavaOnlyStableParcelable parcelable IpPrefix cpp_header "binder/IpPrefix.h";

View File

@@ -1,22 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
parcelable IpPrefixParcelable {
String address;
int prefixLength;
}

View File

@@ -17,5 +17,5 @@
package android.net;
parcelable LinkAddress;
@JavaOnlyStableParcelable parcelable LinkAddress;

View File

@@ -1,24 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
parcelable LinkAddressParcelable {
String address;
int prefixLength;
int flags;
int scope;
}

View File

@@ -17,4 +17,4 @@
package android.net;
parcelable LinkProperties;
@JavaOnlyStableParcelable parcelable LinkProperties;

View File

@@ -1,38 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import android.net.IpPrefixParcelable;
import android.net.LinkAddressParcelable;
import android.net.ProxyInfoParcelable;
import android.net.RouteInfoParcelable;
parcelable LinkPropertiesParcelable {
String ifaceName;
LinkAddressParcelable[] linkAddresses;
String[] dnses;
String[] pcscfs;
String[] validatedPrivateDnses;
boolean usePrivateDns;
String privateDnsServerName;
String domains;
RouteInfoParcelable[] routes;
ProxyInfoParcelable httpProxy;
int mtu;
String tcpBufferSizes;
IpPrefixParcelable nat64Prefix;
}

View File

@@ -17,5 +17,5 @@
package android.net;
parcelable ProxyInfo;
@JavaOnlyStableParcelable parcelable ProxyInfo;

View File

@@ -1,24 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
parcelable ProxyInfoParcelable {
String host;
int port;
String[] exclusionList;
String pacFileUrl;
}

View File

@@ -16,4 +16,4 @@
package android.net;
parcelable RouteInfo;
@JavaOnlyStableParcelable parcelable RouteInfo;

View File

@@ -1,26 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import android.net.IpPrefixParcelable;
parcelable RouteInfoParcelable {
IpPrefixParcelable destination;
String gatewayAddr;
String ifaceName;
int type;
}

View File

@@ -17,10 +17,10 @@
package android.net;
import android.net.LinkAddressParcelable;
import android.net.LinkAddress;
parcelable StaticIpConfigurationParcelable {
LinkAddressParcelable ipAddress;
LinkAddress ipAddress;
String gateway;
String[] dnsServers;
String domains;

View File

@@ -15,7 +15,7 @@
*/
package android.net.ip;
import android.net.ProxyInfoParcelable;
import android.net.ProxyInfo;
import android.net.ProvisioningConfigurationParcelable;
import android.net.TcpKeepalivePacketDataParcelable;
@@ -28,7 +28,7 @@ oneway interface IIpClient {
void startProvisioning(in ProvisioningConfigurationParcelable req);
void stop();
void setTcpBufferSizes(in String tcpBufferSizes);
void setHttpProxy(in ProxyInfoParcelable proxyInfo);
void setHttpProxy(in ProxyInfo proxyInfo);
void setMulticastFilter(boolean enabled);
void addKeepalivePacketFilter(int slot, in TcpKeepalivePacketDataParcelable pkt);
void removeKeepalivePacketFilter(int slot);

View File

@@ -15,7 +15,7 @@
*/
package android.net.ip;
import android.net.LinkPropertiesParcelable;
import android.net.LinkProperties;
import android.net.ip.IIpClient;
import android.net.DhcpResultsParcelable;
@@ -34,11 +34,11 @@ oneway interface IIpClientCallbacks {
// null or not.
void onNewDhcpResults(in DhcpResultsParcelable dhcpResults);
void onProvisioningSuccess(in LinkPropertiesParcelable newLp);
void onProvisioningFailure(in LinkPropertiesParcelable newLp);
void onProvisioningSuccess(in LinkProperties newLp);
void onProvisioningFailure(in LinkProperties newLp);
// Invoked on LinkProperties changes.
void onLinkPropertiesChange(in LinkPropertiesParcelable newLp);
void onLinkPropertiesChange(in LinkProperties newLp);
// Called when the internal IpReachabilityMonitor (if enabled) has
// detected the loss of a critical number of required neighbors.

View File

@@ -18,8 +18,6 @@ package android.net.ip;
import static android.net.RouteInfo.RTN_UNICAST;
import static android.net.shared.IpConfigurationParcelableUtil.toStableParcelable;
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable;
import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;
@@ -33,7 +31,6 @@ import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.ProvisioningConfigurationParcelable;
import android.net.ProxyInfo;
import android.net.ProxyInfoParcelable;
import android.net.RouteInfo;
import android.net.TcpKeepalivePacketDataParcelable;
import android.net.apf.ApfCapabilities;
@@ -201,7 +198,7 @@ public class IpClient extends StateMachine {
public void onProvisioningSuccess(LinkProperties newLp) {
log("onProvisioningSuccess({" + newLp + "})");
try {
mCallback.onProvisioningSuccess(toStableParcelable(newLp));
mCallback.onProvisioningSuccess(newLp);
} catch (RemoteException e) {
log("Failed to call onProvisioningSuccess", e);
}
@@ -210,7 +207,7 @@ public class IpClient extends StateMachine {
public void onProvisioningFailure(LinkProperties newLp) {
log("onProvisioningFailure({" + newLp + "})");
try {
mCallback.onProvisioningFailure(toStableParcelable(newLp));
mCallback.onProvisioningFailure(newLp);
} catch (RemoteException e) {
log("Failed to call onProvisioningFailure", e);
}
@@ -219,7 +216,7 @@ public class IpClient extends StateMachine {
public void onLinkPropertiesChange(LinkProperties newLp) {
log("onLinkPropertiesChange({" + newLp + "})");
try {
mCallback.onLinkPropertiesChange(toStableParcelable(newLp));
mCallback.onLinkPropertiesChange(newLp);
} catch (RemoteException e) {
log("Failed to call onLinkPropertiesChange", e);
}
@@ -525,9 +522,9 @@ public class IpClient extends StateMachine {
IpClient.this.setTcpBufferSizes(tcpBufferSizes);
}
@Override
public void setHttpProxy(ProxyInfoParcelable proxyInfo) {
public void setHttpProxy(ProxyInfo proxyInfo) {
checkNetworkStackCallingPermission();
IpClient.this.setHttpProxy(fromStableParcelable(proxyInfo));
IpClient.this.setHttpProxy(proxyInfo);
}
@Override
public void setMulticastFilter(boolean enabled) {

View File

@@ -16,13 +16,10 @@
package android.net.ip;
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.eq;
@@ -207,8 +204,7 @@ public class IpClientTest {
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
.onLinkPropertiesChange(argThat(
lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
.onLinkPropertiesChange(makeEmptyLinkProperties(iface));
}
@Test
@@ -253,15 +249,13 @@ public class IpClientTest {
mObserver.onInterfaceAddressUpdated(new LinkAddress(addresses[lastAddr]), iface);
LinkProperties want = linkproperties(links(addresses), routes(prefixes));
want.setInterfaceName(iface);
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(argThat(
lp -> fromStableParcelable(lp).equals(want)));
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(want);
ipc.shutdown();
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
.onLinkPropertiesChange(argThat(
lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
.onLinkPropertiesChange(makeEmptyLinkProperties(iface));
}
@Test

View File

@@ -17,12 +17,10 @@
package android.net.ip;
import static android.net.shared.IpConfigurationParcelableUtil.fromStableParcelable;
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
import android.content.Context;
import android.net.DhcpResultsParcelable;
import android.net.LinkProperties;
import android.net.LinkPropertiesParcelable;
import android.net.NetworkStackClient;
import android.os.ConditionVariable;
@@ -122,18 +120,18 @@ public class IpClientUtil {
}
@Override
public void onProvisioningSuccess(LinkPropertiesParcelable newLp) {
mCb.onProvisioningSuccess(fromStableParcelable(newLp));
public void onProvisioningSuccess(LinkProperties newLp) {
mCb.onProvisioningSuccess(newLp);
}
@Override
public void onProvisioningFailure(LinkPropertiesParcelable newLp) {
mCb.onProvisioningFailure(fromStableParcelable(newLp));
public void onProvisioningFailure(LinkProperties newLp) {
mCb.onProvisioningFailure(newLp);
}
// Invoked on LinkProperties changes.
@Override
public void onLinkPropertiesChange(LinkPropertiesParcelable newLp) {
mCb.onLinkPropertiesChange(fromStableParcelable(newLp));
public void onLinkPropertiesChange(LinkProperties newLp) {
mCb.onLinkPropertiesChange(newLp);
}
// Called when the internal IpReachabilityMonitor (if enabled) has

View File

@@ -23,13 +23,12 @@ import static android.text.TextUtils.join;
import android.net.InetAddresses;
import android.net.InitialConfigurationParcelable;
import android.net.IpPrefix;
import android.net.IpPrefixParcelable;
import android.net.LinkAddress;
import android.net.LinkAddressParcelable;
import android.net.RouteInfo;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -148,10 +147,8 @@ public class InitialConfiguration {
*/
public InitialConfigurationParcelable toStableParcelable() {
final InitialConfigurationParcelable p = new InitialConfigurationParcelable();
p.ipAddresses = toParcelableArray(ipAddresses,
LinkPropertiesParcelableUtil::toStableParcelable, LinkAddressParcelable.class);
p.directlyConnectedRoutes = toParcelableArray(directlyConnectedRoutes,
LinkPropertiesParcelableUtil::toStableParcelable, IpPrefixParcelable.class);
p.ipAddresses = ipAddresses.toArray(new LinkAddress[0]);
p.directlyConnectedRoutes = directlyConnectedRoutes.toArray(new IpPrefix[0]);
p.dnsServers = toParcelableArray(
dnsServers, IpConfigurationParcelableUtil::parcelAddress, String.class);
return p;
@@ -164,10 +161,8 @@ public class InitialConfiguration {
public static InitialConfiguration fromStableParcelable(InitialConfigurationParcelable p) {
if (p == null) return null;
final InitialConfiguration config = new InitialConfiguration();
config.ipAddresses.addAll(fromParcelableArray(
p.ipAddresses, LinkPropertiesParcelableUtil::fromStableParcelable));
config.directlyConnectedRoutes.addAll(fromParcelableArray(
p.directlyConnectedRoutes, LinkPropertiesParcelableUtil::fromStableParcelable));
config.ipAddresses.addAll(Arrays.asList(p.ipAddresses));
config.directlyConnectedRoutes.addAll(Arrays.asList(p.directlyConnectedRoutes));
config.dnsServers.addAll(
fromParcelableArray(p.dnsServers, IpConfigurationParcelableUtil::unparcelAddress));
return config;

View File

@@ -44,7 +44,7 @@ public final class IpConfigurationParcelableUtil {
@Nullable StaticIpConfiguration config) {
if (config == null) return null;
final StaticIpConfigurationParcelable p = new StaticIpConfigurationParcelable();
p.ipAddress = LinkPropertiesParcelableUtil.toStableParcelable(config.getIpAddress());
p.ipAddress = config.getIpAddress();
p.gateway = parcelAddress(config.getGateway());
p.dnsServers = toParcelableArray(
config.getDnsServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
@@ -59,7 +59,7 @@ public final class IpConfigurationParcelableUtil {
@Nullable StaticIpConfigurationParcelable p) {
if (p == null) return null;
final StaticIpConfiguration config = new StaticIpConfiguration();
config.setIpAddress(LinkPropertiesParcelableUtil.fromStableParcelable(p.ipAddress));
config.setIpAddress(p.ipAddress);
config.setGateway(unparcelAddress(p.gateway));
for (InetAddress addr : fromParcelableArray(
p.dnsServers, IpConfigurationParcelableUtil::unparcelAddress)) {

View File

@@ -16,25 +16,9 @@
package android.net.shared;
import static android.net.shared.IpConfigurationParcelableUtil.parcelAddress;
import static android.net.shared.IpConfigurationParcelableUtil.unparcelAddress;
import static android.net.shared.ParcelableUtil.fromParcelableArray;
import static android.net.shared.ParcelableUtil.toParcelableArray;
import android.annotation.Nullable;
import android.net.IpPrefix;
import android.net.IpPrefixParcelable;
import android.net.LinkAddress;
import android.net.LinkAddressParcelable;
import android.net.LinkProperties;
import android.net.LinkPropertiesParcelable;
import android.net.ProxyInfo;
import android.net.ProxyInfoParcelable;
import android.net.RouteInfo;
import android.net.RouteInfoParcelable;
import android.net.Uri;
import java.util.Arrays;
/**
* Collection of utility methods to convert to and from stable AIDL parcelables for LinkProperties
@@ -42,177 +26,22 @@ import java.util.Arrays;
* @hide
*/
public final class LinkPropertiesParcelableUtil {
// Temporary methods to facilitate migrating clients away from LinkPropertiesParcelable
// TODO: remove the following methods after migrating clients.
/**
* Convert a ProxyInfo to a ProxyInfoParcelable
* @deprecated conversion to stable parcelable is no longer necessary.
*/
public static ProxyInfoParcelable toStableParcelable(@Nullable ProxyInfo proxyInfo) {
if (proxyInfo == null) {
return null;
}
final ProxyInfoParcelable parcel = new ProxyInfoParcelable();
parcel.host = proxyInfo.getHost();
parcel.port = proxyInfo.getPort();
parcel.exclusionList = proxyInfo.getExclusionList();
parcel.pacFileUrl = proxyInfo.getPacFileUrl().toString();
return parcel;
}
/**
* Convert a ProxyInfoParcelable to a ProxyInfo
*/
public static ProxyInfo fromStableParcelable(@Nullable ProxyInfoParcelable parcel) {
if (parcel == null) {
return null;
}
if (Uri.EMPTY.toString().equals(parcel.pacFileUrl)) {
return ProxyInfo.buildDirectProxy(
parcel.host, parcel.port, Arrays.asList(parcel.exclusionList));
} else {
return ProxyInfo.buildPacProxy(Uri.parse(parcel.pacFileUrl));
}
}
/**
* Convert an IpPrefixParcelable to an IpPrefix
*/
public static IpPrefixParcelable toStableParcelable(@Nullable IpPrefix ipPrefix) {
if (ipPrefix == null) {
return null;
}
final IpPrefixParcelable parcel = new IpPrefixParcelable();
parcel.address = parcelAddress(ipPrefix.getAddress());
parcel.prefixLength = ipPrefix.getPrefixLength();
return parcel;
}
/**
* Convert an IpPrefix to an IpPrefixParcelable
*/
public static IpPrefix fromStableParcelable(@Nullable IpPrefixParcelable parcel) {
if (parcel == null) {
return null;
}
return new IpPrefix(unparcelAddress(parcel.address), parcel.prefixLength);
}
/**
* Convert a RouteInfoParcelable to a RouteInfo
*/
public static RouteInfoParcelable toStableParcelable(@Nullable RouteInfo routeInfo) {
if (routeInfo == null) {
return null;
}
final RouteInfoParcelable parcel = new RouteInfoParcelable();
parcel.destination = toStableParcelable(routeInfo.getDestination());
parcel.gatewayAddr = parcelAddress(routeInfo.getGateway());
parcel.ifaceName = routeInfo.getInterface();
parcel.type = routeInfo.getType();
return parcel;
}
/**
* Convert a RouteInfo to a RouteInfoParcelable
*/
public static RouteInfo fromStableParcelable(@Nullable RouteInfoParcelable parcel) {
if (parcel == null) {
return null;
}
final IpPrefix destination = fromStableParcelable(parcel.destination);
return new RouteInfo(
destination, unparcelAddress(parcel.gatewayAddr),
parcel.ifaceName, parcel.type);
}
/**
* Convert a LinkAddressParcelable to a LinkAddress
*/
public static LinkAddressParcelable toStableParcelable(@Nullable LinkAddress la) {
if (la == null) {
return null;
}
final LinkAddressParcelable parcel = new LinkAddressParcelable();
parcel.address = parcelAddress(la.getAddress());
parcel.prefixLength = la.getPrefixLength();
parcel.flags = la.getFlags();
parcel.scope = la.getScope();
return parcel;
}
/**
* Convert a LinkAddress to a LinkAddressParcelable
*/
public static LinkAddress fromStableParcelable(@Nullable LinkAddressParcelable parcel) {
if (parcel == null) {
return null;
}
return new LinkAddress(
unparcelAddress(parcel.address),
parcel.prefixLength,
parcel.flags,
parcel.scope);
}
/**
* Convert a LinkProperties to a LinkPropertiesParcelable
*/
public static LinkPropertiesParcelable toStableParcelable(@Nullable LinkProperties lp) {
if (lp == null) {
return null;
}
final LinkPropertiesParcelable parcel = new LinkPropertiesParcelable();
parcel.ifaceName = lp.getInterfaceName();
parcel.linkAddresses = toParcelableArray(
lp.getLinkAddresses(),
LinkPropertiesParcelableUtil::toStableParcelable,
LinkAddressParcelable.class);
parcel.dnses = toParcelableArray(
lp.getDnsServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
parcel.pcscfs = toParcelableArray(
lp.getPcscfServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
parcel.validatedPrivateDnses = toParcelableArray(lp.getValidatedPrivateDnsServers(),
IpConfigurationParcelableUtil::parcelAddress, String.class);
parcel.usePrivateDns = lp.isPrivateDnsActive();
parcel.privateDnsServerName = lp.getPrivateDnsServerName();
parcel.domains = lp.getDomains();
parcel.routes = toParcelableArray(
lp.getRoutes(), LinkPropertiesParcelableUtil::toStableParcelable,
RouteInfoParcelable.class);
parcel.httpProxy = toStableParcelable(lp.getHttpProxy());
parcel.mtu = lp.getMtu();
parcel.tcpBufferSizes = lp.getTcpBufferSizes();
parcel.nat64Prefix = toStableParcelable(lp.getNat64Prefix());
return parcel;
}
/**
* Convert a LinkPropertiesParcelable to a LinkProperties
*/
public static LinkProperties fromStableParcelable(@Nullable LinkPropertiesParcelable parcel) {
if (parcel == null) {
return null;
}
final LinkProperties lp = new LinkProperties();
lp.setInterfaceName(parcel.ifaceName);
lp.setLinkAddresses(fromParcelableArray(parcel.linkAddresses,
LinkPropertiesParcelableUtil::fromStableParcelable));
lp.setDnsServers(fromParcelableArray(
parcel.dnses, IpConfigurationParcelableUtil::unparcelAddress));
lp.setPcscfServers(fromParcelableArray(
parcel.pcscfs, IpConfigurationParcelableUtil::unparcelAddress));
lp.setValidatedPrivateDnsServers(
fromParcelableArray(parcel.validatedPrivateDnses,
IpConfigurationParcelableUtil::unparcelAddress));
lp.setUsePrivateDns(parcel.usePrivateDns);
lp.setPrivateDnsServerName(parcel.privateDnsServerName);
lp.setDomains(parcel.domains);
for (RouteInfoParcelable route : parcel.routes) {
lp.addRoute(fromStableParcelable(route));
}
lp.setHttpProxy(fromStableParcelable(parcel.httpProxy));
lp.setMtu(parcel.mtu);
lp.setTcpBufferSizes(parcel.tcpBufferSizes);
lp.setNat64Prefix(fromStableParcelable(parcel.nat64Prefix));
@Deprecated
public static LinkProperties toStableParcelable(@Nullable LinkProperties lp) {
return lp;
}
/**
* @deprecated conversion to stable parcelable is no longer necessary.
*/
@Deprecated
public static ProxyInfo toStableParcelable(@Nullable ProxyInfo info) {
return info;
}
}

View File

@@ -1,184 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.shared;
import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable;
import static android.net.shared.ParcelableTestUtil.assertFieldCountEquals;
import static org.junit.Assert.assertEquals;
import android.net.InetAddresses;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.Uri;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.Collections;
/**
* Tests for {@link LinkPropertiesParcelableUtil}
*/
@RunWith(AndroidJUnit4.class)
@SmallTest
public class LinkPropertiesParcelableUtilTest {
private LinkProperties mLinkProperties;
private static final String TEST_LINKPROPS_IFACE = "TEST_IFACE";
@Before
public void setUp() {
mLinkProperties = new LinkProperties();
mLinkProperties.setInterfaceName(TEST_LINKPROPS_IFACE);
mLinkProperties.setLinkAddresses(Arrays.asList(
new LinkAddress(InetAddresses.parseNumericAddress("192.168.0.42"), 16),
new LinkAddress(InetAddresses.parseNumericAddress("2001:db8::7"), 42)));
mLinkProperties.setDnsServers(Arrays.asList(
InetAddresses.parseNumericAddress("2001:db8::42"),
InetAddresses.parseNumericAddress("192.168.1.1")
));
mLinkProperties.setValidatedPrivateDnsServers(Arrays.asList(
InetAddresses.parseNumericAddress("2001:db8::43"),
InetAddresses.parseNumericAddress("192.168.42.43")
));
mLinkProperties.setPcscfServers(Arrays.asList(
InetAddresses.parseNumericAddress("2001:db8::47"),
InetAddresses.parseNumericAddress("192.168.42.47")
));
mLinkProperties.setUsePrivateDns(true);
mLinkProperties.setPrivateDnsServerName("test.example.com");
mLinkProperties.setDomains("test1.example.com,test2.example.com");
mLinkProperties.addRoute(new RouteInfo(
new IpPrefix(InetAddresses.parseNumericAddress("2001:db8::44"), 45),
InetAddresses.parseNumericAddress("2001:db8::45"),
TEST_LINKPROPS_IFACE,
RouteInfo.RTN_UNICAST
));
mLinkProperties.addRoute(new RouteInfo(
new IpPrefix(InetAddresses.parseNumericAddress("192.168.44.45"), 16),
InetAddresses.parseNumericAddress("192.168.45.1"),
TEST_LINKPROPS_IFACE,
RouteInfo.RTN_THROW
));
mLinkProperties.setHttpProxy(new ProxyInfo("test3.example.com", 8000,
"excl1.example.com,excl2.example.com"));
mLinkProperties.setMtu(5000);
mLinkProperties.setTcpBufferSizes("1,2,3,4,5,6");
mLinkProperties.setNat64Prefix(
new IpPrefix(InetAddresses.parseNumericAddress("2001:db8::48"), 96));
// Verify that this test does not miss any new field added later.
// If any added field is not included in LinkProperties#equals, assertLinkPropertiesEquals
// must also be updated.
assertFieldCountEquals(14, LinkProperties.class);
}
@Test
public void testParcelUnparcel() {
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullInterface() {
mLinkProperties.setInterfaceName(null);
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullPrivateDnsServer() {
mLinkProperties.setPrivateDnsServerName(null);
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullDomains() {
mLinkProperties.setDomains(null);
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullProxy() {
mLinkProperties.setHttpProxy(null);
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullTcpBufferSizes() {
mLinkProperties.setTcpBufferSizes(null);
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_EmptyLinkAddresses() {
mLinkProperties.setLinkAddresses(Collections.emptyList());
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_EmptyDnses() {
mLinkProperties.setDnsServers(Collections.emptyList());
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_EmptyValidatedPrivateDnses() {
mLinkProperties.setValidatedPrivateDnsServers(Collections.emptyList());
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_EmptyRoutes() {
for (RouteInfo r : mLinkProperties.getAllRoutes()) {
mLinkProperties.removeRoute(r);
}
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_PacFileProxyInfo() {
mLinkProperties.setHttpProxy(new ProxyInfo(Uri.parse("http://pacfile.example.com")));
doParcelUnparcelTest();
}
@Test
public void testParcelUnparcel_NullNat64Prefix() {
mLinkProperties.setNat64Prefix(null);
doParcelUnparcelTest();
}
private void doParcelUnparcelTest() {
final LinkProperties unparceled = fromStableParcelable(toStableParcelable(mLinkProperties));
assertLinkPropertiesEquals(mLinkProperties, unparceled);
}
private static void assertLinkPropertiesEquals(LinkProperties expected, LinkProperties actual) {
assertEquals(expected, actual);
// Equality on stacked links is not tested as they should not be passed to processes using
// LinkPropertiesParcelable.
}
}