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

Commit 05baf103 authored by Erik Kline's avatar Erik Kline
Browse files

Migrate to IpClient and eschew MultinetworkPolicyTracker

Test: as follows
    - built
    - flashed
    - treehugger
Bug: 62476366
Bug: 72663849

Merged-In: I50760bd73dbc160979c7c7c5af880a1178c6972e
Merged-In: Idec412e81d85c1c742d7f00c8d698470420aebe5
Change-Id: I1fa52f55f536cf443e69af6326b7662d0771469f
(cherry picked from commit feb82442)
parent 5a1316a7
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -25,8 +25,8 @@ import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.ip.IpManager;
import android.net.ip.IpManager.WaitForProvisioningCallback;
import android.net.ip.IpClient;
import android.net.ip.IpClient.WaitForProvisioningCallback;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Slog;
@@ -49,7 +49,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory {

    // All accesses to these must be synchronized(this).
    private final NetworkInfo mNetworkInfo;
    private IpManager mIpManager;
    private IpClient mIpClient;
    private String mInterfaceName;
    private NetworkAgent mNetworkAgent;

@@ -65,10 +65,10 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory {
        setCapabilityFilter(mNetworkCapabilities);
    }

    private void stopIpManagerLocked() {
        if (mIpManager != null) {
            mIpManager.shutdown();
            mIpManager = null;
    private void stopIpClientLocked() {
        if (mIpClient != null) {
            mIpClient.shutdown();
            mIpClient = null;
        }
    }

@@ -78,13 +78,13 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory {
    @Override
    protected void startNetwork() {
        // TODO: Figure out how to replace this thread with simple invocations
        // of IpManager. This will likely necessitate a rethink about
        // of IpClient. This will likely necessitate a rethink about
        // NetworkAgent, NetworkInfo, and associated instance lifetimes.
        Thread ipProvisioningThread = new Thread(new Runnable() {
            @Override
            public void run() {
                LinkProperties linkProperties;
                final WaitForProvisioningCallback ipmCallback = new WaitForProvisioningCallback() {
                final WaitForProvisioningCallback ipcCallback = new WaitForProvisioningCallback() {
                    @Override
                    public void onLinkPropertiesChange(LinkProperties newLp) {
                        synchronized (BluetoothTetheringNetworkFactory.this) {
@@ -102,18 +102,19 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory {
                    }
                    log("ipProvisioningThread(+" + mInterfaceName + "): " + "mNetworkInfo="
                            + mNetworkInfo);
                    mIpManager = new IpManager(mContext, mInterfaceName, ipmCallback);
                    mIpManager.startProvisioning(mIpManager.buildProvisioningConfiguration()
                    mIpClient = new IpClient(mContext, mInterfaceName, ipcCallback);
                    mIpClient.startProvisioning(mIpClient.buildProvisioningConfiguration()
                            .withoutMultinetworkPolicyTracker()
                            .withoutIpReachabilityMonitor()
                            .build());
                    mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, null);
                }

                linkProperties = ipmCallback.waitForProvisioning();
                linkProperties = ipcCallback.waitForProvisioning();
                if (linkProperties == null) {
                    Slog.e(TAG, "IP provisioning error.");
                    synchronized (BluetoothTetheringNetworkFactory.this) {
                        stopIpManagerLocked();
                        stopIpClientLocked();
                        setScoreFilter(-1);
                    }
                    return;
@@ -149,7 +150,7 @@ public class BluetoothTetheringNetworkFactory extends NetworkFactory {

    // Called by the NetworkFactory, NetworkAgent or PanService to tear down network.
    private synchronized void onCancelRequest() {
        stopIpManagerLocked();
        stopIpClientLocked();
        mInterfaceName = "";

        mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, null);