Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f9783b7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Intruduce VpnConnectivityMetrics" into main

parents 18a28c36 06f54860
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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;

@@ -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() {
@@ -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
@@ -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);
+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;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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;
@@ -3275,6 +3276,11 @@ public class VpnTest extends VpnTestBase {
                super.verifyCallingUidAndPackage(context, packageName, userId);
            }
        }

        @Override
        public VpnConnectivityMetrics makeVpnConnectivityMetrics(int userId) {
            return mVpnConnectivityMetrics;
        }
    }

    /**