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

Commit 113afd6f authored by Cody Kesting's avatar Cody Kesting Committed by Automerger Merge Worker
Browse files

Merge "Use VCN policy listener in DataConnection." am: d1238cf5

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1540585

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie922859d352b99e25ca002a0929d0162654ea597
parents c2abcbbf d1238cf5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ public interface PhoneInternalInterface {
    static final String REASON_RELEASED_BY_CONNECTIVITY_SERVICE = "releasedByConnectivityService";
    static final String REASON_DATA_ENABLED_OVERRIDE = "dataEnabledOverride";
    static final String REASON_IWLAN_DATA_SERVICE_DIED = "iwlanDataServiceDied";
    static final String REASON_VCN_REQUESTED_TEARDOWN = "vcnRequestedTeardown";

    // Reasons for Radio being powered off
    int RADIO_POWER_REASON_USER = 0;
+78 −5
Original line number Diff line number Diff line
@@ -39,7 +39,11 @@ import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.SocketKeepalive;
import android.net.TelephonyNetworkSpecifier;
import android.net.vcn.VcnManager;
import android.net.vcn.VcnManager.VcnUnderlyingNetworkPolicyListener;
import android.net.vcn.VcnUnderlyingNetworkPolicy;
import android.os.AsyncResult;
import android.os.HandlerExecutor;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.SystemClock;
@@ -285,6 +289,7 @@ public class DataConnection extends StateMachine {

    private Phone mPhone;
    private DataServiceManager mDataServiceManager;
    private VcnManager mVcnManager;
    private final int mTransportType;
    private LinkProperties mLinkProperties = new LinkProperties();
    private int mPduSessionId;
@@ -326,6 +331,9 @@ public class DataConnection extends StateMachine {
    private final Map<ApnContext, ConnectionParams> mApnContexts = new ConcurrentHashMap<>();
    PendingIntent mReconnectIntent = null;

    /** Class used to track VCN-defined Network policies for this DcNetworkAgent. */
    private final VcnUnderlyingNetworkPolicyListener mVcnPolicyListener =
            new DataConnectionVcnUnderlyingNetworkPolicyListener();

    // ***** Event codes for driving the state machine, package visible for Dcc
    static final int BASE = Protocol.BASE_DATA_CONNECTION;
@@ -713,6 +721,7 @@ public class DataConnection extends StateMachine {
        mPhone = phone;
        mDct = dct;
        mDataServiceManager = dataServiceManager;
        mVcnManager = mPhone.getContext().getSystemService(VcnManager.class);
        mTransportType = dataServiceManager.getTransportType();
        mDcTesterFailBringUpAll = failBringUpAll;
        mDcController = dcc;
@@ -1728,13 +1737,32 @@ public class DataConnection extends StateMachine {
                mUnmeteredOverride);

        result.setCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED, !mIsSuspended);
        result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);

        result.setAdministratorUids(mAdministratorUids);

        // Check for VCN-specified Network policy before returning NetworkCapabilities
        result.setCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED,
                !isVcnManaged(result));

        return result;
    }

    /**
     * Returns whether the Network represented by this DataConnection is VCN-managed.
     *
     * <p>Determining if the Network is VCN-managed requires polling VcnManager.
     */
    private boolean isVcnManaged(NetworkCapabilities networkCapabilities) {
        VcnUnderlyingNetworkPolicy networkPolicy =
                mVcnManager.getUnderlyingNetworkPolicy(networkCapabilities, getLinkProperties());

        // if the Network does have capability NOT_VCN_MANAGED, return false to indicate it's not
        // VCN-managed
        return !networkPolicy
                .getMergedNetworkCapabilities()
                .hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
    }

    /** @return {@code true} if validation is required, {@code false} otherwise. */
    public boolean isValidationRequired() {
        final NetworkCapabilities nc = getNetworkCapabilities();
@@ -2544,6 +2572,11 @@ public class DataConnection extends StateMachine {
                        + ", mUnmeteredUseOnly = " + mUnmeteredUseOnly);
            }

            // Always register a VcnUnderlyingNetworkPolicyListener, regardless of whether this is a
            // handover or new Network.
            mVcnManager.addVcnUnderlyingNetworkPolicyListener(
                    new HandlerExecutor(getHandler()), mVcnPolicyListener);

            if (mConnectionParams != null
                    && mConnectionParams.mRequestType == REQUEST_TYPE_HANDOVER) {
                // If this is a data setup for handover, we need to reuse the existing network agent
@@ -2594,10 +2627,21 @@ public class DataConnection extends StateMachine {
                updateLinkPropertiesHttpProxy();
                mNetworkAgent = new DcNetworkAgent(DataConnection.this, mPhone, mScore,
                        configBuilder.build(), provider, mTransportType);

                VcnUnderlyingNetworkPolicy policy =
                        mVcnManager.getUnderlyingNetworkPolicy(
                                getNetworkCapabilities(), getLinkProperties());
                if (policy.isTeardownRequested()) {
                    tearDownAll(
                            Phone.REASON_VCN_REQUESTED_TEARDOWN,
                            DcTracker.RELEASE_TYPE_DETACH,
                            null /* onCompletedMsg */);
                } else {
                    // All network agents start out in CONNECTING mode, but DcNetworkAgents are
                    // created when the network is already connected. Hence, send the connected
                    // notification immediately.
                    mNetworkAgent.markConnected();
                }

                // The network agent is always created with NOT_SUSPENDED capability, but the
                // network might be already out of service (or voice call is ongoing) just right
@@ -2646,6 +2690,8 @@ public class DataConnection extends StateMachine {
                    mCid, mApnSetting.getApnTypeBitmask(), RilDataCall.State.DISCONNECTED);
            mDataCallSessionStats.onDataCallDisconnected();

            mVcnManager.removeVcnUnderlyingNetworkPolicyListener(mVcnPolicyListener);

            mPhone.getCarrierPrivilegesTracker().unregisterCarrierPrivilegesListener(getHandler());
        }

@@ -3648,5 +3694,32 @@ public class DataConnection extends StateMachine {
        pw.println();
        pw.flush();
    }

    /**
     * Class used to track VCN-defined Network policies for this DataConnection.
     *
     * <p>MUST be registered with the associated DataConnection's Handler.
     */
    private class DataConnectionVcnUnderlyingNetworkPolicyListener
            implements VcnUnderlyingNetworkPolicyListener {
        @Override
        public void onPolicyChanged() {
            // Poll the current underlying Network policy from VcnManager and send to NetworkAgent.
            final NetworkCapabilities networkCapabilities = getNetworkCapabilities();
            VcnUnderlyingNetworkPolicy policy =
                    mVcnManager.getUnderlyingNetworkPolicy(
                            networkCapabilities, getLinkProperties());
            if (policy.isTeardownRequested()) {
                tearDownAll(
                        Phone.REASON_VCN_REQUESTED_TEARDOWN,
                        DcTracker.RELEASE_TYPE_DETACH,
                        null /* onCompletedMsg */);
            }

            if (mNetworkAgent != null) {
                mNetworkAgent.sendNetworkCapabilities(networkCapabilities, DataConnection.this);
            }
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.database.MatrixCursor;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.Uri;
import android.net.vcn.VcnManager;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Bundle;
@@ -260,6 +261,8 @@ public class ContextFixture implements TestFixture<Context> {
                    return mTelephonyRegistryManager;
                case Context.SYSTEM_CONFIG_SERVICE:
                    return mSystemConfigManager;
                case Context.VCN_MANAGEMENT_SERVICE:
                    return mVcnManager;
                case Context.BATTERY_STATS_SERVICE:
                case Context.DISPLAY_SERVICE:
                case Context.POWER_SERVICE:
@@ -296,6 +299,8 @@ public class ContextFixture implements TestFixture<Context> {
                return Context.ACTIVITY_SERVICE;
            } else if (serviceClass == TelephonyManager.class) {
                return Context.TELEPHONY_SERVICE;
            } else if (serviceClass == VcnManager.class) {
                return Context.VCN_MANAGEMENT_SERVICE;
            }
            return super.getSystemServiceName(serviceClass);
        }
@@ -637,6 +642,7 @@ public class ContextFixture implements TestFixture<Context> {
        mock(TelephonyRegistryManager.class);
    private final SystemConfigManager mSystemConfigManager = mock(SystemConfigManager.class);
    private final PowerWhitelistManager mPowerWhitelistManager = mock(PowerWhitelistManager.class);
    private final VcnManager mVcnManager = mock(VcnManager.class);

    private final ContentProvider mContentProvider = spy(new FakeContentProvider());

+11 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.vcn.VcnManager;
import android.net.vcn.VcnUnderlyingNetworkPolicy;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
@@ -325,6 +328,7 @@ public abstract class TelephonyTest {
    protected AppOpsManager mAppOpsManager;
    protected CarrierConfigManager mCarrierConfigManager;
    protected UserManager mUserManager;
    protected VcnManager mVcnManager;
    protected SimulatedCommands mSimulatedCommands;
    protected ContextFixture mContextFixture;
    protected Context mContext;
@@ -465,6 +469,7 @@ public abstract class TelephonyTest {
        mCarrierConfigManager =
                (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mVcnManager = mContext.getSystemService(VcnManager.class);

        //mTelephonyComponentFactory
        doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString());
@@ -642,6 +647,12 @@ public abstract class TelephonyTest {
        doReturn(2).when(mWifiManager).calculateSignalLevel(anyInt());
        doReturn(4).when(mWifiManager).getMaxSignalLevel();

        doAnswer(invocation -> {
            NetworkCapabilities nc = invocation.getArgument(0);
            return new VcnUnderlyingNetworkPolicy(
                    false /* isTearDownRequested */, nc);
        }).when(mVcnManager).getUnderlyingNetworkPolicy(any(), any());

        //SIM
        doReturn(1).when(mTelephonyManager).getSimCount();
        doReturn(1).when(mTelephonyManager).getPhoneCount();
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
@@ -386,6 +387,7 @@ public class DataConnectionTest extends TelephonyTest {
        verify(mSimulatedCommandsVerifier, times(1))
                .registerForLceInfo(any(Handler.class),
                        eq(DataConnection.EVENT_LINK_CAPACITY_CHANGED), eq(null));
        verify(mVcnManager, atLeastOnce()).getUnderlyingNetworkPolicy(any(), any());

        ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
        verify(mSimulatedCommandsVerifier, times(1)).setupDataCall(