Merge "Log upstream network suspend/resume callbacks"

This commit is contained in:
Treehugger Robot
2017-10-11 04:00:16 +00:00
committed by Gerrit Code Review
3 changed files with 51 additions and 6 deletions

View File

@@ -1371,6 +1371,7 @@ public class Tethering extends BaseNetworkObserver {
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS); sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
} }
} }
mUpstreamNetworkMonitor.setCurrentUpstream((ns != null) ? ns.network : null);
setUpstreamNetwork(ns); setUpstreamNetwork(ns);
} }

View File

@@ -95,7 +95,10 @@ public class UpstreamNetworkMonitor {
private NetworkCallback mDefaultNetworkCallback; private NetworkCallback mDefaultNetworkCallback;
private NetworkCallback mMobileNetworkCallback; private NetworkCallback mMobileNetworkCallback;
private boolean mDunRequired; private boolean mDunRequired;
private Network mCurrentDefault; // The current system default network (not really used yet).
private Network mDefaultInternetNetwork;
// The current upstream network used for tethering.
private Network mTetheringUpstreamNetwork;
public UpstreamNetworkMonitor(Context ctx, StateMachine tgt, SharedLog log, int what) { public UpstreamNetworkMonitor(Context ctx, StateMachine tgt, SharedLog log, int what) {
mContext = ctx; mContext = ctx;
@@ -130,10 +133,12 @@ public class UpstreamNetworkMonitor {
releaseCallback(mDefaultNetworkCallback); releaseCallback(mDefaultNetworkCallback);
mDefaultNetworkCallback = null; mDefaultNetworkCallback = null;
mDefaultInternetNetwork = null;
releaseCallback(mListenAllCallback); releaseCallback(mListenAllCallback);
mListenAllCallback = null; mListenAllCallback = null;
mTetheringUpstreamNetwork = null;
mNetworkMap.clear(); mNetworkMap.clear();
} }
@@ -207,7 +212,7 @@ public class UpstreamNetworkMonitor {
break; break;
default: default:
/* If we've found an active upstream connection that's not DUN/HIPRI /* If we've found an active upstream connection that's not DUN/HIPRI
* we should stop any outstanding DUN/HIPRI start requests. * we should stop any outstanding DUN/HIPRI requests.
* *
* If we found NONE we don't want to do this as we want any previous * If we found NONE we don't want to do this as we want any previous
* requests to keep trying to bring up something we can use. * requests to keep trying to bring up something we can use.
@@ -219,6 +224,10 @@ public class UpstreamNetworkMonitor {
return typeStatePair.ns; return typeStatePair.ns;
} }
public void setCurrentUpstream(Network upstream) {
mTetheringUpstreamNetwork = upstream;
}
public Set<IpPrefix> getLocalPrefixes() { public Set<IpPrefix> getLocalPrefixes() {
return (Set<IpPrefix>) mLocalPrefixes.clone(); return (Set<IpPrefix>) mLocalPrefixes.clone();
} }
@@ -250,7 +259,7 @@ public class UpstreamNetworkMonitor {
// These request*() calls can be deleted post oag/339444. // These request*() calls can be deleted post oag/339444.
return; return;
} }
mCurrentDefault = network; mDefaultInternetNetwork = network;
break; break;
case CALLBACK_MOBILE_REQUEST: case CALLBACK_MOBILE_REQUEST:
@@ -302,6 +311,13 @@ public class UpstreamNetworkMonitor {
network, newNc)); network, newNc));
} }
// Log changes in upstream network signal strength, if available.
if (network.equals(mTetheringUpstreamNetwork) && newNc.hasSignalStrength()) {
final int newSignal = newNc.getSignalStrength();
final String prevSignal = getSignalStrength(prev.networkCapabilities);
mLog.logf("upstream network signal strength: %s -> %s", prevSignal, newSignal);
}
mNetworkMap.put(network, new NetworkState( mNetworkMap.put(network, new NetworkState(
null, prev.linkProperties, newNc, network, null, null)); null, prev.linkProperties, newNc, network, null, null));
// TODO: If sufficient information is available to select a more // TODO: If sufficient information is available to select a more
@@ -330,9 +346,21 @@ public class UpstreamNetworkMonitor {
notifyTarget(EVENT_ON_LINKPROPERTIES, network); notifyTarget(EVENT_ON_LINKPROPERTIES, network);
} }
private void handleSuspended(int callbackType, Network network) {
if (callbackType != CALLBACK_LISTEN_ALL) return;
if (!network.equals(mTetheringUpstreamNetwork)) return;
mLog.log("SUSPENDED current upstream: " + network);
}
private void handleResumed(int callbackType, Network network) {
if (callbackType != CALLBACK_LISTEN_ALL) return;
if (!network.equals(mTetheringUpstreamNetwork)) return;
mLog.log("RESUMED current upstream: " + network);
}
private void handleLost(int callbackType, Network network) { private void handleLost(int callbackType, Network network) {
if (callbackType == CALLBACK_TRACK_DEFAULT) { if (callbackType == CALLBACK_TRACK_DEFAULT) {
mCurrentDefault = null; mDefaultInternetNetwork = null;
// Receiving onLost() for a default network does not necessarily // Receiving onLost() for a default network does not necessarily
// mean the network is gone. We wait for a separate notification // mean the network is gone. We wait for a separate notification
// on either the LISTEN_ALL or MOBILE_REQUEST callbacks before // on either the LISTEN_ALL or MOBILE_REQUEST callbacks before
@@ -401,8 +429,15 @@ public class UpstreamNetworkMonitor {
recomputeLocalPrefixes(); recomputeLocalPrefixes();
} }
// TODO: Handle onNetworkSuspended(); @Override
// TODO: Handle onNetworkResumed(); public void onNetworkSuspended(Network network) {
handleSuspended(mCallbackType, network);
}
@Override
public void onNetworkResumed(Network network) {
handleResumed(mCallbackType, network);
}
@Override @Override
public void onLost(Network network) { public void onLost(Network network) {
@@ -467,4 +502,9 @@ public class UpstreamNetworkMonitor {
return prefixSet; return prefixSet;
} }
private static String getSignalStrength(NetworkCapabilities nc) {
if (nc == null || !nc.hasSignalStrength()) return "unknown";
return Integer.toString(nc.getSignalStrength());
}
} }

View File

@@ -106,6 +106,10 @@ public class SharedLog {
record(Category.NONE, msg); record(Category.NONE, msg);
} }
public void logf(String fmt, Object... args) {
log(String.format(fmt, args));
}
public void mark(String msg) { public void mark(String msg) {
record(Category.MARK, msg); record(Category.MARK, msg);
} }