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

Commit a2640b6f authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

resolve merge conflicts of f8b537d7 to stage-aosp-master

Test: TODO
Change-Id: I7959d7812f8db31de689154f37b92497a992fb6c
parents 2fa5be61 f8b537d7
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ public class Tethering extends BaseNetworkObserver {
    private final VersionedBroadcastListener mCarrierConfigChange;
    // TODO: Delete SimChangeListener; it's obsolete.
    private final SimChangeListener mSimChange;
    private final TetheringDependencies mDeps;

    private volatile TetheringConfiguration mConfig;
    private String mCurrentUpstreamIface;
@@ -198,12 +199,13 @@ public class Tethering extends BaseNetworkObserver {
        mPolicyManager = policyManager;
        mLooper = looper;
        mSystemProperties = systemProperties;
        mDeps = deps;

        mPublicSync = new Object();

        mTetherStates = new ArrayMap<>();

        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper);
        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps);
        mTetherMasterSM.start();

        final Handler smHandler = mTetherMasterSM.getHandler();
@@ -211,8 +213,8 @@ public class Tethering extends BaseNetworkObserver {
                deps.getOffloadHardwareInterface(smHandler, mLog),
                mContext.getContentResolver(), mNMService,
                mLog);
        mUpstreamNetworkMonitor = new UpstreamNetworkMonitor(
                mContext, mTetherMasterSM, mLog, TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
        mUpstreamNetworkMonitor = deps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog,
                TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
        mForwardedDownstreams = new HashSet<>();

        IntentFilter filter = new IntentFilter();
@@ -1184,7 +1186,7 @@ public class Tethering extends BaseNetworkObserver {

        private static final int UPSTREAM_SETTLE_TIME_MS     = 10000;

        TetherMasterSM(String name, Looper looper) {
        TetherMasterSM(String name, Looper looper, TetheringDependencies deps) {
            super(name, looper);

            mInitialState = new InitialState();
@@ -1204,7 +1206,7 @@ public class Tethering extends BaseNetworkObserver {
            addState(mSetDnsForwardersErrorState);

            mNotifyList = new ArrayList<>();
            mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog);
            mIPv6TetheringCoordinator = deps.getIPv6TetheringCoordinator(mNotifyList, mLog);
            mOffload = new OffloadWrapper();

            setInitialState(mInitialState);
@@ -1940,7 +1942,7 @@ public class Tethering extends BaseNetworkObserver {
        final TetherState tetherState = new TetherState(
                new TetherInterfaceStateMachine(
                    iface, mLooper, interfaceType, mLog, mNMService, mStatsService,
                    makeControlCallback(iface)));
                    makeControlCallback(iface), mDeps));
        mTetherStates.put(iface, tetherState);
        tetherState.stateMachine.start();
    }
+8 −7
Original line number Diff line number Diff line
@@ -117,6 +117,8 @@ public class TetherInterfaceStateMachine extends StateMachine {
    private final int mInterfaceType;
    private final LinkProperties mLinkProperties;

    private final TetheringDependencies mDeps;

    private int mLastError;
    private int mServingMode;
    private String mMyUpstreamIfaceName;  // may change over time
@@ -134,18 +136,19 @@ public class TetherInterfaceStateMachine extends StateMachine {
    public TetherInterfaceStateMachine(
            String ifaceName, Looper looper, int interfaceType, SharedLog log,
            INetworkManagementService nMService, INetworkStatsService statsService,
            IControlsTethering tetherController) {
            IControlsTethering tetherController,
            TetheringDependencies deps) {
        super(ifaceName, looper);
        mLog = log.forSubComponent(ifaceName);
        mNMService = nMService;
        // TODO: This should be passed in for testability.
        mNetd = NetdService.getInstance();
        mNetd = deps.getNetdService();
        mStatsService = statsService;
        mTetherController = tetherController;
        mInterfaceCtrl = new InterfaceController(ifaceName, nMService, mNetd, mLog);
        mIfaceName = ifaceName;
        mInterfaceType = interfaceType;
        mLinkProperties = new LinkProperties();
        mDeps = deps;
        resetLinkProperties();
        mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
        mServingMode = IControlsTethering.STATE_AVAILABLE;
@@ -246,16 +249,14 @@ public class TetherInterfaceStateMachine extends StateMachine {
    }

    private boolean startIPv6() {
        // TODO: Refactor for better testability.  This is one of the things
        // that prohibits unittesting IPv6 tethering setup.
        mInterfaceParams = InterfaceParams.getByName(mIfaceName);
        mInterfaceParams = mDeps.getInterfaceParams(mIfaceName);
        if (mInterfaceParams == null) {
            mLog.e("Failed to find InterfaceParams");
            stopIPv6();
            return false;
        }

        mRaDaemon = new RouterAdvertisementDaemon(mInterfaceParams);
        mRaDaemon = mDeps.getRouterAdvertisementDaemon(mInterfaceParams);
        if (!mRaDaemon.start()) {
            stopIPv6();
            return false;
+31 −0
Original line number Diff line number Diff line
@@ -16,9 +16,18 @@

package com.android.server.connectivity.tethering;

import android.content.Context;
import android.net.INetd;
import android.net.ip.RouterAdvertisementDaemon;
import android.net.util.InterfaceParams;
import android.net.util.NetdService;
import android.os.Handler;
import android.net.util.SharedLog;

import com.android.internal.util.StateMachine;

import java.util.ArrayList;


/**
 * Capture tethering dependencies, for injection.
@@ -29,4 +38,26 @@ public class TetheringDependencies {
    public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) {
        return new OffloadHardwareInterface(h, log);
    }

    public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx, StateMachine target,
            SharedLog log, int what) {
        return new UpstreamNetworkMonitor(ctx, target, log, what);
    }

    public IPv6TetheringCoordinator getIPv6TetheringCoordinator(
            ArrayList<TetherInterfaceStateMachine> notifyList, SharedLog log) {
        return new IPv6TetheringCoordinator(notifyList, log);
    }

    public RouterAdvertisementDaemon getRouterAdvertisementDaemon(InterfaceParams ifParams) {
        return new RouterAdvertisementDaemon(ifParams);
    }

    public InterfaceParams getInterfaceParams(String ifName) {
        return InterfaceParams.getByName(ifName);
    }

    public INetd getNetdService() {
        return NetdService.getInstance();
    }
}
+315 −68

File changed.

Preview size limit exceeded, changes collapsed.

+5 −5
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.when;
import static android.net.ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR;
import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR;
import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR;
import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR;
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
import static android.net.ConnectivityManager.TETHERING_USB;
import static android.net.ConnectivityManager.TETHERING_WIFI;
@@ -39,7 +38,6 @@ import static com.android.server.connectivity.tethering.IControlsTethering.STATE
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED;
import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE;

import android.net.ConnectivityManager;
import android.net.INetworkStatsService;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
@@ -75,6 +73,7 @@ public class TetherInterfaceStateMachineTest {
    @Mock private IControlsTethering mTetherHelper;
    @Mock private InterfaceConfiguration mInterfaceConfiguration;
    @Mock private SharedLog mSharedLog;
    @Mock private TetheringDependencies mTetheringDependencies;

    private final TestLooper mLooper = new TestLooper();
    private final ArgumentCaptor<LinkProperties> mLinkPropertiesCaptor =
@@ -84,7 +83,7 @@ public class TetherInterfaceStateMachineTest {
    private void initStateMachine(int interfaceType) throws Exception {
        mTestedSm = new TetherInterfaceStateMachine(
                IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog,
                mNMService, mStatsService, mTetherHelper);
                mNMService, mStatsService, mTetherHelper, mTetheringDependencies);
        mTestedSm.start();
        // Starting the state machine always puts us in a consistent state and notifies
        // the rest of the world that we've changed from an unknown to available state.
@@ -111,7 +110,8 @@ public class TetherInterfaceStateMachineTest {
    @Test
    public void startsOutAvailable() {
        mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(),
                TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper);
                TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper,
                mTetheringDependencies);
        mTestedSm.start();
        mLooper.dispatchAll();
        verify(mTetherHelper).updateInterfaceState(
@@ -346,7 +346,7 @@ public class TetherInterfaceStateMachineTest {
     * Send a command to the state machine under test, and run the event loop to idle.
     *
     * @param command One of the TetherInterfaceStateMachine.CMD_* constants.
     * @param obj An additional argument to pass.
     * @param arg1 An additional argument to pass.
     */
    private void dispatchCommand(int command, int arg1) {
        mTestedSm.sendMessage(command, arg1);
Loading