Move EthernetNetworkAgent.Callbacks to field
Makes the code more consistent and readable. EtherneNetworkAgent#getCallbacks() was not removed as it is still used by the tests. Test: TH Flag: EXEMPT mainline Bug: 1000001 Change-Id: Id16b8309a7bcf3a9e48a1f2432567b26e3774b70
This commit is contained in:
parent
f80f66d424
commit
024d89b290
1 changed files with 16 additions and 14 deletions
|
|
@ -321,6 +321,7 @@ public class EthernetNetworkFactory {
|
|||
private NetworkCapabilities mCapabilities;
|
||||
private @Nullable EthernetIpClientCallback mIpClientCallback;
|
||||
private @Nullable EthernetNetworkAgent mNetworkAgent;
|
||||
private @Nullable EthernetNetworkAgent.Callbacks mNetworkAgentCallback;
|
||||
private IpConfiguration mIpConfig;
|
||||
|
||||
/**
|
||||
|
|
@ -415,6 +416,18 @@ public class EthernetNetworkFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private class EthernetNetworkAgentCallback implements EthernetNetworkAgent.Callbacks {
|
||||
private boolean isStale() {
|
||||
return this != mNetworkAgentCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkUnwanted() {
|
||||
if (isStale()) return;
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private final RequestTracker mRequestTracker = new RequestTracker();
|
||||
private static class RequestTracker {
|
||||
private final Set<Integer> mGlobalRequests = new ArraySet<>();
|
||||
|
|
@ -668,22 +681,10 @@ public class EthernetNetworkFactory {
|
|||
capabilities = LOCAL_NCM_CAPABILITIES;
|
||||
}
|
||||
|
||||
mNetworkAgentCallback = new EthernetNetworkAgentCallback();
|
||||
mNetworkAgent = mDeps.makeEthernetNetworkAgent(mContext, mHandler.getLooper(),
|
||||
capabilities, mLinkProperties, networkAgentConfig, mNetworkProvider,
|
||||
new EthernetNetworkAgent.Callbacks() {
|
||||
@Override
|
||||
public void onNetworkUnwanted() {
|
||||
// if mNetworkAgent is null, we have already called stop.
|
||||
if (mNetworkAgent == null) return;
|
||||
|
||||
if (this == mNetworkAgent.getCallbacks()) {
|
||||
stop();
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring unwanted as we have a more modern " +
|
||||
"instance");
|
||||
}
|
||||
}
|
||||
});
|
||||
mNetworkAgentCallback);
|
||||
mNetworkAgent.register();
|
||||
mNetworkAgent.markConnected();
|
||||
}
|
||||
|
|
@ -761,6 +762,7 @@ public class EthernetNetworkFactory {
|
|||
mIpClient = null;
|
||||
}
|
||||
|
||||
mNetworkAgentCallback = null;
|
||||
mIpClientCallback = null;
|
||||
mMode = Mode.NONE;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue