diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2019-09-02 19:20:54 +0900 |
---|---|---|
committer | Remi NGUYEN VAN <reminv@google.com> | 2020-02-12 10:39:55 +0900 |
commit | dc018dd943f0c11e0b9172dee0db0966871af20d (patch) | |
tree | 964a774fb259941aa3f548a49b80992e268a88cc /src/android/net/dhcp/DhcpServer.java | |
parent | ee23002c1f0a547ea46fa399d20caf542e68ab57 (diff) |
Add DhcpLeaseCallbacks
The callbacks will be used by Tethering to provide callbacks when DHCP
leases are updated.
The current design only supports one client as Tethering may want to
send callbacks to multiple callers, but DhcpServer is only owned by
Tethering.
Bug: 135411507
Test: atest NetworkStackTests
Change-Id: I1e44221d6fbd1b1f2d0d0057a29c7445af1cdbcf
Diffstat (limited to 'src/android/net/dhcp/DhcpServer.java')
-rw-r--r-- | src/android/net/dhcp/DhcpServer.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/android/net/dhcp/DhcpServer.java b/src/android/net/dhcp/DhcpServer.java index 6aadc04..bcca47a 100644 --- a/src/android/net/dhcp/DhcpServer.java +++ b/src/android/net/dhcp/DhcpServer.java @@ -274,10 +274,22 @@ public class DhcpServer extends IDhcpServer.Stub { */ @Override public void start(@Nullable INetworkStackStatusCallback cb) { + startWithCallbacks(cb, null); + } + + /** + * Start listening for and responding to packets, with optional callbacks for lease events. + * + * <p>It is not legal to call this method more than once; in particular the server cannot be + * restarted after being stopped. + */ + @Override + public void startWithCallbacks(@Nullable INetworkStackStatusCallback statusCb, + @Nullable IDhcpLeaseCallbacks leaseCb) { mDeps.checkCaller(); mHandlerThread.start(); mHandler = new ServerHandler(mHandlerThread.getLooper()); - sendMessage(CMD_START_DHCP_SERVER, cb); + sendMessage(CMD_START_DHCP_SERVER, new Pair<>(statusCb, leaseCb)); } /** @@ -344,9 +356,12 @@ public class DhcpServer extends IDhcpServer.Stub { cb = pair.second; break; case CMD_START_DHCP_SERVER: + final Pair<INetworkStackStatusCallback, IDhcpLeaseCallbacks> obj = + (Pair<INetworkStackStatusCallback, IDhcpLeaseCallbacks>) msg.obj; + cb = obj.first; + mLeaseRepo.addLeaseCallbacks(obj.second); mPacketListener = mDeps.makePacketListener(); mPacketListener.start(); - cb = (INetworkStackStatusCallback) msg.obj; break; case CMD_STOP_DHCP_SERVER: if (mPacketListener != null) { |