Generate java code for VCN metrics

Add genrule for VCN metrics atoms and add wrapper utility class for logging using the generated java code, which currently has func for logging safe mode and VCN network validation states.

Bug: 288600040
Flag: EXEMPT METRICS
Test: atest CtsVcnTestCases, FrameworksVcnTests
Change-Id: Ia0f42c3435752399eb3ed480bfe62ffac31ccc1e
This commit is contained in:
Hnin Naing 2025-08-27 00:27:08 +00:00
commit 340990fd30
2 changed files with 76 additions and 2 deletions

View file

@ -52,8 +52,10 @@ java_library {
filegroup {
name: "service-vcn-sources",
srcs: ["src/**/*.java"],
path: "src",
srcs: [
"src/**/*.java",
":statslog-vcn-java-gen",
],
visibility: [
"//packages/modules/Connectivity/service-b",
],
@ -75,6 +77,7 @@ java_defaults {
"framework-connectivity-pre-jarjar",
"framework-connectivity-t-pre-jarjar",
"framework-connectivity-b-pre-jarjar",
"framework-statsd.stubs.module_lib",
"framework-wifi.stubs.module_lib",
"keepanno-annotations",
"modules-utils-statemachine",
@ -115,3 +118,10 @@ java_library {
"//apex_available:platform",
],
}
genrule {
name: "statslog-vcn-java-gen",
tools: ["stats-log-api-gen"],
cmd: "$(location stats-log-api-gen) --java $(out) --module vcn --javaPackage com.android.server.vcn.metrics --javaClass VcnStatsLog",
out: ["com/android/server/vcn/metrics/VcnStatsLog.java"],
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2025 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.server.vcn.metrics;
import static com.android.server.vcn.metrics.VcnStatsLog.VCN_GATEWAY_CONNECTION_STATE_CHANGED__GW_TEARDOWN_REASON__GATEWAY_TEARDOWN_REASON_NONE;
/** Utility class for logging VCN metrics. */
public class VcnMetrics {
private static final int GATEWAY_TEARDOWN_REASON_NONE =
VCN_GATEWAY_CONNECTION_STATE_CHANGED__GW_TEARDOWN_REASON__GATEWAY_TEARDOWN_REASON_NONE;
/** Log an atom when a VcnGatewayConnection has entered safe mode. */
public void logEnterSafeMode(int gatewayConnectionId) {
VcnStatsLog.write(
VcnStatsLog.VCN_GATEWAY_CONNECTION_STATE_CHANGED,
gatewayConnectionId,
GATEWAY_TEARDOWN_REASON_NONE,
true /* isInSafeMode */);
}
/** Log an atom when a VcnGatewayConnection has exited safe mode. */
public void logExitSafeMode(int gatewayConnectionId) {
VcnStatsLog.write(
VcnStatsLog.VCN_GATEWAY_CONNECTION_STATE_CHANGED,
gatewayConnectionId,
GATEWAY_TEARDOWN_REASON_NONE,
false /* isInSafeMode */);
}
/** Log an atom when VCN network has been validated. */
public void logVcnNetworkValidated(int gatewayConnectionId, int networkId) {
VcnStatsLog.write(
VcnStatsLog.VCN_NETWORK_STATE_CHANGED,
gatewayConnectionId,
networkId,
true /* isConnected */,
true /* isValidated */);
}
/** Log an atom when VCN network has been not validated. */
public void logVcnNetworkNotValidated(int gatewayConnectionId, int networkId) {
VcnStatsLog.write(
VcnStatsLog.VCN_NETWORK_STATE_CHANGED,
gatewayConnectionId,
networkId,
true /* isConnected */,
false /* isValidated */);
}
}