diff --git a/service-t/src/com/android/metrics/NetworkNsdReportedMetrics.java b/service-t/src/com/android/metrics/NetworkNsdReportedMetrics.java new file mode 100644 index 0000000000..6c8e273686 --- /dev/null +++ b/service-t/src/com/android/metrics/NetworkNsdReportedMetrics.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.metrics; + +/** + * Class to record the NetworkNsdReported into statsd. Each client should create this class to + * report its data. + */ +public class NetworkNsdReportedMetrics { + // Whether this client is using legacy backend. + private final boolean mIsLegacy; + // The client id. + private final int mClientId; + + public NetworkNsdReportedMetrics(boolean isLegacy, int clientId) { + mIsLegacy = isLegacy; + mClientId = clientId; + } + + // TODO: Report metrics data. +} diff --git a/service-t/src/com/android/server/NsdService.java b/service-t/src/com/android/server/NsdService.java index b06e9cb67b..95717c2cdb 100644 --- a/service-t/src/com/android/server/NsdService.java +++ b/service-t/src/com/android/server/NsdService.java @@ -26,6 +26,7 @@ import static android.provider.DeviceConfig.NAMESPACE_TETHERING; import static com.android.modules.utils.build.SdkLevel.isAtLeastU; import static com.android.server.connectivity.mdns.MdnsRecord.MAX_LABEL_LENGTH; +import static com.android.server.connectivity.mdns.util.MdnsUtils.Clock; import android.annotation.NonNull; import android.annotation.Nullable; @@ -68,6 +69,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.State; import com.android.internal.util.StateMachine; +import com.android.metrics.NetworkNsdReportedMetrics; import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.DeviceConfigUtils; import com.android.net.module.util.InetAddressUtils; @@ -528,8 +530,10 @@ public class NsdService extends INsdManager.Stub { try { cb.asBinder().linkToDeath(arg.connector, 0); final String tag = "Client" + arg.uid + "-" + mClientNumberId++; + final NetworkNsdReportedMetrics metrics = new NetworkNsdReportedMetrics( + !arg.useJavaBackend, (int) new Clock().elapsedRealtime()); cInfo = new ClientInfo(cb, arg.uid, arg.useJavaBackend, - mServiceLogs.forSubComponent(tag)); + mServiceLogs.forSubComponent(tag), metrics); mClients.put(arg.connector, cInfo); } catch (RemoteException e) { Log.w(TAG, "Client request id " + clientRequestId @@ -2087,14 +2091,17 @@ public class NsdService extends INsdManager.Stub { private final boolean mUseJavaBackend; // Store client logs private final SharedLog mClientLogs; + // Report the nsd metrics data + private final NetworkNsdReportedMetrics mMetrics; private ClientInfo(INsdManagerCallback cb, int uid, boolean useJavaBackend, - SharedLog sharedLog) { + SharedLog sharedLog, NetworkNsdReportedMetrics metrics) { mCb = cb; mUid = uid; mUseJavaBackend = useJavaBackend; mClientLogs = sharedLog; mClientLogs.log("New client. useJavaBackend=" + useJavaBackend); + mMetrics = metrics; } @Override