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
Merged-In: I602ff2c688909473b03b72c9407d4286608cff4c
This commit is contained in:
Chiachang Wang
2021-03-25 17:51:00 +08:00
parent c542ed20fa
commit 3ffcb398e2
5 changed files with 37 additions and 0 deletions

View File

@@ -47,4 +47,5 @@ oneway interface INetworkAgent {
void onQosFilterCallbackRegistered(int qosCallbackId, in QosFilterParcelable filterParcel);
void onQosCallbackUnregistered(int qosCallbackId);
void onNetworkCreated();
void onNetworkDisconnected();
}

View File

@@ -370,6 +370,14 @@ public abstract class NetworkAgent {
*/
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) {
// The subtype can be changed with (TODO) setLegacySubtype, but it starts
// with 0 (TelephonyManager.NETWORK_TYPE_UNKNOWN) and an empty description.
@@ -574,6 +582,10 @@ public abstract class NetworkAgent {
onNetworkCreated();
break;
}
case CMD_NETWORK_DISCONNECTED: {
onNetworkDisconnected();
break;
}
}
}
}
@@ -719,6 +731,11 @@ public abstract class NetworkAgent {
public void onNetworkCreated() {
mHandler.sendMessage(mHandler.obtainMessage(CMD_NETWORK_CREATED));
}
@Override
public void onNetworkDisconnected() {
mHandler.sendMessage(mHandler.obtainMessage(CMD_NETWORK_DISCONNECTED));
}
}
/**
@@ -1031,6 +1048,12 @@ public abstract class NetworkAgent {
*/
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.
*