OSDN Git Service

Fix DUN-based tethering.
authorRobert Greenwalt <rgreenwalt@google.com>
Wed, 23 Jul 2014 18:44:01 +0000 (11:44 -0700)
committerRobert Greenwalt <rgreenwalt@google.com>
Thu, 24 Jul 2014 21:39:51 +0000 (14:39 -0700)
It was calling into dead ConnectivityService code rather than using
the new ConnectivityManager shim code.

bug:15221541
Change-Id: I1e3eea8a658a162ce36673ed1cf7b1e7e4372c42

core/java/android/net/ConnectivityManager.java
services/core/java/com/android/server/ConnectivityService.java
services/core/java/com/android/server/connectivity/Tethering.java

index e31f012..0df4d45 100644 (file)
@@ -1196,7 +1196,7 @@ public class ConnectivityManager {
         };
     }
 
-    private HashMap<NetworkCapabilities, LegacyRequest> sLegacyRequests =
+    private static HashMap<NetworkCapabilities, LegacyRequest> sLegacyRequests =
             new HashMap<NetworkCapabilities, LegacyRequest>();
 
     private NetworkRequest findRequestForFeature(NetworkCapabilities netCap) {
index e44f578..36be58c 100644 (file)
@@ -788,7 +788,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
             }
         }
 
-        mTethering = new Tethering(mContext, mNetd, statsService, this, mHandler.getLooper());
+        mTethering = new Tethering(mContext, mNetd, statsService, mHandler.getLooper());
 
         //set up the listener for user state for creating user VPNs
         IntentFilter intentFilter = new IntentFilter();
index d948942..013e9fe 100644 (file)
@@ -27,7 +27,6 @@ import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.hardware.usb.UsbManager;
 import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
 import android.net.INetworkStatsService;
 import android.net.InterfaceConfiguration;
 import android.net.LinkAddress;
@@ -95,7 +94,7 @@ public class Tethering extends BaseNetworkObserver {
 
     private final INetworkManagementService mNMService;
     private final INetworkStatsService mStatsService;
-    private final IConnectivityManager mConnService;
+    private final ConnectivityManager mConnManager;
     private Looper mLooper;
 
     private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces
@@ -132,11 +131,11 @@ public class Tethering extends BaseNetworkObserver {
                                          // when RNDIS is enabled
 
     public Tethering(Context context, INetworkManagementService nmService,
-            INetworkStatsService statsService, IConnectivityManager connService, Looper looper) {
+            INetworkStatsService statsService, Looper looper) {
         mContext = context;
         mNMService = nmService;
         mStatsService = statsService;
-        mConnService = connService;
+        mConnManager = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         mLooper = looper;
 
         mPublicSync = new Object();
@@ -367,11 +366,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() {
-        try {
-            if (!mConnService.isTetheringSupported()) return;
-        } catch (RemoteException e) {
-            return;
-        }
+        if (!mConnManager.isTetheringSupported()) return;
 
         ArrayList<String> availableList = new ArrayList<String>();
         ArrayList<String> activeList = new ArrayList<String>();
@@ -1188,11 +1183,8 @@ public class Tethering extends BaseNetworkObserver {
                 int result = PhoneConstants.APN_REQUEST_FAILED;
                 String enableString = enableString(apnType);
                 if (enableString == null) return false;
-                try {
-                    result = mConnService.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                            enableString, new Binder());
-                } catch (Exception e) {
-                }
+                result = mConnManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                        enableString);
                 switch (result) {
                 case PhoneConstants.APN_ALREADY_ACTIVE:
                 case PhoneConstants.APN_REQUEST_STARTED:
@@ -1213,12 +1205,8 @@ public class Tethering extends BaseNetworkObserver {
                 // ignore pending renewal requests
                 ++mCurrentConnectionSequence;
                 if (mMobileApnReserved != ConnectivityManager.TYPE_NONE) {
-                    try {
-                        mConnService.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                                enableString(mMobileApnReserved));
-                    } catch (Exception e) {
-                        return false;
-                    }
+                    mConnManager.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                            enableString(mMobileApnReserved));
                     mMobileApnReserved = ConnectivityManager.TYPE_NONE;
                 }
                 return true;
@@ -1281,10 +1269,7 @@ public class Tethering extends BaseNetworkObserver {
                     }
 
                     for (Integer netType : mUpstreamIfaceTypes) {
-                        NetworkInfo info = null;
-                        try {
-                            info = mConnService.getNetworkInfo(netType.intValue());
-                        } catch (RemoteException e) { }
+                        NetworkInfo info = mConnManager.getNetworkInfo(netType.intValue());
                         if ((info != null) && info.isConnected()) {
                             upType = netType.intValue();
                             break;
@@ -1322,10 +1307,7 @@ public class Tethering extends BaseNetworkObserver {
                         sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
                     }
                 } else {
-                    LinkProperties linkProperties = null;
-                    try {
-                        linkProperties = mConnService.getLinkPropertiesForType(upType);
-                    } catch (RemoteException e) { }
+                    LinkProperties linkProperties = mConnManager.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