From 8e87f12bed17c43b5bfe20b0fe883e260181b3e2 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Thu, 11 Feb 2010 18:18:40 -0800 Subject: [PATCH] Update Tethering. Adds telephony support, async model, multiple tethered iface suport, better notifications, device config. bug:2413855 --- .../java/android/net/ConnectivityManager.java | 45 +++++++++++++++++- .../android/net/IConnectivityManager.aidl | 6 +++ .../android/server/ConnectivityService.java | 46 +++++++++++++++++-- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index d435df5842..badb7670ad 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -125,13 +125,21 @@ public class ConnectivityManager /** * @hide + * gives a String[] */ - public static final String EXTRA_AVAILABLE_TETHER_COUNT = "availableCount"; + public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; /** * @hide + * gives a String[] */ - public static final String EXTRA_ACTIVE_TETHER_COUNT = "activeCount"; + public static final String EXTRA_ACTIVE_TETHER = "activeArray"; + + /** + * @hide + * gives a String[] + */ + public static final String EXTRA_ERRORED_TETHER = "erroredArray"; /** * The Default Mobile data connection. When active, all data traffic @@ -400,4 +408,37 @@ public class ConnectivityManager return false; } } + + /** + * {@hide} + */ + public boolean isTetheringSupported() { + try { + return mService.isTetheringSupported(); + } catch (RemoteException e) { + return false; + } + } + + /** + * {@hide} + */ + public String[] getTetherableUsbRegexs() { + try { + return mService.getTetherableUsbRegexs(); + } catch (RemoteException e) { + return new String[0]; + } + } + + /** + * {@hide} + */ + public String[] getTetherableWifiRegexs() { + try { + return mService.getTetherableWifiRegexs(); + } catch (RemoteException e) { + return new String[0]; + } + } } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index caa3f2bbc7..508e9c3acb 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -55,7 +55,13 @@ interface IConnectivityManager boolean untether(String iface); + boolean isTetheringSupported(); + String[] getTetherableIfaces(); String[] getTetheredIfaces(); + + String[] getTetherableUsbRegexs(); + + String[] getTetherableWifiRegexs(); } diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 42590160d9..108246daa1 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -798,6 +798,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { "ConnectivityService"); } + private void enforceTetherAccessPermission() { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.ACCESS_NETWORK_STATE, + "ConnectivityService"); + } + /** * Handle a {@code DISCONNECTED} event. If this pertains to the non-active * network, we ignore it. If it is for the active network, we send out a @@ -1289,6 +1295,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { pw.println(requester.toString()); } pw.println(); + + mTethering.dump(fd, pw, args); } // must be stateless - things change under us. @@ -1386,24 +1394,54 @@ public class ConnectivityService extends IConnectivityManager.Stub { // javadoc from interface public boolean tether(String iface) { enforceTetherChangePermission(); - return mTethering.tether(iface); + return isTetheringSupported() && mTethering.tether(iface); } // javadoc from interface public boolean untether(String iface) { enforceTetherChangePermission(); - return mTethering.untether(iface); + return isTetheringSupported() && mTethering.untether(iface); + } + + // TODO - proper iface API for selection by property, inspection, etc + public String[] getTetherableUsbRegexs() { + enforceTetherAccessPermission(); + if (isTetheringSupported()) { + return mTethering.getTetherableUsbRegexs(); + } else { + return new String[0]; + } + } + + public String[] getTetherableWifiRegexs() { + enforceTetherAccessPermission(); + if (isTetheringSupported()) { + return mTethering.getTetherableWifiRegexs(); + } else { + return new String[0]; + } } // TODO - move iface listing, queries, etc to new module // javadoc from interface public String[] getTetherableIfaces() { - enforceAccessPermission(); + enforceTetherAccessPermission(); return mTethering.getTetherableIfaces(); } public String[] getTetheredIfaces() { - enforceAccessPermission(); + enforceTetherAccessPermission(); return mTethering.getTetheredIfaces(); } + + // if ro.tether.denied = true we default to no tethering + // gservices could set the secure setting to 1 though to enable it on a build where it + // had previously been turned off. + public boolean isTetheringSupported() { + enforceTetherAccessPermission(); + int defaultVal = (SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1); + return ((Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.TETHER_SUPPORTED, defaultVal) != 0) && + (mNetTrackers[ConnectivityManager.TYPE_MOBILE_DUN] != null)); + } }