New API to stop service resolution
Resolve service may take long time due to network issue or using wrong service information, but users are not able to stop it. They can only wait for the callback of resolveService to end, which sometimes takes a long time. Thus, add the new API that users can stop the service resolution. Bug: 245369943 Test: atest FrameworksNetTests CtsNetTestCases Change-Id: I6b6183c8c73f8db981b9afa51fbc73bf886d9ed3
This commit is contained in:
@@ -385,6 +385,13 @@ public class NsdService extends INsdManager.Stub {
|
||||
clientId, NsdManager.FAILURE_INTERNAL_ERROR);
|
||||
}
|
||||
break;
|
||||
case NsdManager.STOP_RESOLUTION:
|
||||
cInfo = getClientInfoForReply(msg);
|
||||
if (cInfo != null) {
|
||||
cInfo.onStopResolutionFailed(
|
||||
clientId, NsdManager.FAILURE_OPERATION_NOT_RUNNING);
|
||||
}
|
||||
break;
|
||||
case NsdManager.DAEMON_CLEANUP:
|
||||
maybeStopDaemon();
|
||||
break;
|
||||
@@ -689,6 +696,29 @@ public class NsdService extends INsdManager.Stub {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NsdManager.STOP_RESOLUTION:
|
||||
if (DBG) Log.d(TAG, "Stop service resolution");
|
||||
args = (ListenerArgs) msg.obj;
|
||||
clientInfo = mClients.get(args.connector);
|
||||
// If the binder death notification for a INsdManagerCallback was received
|
||||
// before any calls are received by NsdService, the clientInfo would be
|
||||
// cleared and cause NPE. Add a null check here to prevent this corner case.
|
||||
if (clientInfo == null) {
|
||||
Log.e(TAG, "Unknown connector in stop resolution");
|
||||
break;
|
||||
}
|
||||
|
||||
id = clientInfo.mClientIds.get(clientId);
|
||||
removeRequestMap(clientId, id, clientInfo);
|
||||
if (stopResolveService(id)) {
|
||||
clientInfo.onStopResolutionSucceeded(clientId);
|
||||
} else {
|
||||
clientInfo.onStopResolutionFailed(
|
||||
clientId, NsdManager.FAILURE_OPERATION_NOT_RUNNING);
|
||||
}
|
||||
clientInfo.mResolvedService = null;
|
||||
// TODO: Implement the stop resolution with MdnsDiscoveryManager.
|
||||
break;
|
||||
case MDNS_SERVICE_EVENT:
|
||||
if (!handleMDnsServiceEvent(msg.arg1, msg.arg2, msg.obj)) {
|
||||
return NOT_HANDLED;
|
||||
@@ -1155,6 +1185,12 @@ public class NsdService extends INsdManager.Stub {
|
||||
new ListenerArgs(this, serviceInfo)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopResolution(int listenerKey) {
|
||||
mNsdStateMachine.sendMessage(mNsdStateMachine.obtainMessage(
|
||||
NsdManager.STOP_RESOLUTION, 0, listenerKey, new ListenerArgs(this, null)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDaemon() {
|
||||
mNsdStateMachine.sendMessage(mNsdStateMachine.obtainMessage(
|
||||
@@ -1488,5 +1524,21 @@ public class NsdService extends INsdManager.Stub {
|
||||
Log.e(TAG, "Error calling onResolveServiceSucceeded", e);
|
||||
}
|
||||
}
|
||||
|
||||
void onStopResolutionFailed(int listenerKey, int error) {
|
||||
try {
|
||||
mCb.onStopResolutionFailed(listenerKey, error);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling onStopResolutionFailed", e);
|
||||
}
|
||||
}
|
||||
|
||||
void onStopResolutionSucceeded(int listenerKey) {
|
||||
try {
|
||||
mCb.onStopResolutionSucceeded(listenerKey);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling onStopResolutionSucceeded", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user