From 1b2935806fbb3da7efda8d11bf8d00cdf4ec4c12 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Wed, 11 Oct 2017 19:43:10 +0900 Subject: [PATCH 1/2] Rename IpManager to IpClient Test: as follows - built - flashed - booted - runtest frameworks-net passes Bug: 62476366 Change-Id: I36255a2c8e1a2f52693716b445359cce0b4304af --- .../net/java/android/net/apf/ApfFilter.java | 16 ++-- .../net/ip/{IpManager.java => IpClient.java} | 91 +++++++------------ 2 files changed, 39 insertions(+), 68 deletions(-) rename services/net/java/android/net/ip/{IpManager.java => IpClient.java} (95%) diff --git a/services/net/java/android/net/apf/ApfFilter.java b/services/net/java/android/net/apf/ApfFilter.java index 190b3a613ca1b..5c2b66f6b24fd 100644 --- a/services/net/java/android/net/apf/ApfFilter.java +++ b/services/net/java/android/net/apf/ApfFilter.java @@ -33,7 +33,7 @@ import android.net.NetworkUtils; import android.net.apf.ApfGenerator; import android.net.apf.ApfGenerator.IllegalInstructionException; import android.net.apf.ApfGenerator.Register; -import android.net.ip.IpManager; +import android.net.ip.IpClient; import android.net.metrics.ApfProgramEvent; import android.net.metrics.ApfStats; import android.net.metrics.IpConnectivityLog; @@ -238,7 +238,7 @@ public class ApfFilter { private static final int APF_MAX_ETH_TYPE_BLACK_LIST_LEN = 20; private final ApfCapabilities mApfCapabilities; - private final IpManager.Callback mIpManagerCallback; + private final IpClient.Callback mIpClientCallback; private final NetworkInterface mNetworkInterface; private final IpConnectivityLog mMetricsLog; @@ -262,10 +262,10 @@ public class ApfFilter { @VisibleForTesting ApfFilter(ApfCapabilities apfCapabilities, NetworkInterface networkInterface, - IpManager.Callback ipManagerCallback, boolean multicastFilter, + IpClient.Callback ipClientCallback, boolean multicastFilter, boolean ieee802_3Filter, int[] ethTypeBlackList, IpConnectivityLog log) { mApfCapabilities = apfCapabilities; - mIpManagerCallback = ipManagerCallback; + mIpClientCallback = ipClientCallback; mNetworkInterface = networkInterface; mMulticastFilter = multicastFilter; mDrop802_3Frames = ieee802_3Filter; @@ -275,7 +275,7 @@ public class ApfFilter { mMetricsLog = log; - // TODO: ApfFilter should not generate programs until IpManager sends provisioning success. + // TODO: ApfFilter should not generate programs until IpClient sends provisioning success. maybeStartFilter(); } @@ -1051,7 +1051,7 @@ public class ApfFilter { if (VDBG) { hexDump("Installing filter: ", program, program.length); } - mIpManagerCallback.installPacketFilter(program); + mIpClientCallback.installPacketFilter(program); logApfProgramEventLocked(now); mLastInstallEvent = new ApfProgramEvent(); mLastInstallEvent.lifetime = programMinLifetime; @@ -1161,7 +1161,7 @@ public class ApfFilter { * filtering using APF programs. */ public static ApfFilter maybeCreate(ApfCapabilities apfCapabilities, - NetworkInterface networkInterface, IpManager.Callback ipManagerCallback, + NetworkInterface networkInterface, IpClient.Callback ipClientCallback, boolean multicastFilter, boolean ieee802_3Filter, int[] ethTypeBlackList) { if (apfCapabilities == null || networkInterface == null) return null; if (apfCapabilities.apfVersionSupported == 0) return null; @@ -1178,7 +1178,7 @@ public class ApfFilter { Log.e(TAG, "Unsupported APF version: " + apfCapabilities.apfVersionSupported); return null; } - return new ApfFilter(apfCapabilities, networkInterface, ipManagerCallback, + return new ApfFilter(apfCapabilities, networkInterface, ipClientCallback, multicastFilter, ieee802_3Filter, ethTypeBlackList, new IpConnectivityLog()); } diff --git a/services/net/java/android/net/ip/IpManager.java b/services/net/java/android/net/ip/IpClient.java similarity index 95% rename from services/net/java/android/net/ip/IpManager.java rename to services/net/java/android/net/ip/IpClient.java index e33f6c99aea8b..2359fab412602 100644 --- a/services/net/java/android/net/ip/IpManager.java +++ b/services/net/java/android/net/ip/IpClient.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2017 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. @@ -77,36 +77,36 @@ import java.util.stream.Collectors; /** - * IpManager + * IpClient * * This class provides the interface to IP-layer provisioning and maintenance * functionality that can be used by transport layers like Wi-Fi, Ethernet, * et cetera. * * [ Lifetime ] - * IpManager is designed to be instantiated as soon as the interface name is + * IpClient is designed to be instantiated as soon as the interface name is * known and can be as long-lived as the class containing it (i.e. declaring * it "private final" is okay). * * @hide */ -public class IpManager extends StateMachine { +public class IpClient extends StateMachine { private static final boolean DBG = false; // For message logging. - private static final Class[] sMessageClasses = { IpManager.class, DhcpClient.class }; + private static final Class[] sMessageClasses = { IpClient.class, DhcpClient.class }; private static final SparseArray sWhatToString = MessageUtils.findMessageNames(sMessageClasses); /** - * Callbacks for handling IpManager events. + * Callbacks for handling IpClient events. */ public static class Callback { // In order to receive onPreDhcpAction(), call #withPreDhcpAction() // when constructing a ProvisioningConfiguration. // // Implementations of onPreDhcpAction() must call - // IpManager#completedPreDhcpAction() to indicate that DHCP is clear + // IpClient#completedPreDhcpAction() to indicate that DHCP is clear // to proceed. public void onPreDhcpAction() {} public void onPostDhcpAction() {} @@ -129,7 +129,7 @@ public class IpManager extends StateMachine { // detected the loss of a critical number of required neighbors. public void onReachabilityLost(String logMsg) {} - // Called when the IpManager state machine terminates. + // Called when the IpClient state machine terminates. public void onQuit() {} // Install an APF program to filter incoming packets. @@ -144,41 +144,12 @@ public class IpManager extends StateMachine { public void setNeighborDiscoveryOffload(boolean enable) {} } - public static class WaitForProvisioningCallback extends Callback { - private LinkProperties mCallbackLinkProperties; - - public LinkProperties waitForProvisioning() { - synchronized (this) { - try { - wait(); - } catch (InterruptedException e) {} - return mCallbackLinkProperties; - } - } - - @Override - public void onProvisioningSuccess(LinkProperties newLp) { - synchronized (this) { - mCallbackLinkProperties = newLp; - notify(); - } - } - - @Override - public void onProvisioningFailure(LinkProperties newLp) { - synchronized (this) { - mCallbackLinkProperties = null; - notify(); - } - } - } - // Use a wrapper class to log in order to ensure complete and detailed // logging. This method is lighter weight than annotations/reflection // and has the following benefits: // // - No invoked method can be forgotten. - // Any new method added to IpManager.Callback must be overridden + // Any new method added to IpClient.Callback must be overridden // here or it will never be called. // // - No invoking call site can be forgotten. @@ -261,23 +232,23 @@ public class IpManager extends StateMachine { /** * This class encapsulates parameters to be passed to - * IpManager#startProvisioning(). A defensive copy is made by IpManager - * and the values specified herein are in force until IpManager#stop() + * IpClient#startProvisioning(). A defensive copy is made by IpClient + * and the values specified herein are in force until IpClient#stop() * is called. * * Example use: * * final ProvisioningConfiguration config = - * mIpManager.buildProvisioningConfiguration() + * mIpClient.buildProvisioningConfiguration() * .withPreDhcpAction() * .withProvisioningTimeoutMs(36 * 1000) * .build(); - * mIpManager.startProvisioning(config); + * mIpClient.startProvisioning(config); * ... - * mIpManager.stop(); + * mIpClient.stop(); * * The specified provisioning configuration will only be active until - * IpManager#stop() is called. Future calls to IpManager#startProvisioning() + * IpClient#stop() is called. Future calls to IpClient#startProvisioning() * must specify the configuration again. */ public static class ProvisioningConfiguration { @@ -537,7 +508,7 @@ public class IpManager extends StateMachine { } } - public static final String DUMP_ARG = "ipmanager"; + public static final String DUMP_ARG = "ipclient"; public static final String DUMP_ARG_CONFIRM = "confirm"; private static final int CMD_TERMINATE_AFTER_STOP = 1; @@ -560,7 +531,7 @@ public class IpManager extends StateMachine { private static final boolean SEND_CALLBACKS = true; // This must match the interface prefix in clatd.c. - // TODO: Revert this hack once IpManager and Nat464Xlat work in concert. + // TODO: Revert this hack once IpClient and Nat464Xlat work in concert. private static final String CLAT_PREFIX = "v4-"; private final State mStoppedState = new StoppedState(); @@ -601,7 +572,7 @@ public class IpManager extends StateMachine { private boolean mMulticastFiltering; private long mStartTimeMillis; - public IpManager(Context context, String ifName, Callback callback) { + public IpClient(Context context, String ifName, Callback callback) { this(context, ifName, callback, INetworkManagementService.Stub.asInterface( ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)), NetdService.getInstance()); @@ -609,17 +580,17 @@ public class IpManager extends StateMachine { /** * An expanded constructor, useful for dependency injection. - * TODO: migrate all test users to mock IpManager directly and remove this ctor. + * TODO: migrate all test users to mock IpClient directly and remove this ctor. */ - public IpManager(Context context, String ifName, Callback callback, + public IpClient(Context context, String ifName, Callback callback, INetworkManagementService nwService) { this(context, ifName, callback, nwService, NetdService.getInstance()); } @VisibleForTesting - IpManager(Context context, String ifName, Callback callback, + IpClient(Context context, String ifName, Callback callback, INetworkManagementService nwService, INetd netd) { - super(IpManager.class.getSimpleName() + "." + ifName); + super(IpClient.class.getSimpleName() + "." + ifName); mTag = getName(); mContext = context; @@ -661,7 +632,7 @@ public class IpManager extends StateMachine { // TODO: Also observe mInterfaceName going down and take some // kind of appropriate action. if (mClatInterfaceName.equals(iface)) { - // TODO: consider sending a message to the IpManager main + // TODO: consider sending a message to the IpClient main // StateMachine thread, in case "NDO enabled" state becomes // tied to more things that 464xlat operation. mCallback.setNeighborDiscoveryOffload(true); @@ -735,7 +706,7 @@ public class IpManager extends StateMachine { mCallback.onQuit(); } - // Shut down this IpManager instance altogether. + // Shut down this IpClient instance altogether. public void shutdown() { stop(); sendMessage(CMD_TERMINATE_AFTER_STOP); @@ -829,7 +800,7 @@ public class IpManager extends StateMachine { } else { pw.print("No active ApfFilter; "); if (provisioningConfig == null) { - pw.println("IpManager not yet started."); + pw.println("IpClient not yet started."); } else if (apfCapabilities == null || apfCapabilities.apfVersionSupported == 0) { pw.println("Hardware does not support APF."); } else { @@ -895,7 +866,7 @@ public class IpManager extends StateMachine { protected boolean recordLogRec(Message msg) { // Don't log EVENT_NETLINK_LINKPROPERTIES_CHANGED. They can be noisy, // and we already log any LinkProperties change that results in an - // invocation of IpManager.Callback#onLinkPropertiesChange(). + // invocation of IpClient.Callback#onLinkPropertiesChange(). final boolean shouldLog = (msg.what != EVENT_NETLINK_LINKPROPERTIES_CHANGED); if (!shouldLog) { mMsgStateLogger.reset(); @@ -1056,9 +1027,9 @@ public class IpManager extends StateMachine { } } - // Updates all IpManager-related state concerned with LinkProperties. + // Updates all IpClient-related state concerned with LinkProperties. // Returns a ProvisioningChange for possibly notifying other interested - // parties that are not fronted by IpManager. + // parties that are not fronted by IpClient. private ProvisioningChange setLinkProperties(LinkProperties newLp) { if (mApfFilter != null) { mApfFilter.setLinkProperties(newLp); @@ -1092,7 +1063,7 @@ public class IpManager extends StateMachine { // // N.B.: this is fundamentally race-prone and should be fixed by // changing NetlinkTracker from a hybrid edge/level model to an - // edge-only model, or by giving IpManager its own netlink socket(s) + // edge-only model, or by giving IpClient its own netlink socket(s) // so as to track all required information directly. LinkProperties netlinkLinkProperties = mNetlinkTracker.getLinkProperties(); newLp.setLinkAddresses(netlinkLinkProperties.getLinkAddresses()); @@ -1238,7 +1209,7 @@ public class IpManager extends StateMachine { } } else { // Start DHCPv4. - mDhcpClient = DhcpClient.makeDhcpClient(mContext, IpManager.this, mInterfaceName); + mDhcpClient = DhcpClient.makeDhcpClient(mContext, IpClient.this, mInterfaceName); mDhcpClient.registerForPreDhcpNotification(); mDhcpClient.sendMessage(DhcpClient.CMD_START_DHCP); } @@ -1405,7 +1376,7 @@ public class IpManager extends StateMachine { } else { // Clear all IPv4 and IPv6 before proceeding to RunningState. // Clean up any leftover state from an abnormal exit from - // tethering or during an IpManager restart. + // tethering or during an IpClient restart. stopAllIP(); } } From 6d8b80a5b9b0648af4c57f26ab341e3b0c41b5ce Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Wed, 11 Oct 2017 22:00:11 +0900 Subject: [PATCH 2/2] Skeletal IpManager proxying to the new IpClient Test: as follows - built - flashed - booted - runtest frameworks-net passes - both wifi and ethernet connectivity works Bug: 62476366 Change-Id: I3b56e75d545594b88849a621e4ae09f2e1d45c69 --- .../net/java/android/net/ip/IpManager.java | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 services/net/java/android/net/ip/IpManager.java diff --git a/services/net/java/android/net/ip/IpManager.java b/services/net/java/android/net/ip/IpManager.java new file mode 100644 index 0000000000000..b12cb32cd5f1a --- /dev/null +++ b/services/net/java/android/net/ip/IpManager.java @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2017 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.ip; + +import android.content.Context; +import android.net.INetd; +import android.net.LinkProperties; +import android.net.Network; +import android.net.StaticIpConfiguration; +import android.net.apf.ApfCapabilities; +import android.net.util.NetdService; +import android.os.INetworkManagementService; +import android.os.ServiceManager; +import android.net.apf.ApfCapabilities; + +import com.android.internal.annotations.VisibleForTesting; + + +/* + * TODO: Delete this altogether in favor of its renamed successor: IpClient. + * + * @hide + */ +public class IpManager extends IpClient { + public static class ProvisioningConfiguration extends IpClient.ProvisioningConfiguration { + public ProvisioningConfiguration(IpClient.ProvisioningConfiguration ipcConfig) { + super(ipcConfig); + } + + public static class Builder extends IpClient.ProvisioningConfiguration.Builder { + @Override + public Builder withoutIPv4() { + super.withoutIPv4(); + return this; + } + @Override + public Builder withoutIPv6() { + super.withoutIPv6(); + return this; + } + @Override + public Builder withoutIpReachabilityMonitor() { + super.withoutIpReachabilityMonitor(); + return this; + } + @Override + public Builder withPreDhcpAction() { + super.withPreDhcpAction(); + return this; + } + @Override + public Builder withPreDhcpAction(int dhcpActionTimeoutMs) { + super.withPreDhcpAction(dhcpActionTimeoutMs); + return this; + } + // No Override; locally defined type. + public Builder withInitialConfiguration(InitialConfiguration initialConfig) { + super.withInitialConfiguration((IpClient.InitialConfiguration) initialConfig); + return this; + } + @Override + public Builder withStaticConfiguration(StaticIpConfiguration staticConfig) { + super.withStaticConfiguration(staticConfig); + return this; + } + @Override + public Builder withApfCapabilities(ApfCapabilities apfCapabilities) { + super.withApfCapabilities(apfCapabilities); + return this; + } + @Override + public Builder withProvisioningTimeoutMs(int timeoutMs) { + super.withProvisioningTimeoutMs(timeoutMs); + return this; + } + @Override + public Builder withIPv6AddrGenModeEUI64() { + super.withIPv6AddrGenModeEUI64(); + return this; + } + @Override + public Builder withIPv6AddrGenModeStablePrivacy() { + super.withIPv6AddrGenModeStablePrivacy(); + return this; + } + @Override + public Builder withNetwork(Network network) { + super.withNetwork(network); + return this; + } + @Override + public Builder withDisplayName(String displayName) { + super.withDisplayName(displayName); + return this; + } + @Override + public ProvisioningConfiguration build() { + return new ProvisioningConfiguration(super.build()); + } + } + } + + public static ProvisioningConfiguration.Builder buildProvisioningConfiguration() { + return new ProvisioningConfiguration.Builder(); + } + + public static class InitialConfiguration extends IpClient.InitialConfiguration { + } + + public static class Callback extends IpClient.Callback { + } + + public static class WaitForProvisioningCallback extends Callback { + private LinkProperties mCallbackLinkProperties; + + public LinkProperties waitForProvisioning() { + synchronized (this) { + try { + wait(); + } catch (InterruptedException e) {} + return mCallbackLinkProperties; + } + } + + @Override + public void onProvisioningSuccess(LinkProperties newLp) { + synchronized (this) { + mCallbackLinkProperties = newLp; + notify(); + } + } + + @Override + public void onProvisioningFailure(LinkProperties newLp) { + synchronized (this) { + mCallbackLinkProperties = null; + notify(); + } + } + } + + public IpManager(Context context, String ifName, Callback callback) { + this(context, ifName, callback, INetworkManagementService.Stub.asInterface( + ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)), + NetdService.getInstance()); + } + + public IpManager(Context context, String ifName, Callback callback, + INetworkManagementService nwService) { + this(context, ifName, callback, nwService, NetdService.getInstance()); + } + + @VisibleForTesting + public IpManager(Context context, String ifName, Callback callback, + INetworkManagementService nwService, INetd netd) { + super(context, ifName, callback, nwService, netd); + } + + public void startProvisioning(ProvisioningConfiguration req) { + super.startProvisioning((IpClient.ProvisioningConfiguration) req); + } +}