From 0b56ef5211e027ec2fdeececcedd9fa2a118723a Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Tue, 24 Jun 2025 20:07:56 +0900 Subject: [PATCH] NsdManager dumpsys explicitly marks offload client Improve the NsdManager dumpsys output to explicitly mark which client is using the offload engine. This clarifies debugging and monitoring of offload-related operations. Example output: Active clients: mUid 1000, mResolvedService null, mIsLegacy false, mUseJavaBackend true, mClientRequests: 2: Advertiser: serviceFullName=Google Inc. Gambit #17D9._meshcop._udp, net=null {2, startTime 79747, foundServices 0, lostServices 0, fromCache false, sentQueries 0} mUid 1073, mResolvedService null, mIsLegacy false, mUseJavaBackend true, isOffloadEngine, mClientRequests: mUid 10059, mResolvedService null, mIsLegacy false, mUseJavaBackend true, mClientRequests: 4: Advertiser: serviceFullName=gambit-e0efff2d1e84b8272cc285a46d235baf._googlecast._tcp, net=null {6, startTime 123664, foundServices 0, lostServices 0, fromCache false, sentQueries 0} mUid 1000, mResolvedService null, mIsLegacy false, mUseJavaBackend true, isOffloadEngine, mClientRequests: mUid 10060, mResolvedService null, mIsLegacy false, mUseJavaBackend true, mClientRequests: 2: Advertiser: serviceFullName=GoogleTV2444._androidtvremote2._tcp, net=null {3, startTime 99098, foundServices 0, lostServices 0, fromCache false, sentQueries 0} Test: TH Flag: EXEMPT log only change Change-Id: Ie1fefd6c353f4f5261f6ca00a21d37c8d2f2cd64 --- .../src/com/android/server/NsdService.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/service-t/src/com/android/server/NsdService.java b/service-t/src/com/android/server/NsdService.java index 7a72f72246..63f1bd06c1 100644 --- a/service-t/src/com/android/server/NsdService.java +++ b/service-t/src/com/android/server/NsdService.java @@ -270,13 +270,16 @@ public class NsdService extends INsdManager.Stub { final long mOffloadCapabilities; final long mOffloadType; @NonNull final IOffloadEngine mOffloadEngine; + final NsdServiceConnector mConnector; OffloadEngineInfo(@NonNull IOffloadEngine offloadEngine, - @NonNull String interfaceName, long capabilities, long offloadType) { + @NonNull String interfaceName, long capabilities, long offloadType, + NsdServiceConnector connector) { this.mOffloadEngine = offloadEngine; this.mInterfaceName = interfaceName; this.mOffloadCapabilities = capabilities; this.mOffloadType = offloadType; + this.mConnector = connector; } } @@ -1344,6 +1347,12 @@ public class NsdService extends INsdManager.Stub { break; case NsdManager.REGISTER_OFFLOAD_ENGINE: offloadEngineInfo = (OffloadEngineInfo) msg.obj; + clientInfo = mClients.get(offloadEngineInfo.mConnector); + if (clientInfo == null) { + Log.e(TAG, "Unknown connector in calls to register offload engine"); + break; + } + clientInfo.markIsOffloadEngine(); // TODO: Limits the number of registrations created by a given class. mOffloadEngines.register(offloadEngineInfo.mOffloadEngine, offloadEngineInfo); @@ -2461,7 +2470,7 @@ public class NsdService extends INsdManager.Stub { mNsdStateMachine.sendMessage( mNsdStateMachine.obtainMessage(NsdManager.REGISTER_OFFLOAD_ENGINE, new OffloadEngineInfo(cb, ifaceName, offloadCapabilities, - offloadTypes))); + offloadTypes, this))); } @Override @@ -2886,6 +2895,7 @@ public class NsdService extends INsdManager.Stub { private final SharedLog mClientLogs; // Report the nsd metrics data private final NetworkNsdReportedMetrics mMetrics; + private boolean mIsOffloadEngine = false; private ClientInfo(INsdManagerCallback cb, int uid, boolean useJavaBackend, SharedLog sharedLog, NetworkNsdReportedMetrics metrics) { @@ -2904,6 +2914,9 @@ public class NsdService extends INsdManager.Stub { sb.append("mResolvedService ").append(mResolvedService).append(", "); sb.append("mIsLegacy ").append(mIsPreSClient).append(", "); sb.append("mUseJavaBackend ").append(mUseJavaBackend).append(", "); + if (mIsOffloadEngine) { + sb.append("isOffloadEngine").append(", "); + } sb.append("mClientRequests:\n"); for (int i = 0; i < mClientRequests.size(); i++) { int clientRequestId = mClientRequests.keyAt(i); @@ -2926,6 +2939,10 @@ public class NsdService extends INsdManager.Stub { mIsPreSClient = true; } + private void markIsOffloadEngine() { + mIsOffloadEngine = true; + } + private MdnsListener unregisterMdnsListenerFromRequest(ClientRequest request) { final MdnsListener listener = ((DiscoveryManagerRequest) request).mListener;