summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-06-08 15:10:26 -0700
committerMike Lockwood <lockwood@android.com>2011-06-19 20:50:46 -0400
commit3c2a2f6789ee257e3838ffb0f3f117e08825ad5f (patch)
tree5d4658b7437d3ba3a13498535fb6afe891d7d13e /services
parent75a0e9c0f076093368ca50ac7e905a48af919f8b (diff)
downloadframeworks_base-3c2a2f6789ee257e3838ffb0f3f117e08825ad5f.zip
frameworks_base-3c2a2f6789ee257e3838ffb0f3f117e08825ad5f.tar.gz
frameworks_base-3c2a2f6789ee257e3838ffb0f3f117e08825ad5f.tar.bz2
Tethering: Use UsbManager to enable/disable RNDIS
Remove obsolete RNDIS support from NetworkManagementService This change fixes USB tethering, which broke after the new USB gadget driver changes went in. Change-Id: Idd987fb2c39c40e81ebc92e6d8dae9fe77ed4ddc Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/NetworkManagementService.java47
-rw-r--r--services/java/com/android/server/connectivity/Tethering.java100
2 files changed, 57 insertions, 90 deletions
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index d5bdd21..9c73a5d 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -78,7 +78,6 @@ class NetworkManagementService extends INetworkManagementService.Stub {
public static final int IpFwdStatusResult = 211;
public static final int InterfaceGetCfgResult = 213;
public static final int SoftapStatusResult = 214;
- public static final int UsbRNDISStatusResult = 215;
public static final int InterfaceRxCounterResult = 216;
public static final int InterfaceTxCounterResult = 217;
public static final int InterfaceRxThrottleResult = 218;
@@ -718,52 +717,6 @@ class NetworkManagementService extends INetworkManagementService.Stub {
}
}
- public void startUsbRNDIS() throws IllegalStateException {
- mContext.enforceCallingOrSelfPermission(
- android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
- try {
- mConnector.doCommand("usb startrndis");
- } catch (NativeDaemonConnectorException e) {
- throw new IllegalStateException(
- "Error communicating to native daemon for starting RNDIS", e);
- }
- }
-
- public void stopUsbRNDIS() throws IllegalStateException {
- mContext.enforceCallingOrSelfPermission(
- android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
- try {
- mConnector.doCommand("usb stoprndis");
- } catch (NativeDaemonConnectorException e) {
- throw new IllegalStateException("Error communicating to native daemon", e);
- }
- }
-
- public boolean isUsbRNDISStarted() throws IllegalStateException {
- mContext.enforceCallingOrSelfPermission(
- android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");
- ArrayList<String> rsp;
- try {
- rsp = mConnector.doCommand("usb rndisstatus");
- } catch (NativeDaemonConnectorException e) {
- throw new IllegalStateException(
- "Error communicating to native daemon to check RNDIS status", e);
- }
-
- for (String line : rsp) {
- String []tok = line.split(" ");
- int code = Integer.parseInt(tok[0]);
- if (code == NetdResponseCode.UsbRNDISStatusResult) {
- if (tok[3].equals("started"))
- return true;
- return false;
- } else {
- throw new IllegalStateException(String.format("Unexpected response code %d", code));
- }
- }
- throw new IllegalStateException("Got an empty response");
- }
-
public void startAccessPoint(WifiConfiguration wifiConfig, String wlanIface, String softapIface)
throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 5fa26ef..15e67d0 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -471,11 +471,20 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
// used on cable insert/remove
private void enableUsbIfaces(boolean enable) {
+ // add/remove USB interfaces when USB is connected/disconnected
+ for (String intf : mTetherableUsbRegexs) {
+ if (enable) {
+ interfaceAdded(intf);
+ } else {
+ interfaceRemoved(intf);
+ }
+ }
+
String[] ifaces = new String[0];
try {
ifaces = mNMService.listInterfaces();
} catch (Exception e) {
- Log.e(TAG, "Error listing Interfaces :" + e);
+ Log.e(TAG, "Error listing Interfaces", e);
return;
}
for (String iface : ifaces) {
@@ -493,20 +502,19 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private boolean enableUsbRndis(boolean enabled) {
if (DEBUG) Log.d(TAG, "enableUsbRndis(" + enabled + ")");
+ UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
+ if (usbManager == null) {
+ Log.d(TAG, "could not get UsbManager");
+ return false;
+ }
try {
if (enabled) {
- synchronized (this) {
- if (!mNMService.isUsbRNDISStarted()) {
- mNMService.startUsbRNDIS();
- }
- }
+ usbManager.setPrimaryFunction(UsbManager.USB_FUNCTION_RNDIS);
} else {
- if (mNMService.isUsbRNDISStarted()) {
- mNMService.stopUsbRNDIS();
- }
+ usbManager.setPrimaryFunction(null);
}
} catch (Exception e) {
- Log.e(TAG, "Error toggling usb RNDIS :" + e);
+ Log.e(TAG, "Error toggling usb RNDIS", e);
return false;
}
return true;
@@ -516,35 +524,46 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private boolean configureUsbIface(boolean enabled) {
if (DEBUG) Log.d(TAG, "configureUsbIface(" + enabled + ")");
- // bring toggle the interfaces
- String[] ifaces = new String[0];
- try {
- ifaces = mNMService.listInterfaces();
- } catch (Exception e) {
- Log.e(TAG, "Error listing Interfaces :" + e);
- return false;
+ if (enabled) {
+ // must enable RNDIS first to create the interface
+ enableUsbRndis(enabled);
}
- for (String iface : ifaces) {
- if (isUsb(iface)) {
- InterfaceConfiguration ifcg = null;
- try {
- ifcg = mNMService.getInterfaceConfig(iface);
- if (ifcg != null) {
- InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
- ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
- if (enabled) {
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
- } else {
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
+
+ try {
+ // bring toggle the interfaces
+ String[] ifaces = new String[0];
+ try {
+ ifaces = mNMService.listInterfaces();
+ } catch (Exception e) {
+ Log.e(TAG, "Error listing Interfaces", e);
+ return false;
+ }
+ for (String iface : ifaces) {
+ if (isUsb(iface)) {
+ InterfaceConfiguration ifcg = null;
+ try {
+ ifcg = mNMService.getInterfaceConfig(iface);
+ if (ifcg != null) {
+ InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
+ ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
+ if (enabled) {
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
+ } else {
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
+ }
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
+ mNMService.setInterfaceConfig(iface, ifcg);
}
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
- mNMService.setInterfaceConfig(iface, ifcg);
+ } catch (Exception e) {
+ Log.e(TAG, "Error configuring interface " + iface, e);
+ return false;
}
- } catch (Exception e) {
- Log.e(TAG, "Error configuring interface " + iface + ", :" + e);
- return false;
}
+ }
+ } finally {
+ if (!enabled) {
+ enableUsbRndis(false);
}
}
@@ -853,17 +872,12 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
transitionTo(mInitialState);
return;
}
- if (mUsb) Tethering.this.enableUsbRndis(true);
if (DEBUG) Log.d(TAG, "Tethered " + mIfaceName);
setAvailable(false);
setTethered(true);
sendTetherStateChangedBroadcast();
}
@Override
- public void exit() {
- if (mUsb) Tethering.this.enableUsbRndis(false);
- }
- @Override
public boolean processMessage(Message message) {
if (DEBUG) Log.d(TAG, "TetheredState.processMessage what=" + message.what);
boolean retValue = true;
@@ -1201,7 +1215,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
try {
ifaces = mNMService.listInterfaces();
} catch (Exception e) {
- Log.e(TAG, "Error listing Interfaces :" + e);
+ Log.e(TAG, "Error listing Interfaces", e);
return null;
}
@@ -1216,7 +1230,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
return iface;
}
} catch (Exception e) {
- Log.e(TAG, "Error getting iface config :" + e);
+ Log.e(TAG, "Error getting iface config", e);
// ignore - try next
continue;
}
@@ -1267,7 +1281,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
}
} catch (RemoteException e) {
- Log.e(TAG, "RemoteException calling ConnectivityManager " + e);
+ Log.e(TAG, "RemoteException calling ConnectivityManager", e);
iface = null;
}
}