Merge "Fix the comments from aosp/1717479."
This commit is contained in:
@@ -61,7 +61,7 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
private static final String MDNS_TAG = "mDnsConnector";
|
private static final String MDNS_TAG = "mDnsConnector";
|
||||||
|
|
||||||
private static final boolean DBG = true;
|
private static final boolean DBG = true;
|
||||||
private static final long CLEANUP_DELAY_MS = 3000;
|
private static final long CLEANUP_DELAY_MS = 10000;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final NsdSettings mNsdSettings;
|
private final NsdSettings mNsdSettings;
|
||||||
@@ -94,19 +94,25 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
return NsdManager.nameOf(what);
|
return NsdManager.nameOf(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybeStartDaemon() {
|
private void maybeStartDaemon() {
|
||||||
mDaemon.maybeStart();
|
mDaemon.maybeStart();
|
||||||
maybeScheduleStop();
|
maybeScheduleStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybeScheduleStop() {
|
private boolean isAnyRequestActive() {
|
||||||
|
return mIdToClientInfoMap.size() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleStop() {
|
||||||
|
sendMessageDelayed(NsdManager.DAEMON_CLEANUP, mCleanupDelayMs);
|
||||||
|
}
|
||||||
|
private void maybeScheduleStop() {
|
||||||
if (!isAnyRequestActive()) {
|
if (!isAnyRequestActive()) {
|
||||||
cancelStop();
|
scheduleStop();
|
||||||
sendMessageDelayed(NsdManager.DAEMON_CLEANUP, mCleanupDelayMs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancelStop() {
|
private void cancelStop() {
|
||||||
this.removeMessages(NsdManager.DAEMON_CLEANUP);
|
this.removeMessages(NsdManager.DAEMON_CLEANUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,11 +170,16 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
|
if (DBG) Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cInfo = mClients.get(msg.replyTo);
|
cInfo = mClients.get(msg.replyTo);
|
||||||
if (cInfo != null) {
|
if (cInfo != null) {
|
||||||
cInfo.expungeAllRequests();
|
cInfo.expungeAllRequests();
|
||||||
mClients.remove(msg.replyTo);
|
mClients.remove(msg.replyTo);
|
||||||
}
|
}
|
||||||
|
//Last client
|
||||||
|
if (mClients.size() == 0) {
|
||||||
|
scheduleStop();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION:
|
case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION:
|
||||||
AsyncChannel ac = new AsyncChannel();
|
AsyncChannel ac = new AsyncChannel();
|
||||||
@@ -235,7 +246,7 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
public void exit() {
|
public void exit() {
|
||||||
// TODO: it is incorrect to stop the daemon without expunging all requests
|
// TODO: it is incorrect to stop the daemon without expunging all requests
|
||||||
// and sending error callbacks to clients.
|
// and sending error callbacks to clients.
|
||||||
maybeScheduleStop();
|
scheduleStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean requestLimitReached(ClientInfo clientInfo) {
|
private boolean requestLimitReached(ClientInfo clientInfo) {
|
||||||
@@ -271,9 +282,6 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
return NOT_HANDLED;
|
return NOT_HANDLED;
|
||||||
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
|
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
|
||||||
return NOT_HANDLED;
|
return NOT_HANDLED;
|
||||||
}
|
|
||||||
|
|
||||||
switch (msg.what) {
|
|
||||||
case NsdManager.DISABLE:
|
case NsdManager.DISABLE:
|
||||||
//TODO: cleanup clients
|
//TODO: cleanup clients
|
||||||
transitionTo(mDisabledState);
|
transitionTo(mDisabledState);
|
||||||
@@ -531,10 +539,6 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAnyRequestActive() {
|
|
||||||
return mIdToClientInfoMap.size() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String unescape(String s) {
|
private String unescape(String s) {
|
||||||
StringBuilder sb = new StringBuilder(s.length());
|
StringBuilder sb = new StringBuilder(s.length());
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
@@ -907,7 +911,6 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
}
|
}
|
||||||
mClientIds.clear();
|
mClientIds.clear();
|
||||||
mClientRequests.clear();
|
mClientRequests.clear();
|
||||||
mNsdStateMachine.maybeScheduleStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mClientIds is a sparse array of listener id -> mDnsClient id. For a given mDnsClient id,
|
// mClientIds is a sparse array of listener id -> mDnsClient id. For a given mDnsClient id,
|
||||||
|
|||||||
Reference in New Issue
Block a user