Add constructor with more inputs for dependency injection.

Bug: 26991160
Bug: 27406552
Change-Id: If4a0a2f1afb1da4ad59df9eb31c540047c84659b
This commit is contained in:
Erik Kline
2016-03-01 10:37:50 +09:00
parent 4aeafd8f27
commit b9df11099f

View File

@@ -241,15 +241,22 @@ public class IpManager extends StateMachine {
public IpManager(Context context, String ifName, Callback callback)
throws IllegalArgumentException {
this(context, ifName, callback, INetworkManagementService.Stub.asInterface(
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)));
}
/**
* An expanded constructor, useful for dependency injection.
*/
public IpManager(Context context, String ifName, Callback callback,
INetworkManagementService nwService) throws IllegalArgumentException {
super(IpManager.class.getSimpleName() + "." + ifName);
mTag = getName();
mContext = context;
mInterfaceName = ifName;
mCallback = callback;
mNwService = INetworkManagementService.Stub.asInterface(
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
mNwService = nwService;
mNetlinkTracker = new NetlinkTracker(
mInterfaceName,
@@ -277,25 +284,6 @@ public class IpManager extends StateMachine {
super.start();
}
/**
* A special constructor for use in testing that bypasses some of the more
* complicated setup bits.
*
* TODO: Figure out how to delete this yet preserve testability.
*/
@VisibleForTesting
protected IpManager(String ifName, Callback callback) {
super(IpManager.class.getSimpleName() + ".test-" + ifName);
mTag = getName();
mInterfaceName = ifName;
mCallback = callback;
mContext = null;
mNwService = null;
mNetlinkTracker = null;
}
@Override
protected void onQuitting() {
mCallback.onQuit();