Loading services/core/java/com/android/server/connectivity/Vpn.java +18 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import static android.telephony.CarrierConfigManager.KEY_MIN_UDP_PORT_4500_NAT_T import static android.telephony.CarrierConfigManager.KEY_PREFERRED_IKE_PROTOCOL_INT; import static com.android.net.module.util.NetworkStackConstants.IPV6_MIN_MTU; import static com.android.server.connectivity.Flags.collectVpnMetrics; import static java.util.Objects.requireNonNull; Loading Loading @@ -386,6 +387,12 @@ public class Vpn { private final UserManager mUserManager; private final VpnProfileStore mVpnProfileStore; /** * Instance responsible for collecting VPN connectivity metrics. * This field will be null if the {@link collectVpnMetrics} flag is set to false. */ @Nullable private final VpnConnectivityMetrics mVpnConnectivityMetrics; @VisibleForTesting VpnProfileStore getVpnProfileStore() { Loading Loading @@ -594,6 +601,15 @@ public class Vpn { throw new SecurityException(packageName + " does not belong to uid " + callingUid); } } /** * @see VpnConnectivityMetrics. * * <p>This method is only called when {@link collectVpnMetrics} is true. */ public VpnConnectivityMetrics makeVpnConnectivityMetrics(int userId) { return new VpnConnectivityMetrics(userId); } } // A helper class to ensure JNI registration before use. This avoids native lib dependencies in Loading Loading @@ -650,6 +666,8 @@ public class Vpn { mPackage = VpnConfig.LEGACY_VPN; mOwnerUID = getAppUid(mContext, mPackage, mUserId); mIsPackageTargetingAtLeastQ = doesPackageTargetAtLeastQ(mPackage); mVpnConnectivityMetrics = collectVpnMetrics() ? mDeps.makeVpnConnectivityMetrics(userId) : null; try { netService.registerObserver(mObserver); Loading services/core/java/com/android/server/connectivity/VpnConnectivityMetrics.java 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * 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.connectivity; /** * Class to record the VpnConnectionReported into statsd. */ public class VpnConnectivityMetrics { private static final String TAG = VpnConnectivityMetrics.class.getSimpleName(); private final int mUserId; public VpnConnectivityMetrics(int userId) { mUserId = userId; } } services/core/java/com/android/server/connectivity/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,10 @@ flag { description: "This flag controls if airplane mode sync between phones and watches are enabled." bug: "414622391" } flag { name: "collect_vpn_metrics" namespace: "android_core_networking" description: "This flag controls VPN metrics collection." bug: "306313287" } No newline at end of file services/tests/VpnTests/java/com/android/server/connectivity/VpnTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,7 @@ public class VpnTest extends VpnTestBase { @Mock private SubscriptionManager mSubscriptionManager; @Mock private IpSecService mIpSecService; @Mock private VpnProfileStore mVpnProfileStore; @Mock private VpnConnectivityMetrics mVpnConnectivityMetrics; private final TestExecutor mExecutor; @Mock DeviceIdleInternal mDeviceIdleInternal; private final VpnProfile mVpnProfile; Loading Loading @@ -3275,6 +3276,11 @@ public class VpnTest extends VpnTestBase { super.verifyCallingUidAndPackage(context, packageName, userId); } } @Override public VpnConnectivityMetrics makeVpnConnectivityMetrics(int userId) { return mVpnConnectivityMetrics; } } /** Loading Loading
services/core/java/com/android/server/connectivity/Vpn.java +18 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import static android.telephony.CarrierConfigManager.KEY_MIN_UDP_PORT_4500_NAT_T import static android.telephony.CarrierConfigManager.KEY_PREFERRED_IKE_PROTOCOL_INT; import static com.android.net.module.util.NetworkStackConstants.IPV6_MIN_MTU; import static com.android.server.connectivity.Flags.collectVpnMetrics; import static java.util.Objects.requireNonNull; Loading Loading @@ -386,6 +387,12 @@ public class Vpn { private final UserManager mUserManager; private final VpnProfileStore mVpnProfileStore; /** * Instance responsible for collecting VPN connectivity metrics. * This field will be null if the {@link collectVpnMetrics} flag is set to false. */ @Nullable private final VpnConnectivityMetrics mVpnConnectivityMetrics; @VisibleForTesting VpnProfileStore getVpnProfileStore() { Loading Loading @@ -594,6 +601,15 @@ public class Vpn { throw new SecurityException(packageName + " does not belong to uid " + callingUid); } } /** * @see VpnConnectivityMetrics. * * <p>This method is only called when {@link collectVpnMetrics} is true. */ public VpnConnectivityMetrics makeVpnConnectivityMetrics(int userId) { return new VpnConnectivityMetrics(userId); } } // A helper class to ensure JNI registration before use. This avoids native lib dependencies in Loading Loading @@ -650,6 +666,8 @@ public class Vpn { mPackage = VpnConfig.LEGACY_VPN; mOwnerUID = getAppUid(mContext, mPackage, mUserId); mIsPackageTargetingAtLeastQ = doesPackageTargetAtLeastQ(mPackage); mVpnConnectivityMetrics = collectVpnMetrics() ? mDeps.makeVpnConnectivityMetrics(userId) : null; try { netService.registerObserver(mObserver); Loading
services/core/java/com/android/server/connectivity/VpnConnectivityMetrics.java 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * 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.connectivity; /** * Class to record the VpnConnectionReported into statsd. */ public class VpnConnectivityMetrics { private static final String TAG = VpnConnectivityMetrics.class.getSimpleName(); private final int mUserId; public VpnConnectivityMetrics(int userId) { mUserId = userId; } }
services/core/java/com/android/server/connectivity/flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,10 @@ flag { description: "This flag controls if airplane mode sync between phones and watches are enabled." bug: "414622391" } flag { name: "collect_vpn_metrics" namespace: "android_core_networking" description: "This flag controls VPN metrics collection." bug: "306313287" } No newline at end of file
services/tests/VpnTests/java/com/android/server/connectivity/VpnTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,7 @@ public class VpnTest extends VpnTestBase { @Mock private SubscriptionManager mSubscriptionManager; @Mock private IpSecService mIpSecService; @Mock private VpnProfileStore mVpnProfileStore; @Mock private VpnConnectivityMetrics mVpnConnectivityMetrics; private final TestExecutor mExecutor; @Mock DeviceIdleInternal mDeviceIdleInternal; private final VpnProfile mVpnProfile; Loading Loading @@ -3275,6 +3276,11 @@ public class VpnTest extends VpnTestBase { super.verifyCallingUidAndPackage(context, packageName, userId); } } @Override public VpnConnectivityMetrics makeVpnConnectivityMetrics(int userId) { return mVpnConnectivityMetrics; } } /** Loading