diff options
author | Sreeram Ramachandran <sreeram@google.com> | 2014-07-24 16:05:17 -0700 |
---|---|---|
committer | Sreeram Ramachandran <sreeram@google.com> | 2014-07-24 16:26:59 -0700 |
commit | 62a61314bc880df15a1d284ce12bc08b9c79a4dd (patch) | |
tree | 88a5449229d91cf2ef9d9a520cb6be109d13a97a /services/core/java/com/android/server/connectivity/Tethering.java | |
parent | 4774470e20518112bfa2991505917c16c014dbfa (diff) | |
download | frameworks_base-62a61314bc880df15a1d284ce12bc08b9c79a4dd.zip frameworks_base-62a61314bc880df15a1d284ce12bc08b9c79a4dd.tar.gz frameworks_base-62a61314bc880df15a1d284ce12bc08b9c79a4dd.tar.bz2 |
Don't create a ConnectivityManager when the service isn't ready yet.
Bug: 16550853
Change-Id: Ib244c93dc982cbfe5d065a20e4b8f0aeefb15b8f
Diffstat (limited to 'services/core/java/com/android/server/connectivity/Tethering.java')
-rw-r--r-- | services/core/java/com/android/server/connectivity/Tethering.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 013e9fe..fa8626f 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -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 |