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

Commit 957a089a authored by Sreeram Ramachandran's avatar Sreeram Ramachandran Committed by Android Git Automerger
Browse files

am f5aef029: Merge "Don\'t create a ConnectivityManager when the service...

am f5aef029: Merge "Don\'t create a ConnectivityManager when the service isn\'t ready yet." into lmp-dev

* commit 'f5aef029de32103cd5b80b2e4bf34936a1031b59':
  Don't create a ConnectivityManager when the service isn't ready yet.
parents b60b005b ba6e4c60
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ public class Tethering extends BaseNetworkObserver {

    private final INetworkManagementService mNMService;
    private final INetworkStatsService mStatsService;
    private final ConnectivityManager mConnManager;
    private Looper mLooper;

    private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces
@@ -135,7 +134,6 @@ public class Tethering extends BaseNetworkObserver {
        mContext = context;
        mNMService = nmService;
        mStatsService = statsService;
        mConnManager = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        mLooper = looper;

        mPublicSync = new Object();
@@ -175,6 +173,12 @@ public class Tethering extends BaseNetworkObserver {
        mDefaultDnsServers[1] = DNS_DEFAULT_SERVER2;
    }

    // We can't do this once in the Tethering() constructor and cache the value, because the
    // CONNECTIVITY_SERVICE is registered only after the Tethering() constructor has completed.
    private ConnectivityManager getConnectivityManager() {
        return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    void updateConfiguration() {
        String[] tetherableUsbRegexs = mContext.getResources().getStringArray(
                com.android.internal.R.array.config_tether_usb_regexs);
@@ -366,7 +370,7 @@ public class Tethering extends BaseNetworkObserver {
    // TODO - move all private methods used only by the state machine into the state machine
    // to clarify what needs synchronized protection.
    private void sendTetherStateChangedBroadcast() {
        if (!mConnManager.isTetheringSupported()) return;
        if (!getConnectivityManager().isTetheringSupported()) return;

        ArrayList<String> availableList = new ArrayList<String>();
        ArrayList<String> activeList = new ArrayList<String>();
@@ -1183,8 +1187,8 @@ public class Tethering extends BaseNetworkObserver {
                int result = PhoneConstants.APN_REQUEST_FAILED;
                String enableString = enableString(apnType);
                if (enableString == null) return false;
                result = mConnManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
                        enableString);
                result = getConnectivityManager().startUsingNetworkFeature(
                        ConnectivityManager.TYPE_MOBILE, enableString);
                switch (result) {
                case PhoneConstants.APN_ALREADY_ACTIVE:
                case PhoneConstants.APN_REQUEST_STARTED:
@@ -1205,8 +1209,8 @@ public class Tethering extends BaseNetworkObserver {
                // ignore pending renewal requests
                ++mCurrentConnectionSequence;
                if (mMobileApnReserved != ConnectivityManager.TYPE_NONE) {
                    mConnManager.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
                            enableString(mMobileApnReserved));
                    getConnectivityManager().stopUsingNetworkFeature(
                            ConnectivityManager.TYPE_MOBILE, enableString(mMobileApnReserved));
                    mMobileApnReserved = ConnectivityManager.TYPE_NONE;
                }
                return true;
@@ -1269,7 +1273,8 @@ public class Tethering extends BaseNetworkObserver {
                    }

                    for (Integer netType : mUpstreamIfaceTypes) {
                        NetworkInfo info = mConnManager.getNetworkInfo(netType.intValue());
                        NetworkInfo info =
                                getConnectivityManager().getNetworkInfo(netType.intValue());
                        if ((info != null) && info.isConnected()) {
                            upType = netType.intValue();
                            break;
@@ -1307,7 +1312,8 @@ public class Tethering extends BaseNetworkObserver {
                        sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
                    }
                } else {
                    LinkProperties linkProperties = mConnManager.getLinkProperties(upType);
                    LinkProperties linkProperties =
                            getConnectivityManager().getLinkProperties(upType);
                    if (linkProperties != null) {
                        // Find the interface with the default IPv4 route. It may be the
                        // interface described by linkProperties, or one of the interfaces