Merge "Correct isLegacy metric data" into main

This commit is contained in:
Paul Hu
2023-09-12 08:41:10 +00:00
committed by Gerrit Code Review
4 changed files with 222 additions and 187 deletions

View File

@@ -34,20 +34,17 @@ public class NetworkNsdReportedMetrics {
// The upper bound for the random number used in metrics data sampling determines the possible // The upper bound for the random number used in metrics data sampling determines the possible
// sample rate. // sample rate.
private static final int RANDOM_NUMBER_UPPER_BOUND = 1000; private static final int RANDOM_NUMBER_UPPER_BOUND = 1000;
// Whether this client is using legacy backend.
private final boolean mIsLegacy;
// The client id. // The client id.
private final int mClientId; private final int mClientId;
private final Dependencies mDependencies; private final Dependencies mDependencies;
private final Random mRandom; private final Random mRandom;
public NetworkNsdReportedMetrics(boolean isLegacy, int clientId) { public NetworkNsdReportedMetrics(int clientId) {
this(isLegacy, clientId, new Dependencies()); this(clientId, new Dependencies());
} }
@VisibleForTesting @VisibleForTesting
NetworkNsdReportedMetrics(boolean isLegacy, int clientId, Dependencies dependencies) { NetworkNsdReportedMetrics(int clientId, Dependencies dependencies) {
mIsLegacy = isLegacy;
mClientId = clientId; mClientId = clientId;
mDependencies = dependencies; mDependencies = dependencies;
mRandom = dependencies.makeRandomGenerator(); mRandom = dependencies.makeRandomGenerator();
@@ -89,23 +86,25 @@ public class NetworkNsdReportedMetrics {
} }
} }
private Builder makeReportedBuilder() { private Builder makeReportedBuilder(boolean isLegacy, int transactionId) {
final Builder builder = NetworkNsdReported.newBuilder(); final Builder builder = NetworkNsdReported.newBuilder();
builder.setIsLegacy(mIsLegacy); builder.setIsLegacy(isLegacy);
builder.setClientId(mClientId); builder.setClientId(mClientId);
builder.setRandomNumber(mRandom.nextInt(RANDOM_NUMBER_UPPER_BOUND)); builder.setRandomNumber(mRandom.nextInt(RANDOM_NUMBER_UPPER_BOUND));
builder.setTransactionId(transactionId);
return builder; return builder;
} }
/** /**
* Report service registration succeeded metric data. * Report service registration succeeded metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration. * @param transactionId The transaction id of service registration.
* @param durationMs The duration of service registration success. * @param durationMs The duration of service registration success.
*/ */
public void reportServiceRegistrationSucceeded(int transactionId, long durationMs) { public void reportServiceRegistrationSucceeded(boolean isLegacy, int transactionId,
final Builder builder = makeReportedBuilder(); long durationMs) {
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_REGISTER); builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTERED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTERED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -115,12 +114,13 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service registration failed metric data. * Report service registration failed metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration. * @param transactionId The transaction id of service registration.
* @param durationMs The duration of service registration failed. * @param durationMs The duration of service registration failed.
*/ */
public void reportServiceRegistrationFailed(int transactionId, long durationMs) { public void reportServiceRegistrationFailed(boolean isLegacy, int transactionId,
final Builder builder = makeReportedBuilder(); long durationMs) {
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_REGISTER); builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTRATION_FAILED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTRATION_FAILED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -130,6 +130,7 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service unregistration success metric data. * Report service unregistration success metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration. * @param transactionId The transaction id of service registration.
* @param durationMs The duration of service stayed registered. * @param durationMs The duration of service stayed registered.
* @param repliedRequestsCount The replied request count of this service before unregistered it. * @param repliedRequestsCount The replied request count of this service before unregistered it.
@@ -137,11 +138,10 @@ public class NetworkNsdReportedMetrics {
* @param conflictDuringProbingCount The number of conflict during probing. * @param conflictDuringProbingCount The number of conflict during probing.
* @param conflictAfterProbingCount The number of conflict after probing. * @param conflictAfterProbingCount The number of conflict after probing.
*/ */
public void reportServiceUnregistration(int transactionId, long durationMs, public void reportServiceUnregistration(boolean isLegacy, int transactionId, long durationMs,
int repliedRequestsCount, int sentPacketCount, int conflictDuringProbingCount, int repliedRequestsCount, int sentPacketCount, int conflictDuringProbingCount,
int conflictAfterProbingCount) { int conflictAfterProbingCount) {
final Builder builder = makeReportedBuilder(); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setTransactionId(transactionId);
builder.setType(NsdEventType.NET_REGISTER); builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_UNREGISTERED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_UNREGISTERED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -155,11 +155,11 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service discovery started metric data. * Report service discovery started metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery. * @param transactionId The transaction id of service discovery.
*/ */
public void reportServiceDiscoveryStarted(int transactionId) { public void reportServiceDiscoveryStarted(boolean isLegacy, int transactionId) {
final Builder builder = makeReportedBuilder(); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setTransactionId(transactionId);
builder.setType(NsdEventType.NET_DISCOVER); builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STARTED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STARTED);
mDependencies.statsWrite(builder.build()); mDependencies.statsWrite(builder.build());
@@ -168,12 +168,13 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service discovery failed metric data. * Report service discovery failed metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery. * @param transactionId The transaction id of service discovery.
* @param durationMs The duration of service discovery failed. * @param durationMs The duration of service discovery failed.
*/ */
public void reportServiceDiscoveryFailed(int transactionId, long durationMs) { public void reportServiceDiscoveryFailed(boolean isLegacy, int transactionId,
final Builder builder = makeReportedBuilder(); long durationMs) {
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_DISCOVER); builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_FAILED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_FAILED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -183,6 +184,7 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service discovery stop metric data. * Report service discovery stop metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery. * @param transactionId The transaction id of service discovery.
* @param durationMs The duration of discovering services. * @param durationMs The duration of discovering services.
* @param foundCallbackCount The count of found service callbacks before stop discovery. * @param foundCallbackCount The count of found service callbacks before stop discovery.
@@ -190,10 +192,9 @@ public class NetworkNsdReportedMetrics {
* @param servicesCount The count of found services. * @param servicesCount The count of found services.
* @param sentQueryCount The count of sent queries before stop discovery. * @param sentQueryCount The count of sent queries before stop discovery.
*/ */
public void reportServiceDiscoveryStop(int transactionId, long durationMs, public void reportServiceDiscoveryStop(boolean isLegacy, int transactionId, long durationMs,
int foundCallbackCount, int lostCallbackCount, int servicesCount, int sentQueryCount) { int foundCallbackCount, int lostCallbackCount, int servicesCount, int sentQueryCount) {
final Builder builder = makeReportedBuilder(); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setTransactionId(transactionId);
builder.setType(NsdEventType.NET_DISCOVER); builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STOP); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STOP);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -207,15 +208,15 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service resolution success metric data. * Report service resolution success metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution. * @param transactionId The transaction id of service resolution.
* @param durationMs The duration of resolving services. * @param durationMs The duration of resolving services.
* @param isServiceFromCache Whether the resolved service is from cache. * @param isServiceFromCache Whether the resolved service is from cache.
* @param sentQueryCount The count of sent queries during resolving. * @param sentQueryCount The count of sent queries during resolving.
*/ */
public void reportServiceResolved(int transactionId, long durationMs, public void reportServiceResolved(boolean isLegacy, int transactionId, long durationMs,
boolean isServiceFromCache, int sentQueryCount) { boolean isServiceFromCache, int sentQueryCount) {
final Builder builder = makeReportedBuilder(); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setTransactionId(transactionId);
builder.setType(NsdEventType.NET_RESOLVE); builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLVED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLVED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -227,12 +228,13 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service resolution failed metric data. * Report service resolution failed metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution. * @param transactionId The transaction id of service resolution.
* @param durationMs The duration of service resolution failed. * @param durationMs The duration of service resolution failed.
*/ */
public void reportServiceResolutionFailed(int transactionId, long durationMs) { public void reportServiceResolutionFailed(boolean isLegacy, int transactionId,
final Builder builder = makeReportedBuilder(); long durationMs) {
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_RESOLVE); builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_FAILED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_FAILED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -242,12 +244,12 @@ public class NetworkNsdReportedMetrics {
/** /**
* Report service resolution stop metric data. * Report service resolution stop metric data.
* *
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution. * @param transactionId The transaction id of service resolution.
* @param durationMs The duration before stop resolving the service. * @param durationMs The duration before stop resolving the service.
*/ */
public void reportServiceResolutionStop(int transactionId, long durationMs) { public void reportServiceResolutionStop(boolean isLegacy, int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder(); final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setTransactionId(transactionId);
builder.setType(NsdEventType.NET_RESOLVE); builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_STOP); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_STOP);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);
@@ -260,8 +262,8 @@ public class NetworkNsdReportedMetrics {
* @param transactionId The transaction id of service info callback registration. * @param transactionId The transaction id of service info callback registration.
*/ */
public void reportServiceInfoCallbackRegistered(int transactionId) { public void reportServiceInfoCallbackRegistered(int transactionId) {
final Builder builder = makeReportedBuilder(); // service info callback is always using new backend.
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK); builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTERED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTERED);
mDependencies.statsWrite(builder.build()); mDependencies.statsWrite(builder.build());
@@ -273,8 +275,8 @@ public class NetworkNsdReportedMetrics {
* @param transactionId The transaction id of service callback registration. * @param transactionId The transaction id of service callback registration.
*/ */
public void reportServiceInfoCallbackRegistrationFailed(int transactionId) { public void reportServiceInfoCallbackRegistrationFailed(int transactionId) {
final Builder builder = makeReportedBuilder(); // service info callback is always using new backend.
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK); builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTRATION_FAILED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTRATION_FAILED);
mDependencies.statsWrite(builder.build()); mDependencies.statsWrite(builder.build());
@@ -293,8 +295,8 @@ public class NetworkNsdReportedMetrics {
public void reportServiceInfoCallbackUnregistered(int transactionId, long durationMs, public void reportServiceInfoCallbackUnregistered(int transactionId, long durationMs,
int updateCallbackCount, int lostCallbackCount, boolean isServiceFromCache, int updateCallbackCount, int lostCallbackCount, boolean isServiceFromCache,
int sentQueryCount) { int sentQueryCount) {
final Builder builder = makeReportedBuilder(); // service info callback is always using new backend.
builder.setTransactionId(transactionId); final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK); builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_UNREGISTERED); builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_UNREGISTERED);
builder.setEventDurationMillisec(durationMs); builder.setEventDurationMillisec(durationMs);

View File

@@ -608,7 +608,7 @@ public class NsdService extends INsdManager.Stub {
final String tag = "Client" + arg.uid + "-" + mClientNumberId++; final String tag = "Client" + arg.uid + "-" + mClientNumberId++;
final NetworkNsdReportedMetrics metrics = final NetworkNsdReportedMetrics metrics =
mDeps.makeNetworkNsdReportedMetrics( mDeps.makeNetworkNsdReportedMetrics(
!arg.useJavaBackend, (int) mClock.elapsedRealtime()); (int) mClock.elapsedRealtime());
cInfo = new ClientInfo(cb, arg.uid, arg.useJavaBackend, cInfo = new ClientInfo(cb, arg.uid, arg.useJavaBackend,
mServiceLogs.forSubComponent(tag), metrics); mServiceLogs.forSubComponent(tag), metrics);
mClients.put(arg.connector, cInfo); mClients.put(arg.connector, cInfo);
@@ -632,8 +632,8 @@ public class NsdService extends INsdManager.Stub {
case NsdManager.DISCOVER_SERVICES: case NsdManager.DISCOVER_SERVICES:
cInfo = getClientInfoForReply(msg); cInfo = getClientInfoForReply(msg);
if (cInfo != null) { if (cInfo != null) {
cInfo.onDiscoverServicesFailedImmediately( cInfo.onDiscoverServicesFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
break; break;
case NsdManager.STOP_DISCOVERY: case NsdManager.STOP_DISCOVERY:
@@ -646,8 +646,8 @@ public class NsdService extends INsdManager.Stub {
case NsdManager.REGISTER_SERVICE: case NsdManager.REGISTER_SERVICE:
cInfo = getClientInfoForReply(msg); cInfo = getClientInfoForReply(msg);
if (cInfo != null) { if (cInfo != null) {
cInfo.onRegisterServiceFailedImmediately( cInfo.onRegisterServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
break; break;
case NsdManager.UNREGISTER_SERVICE: case NsdManager.UNREGISTER_SERVICE:
@@ -660,8 +660,8 @@ public class NsdService extends INsdManager.Stub {
case NsdManager.RESOLVE_SERVICE: case NsdManager.RESOLVE_SERVICE:
cInfo = getClientInfoForReply(msg); cInfo = getClientInfoForReply(msg);
if (cInfo != null) { if (cInfo != null) {
cInfo.onResolveServiceFailedImmediately( cInfo.onResolveServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
break; break;
case NsdManager.STOP_RESOLUTION: case NsdManager.STOP_RESOLUTION:
@@ -726,13 +726,15 @@ public class NsdService extends INsdManager.Stub {
return false; return false;
} }
private void storeLegacyRequestMap(int clientRequestId, int transactionId, private ClientRequest storeLegacyRequestMap(int clientRequestId, int transactionId,
ClientInfo clientInfo, int what, long startTimeMs) { ClientInfo clientInfo, int what, long startTimeMs) {
clientInfo.mClientRequests.put(clientRequestId, final LegacyClientRequest request =
new LegacyClientRequest(transactionId, what, startTimeMs)); new LegacyClientRequest(transactionId, what, startTimeMs);
clientInfo.mClientRequests.put(clientRequestId, request);
mTransactionIdToClientInfoMap.put(transactionId, clientInfo); mTransactionIdToClientInfoMap.put(transactionId, clientInfo);
// Remove the cleanup event because here comes a new request. // Remove the cleanup event because here comes a new request.
cancelStop(); cancelStop();
return request;
} }
private void storeAdvertiserRequestMap(int clientRequestId, int transactionId, private void storeAdvertiserRequestMap(int clientRequestId, int transactionId,
@@ -758,13 +760,15 @@ public class NsdService extends INsdManager.Stub {
} }
} }
private void storeDiscoveryManagerRequestMap(int clientRequestId, int transactionId, private ClientRequest storeDiscoveryManagerRequestMap(int clientRequestId,
MdnsListener listener, ClientInfo clientInfo, int transactionId, MdnsListener listener, ClientInfo clientInfo,
@Nullable Network requestedNetwork) { @Nullable Network requestedNetwork) {
clientInfo.mClientRequests.put(clientRequestId, new DiscoveryManagerRequest( final DiscoveryManagerRequest request = new DiscoveryManagerRequest(transactionId,
transactionId, listener, requestedNetwork, mClock.elapsedRealtime())); listener, requestedNetwork, mClock.elapsedRealtime());
clientInfo.mClientRequests.put(clientRequestId, request);
mTransactionIdToClientInfoMap.put(transactionId, clientInfo); mTransactionIdToClientInfoMap.put(transactionId, clientInfo);
updateMulticastLock(); updateMulticastLock();
return request;
} }
/** /**
@@ -806,8 +810,8 @@ public class NsdService extends INsdManager.Stub {
} }
if (requestLimitReached(clientInfo)) { if (requestLimitReached(clientInfo)) {
clientInfo.onDiscoverServicesFailedImmediately( clientInfo.onDiscoverServicesFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_MAX_LIMIT); NsdManager.FAILURE_MAX_LIMIT, true /* isLegacy */);
break; break;
} }
@@ -821,8 +825,8 @@ public class NsdService extends INsdManager.Stub {
|| mDeps.isMdnsDiscoveryManagerEnabled(mContext) || mDeps.isMdnsDiscoveryManagerEnabled(mContext)
|| useDiscoveryManagerForType(serviceType)) { || useDiscoveryManagerForType(serviceType)) {
if (serviceType == null) { if (serviceType == null) {
clientInfo.onDiscoverServicesFailedImmediately( clientInfo.onDiscoverServicesFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, false /* isLegacy */);
break; break;
} }
@@ -842,10 +846,10 @@ public class NsdService extends INsdManager.Stub {
} }
mMdnsDiscoveryManager.registerListener( mMdnsDiscoveryManager.registerListener(
listenServiceType, listener, optionsBuilder.build()); listenServiceType, listener, optionsBuilder.build());
storeDiscoveryManagerRequestMap(clientRequestId, transactionId, final ClientRequest request = storeDiscoveryManagerRequestMap(
listener, clientInfo, info.getNetwork()); clientRequestId, transactionId, listener, clientInfo,
clientInfo.onDiscoverServicesStarted( info.getNetwork());
clientRequestId, info, transactionId); clientInfo.onDiscoverServicesStarted(clientRequestId, info, request);
clientInfo.log("Register a DiscoveryListener " + transactionId clientInfo.log("Register a DiscoveryListener " + transactionId
+ " for service type:" + listenServiceType); + " for service type:" + listenServiceType);
} else { } else {
@@ -855,14 +859,15 @@ public class NsdService extends INsdManager.Stub {
Log.d(TAG, "Discover " + msg.arg2 + " " + transactionId Log.d(TAG, "Discover " + msg.arg2 + " " + transactionId
+ info.getServiceType()); + info.getServiceType());
} }
storeLegacyRequestMap(clientRequestId, transactionId, clientInfo, final ClientRequest request = storeLegacyRequestMap(clientRequestId,
msg.what, mClock.elapsedRealtime()); transactionId, clientInfo, msg.what,
mClock.elapsedRealtime());
clientInfo.onDiscoverServicesStarted( clientInfo.onDiscoverServicesStarted(
clientRequestId, info, transactionId); clientRequestId, info, request);
} else { } else {
stopServiceDiscovery(transactionId); stopServiceDiscovery(transactionId);
clientInfo.onDiscoverServicesFailedImmediately( clientInfo.onDiscoverServicesFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
} }
break; break;
@@ -918,8 +923,8 @@ public class NsdService extends INsdManager.Stub {
} }
if (requestLimitReached(clientInfo)) { if (requestLimitReached(clientInfo)) {
clientInfo.onRegisterServiceFailedImmediately( clientInfo.onRegisterServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_MAX_LIMIT); NsdManager.FAILURE_MAX_LIMIT, true /* isLegacy */);
break; break;
} }
@@ -934,8 +939,8 @@ public class NsdService extends INsdManager.Stub {
|| useAdvertiserForType(registerServiceType)) { || useAdvertiserForType(registerServiceType)) {
if (registerServiceType == null) { if (registerServiceType == null) {
Log.e(TAG, "Invalid service type: " + serviceType); Log.e(TAG, "Invalid service type: " + serviceType);
clientInfo.onRegisterServiceFailedImmediately( clientInfo.onRegisterServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, false /* isLegacy */);
break; break;
} }
serviceInfo.setServiceType(registerServiceType); serviceInfo.setServiceType(registerServiceType);
@@ -962,8 +967,8 @@ public class NsdService extends INsdManager.Stub {
// Return success after mDns reports success // Return success after mDns reports success
} else { } else {
unregisterService(transactionId); unregisterService(transactionId);
clientInfo.onRegisterServiceFailedImmediately( clientInfo.onRegisterServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
} }
@@ -992,18 +997,15 @@ public class NsdService extends INsdManager.Stub {
// Note isMdnsAdvertiserEnabled may have changed to false at this point, // Note isMdnsAdvertiserEnabled may have changed to false at this point,
// so this needs to check the type of the original request to unregister // so this needs to check the type of the original request to unregister
// instead of looking at the flag value. // instead of looking at the flag value.
final long stopTimeMs = mClock.elapsedRealtime();
if (request instanceof AdvertiserClientRequest) { if (request instanceof AdvertiserClientRequest) {
final AdvertiserMetrics metrics = final AdvertiserMetrics metrics =
mAdvertiser.getAdvertiserMetrics(transactionId); mAdvertiser.getAdvertiserMetrics(transactionId);
mAdvertiser.removeService(transactionId); mAdvertiser.removeService(transactionId);
clientInfo.onUnregisterServiceSucceeded(clientRequestId, transactionId, clientInfo.onUnregisterServiceSucceeded(
request.calculateRequestDurationMs(stopTimeMs), metrics); clientRequestId, request, metrics);
} else { } else {
if (unregisterService(transactionId)) { if (unregisterService(transactionId)) {
clientInfo.onUnregisterServiceSucceeded(clientRequestId, clientInfo.onUnregisterServiceSucceeded(clientRequestId, request,
transactionId,
request.calculateRequestDurationMs(stopTimeMs),
new AdvertiserMetrics(NO_PACKET /* repliedRequestsCount */, new AdvertiserMetrics(NO_PACKET /* repliedRequestsCount */,
NO_PACKET /* sentPacketCount */, NO_PACKET /* sentPacketCount */,
0 /* conflictDuringProbingCount */, 0 /* conflictDuringProbingCount */,
@@ -1037,8 +1039,8 @@ public class NsdService extends INsdManager.Stub {
|| mDeps.isMdnsDiscoveryManagerEnabled(mContext) || mDeps.isMdnsDiscoveryManagerEnabled(mContext)
|| useDiscoveryManagerForType(serviceType)) { || useDiscoveryManagerForType(serviceType)) {
if (serviceType == null) { if (serviceType == null) {
clientInfo.onResolveServiceFailedImmediately( clientInfo.onResolveServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, false /* isLegacy */);
break; break;
} }
final String resolveServiceType = serviceType + ".local"; final String resolveServiceType = serviceType + ".local";
@@ -1060,8 +1062,8 @@ public class NsdService extends INsdManager.Stub {
+ " for service type:" + resolveServiceType); + " for service type:" + resolveServiceType);
} else { } else {
if (clientInfo.mResolvedService != null) { if (clientInfo.mResolvedService != null) {
clientInfo.onResolveServiceFailedImmediately( clientInfo.onResolveServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_ALREADY_ACTIVE); NsdManager.FAILURE_ALREADY_ACTIVE, true /* isLegacy */);
break; break;
} }
@@ -1071,8 +1073,8 @@ public class NsdService extends INsdManager.Stub {
storeLegacyRequestMap(clientRequestId, transactionId, clientInfo, storeLegacyRequestMap(clientRequestId, transactionId, clientInfo,
msg.what, mClock.elapsedRealtime()); msg.what, mClock.elapsedRealtime());
} else { } else {
clientInfo.onResolveServiceFailedImmediately( clientInfo.onResolveServiceFailedImmediately(clientRequestId,
clientRequestId, NsdManager.FAILURE_INTERNAL_ERROR); NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */);
} }
} }
break; break;
@@ -1282,21 +1284,21 @@ public class NsdService extends INsdManager.Stub {
} }
case IMDnsEventListener.SERVICE_DISCOVERY_FAILED: case IMDnsEventListener.SERVICE_DISCOVERY_FAILED:
clientInfo.onDiscoverServicesFailed(clientRequestId, clientInfo.onDiscoverServicesFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
break; break;
case IMDnsEventListener.SERVICE_REGISTERED: { case IMDnsEventListener.SERVICE_REGISTERED: {
final RegistrationInfo info = (RegistrationInfo) obj; final RegistrationInfo info = (RegistrationInfo) obj;
final String name = info.serviceName; final String name = info.serviceName;
servInfo = new NsdServiceInfo(name, null /* serviceType */); servInfo = new NsdServiceInfo(name, null /* serviceType */);
clientInfo.onRegisterServiceSucceeded(clientRequestId, servInfo, clientInfo.onRegisterServiceSucceeded(clientRequestId, servInfo, request);
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
break; break;
} }
case IMDnsEventListener.SERVICE_REGISTRATION_FAILED: case IMDnsEventListener.SERVICE_REGISTRATION_FAILED:
clientInfo.onRegisterServiceFailed(clientRequestId, clientInfo.onRegisterServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
break; break;
case IMDnsEventListener.SERVICE_RESOLVED: { case IMDnsEventListener.SERVICE_RESOLVED: {
@@ -1334,7 +1336,8 @@ public class NsdService extends INsdManager.Stub {
NsdManager.RESOLVE_SERVICE, request.mStartTimeMs); NsdManager.RESOLVE_SERVICE, request.mStartTimeMs);
} else { } else {
clientInfo.onResolveServiceFailed(clientRequestId, clientInfo.onResolveServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
clientInfo.mResolvedService = null; clientInfo.mResolvedService = null;
} }
@@ -1345,7 +1348,8 @@ public class NsdService extends INsdManager.Stub {
stopResolveService(transactionId); stopResolveService(transactionId);
removeRequestMap(clientRequestId, transactionId, clientInfo); removeRequestMap(clientRequestId, transactionId, clientInfo);
clientInfo.onResolveServiceFailed(clientRequestId, clientInfo.onResolveServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
clientInfo.mResolvedService = null; clientInfo.mResolvedService = null;
break; break;
@@ -1354,7 +1358,8 @@ public class NsdService extends INsdManager.Stub {
stopGetAddrInfo(transactionId); stopGetAddrInfo(transactionId);
removeRequestMap(clientRequestId, transactionId, clientInfo); removeRequestMap(clientRequestId, transactionId, clientInfo);
clientInfo.onResolveServiceFailed(clientRequestId, clientInfo.onResolveServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
clientInfo.mResolvedService = null; clientInfo.mResolvedService = null;
break; break;
@@ -1381,7 +1386,8 @@ public class NsdService extends INsdManager.Stub {
clientRequestId, clientInfo.mResolvedService, request); clientRequestId, clientInfo.mResolvedService, request);
} else { } else {
clientInfo.onResolveServiceFailed(clientRequestId, clientInfo.onResolveServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, true /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
} }
stopGetAddrInfo(transactionId); stopGetAddrInfo(transactionId);
@@ -1498,7 +1504,8 @@ public class NsdService extends INsdManager.Stub {
} else { } else {
// No address. Notify resolution failure. // No address. Notify resolution failure.
clientInfo.onResolveServiceFailed(clientRequestId, clientInfo.onResolveServiceFailed(clientRequestId,
NsdManager.FAILURE_INTERNAL_ERROR, transactionId, NsdManager.FAILURE_INTERNAL_ERROR, false /* isLegacy */,
transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
} }
@@ -1799,9 +1806,8 @@ public class NsdService extends INsdManager.Stub {
/** /**
* @see NetworkNsdReportedMetrics * @see NetworkNsdReportedMetrics
*/ */
public NetworkNsdReportedMetrics makeNetworkNsdReportedMetrics( public NetworkNsdReportedMetrics makeNetworkNsdReportedMetrics(int clientId) {
boolean isLegacy, int clientId) { return new NetworkNsdReportedMetrics(clientId);
return new NetworkNsdReportedMetrics(isLegacy, clientId);
} }
/** /**
@@ -1961,8 +1967,7 @@ public class NsdService extends INsdManager.Stub {
// historical behavior. // historical behavior.
final NsdServiceInfo cbInfo = new NsdServiceInfo(registeredInfo.getServiceName(), null); final NsdServiceInfo cbInfo = new NsdServiceInfo(registeredInfo.getServiceName(), null);
final ClientRequest request = clientInfo.mClientRequests.get(clientRequestId); final ClientRequest request = clientInfo.mClientRequests.get(clientRequestId);
clientInfo.onRegisterServiceSucceeded(clientRequestId, cbInfo, transactionId, clientInfo.onRegisterServiceSucceeded(clientRequestId, cbInfo, request);
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
} }
@Override @Override
@@ -1973,8 +1978,8 @@ public class NsdService extends INsdManager.Stub {
final int clientRequestId = getClientRequestIdOrLog(clientInfo, transactionId); final int clientRequestId = getClientRequestIdOrLog(clientInfo, transactionId);
if (clientRequestId < 0) return; if (clientRequestId < 0) return;
final ClientRequest request = clientInfo.mClientRequests.get(clientRequestId); final ClientRequest request = clientInfo.mClientRequests.get(clientRequestId);
clientInfo.onRegisterServiceFailed(clientRequestId, errorCode, transactionId, clientInfo.onRegisterServiceFailed(clientRequestId, errorCode, false /* isLegacy */,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); transactionId, request.calculateRequestDurationMs(mClock.elapsedRealtime()));
} }
@Override @Override
@@ -2491,14 +2496,14 @@ public class NsdService extends INsdManager.Stub {
if (request instanceof DiscoveryManagerRequest) { if (request instanceof DiscoveryManagerRequest) {
final MdnsListener listener = unregisterMdnsListenerFromRequest(request); final MdnsListener listener = unregisterMdnsListenerFromRequest(request);
if (listener instanceof DiscoveryListener) { if (listener instanceof DiscoveryListener) {
mMetrics.reportServiceDiscoveryStop(transactionId, mMetrics.reportServiceDiscoveryStop(false /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
request.getFoundServiceCount(), request.getFoundServiceCount(),
request.getLostServiceCount(), request.getLostServiceCount(),
request.getServicesCount(), request.getServicesCount(),
request.getSentQueryCount()); request.getSentQueryCount());
} else if (listener instanceof ResolutionListener) { } else if (listener instanceof ResolutionListener) {
mMetrics.reportServiceResolutionStop(transactionId, mMetrics.reportServiceResolutionStop(false /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
} else if (listener instanceof ServiceInfoListener) { } else if (listener instanceof ServiceInfoListener) {
mMetrics.reportServiceInfoCallbackUnregistered(transactionId, mMetrics.reportServiceInfoCallbackUnregistered(transactionId,
@@ -2515,7 +2520,7 @@ public class NsdService extends INsdManager.Stub {
final AdvertiserMetrics metrics = final AdvertiserMetrics metrics =
mAdvertiser.getAdvertiserMetrics(transactionId); mAdvertiser.getAdvertiserMetrics(transactionId);
mAdvertiser.removeService(transactionId); mAdvertiser.removeService(transactionId);
mMetrics.reportServiceUnregistration(transactionId, mMetrics.reportServiceUnregistration(false /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
metrics.mRepliedRequestsCount, metrics.mSentPacketCount, metrics.mRepliedRequestsCount, metrics.mSentPacketCount,
metrics.mConflictDuringProbingCount, metrics.mConflictDuringProbingCount,
@@ -2530,7 +2535,7 @@ public class NsdService extends INsdManager.Stub {
switch (((LegacyClientRequest) request).mRequestCode) { switch (((LegacyClientRequest) request).mRequestCode) {
case NsdManager.DISCOVER_SERVICES: case NsdManager.DISCOVER_SERVICES:
stopServiceDiscovery(transactionId); stopServiceDiscovery(transactionId);
mMetrics.reportServiceDiscoveryStop(transactionId, mMetrics.reportServiceDiscoveryStop(true /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
request.getFoundServiceCount(), request.getFoundServiceCount(),
request.getLostServiceCount(), request.getLostServiceCount(),
@@ -2539,12 +2544,12 @@ public class NsdService extends INsdManager.Stub {
break; break;
case NsdManager.RESOLVE_SERVICE: case NsdManager.RESOLVE_SERVICE:
stopResolveService(transactionId); stopResolveService(transactionId);
mMetrics.reportServiceResolutionStop(transactionId, mMetrics.reportServiceResolutionStop(true /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
break; break;
case NsdManager.REGISTER_SERVICE: case NsdManager.REGISTER_SERVICE:
unregisterService(transactionId); unregisterService(transactionId);
mMetrics.reportServiceUnregistration(transactionId, mMetrics.reportServiceUnregistration(true /* isLegacy */, transactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
NO_PACKET /* repliedRequestsCount */, NO_PACKET /* repliedRequestsCount */,
NO_PACKET /* sentPacketCount */, NO_PACKET /* sentPacketCount */,
@@ -2593,21 +2598,29 @@ public class NsdService extends INsdManager.Stub {
mClientLogs.log(message); mClientLogs.log(message);
} }
void onDiscoverServicesStarted(int listenerKey, NsdServiceInfo info, int transactionId) { private static boolean isLegacyClientRequest(@NonNull ClientRequest request) {
mMetrics.reportServiceDiscoveryStarted(transactionId); return !(request instanceof DiscoveryManagerRequest)
&& !(request instanceof AdvertiserClientRequest);
}
void onDiscoverServicesStarted(int listenerKey, NsdServiceInfo info,
ClientRequest request) {
mMetrics.reportServiceDiscoveryStarted(
isLegacyClientRequest(request), request.mTransactionId);
try { try {
mCb.onDiscoverServicesStarted(listenerKey, info); mCb.onDiscoverServicesStarted(listenerKey, info);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Error calling onDiscoverServicesStarted", e); Log.e(TAG, "Error calling onDiscoverServicesStarted", e);
} }
} }
void onDiscoverServicesFailedImmediately(int listenerKey, int error) { void onDiscoverServicesFailedImmediately(int listenerKey, int error, boolean isLegacy) {
onDiscoverServicesFailed(listenerKey, error, NO_TRANSACTION, 0L /* durationMs */); onDiscoverServicesFailed(listenerKey, error, isLegacy, NO_TRANSACTION,
0L /* durationMs */);
} }
void onDiscoverServicesFailed(int listenerKey, int error, int transactionId, void onDiscoverServicesFailed(int listenerKey, int error, boolean isLegacy,
long durationMs) { int transactionId, long durationMs) {
mMetrics.reportServiceDiscoveryFailed(transactionId, durationMs); mMetrics.reportServiceDiscoveryFailed(isLegacy, transactionId, durationMs);
try { try {
mCb.onDiscoverServicesFailed(listenerKey, error); mCb.onDiscoverServicesFailed(listenerKey, error);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -2643,6 +2656,7 @@ public class NsdService extends INsdManager.Stub {
void onStopDiscoverySucceeded(int listenerKey, ClientRequest request) { void onStopDiscoverySucceeded(int listenerKey, ClientRequest request) {
mMetrics.reportServiceDiscoveryStop( mMetrics.reportServiceDiscoveryStop(
isLegacyClientRequest(request),
request.mTransactionId, request.mTransactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
request.getFoundServiceCount(), request.getFoundServiceCount(),
@@ -2656,13 +2670,14 @@ public class NsdService extends INsdManager.Stub {
} }
} }
void onRegisterServiceFailedImmediately(int listenerKey, int error) { void onRegisterServiceFailedImmediately(int listenerKey, int error, boolean isLegacy) {
onRegisterServiceFailed(listenerKey, error, NO_TRANSACTION, 0L /* durationMs */); onRegisterServiceFailed(listenerKey, error, isLegacy, NO_TRANSACTION,
0L /* durationMs */);
} }
void onRegisterServiceFailed(int listenerKey, int error, int transactionId, void onRegisterServiceFailed(int listenerKey, int error, boolean isLegacy,
long durationMs) { int transactionId, long durationMs) {
mMetrics.reportServiceRegistrationFailed(transactionId, durationMs); mMetrics.reportServiceRegistrationFailed(isLegacy, transactionId, durationMs);
try { try {
mCb.onRegisterServiceFailed(listenerKey, error); mCb.onRegisterServiceFailed(listenerKey, error);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -2670,9 +2685,11 @@ public class NsdService extends INsdManager.Stub {
} }
} }
void onRegisterServiceSucceeded(int listenerKey, NsdServiceInfo info, int transactionId, void onRegisterServiceSucceeded(int listenerKey, NsdServiceInfo info,
long durationMs) { ClientRequest request) {
mMetrics.reportServiceRegistrationSucceeded(transactionId, durationMs); mMetrics.reportServiceRegistrationSucceeded(isLegacyClientRequest(request),
request.mTransactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()));
try { try {
mCb.onRegisterServiceSucceeded(listenerKey, info); mCb.onRegisterServiceSucceeded(listenerKey, info);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -2688,9 +2705,11 @@ public class NsdService extends INsdManager.Stub {
} }
} }
void onUnregisterServiceSucceeded(int listenerKey, int transactionId, long durationMs, void onUnregisterServiceSucceeded(int listenerKey, ClientRequest request,
AdvertiserMetrics metrics) { AdvertiserMetrics metrics) {
mMetrics.reportServiceUnregistration(transactionId, durationMs, mMetrics.reportServiceUnregistration(isLegacyClientRequest(request),
request.mTransactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()),
metrics.mRepliedRequestsCount, metrics.mSentPacketCount, metrics.mRepliedRequestsCount, metrics.mSentPacketCount,
metrics.mConflictDuringProbingCount, metrics.mConflictAfterProbingCount); metrics.mConflictDuringProbingCount, metrics.mConflictAfterProbingCount);
try { try {
@@ -2700,13 +2719,14 @@ public class NsdService extends INsdManager.Stub {
} }
} }
void onResolveServiceFailedImmediately(int listenerKey, int error) { void onResolveServiceFailedImmediately(int listenerKey, int error, boolean isLegacy) {
onResolveServiceFailed(listenerKey, error, NO_TRANSACTION, 0L /* durationMs */); onResolveServiceFailed(listenerKey, error, isLegacy, NO_TRANSACTION,
0L /* durationMs */);
} }
void onResolveServiceFailed(int listenerKey, int error, int transactionId, void onResolveServiceFailed(int listenerKey, int error, boolean isLegacy,
long durationMs) { int transactionId, long durationMs) {
mMetrics.reportServiceResolutionFailed(transactionId, durationMs); mMetrics.reportServiceResolutionFailed(isLegacy, transactionId, durationMs);
try { try {
mCb.onResolveServiceFailed(listenerKey, error); mCb.onResolveServiceFailed(listenerKey, error);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -2717,6 +2737,7 @@ public class NsdService extends INsdManager.Stub {
void onResolveServiceSucceeded(int listenerKey, NsdServiceInfo info, void onResolveServiceSucceeded(int listenerKey, NsdServiceInfo info,
ClientRequest request) { ClientRequest request) {
mMetrics.reportServiceResolved( mMetrics.reportServiceResolved(
isLegacyClientRequest(request),
request.mTransactionId, request.mTransactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime()), request.calculateRequestDurationMs(mClock.elapsedRealtime()),
request.isServiceFromCache(), request.isServiceFromCache(),
@@ -2738,6 +2759,7 @@ public class NsdService extends INsdManager.Stub {
void onStopResolutionSucceeded(int listenerKey, ClientRequest request) { void onStopResolutionSucceeded(int listenerKey, ClientRequest request) {
mMetrics.reportServiceResolutionStop( mMetrics.reportServiceResolutionStop(
isLegacyClientRequest(request),
request.mTransactionId, request.mTransactionId,
request.calculateRequestDurationMs(mClock.elapsedRealtime())); request.calculateRequestDurationMs(mClock.elapsedRealtime()));
try { try {

View File

@@ -49,8 +49,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceRegistrationSucceeded(transactionId, durationMs) metrics.reportServiceRegistrationSucceeded(true /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -69,8 +69,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceRegistrationFailed(transactionId, durationMs) metrics.reportServiceRegistrationFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -93,9 +93,10 @@ class NetworkNsdReportedMetricsTest {
val sentPacketCount = 50 val sentPacketCount = 50
val conflictDuringProbingCount = 2 val conflictDuringProbingCount = 2
val conflictAfterProbingCount = 1 val conflictAfterProbingCount = 1
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceUnregistration(transactionId, durationMs, repliedRequestsCount, metrics.reportServiceUnregistration(true /* isLegacy */, transactionId, durationMs,
sentPacketCount, conflictDuringProbingCount, conflictAfterProbingCount) repliedRequestsCount, sentPacketCount, conflictDuringProbingCount,
conflictAfterProbingCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -117,8 +118,8 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceDiscoveryStarted() { fun testReportServiceDiscoveryStarted() {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryStarted(transactionId) metrics.reportServiceDiscoveryStarted(true /* isLegacy */, transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -136,8 +137,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryFailed(transactionId, durationMs) metrics.reportServiceDiscoveryFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -160,9 +161,9 @@ class NetworkNsdReportedMetricsTest {
val lostCallbackCount = 49 val lostCallbackCount = 49
val servicesCount = 75 val servicesCount = 75
val sentQueryCount = 150 val sentQueryCount = 150
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryStop(transactionId, durationMs, foundCallbackCount, metrics.reportServiceDiscoveryStop(true /* isLegacy */, transactionId, durationMs,
lostCallbackCount, servicesCount, sentQueryCount) foundCallbackCount, lostCallbackCount, servicesCount, sentQueryCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -187,9 +188,9 @@ class NetworkNsdReportedMetricsTest {
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val sentQueryCount = 0 val sentQueryCount = 0
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolved(transactionId, durationMs, true /* isServiceFromCache */, metrics.reportServiceResolved(true /* isLegacy */, transactionId, durationMs,
sentQueryCount) true /* isServiceFromCache */, sentQueryCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -210,8 +211,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolutionFailed(transactionId, durationMs) metrics.reportServiceResolutionFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -230,8 +231,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val durationMs = 10L val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolutionStop(transactionId, durationMs) metrics.reportServiceResolutionStop(true /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
@@ -249,7 +250,7 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceInfoCallbackRegistered() { fun testReportServiceInfoCallbackRegistered() {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackRegistered(transactionId) metrics.reportServiceInfoCallbackRegistered(transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
@@ -267,13 +268,13 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceInfoCallbackRegistrationFailed() { fun testReportServiceInfoCallbackRegistrationFailed() {
val clientId = 99 val clientId = 99
val transactionId = 100 val transactionId = 100
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackRegistrationFailed(transactionId) metrics.reportServiceInfoCallbackRegistrationFailed(transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java) val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture()) verify(deps).statsWrite(eventCaptor.capture())
eventCaptor.value.let { eventCaptor.value.let {
assertTrue(it.isLegacy) assertFalse(it.isLegacy)
assertEquals(clientId, it.clientId) assertEquals(clientId, it.clientId)
assertEquals(transactionId, it.transactionId) assertEquals(transactionId, it.transactionId)
assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type) assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type)
@@ -290,7 +291,7 @@ class NetworkNsdReportedMetricsTest {
val updateCallbackCount = 100 val updateCallbackCount = 100
val lostCallbackCount = 10 val lostCallbackCount = 10
val sentQueryCount = 150 val sentQueryCount = 150
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps) val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackUnregistered(transactionId, durationMs, metrics.reportServiceInfoCallbackUnregistered(transactionId, durationMs,
updateCallbackCount, lostCallbackCount, false /* isServiceFromCache */, updateCallbackCount, lostCallbackCount, false /* isServiceFromCache */,
sentQueryCount) sentQueryCount)

View File

@@ -49,7 +49,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
@@ -227,7 +226,7 @@ public class NsdServiceTest {
doReturn(DEFAULT_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF).when(mDeps).getDeviceConfigInt( doReturn(DEFAULT_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF).when(mDeps).getDeviceConfigInt(
eq(NsdService.MDNS_CONFIG_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF), anyInt()); eq(NsdService.MDNS_CONFIG_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF), anyInt());
doReturn(mAdvertiser).when(mDeps).makeMdnsAdvertiser(any(), any(), any(), any(), any()); doReturn(mAdvertiser).when(mDeps).makeMdnsAdvertiser(any(), any(), any(), any(), any());
doReturn(mMetrics).when(mDeps).makeNetworkNsdReportedMetrics(anyBoolean(), anyInt()); doReturn(mMetrics).when(mDeps).makeNetworkNsdReportedMetrics(anyInt());
doReturn(mClock).when(mDeps).makeClock(); doReturn(mClock).when(mDeps).makeClock();
doReturn(TEST_TIME_MS).when(mClock).elapsedRealtime(); doReturn(TEST_TIME_MS).when(mClock).elapsedRealtime();
mService = makeService(); mService = makeService();
@@ -412,7 +411,7 @@ public class NsdServiceTest {
// this needs to use a timeout // this needs to use a timeout
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE); verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue(); final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId); verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
final DiscoveryInfo discoveryInfo = new DiscoveryInfo( final DiscoveryInfo discoveryInfo = new DiscoveryInfo(
discId, discId,
@@ -481,7 +480,7 @@ public class NsdServiceTest {
final ArgumentCaptor<NsdServiceInfo> resInfoCaptor = final ArgumentCaptor<NsdServiceInfo> resInfoCaptor =
ArgumentCaptor.forClass(NsdServiceInfo.class); ArgumentCaptor.forClass(NsdServiceInfo.class);
verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(resInfoCaptor.capture()); verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(resInfoCaptor.capture());
verify(mMetrics).reportServiceResolved(getAddrId, 10L /* durationMs */, verify(mMetrics).reportServiceResolved(true /* isLegacy */, getAddrId, 10L /* durationMs */,
false /* isServiceFromCache */, 0 /* sentQueryCount */); false /* isServiceFromCache */, 0 /* sentQueryCount */);
final NsdServiceInfo resolvedService = resInfoCaptor.getValue(); final NsdServiceInfo resolvedService = resInfoCaptor.getValue();
@@ -509,7 +508,7 @@ public class NsdServiceTest {
// this needs to use a timeout // this needs to use a timeout
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE); verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue(); final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId); verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
final DiscoveryInfo discoveryInfo = new DiscoveryInfo( final DiscoveryInfo discoveryInfo = new DiscoveryInfo(
discId, discId,
@@ -559,7 +558,8 @@ public class NsdServiceTest {
.onServiceRegistered(registeredInfoCaptor.capture()); .onServiceRegistered(registeredInfoCaptor.capture());
final NsdServiceInfo registeredInfo = registeredInfoCaptor.getValue(); final NsdServiceInfo registeredInfo = registeredInfoCaptor.getValue();
assertEquals(SERVICE_NAME, registeredInfo.getServiceName()); assertEquals(SERVICE_NAME, registeredInfo.getServiceName());
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */); verify(mMetrics).reportServiceRegistrationSucceeded(
true /* isLegacy */, regId, 10L /* durationMs */);
// Fail to register service. // Fail to register service.
final RegistrationInfo registrationFailedInfo = new RegistrationInfo( final RegistrationInfo registrationFailedInfo = new RegistrationInfo(
@@ -574,7 +574,8 @@ public class NsdServiceTest {
eventListener.onServiceRegistrationStatus(registrationFailedInfo); eventListener.onServiceRegistrationStatus(registrationFailedInfo);
verify(regListener, timeout(TIMEOUT_MS)) verify(regListener, timeout(TIMEOUT_MS))
.onRegistrationFailed(any(), eq(FAILURE_INTERNAL_ERROR)); .onRegistrationFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceRegistrationFailed(regId, 20L /* durationMs */); verify(mMetrics).reportServiceRegistrationFailed(
true /* isLegacy */, regId, 20L /* durationMs */);
} }
@Test @Test
@@ -590,7 +591,7 @@ public class NsdServiceTest {
verify(mMockMDnsM).discover(discIdCaptor.capture(), eq(SERVICE_TYPE), eq(IFACE_IDX_ANY)); verify(mMockMDnsM).discover(discIdCaptor.capture(), eq(SERVICE_TYPE), eq(IFACE_IDX_ANY));
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE); verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue(); final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId); verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
// Fail to discover service. // Fail to discover service.
final DiscoveryInfo discoveryFailedInfo = new DiscoveryInfo( final DiscoveryInfo discoveryFailedInfo = new DiscoveryInfo(
@@ -605,7 +606,8 @@ public class NsdServiceTest {
eventListener.onServiceDiscoveryStatus(discoveryFailedInfo); eventListener.onServiceDiscoveryStatus(discoveryFailedInfo);
verify(discListener, timeout(TIMEOUT_MS)) verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(SERVICE_TYPE, FAILURE_INTERNAL_ERROR); .onStartDiscoveryFailed(SERVICE_TYPE, FAILURE_INTERNAL_ERROR);
verify(mMetrics).reportServiceDiscoveryFailed(discId, 10L /* durationMs */); verify(mMetrics).reportServiceDiscoveryFailed(
true /* isLegacy */, discId, 10L /* durationMs */);
} }
@Test @Test
@@ -639,7 +641,8 @@ public class NsdServiceTest {
eventListener.onServiceResolutionStatus(resolutionFailedInfo); eventListener.onServiceResolutionStatus(resolutionFailedInfo);
verify(resolveListener, timeout(TIMEOUT_MS)) verify(resolveListener, timeout(TIMEOUT_MS))
.onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR)); .onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceResolutionFailed(resolvId, 10L /* durationMs */); verify(mMetrics).reportServiceResolutionFailed(
true /* isLegacy */, resolvId, 10L /* durationMs */);
} }
@Test @Test
@@ -689,7 +692,8 @@ public class NsdServiceTest {
eventListener.onGettingServiceAddressStatus(gettingAddrFailedInfo); eventListener.onGettingServiceAddressStatus(gettingAddrFailedInfo);
verify(resolveListener, timeout(TIMEOUT_MS)) verify(resolveListener, timeout(TIMEOUT_MS))
.onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR)); .onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceResolutionFailed(getAddrId, 10L /* durationMs */); verify(mMetrics).reportServiceResolutionFailed(
true /* isLegacy */, getAddrId, 10L /* durationMs */);
} }
@Test @Test
@@ -734,7 +738,8 @@ public class NsdServiceTest {
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns -> verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
request.getServiceName().equals(ns.getServiceName()) request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType()))); && request.getServiceType().equals(ns.getServiceType())));
verify(mMetrics).reportServiceResolutionStop(resolveId, 10L /* durationMs */); verify(mMetrics).reportServiceResolutionStop(
true /* isLegacy */, resolveId, 10L /* durationMs */);
} }
@Test @Test
@@ -805,7 +810,8 @@ public class NsdServiceTest {
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns -> verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
request.getServiceName().equals(ns.getServiceName()) request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType()))); && request.getServiceType().equals(ns.getServiceType())));
verify(mMetrics).reportServiceResolutionStop(getAddrId, 10L /* durationMs */); verify(mMetrics).reportServiceResolutionStop(
true /* isLegacy */, getAddrId, 10L /* durationMs */);
} }
private void verifyUpdatedServiceInfo(NsdServiceInfo info, String serviceName, private void verifyUpdatedServiceInfo(NsdServiceInfo info, String serviceName,
@@ -996,7 +1002,7 @@ public class NsdServiceTest {
final MdnsListener listener = listenerCaptor.getValue(); final MdnsListener listener = listenerCaptor.getValue();
final int discId = listener.mTransactionId; final int discId = listener.mTransactionId;
verify(mMetrics).reportServiceDiscoveryStarted(discId); verify(mMetrics).reportServiceDiscoveryStarted(false /* isLegacy */, discId);
// Callbacks for query sent. // Callbacks for query sent.
listener.onDiscoveryQuerySent(Collections.emptyList(), 1 /* transactionId */); listener.onDiscoveryQuerySent(Collections.emptyList(), 1 /* transactionId */);
@@ -1050,9 +1056,9 @@ public class NsdServiceTest {
verify(mDiscoveryManager).unregisterListener(eq(serviceTypeWithLocalDomain), any()); verify(mDiscoveryManager).unregisterListener(eq(serviceTypeWithLocalDomain), any());
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStopped(SERVICE_TYPE); verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStopped(SERVICE_TYPE);
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive(); verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
verify(mMetrics).reportServiceDiscoveryStop(discId, 10L /* durationMs */, verify(mMetrics).reportServiceDiscoveryStop(false /* isLegacy */, discId,
1 /* foundCallbackCount */, 1 /* lostCallbackCount */, 1 /* servicesCount */, 10L /* durationMs */, 1 /* foundCallbackCount */, 1 /* lostCallbackCount */,
3 /* sentQueryCount */); 1 /* servicesCount */, 3 /* sentQueryCount */);
} }
@Test @Test
@@ -1068,8 +1074,8 @@ public class NsdServiceTest {
waitForIdle(); waitForIdle();
verify(discListener, timeout(TIMEOUT_MS)) verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(invalidServiceType, FAILURE_INTERNAL_ERROR); .onStartDiscoveryFailed(invalidServiceType, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(1)) verify(mMetrics, times(1)).reportServiceDiscoveryFailed(
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */); false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
final String serviceTypeWithLocalDomain = SERVICE_TYPE + ".local"; final String serviceTypeWithLocalDomain = SERVICE_TYPE + ".local";
client.discoverServices( client.discoverServices(
@@ -1077,8 +1083,8 @@ public class NsdServiceTest {
waitForIdle(); waitForIdle();
verify(discListener, timeout(TIMEOUT_MS)) verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(serviceTypeWithLocalDomain, FAILURE_INTERNAL_ERROR); .onStartDiscoveryFailed(serviceTypeWithLocalDomain, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(2)) verify(mMetrics, times(2)).reportServiceDiscoveryFailed(
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */); false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
final String serviceTypeWithoutTcpOrUdpEnding = "_test._com"; final String serviceTypeWithoutTcpOrUdpEnding = "_test._com";
client.discoverServices( client.discoverServices(
@@ -1086,8 +1092,8 @@ public class NsdServiceTest {
waitForIdle(); waitForIdle();
verify(discListener, timeout(TIMEOUT_MS)) verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(serviceTypeWithoutTcpOrUdpEnding, FAILURE_INTERNAL_ERROR); .onStartDiscoveryFailed(serviceTypeWithoutTcpOrUdpEnding, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(3)) verify(mMetrics, times(3)).reportServiceDiscoveryFailed(
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */); false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
} }
@Test @Test
@@ -1164,8 +1170,8 @@ public class NsdServiceTest {
final ArgumentCaptor<NsdServiceInfo> infoCaptor = final ArgumentCaptor<NsdServiceInfo> infoCaptor =
ArgumentCaptor.forClass(NsdServiceInfo.class); ArgumentCaptor.forClass(NsdServiceInfo.class);
verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(infoCaptor.capture()); verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(infoCaptor.capture());
verify(mMetrics).reportServiceResolved(listener.mTransactionId, 10 /* durationMs */, verify(mMetrics).reportServiceResolved(false /* isLegacy */, listener.mTransactionId,
true /* isServiceFromCache */, 0 /* sendQueryCount */); 10 /* durationMs */, true /* isServiceFromCache */, 0 /* sendQueryCount */);
final NsdServiceInfo info = infoCaptor.getValue(); final NsdServiceInfo info = infoCaptor.getValue();
assertEquals(SERVICE_NAME, info.getServiceName()); assertEquals(SERVICE_NAME, info.getServiceName());
@@ -1309,7 +1315,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered(argThat(info -> matches(info, verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered(argThat(info -> matches(info,
new NsdServiceInfo(regInfo.getServiceName(), null)))); new NsdServiceInfo(regInfo.getServiceName(), null))));
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */); verify(mMetrics).reportServiceRegistrationSucceeded(
false /* isLegacy */, regId, 10L /* durationMs */);
final MdnsAdvertiser.AdvertiserMetrics metrics = new MdnsAdvertiser.AdvertiserMetrics( final MdnsAdvertiser.AdvertiserMetrics metrics = new MdnsAdvertiser.AdvertiserMetrics(
50 /* repliedRequestCount */, 100 /* sentPacketCount */, 50 /* repliedRequestCount */, 100 /* sentPacketCount */,
@@ -1322,8 +1329,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceUnregistered( verify(regListener, timeout(TIMEOUT_MS)).onServiceUnregistered(
argThat(info -> matches(info, regInfo))); argThat(info -> matches(info, regInfo)));
verify(mSocketProvider, timeout(TIMEOUT_MS)).requestStopWhenInactive(); verify(mSocketProvider, timeout(TIMEOUT_MS)).requestStopWhenInactive();
verify(mMetrics).reportServiceUnregistration(regId, 100L /* durationMs */, verify(mMetrics).reportServiceUnregistration(false /* isLegacy */, regId,
50 /* repliedRequestCount */, 100 /* sentPacketCount */, 100L /* durationMs */, 50 /* repliedRequestCount */, 100 /* sentPacketCount */,
3 /* conflictDuringProbingCount */, 2 /* conflictAfterProbingCount */); 3 /* conflictDuringProbingCount */, 2 /* conflictAfterProbingCount */);
} }
@@ -1350,7 +1357,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onRegistrationFailed( verify(regListener, timeout(TIMEOUT_MS)).onRegistrationFailed(
argThat(info -> matches(info, regInfo)), eq(FAILURE_INTERNAL_ERROR)); argThat(info -> matches(info, regInfo)), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceRegistrationFailed(NO_TRANSACTION, 0L /* durationMs */); verify(mMetrics).reportServiceRegistrationFailed(
false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
} }
@Test @Test
@@ -1386,7 +1394,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered( verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered(
argThat(info -> matches(info, new NsdServiceInfo(regInfo.getServiceName(), null)))); argThat(info -> matches(info, new NsdServiceInfo(regInfo.getServiceName(), null))));
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */); verify(mMetrics).reportServiceRegistrationSucceeded(
false /* isLegacy */, regId, 10L /* durationMs */);
} }
@Test @Test
@@ -1426,7 +1435,8 @@ public class NsdServiceTest {
request.getServiceName().equals(ns.getServiceName()) request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType()))); && request.getServiceType().equals(ns.getServiceType())));
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive(); verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
verify(mMetrics).reportServiceResolutionStop(listener.mTransactionId, 10L /* durationMs */); verify(mMetrics).reportServiceResolutionStop(
false /* isLegacy */, listener.mTransactionId, 10L /* durationMs */);
} }
@Test @Test