Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34a2358d authored by Chiachang Wang's avatar Chiachang Wang
Browse files

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
parent 7236cf6d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -218,6 +218,7 @@ package android.net {
    method public void onAddKeepalivePacketFilter(int, @NonNull android.net.KeepalivePacketData);
    method public void onAutomaticReconnectDisabled();
    method public void onNetworkCreated();
    method public void onNetworkDisconnected();
    method public void onNetworkUnwanted();
    method public void onQosCallbackRegistered(int, @NonNull android.net.QosFilter);
    method public void onQosCallbackUnregistered(int);
+1 −0
Original line number Diff line number Diff line
@@ -47,4 +47,5 @@ oneway interface INetworkAgent {
    void onQosFilterCallbackRegistered(int qosCallbackId, in QosFilterParcelable filterParcel);
    void onQosCallbackUnregistered(int qosCallbackId);
    void onNetworkCreated();
    void onNetworkDisconnected();
}
+23 −0
Original line number Diff line number Diff line
@@ -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.
     *
+1 −0
Original line number Diff line number Diff line
@@ -3701,6 +3701,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            mDnsManager.removeNetwork(nai.network);
        }
        mNetIdManager.releaseNetId(nai.network.getNetId());
        nai.onNetworkDisconnected();
    }

    private boolean createNativeNetwork(@NonNull NetworkAgentInfo networkAgent) {
+11 −0
Original line number Diff line number Diff line
@@ -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
    private class NetworkAgentMessageHandler extends INetworkAgentRegistry.Stub {
        private final Handler mHandler;