Add NetworkNsdReportedMetrics
Add helper class NetworkNsdReportedMetrics to build and report nsd metrics data. Bug: 287546772 Test: m Change-Id: I8271811c52a88329fd54e8e0f6cc455d3a3d22f7
This commit is contained in:
@@ -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.
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import static android.provider.DeviceConfig.NAMESPACE_TETHERING;
|
|||||||
|
|
||||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastU;
|
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.MdnsRecord.MAX_LABEL_LENGTH;
|
||||||
|
import static com.android.server.connectivity.mdns.util.MdnsUtils.Clock;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
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.IndentingPrintWriter;
|
||||||
import com.android.internal.util.State;
|
import com.android.internal.util.State;
|
||||||
import com.android.internal.util.StateMachine;
|
import com.android.internal.util.StateMachine;
|
||||||
|
import com.android.metrics.NetworkNsdReportedMetrics;
|
||||||
import com.android.net.module.util.CollectionUtils;
|
import com.android.net.module.util.CollectionUtils;
|
||||||
import com.android.net.module.util.DeviceConfigUtils;
|
import com.android.net.module.util.DeviceConfigUtils;
|
||||||
import com.android.net.module.util.InetAddressUtils;
|
import com.android.net.module.util.InetAddressUtils;
|
||||||
@@ -528,8 +530,10 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
try {
|
try {
|
||||||
cb.asBinder().linkToDeath(arg.connector, 0);
|
cb.asBinder().linkToDeath(arg.connector, 0);
|
||||||
final String tag = "Client" + arg.uid + "-" + mClientNumberId++;
|
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,
|
cInfo = new ClientInfo(cb, arg.uid, arg.useJavaBackend,
|
||||||
mServiceLogs.forSubComponent(tag));
|
mServiceLogs.forSubComponent(tag), metrics);
|
||||||
mClients.put(arg.connector, cInfo);
|
mClients.put(arg.connector, cInfo);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, "Client request id " + clientRequestId
|
Log.w(TAG, "Client request id " + clientRequestId
|
||||||
@@ -2087,14 +2091,17 @@ public class NsdService extends INsdManager.Stub {
|
|||||||
private final boolean mUseJavaBackend;
|
private final boolean mUseJavaBackend;
|
||||||
// Store client logs
|
// Store client logs
|
||||||
private final SharedLog mClientLogs;
|
private final SharedLog mClientLogs;
|
||||||
|
// Report the nsd metrics data
|
||||||
|
private final NetworkNsdReportedMetrics mMetrics;
|
||||||
|
|
||||||
private ClientInfo(INsdManagerCallback cb, int uid, boolean useJavaBackend,
|
private ClientInfo(INsdManagerCallback cb, int uid, boolean useJavaBackend,
|
||||||
SharedLog sharedLog) {
|
SharedLog sharedLog, NetworkNsdReportedMetrics metrics) {
|
||||||
mCb = cb;
|
mCb = cb;
|
||||||
mUid = uid;
|
mUid = uid;
|
||||||
mUseJavaBackend = useJavaBackend;
|
mUseJavaBackend = useJavaBackend;
|
||||||
mClientLogs = sharedLog;
|
mClientLogs = sharedLog;
|
||||||
mClientLogs.log("New client. useJavaBackend=" + useJavaBackend);
|
mClientLogs.log("New client. useJavaBackend=" + useJavaBackend);
|
||||||
|
mMetrics = metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user