IpManager: add display name for helpful logging, and Network
Test: as follows
- built
- flashed
- booted
- runtest frameworks-net passes
Bug: 62476366
Change-Id: I509506814fa704e54f3d67158203276312a24fa1
This commit is contained in:
@@ -25,6 +25,7 @@ import android.os.Handler;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.PacketSocketAddress;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.LocalLog;
|
||||
|
||||
@@ -59,11 +60,14 @@ public class ConnectivityPacketTracker {
|
||||
private static final boolean DBG = false;
|
||||
private static final String MARK_START = "--- START ---";
|
||||
private static final String MARK_STOP = "--- STOP ---";
|
||||
private static final String MARK_NAMED_START = "--- START (%s) ---";
|
||||
private static final String MARK_NAMED_STOP = "--- STOP (%s) ---";
|
||||
|
||||
private final String mTag;
|
||||
private final LocalLog mLog;
|
||||
private final BlockingSocketReader mPacketListener;
|
||||
private boolean mRunning;
|
||||
private String mDisplayName;
|
||||
|
||||
public ConnectivityPacketTracker(Handler h, NetworkInterface netif, LocalLog log) {
|
||||
final String ifname;
|
||||
@@ -85,14 +89,16 @@ public class ConnectivityPacketTracker {
|
||||
mPacketListener = new PacketListener(h, ifindex, hwaddr, mtu);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
public void start(String displayName) {
|
||||
mRunning = true;
|
||||
mDisplayName = displayName;
|
||||
mPacketListener.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
mPacketListener.stop();
|
||||
mRunning = false;
|
||||
mDisplayName = null;
|
||||
}
|
||||
|
||||
private final class PacketListener extends BlockingSocketReader {
|
||||
@@ -133,16 +139,19 @@ public class ConnectivityPacketTracker {
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
mLog.log(MARK_START);
|
||||
final String msg = TextUtils.isEmpty(mDisplayName)
|
||||
? MARK_START
|
||||
: String.format(MARK_NAMED_START, mDisplayName);
|
||||
mLog.log(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (mRunning) {
|
||||
mLog.log(MARK_STOP);
|
||||
} else {
|
||||
mLog.log(MARK_STOP + " (packet listener stopped unexpectedly)");
|
||||
}
|
||||
String msg = TextUtils.isEmpty(mDisplayName)
|
||||
? MARK_STOP
|
||||
: String.format(MARK_NAMED_STOP, mDisplayName);
|
||||
if (!mRunning) msg += " (packet listener stopped unexpectedly)";
|
||||
mLog.log(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.net.IpPrefix;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties.ProvisioningChange;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.ProxyInfo;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.StaticIpConfiguration;
|
||||
@@ -348,6 +349,16 @@ public class IpManager extends StateMachine {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withNetwork(Network network) {
|
||||
mConfig.mNetwork = network;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withDisplayName(String displayName) {
|
||||
mConfig.mDisplayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProvisioningConfiguration build() {
|
||||
return new ProvisioningConfiguration(mConfig);
|
||||
}
|
||||
@@ -362,6 +373,8 @@ public class IpManager extends StateMachine {
|
||||
/* package */ ApfCapabilities mApfCapabilities;
|
||||
/* package */ int mProvisioningTimeoutMs = DEFAULT_TIMEOUT_MS;
|
||||
/* package */ int mIPv6AddrGenMode = INetd.IPV6_ADDR_GEN_MODE_STABLE_PRIVACY;
|
||||
/* package */ Network mNetwork = null;
|
||||
/* package */ String mDisplayName = null;
|
||||
|
||||
public ProvisioningConfiguration() {} // used by Builder
|
||||
|
||||
@@ -374,6 +387,9 @@ public class IpManager extends StateMachine {
|
||||
mStaticIpConfig = other.mStaticIpConfig;
|
||||
mApfCapabilities = other.mApfCapabilities;
|
||||
mProvisioningTimeoutMs = other.mProvisioningTimeoutMs;
|
||||
mIPv6AddrGenMode = other.mIPv6AddrGenMode;
|
||||
mNetwork = other.mNetwork;
|
||||
mDisplayName = other.mDisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,6 +404,8 @@ public class IpManager extends StateMachine {
|
||||
.add("mApfCapabilities: " + mApfCapabilities)
|
||||
.add("mProvisioningTimeoutMs: " + mProvisioningTimeoutMs)
|
||||
.add("mIPv6AddrGenMode: " + mIPv6AddrGenMode)
|
||||
.add("mNetwork: " + mNetwork)
|
||||
.add("mDisplayName: " + mDisplayName)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@@ -1441,10 +1459,10 @@ public class IpManager extends StateMachine {
|
||||
@Override
|
||||
public void enter() {
|
||||
// Get the Configuration for ApfFilter from Context
|
||||
boolean filter802_3Frames =
|
||||
final boolean filter802_3Frames =
|
||||
mContext.getResources().getBoolean(R.bool.config_apfDrop802_3Frames);
|
||||
|
||||
int[] ethTypeBlackList = mContext.getResources().getIntArray(
|
||||
final int[] ethTypeBlackList = mContext.getResources().getIntArray(
|
||||
R.array.config_apfEthTypeBlackList);
|
||||
|
||||
mApfFilter = ApfFilter.maybeCreate(mConfiguration.mApfCapabilities, mNetworkInterface,
|
||||
@@ -1456,7 +1474,7 @@ public class IpManager extends StateMachine {
|
||||
}
|
||||
|
||||
mPacketTracker = createPacketTracker();
|
||||
if (mPacketTracker != null) mPacketTracker.start();
|
||||
if (mPacketTracker != null) mPacketTracker.start(mConfiguration.mDisplayName);
|
||||
|
||||
if (mConfiguration.mEnableIPv6 && !startIPv6()) {
|
||||
doImmediateProvisioningFailure(IpManagerEvent.ERROR_STARTING_IPV6);
|
||||
@@ -1470,7 +1488,7 @@ public class IpManager extends StateMachine {
|
||||
return;
|
||||
}
|
||||
|
||||
InitialConfiguration config = mConfiguration.mInitialConfig;
|
||||
final InitialConfiguration config = mConfiguration.mInitialConfig;
|
||||
if ((config != null) && !applyInitialConfig(config)) {
|
||||
// TODO introduce a new IpManagerEvent constant to distinguish this error case.
|
||||
doImmediateProvisioningFailure(IpManagerEvent.ERROR_INVALID_PROVISIONING);
|
||||
|
||||
Reference in New Issue
Block a user