Add network disconnected callback
Create a network callback to notify network agent after the native network being destroyed by netd which means the network is fully disconnected. The NetworkAgent may handle this event after sending disconnect state to ConnectivityService to proceed its pending works that have to be done after it. Bug: 178725261 Test: make update-api Change-Id: I602ff2c688909473b03b72c9407d4286608cff4c CTS-Coverage-Bug: 178725261
This commit is contained in:
@@ -219,6 +219,7 @@ package android.net {
|
|||||||
method public void onAutomaticReconnectDisabled();
|
method public void onAutomaticReconnectDisabled();
|
||||||
method public void onBandwidthUpdateRequested();
|
method public void onBandwidthUpdateRequested();
|
||||||
method public void onNetworkCreated();
|
method public void onNetworkCreated();
|
||||||
|
method public void onNetworkDisconnected();
|
||||||
method public void onNetworkUnwanted();
|
method public void onNetworkUnwanted();
|
||||||
method public void onQosCallbackRegistered(int, @NonNull android.net.QosFilter);
|
method public void onQosCallbackRegistered(int, @NonNull android.net.QosFilter);
|
||||||
method public void onQosCallbackUnregistered(int);
|
method public void onQosCallbackUnregistered(int);
|
||||||
|
|||||||
@@ -47,4 +47,5 @@ oneway interface INetworkAgent {
|
|||||||
void onQosFilterCallbackRegistered(int qosCallbackId, in QosFilterParcelable filterParcel);
|
void onQosFilterCallbackRegistered(int qosCallbackId, in QosFilterParcelable filterParcel);
|
||||||
void onQosCallbackUnregistered(int qosCallbackId);
|
void onQosCallbackUnregistered(int qosCallbackId);
|
||||||
void onNetworkCreated();
|
void onNetworkCreated();
|
||||||
|
void onNetworkDisconnected();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,6 +370,14 @@ public abstract class NetworkAgent {
|
|||||||
*/
|
*/
|
||||||
public static final int CMD_NETWORK_CREATED = BASE + 22;
|
public static final int CMD_NETWORK_CREATED = BASE + 22;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sent by ConnectivityService to {@link NetworkAgent} to inform the agent that its native
|
||||||
|
* network was destroyed.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int CMD_NETWORK_DISCONNECTED = BASE + 23;
|
||||||
|
|
||||||
private static NetworkInfo getLegacyNetworkInfo(final NetworkAgentConfig config) {
|
private static NetworkInfo getLegacyNetworkInfo(final NetworkAgentConfig config) {
|
||||||
final NetworkInfo ni = new NetworkInfo(config.legacyType, config.legacySubType,
|
final NetworkInfo ni = new NetworkInfo(config.legacyType, config.legacySubType,
|
||||||
config.legacyTypeName, config.legacySubTypeName);
|
config.legacyTypeName, config.legacySubTypeName);
|
||||||
@@ -573,6 +581,10 @@ public abstract class NetworkAgent {
|
|||||||
onNetworkCreated();
|
onNetworkCreated();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CMD_NETWORK_DISCONNECTED: {
|
||||||
|
onNetworkDisconnected();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,6 +730,11 @@ public abstract class NetworkAgent {
|
|||||||
public void onNetworkCreated() {
|
public void onNetworkCreated() {
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(CMD_NETWORK_CREATED));
|
mHandler.sendMessage(mHandler.obtainMessage(CMD_NETWORK_CREATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNetworkDisconnected() {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(CMD_NETWORK_DISCONNECTED));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1032,6 +1049,12 @@ public abstract class NetworkAgent {
|
|||||||
*/
|
*/
|
||||||
public void onNetworkCreated() {}
|
public void onNetworkCreated() {}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when ConnectivityService has successfully destroy this NetworkAgent's native network.
|
||||||
|
*/
|
||||||
|
public void onNetworkDisconnected() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that the network hardware send the specified packet at the specified interval.
|
* Requests that the network hardware send the specified packet at the specified interval.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3716,6 +3716,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mDnsManager.removeNetwork(nai.network);
|
mDnsManager.removeNetwork(nai.network);
|
||||||
}
|
}
|
||||||
mNetIdManager.releaseNetId(nai.network.getNetId());
|
mNetIdManager.releaseNetId(nai.network.getNetId());
|
||||||
|
nai.onNetworkDisconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean createNativeNetwork(@NonNull NetworkAgentInfo networkAgent) {
|
private boolean createNativeNetwork(@NonNull NetworkAgentInfo networkAgent) {
|
||||||
|
|||||||
@@ -588,6 +588,17 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the NetworkAgent that the network is disconnected and destroyed.
|
||||||
|
*/
|
||||||
|
public void onNetworkDisconnected() {
|
||||||
|
try {
|
||||||
|
networkAgent.onNetworkDisconnected();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Error sending network disconnected event", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: consider moving out of NetworkAgentInfo into its own class
|
// TODO: consider moving out of NetworkAgentInfo into its own class
|
||||||
private class NetworkAgentMessageHandler extends INetworkAgentRegistry.Stub {
|
private class NetworkAgentMessageHandler extends INetworkAgentRegistry.Stub {
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
|
|||||||
Reference in New Issue
Block a user