diff options
22 files changed, 58 insertions, 558 deletions
diff --git a/Android.bp b/Android.bp index fa5a56a287a5..0e7b2659a871 100644 --- a/Android.bp +++ b/Android.bp @@ -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", } diff --git a/core/java/android/net/InitialConfigurationParcelable.aidl b/core/java/android/net/InitialConfigurationParcelable.aidl index bdda355955a5..3fa88c377a64 100644 --- a/core/java/android/net/InitialConfigurationParcelable.aidl +++ b/core/java/android/net/InitialConfigurationParcelable.aidl @@ -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; }
\ No newline at end of file diff --git a/core/java/android/net/IpPrefix.aidl b/core/java/android/net/IpPrefix.aidl index 837db5f1ef37..0d70f2a1ed2c 100644 --- a/core/java/android/net/IpPrefix.aidl +++ b/core/java/android/net/IpPrefix.aidl @@ -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"; diff --git a/core/java/android/net/IpPrefixParcelable.aidl b/core/java/android/net/IpPrefixParcelable.aidl deleted file mode 100644 index 93a8d41936cc..000000000000 --- a/core/java/android/net/IpPrefixParcelable.aidl +++ /dev/null @@ -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; -}
\ No newline at end of file diff --git a/core/java/android/net/LinkAddress.aidl b/core/java/android/net/LinkAddress.aidl index e7d8646078da..9c804db08d61 100644 --- a/core/java/android/net/LinkAddress.aidl +++ b/core/java/android/net/LinkAddress.aidl @@ -17,5 +17,5 @@ package android.net; -parcelable LinkAddress; +@JavaOnlyStableParcelable parcelable LinkAddress; diff --git a/core/java/android/net/LinkAddressParcelable.aidl b/core/java/android/net/LinkAddressParcelable.aidl deleted file mode 100644 index af8e79b21f69..000000000000 --- a/core/java/android/net/LinkAddressParcelable.aidl +++ /dev/null @@ -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; -}
\ No newline at end of file diff --git a/core/java/android/net/LinkProperties.aidl b/core/java/android/net/LinkProperties.aidl index 3cb9525761ed..a8b3c7b0392f 100644 --- a/core/java/android/net/LinkProperties.aidl +++ b/core/java/android/net/LinkProperties.aidl @@ -17,4 +17,4 @@ package android.net; -parcelable LinkProperties; +@JavaOnlyStableParcelable parcelable LinkProperties; diff --git a/core/java/android/net/LinkPropertiesParcelable.aidl b/core/java/android/net/LinkPropertiesParcelable.aidl deleted file mode 100644 index 6b52239b4168..000000000000 --- a/core/java/android/net/LinkPropertiesParcelable.aidl +++ /dev/null @@ -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; -}
\ No newline at end of file diff --git a/core/java/android/net/ProxyInfo.aidl b/core/java/android/net/ProxyInfo.aidl index 2c91960e4dcb..a5d0c120e747 100644 --- a/core/java/android/net/ProxyInfo.aidl +++ b/core/java/android/net/ProxyInfo.aidl @@ -17,5 +17,5 @@ package android.net; -parcelable ProxyInfo; +@JavaOnlyStableParcelable parcelable ProxyInfo; diff --git a/core/java/android/net/ProxyInfoParcelable.aidl b/core/java/android/net/ProxyInfoParcelable.aidl deleted file mode 100644 index 59fd8467b820..000000000000 --- a/core/java/android/net/ProxyInfoParcelable.aidl +++ /dev/null @@ -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; -} diff --git a/core/java/android/net/RouteInfo.aidl b/core/java/android/net/RouteInfo.aidl index 2296a576873d..7af9fdaef342 100644 --- a/core/java/android/net/RouteInfo.aidl +++ b/core/java/android/net/RouteInfo.aidl @@ -16,4 +16,4 @@ package android.net; -parcelable RouteInfo; +@JavaOnlyStableParcelable parcelable RouteInfo; diff --git a/core/java/android/net/RouteInfoParcelable.aidl b/core/java/android/net/RouteInfoParcelable.aidl deleted file mode 100644 index 15bcdcfc2000..000000000000 --- a/core/java/android/net/RouteInfoParcelable.aidl +++ /dev/null @@ -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; -} diff --git a/core/java/android/net/StaticIpConfigurationParcelable.aidl b/core/java/android/net/StaticIpConfigurationParcelable.aidl index 45dc0210dfba..6fffb423edb5 100644 --- a/core/java/android/net/StaticIpConfigurationParcelable.aidl +++ b/core/java/android/net/StaticIpConfigurationParcelable.aidl @@ -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; diff --git a/core/java/android/net/ip/IIpClient.aidl b/core/java/android/net/ip/IIpClient.aidl index a4a80e1efe6f..b834e45c6852 100644 --- a/core/java/android/net/ip/IIpClient.aidl +++ b/core/java/android/net/ip/IIpClient.aidl @@ -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); diff --git a/core/java/android/net/ip/IIpClientCallbacks.aidl b/core/java/android/net/ip/IIpClientCallbacks.aidl index f077e3b77ac7..3681416611a9 100644 --- a/core/java/android/net/ip/IIpClientCallbacks.aidl +++ b/core/java/android/net/ip/IIpClientCallbacks.aidl @@ -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. diff --git a/packages/NetworkStack/src/android/net/ip/IpClient.java b/packages/NetworkStack/src/android/net/ip/IpClient.java index b1f6d246563e..7c7cdbdb8530 100644 --- a/packages/NetworkStack/src/android/net/ip/IpClient.java +++ b/packages/NetworkStack/src/android/net/ip/IpClient.java @@ -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) { diff --git a/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java b/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java index bd488ea4145f..4536c473915a 100644 --- a/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java +++ b/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java @@ -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 diff --git a/services/net/java/android/net/ip/IpClientUtil.java b/services/net/java/android/net/ip/IpClientUtil.java index bf917bf88b2d..90624e0518f8 100644 --- a/services/net/java/android/net/ip/IpClientUtil.java +++ b/services/net/java/android/net/ip/IpClientUtil.java @@ -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 diff --git a/services/net/java/android/net/shared/InitialConfiguration.java b/services/net/java/android/net/shared/InitialConfiguration.java index 4ad71381da04..e423d62da7c9 100644 --- a/services/net/java/android/net/shared/InitialConfiguration.java +++ b/services/net/java/android/net/shared/InitialConfiguration.java @@ -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; diff --git a/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java b/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java index 1f0525e4da88..6b5826f8b095 100644 --- a/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java +++ b/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java @@ -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)) { diff --git a/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java b/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java index 51d955d5c2ad..1729da6eb141 100644 --- a/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java +++ b/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java @@ -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 - */ - 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 + * @deprecated conversion to stable parcelable is no longer necessary. */ - 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; + @Deprecated + public static LinkProperties toStableParcelable(@Nullable LinkProperties lp) { + return lp; } /** - * Convert a LinkPropertiesParcelable to a LinkProperties + * @deprecated conversion to stable parcelable is no longer necessary. */ - 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)); - return lp; + @Deprecated + public static ProxyInfo toStableParcelable(@Nullable ProxyInfo info) { + return info; } } diff --git a/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java b/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java deleted file mode 100644 index 2d0e03d3187a..000000000000 --- a/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java +++ /dev/null @@ -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. - } -} |