Fields Summary |
---|
private android.content.Context | mContext |
private static final String | TAG |
private static final boolean | DBG |
private static final boolean | VDBG |
private String[] | mTetherableUsbRegexs |
private String[] | mTetherableWifiRegexs |
private String[] | mTetherableBluetoothRegexs |
private Collection | mUpstreamIfaceTypes |
private Object | mPublicSync |
private static final Integer | MOBILE_TYPE |
private static final Integer | HIPRI_TYPE |
private static final Integer | DUN_TYPE |
private int | mPreferredUpstreamMobileApn |
private final android.os.INetworkManagementService | mNMService |
private final android.net.INetworkStatsService | mStatsService |
private android.os.Looper | mLooper |
private HashMap | mIfaces |
private android.content.BroadcastReceiver | mStateReceiver |
private static final String | USB_NEAR_IFACE_ADDR |
private static final int | USB_PREFIX_LENGTH |
private String[] | mDhcpRange |
private static final String[] | DHCP_DEFAULT_RANGE |
private String[] | mDefaultDnsServers |
private static final String | DNS_DEFAULT_SERVER1 |
private static final String | DNS_DEFAULT_SERVER2 |
private com.android.internal.util.StateMachine | mTetherMasterSM |
private android.app.Notification | mTetheredNotification |
private boolean | mRndisEnabled |
private boolean | mUsbTetherRequested |
Methods Summary |
---|
public void | checkDunRequired()
int secureSetting = 2;
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null) {
secureSetting = tm.getTetherApnRequired();
}
synchronized (mPublicSync) {
// 2 = not set, 0 = DUN not required, 1 = DUN required
if (secureSetting != 2) {
int requiredApn = (secureSetting == 1 ?
ConnectivityManager.TYPE_MOBILE_DUN :
ConnectivityManager.TYPE_MOBILE_HIPRI);
if (requiredApn == ConnectivityManager.TYPE_MOBILE_DUN) {
while (mUpstreamIfaceTypes.contains(MOBILE_TYPE)) {
mUpstreamIfaceTypes.remove(MOBILE_TYPE);
}
while (mUpstreamIfaceTypes.contains(HIPRI_TYPE)) {
mUpstreamIfaceTypes.remove(HIPRI_TYPE);
}
if (mUpstreamIfaceTypes.contains(DUN_TYPE) == false) {
mUpstreamIfaceTypes.add(DUN_TYPE);
}
} else {
while (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
mUpstreamIfaceTypes.remove(DUN_TYPE);
}
if (mUpstreamIfaceTypes.contains(MOBILE_TYPE) == false) {
mUpstreamIfaceTypes.add(MOBILE_TYPE);
}
if (mUpstreamIfaceTypes.contains(HIPRI_TYPE) == false) {
mUpstreamIfaceTypes.add(HIPRI_TYPE);
}
}
}
if (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN;
} else {
mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
}
}
|
private void | clearTetheredNotification()
NotificationManager notificationManager =
(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null && mTetheredNotification != null) {
notificationManager.cancelAsUser(null, mTetheredNotification.icon,
UserHandle.ALL);
mTetheredNotification = null;
}
|
private boolean | configureUsbIface(boolean enabled)
if (VDBG) Log.d(TAG, "configureUsbIface(" + enabled + ")");
// toggle the USB 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.setLinkAddress(new LinkAddress(addr, USB_PREFIX_LENGTH));
if (enabled) {
ifcg.setInterfaceUp();
} else {
ifcg.setInterfaceDown();
}
ifcg.clearFlag("running");
mNMService.setInterfaceConfig(iface, ifcg);
}
} catch (Exception e) {
Log.e(TAG, "Error configuring interface " + iface, e);
return false;
}
}
}
return true;
|
public void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: can't dump ConnectivityService.Tether " +
"from from pid=" + Binder.getCallingPid() + ", uid=" +
Binder.getCallingUid());
return;
}
synchronized (mPublicSync) {
pw.println("mUpstreamIfaceTypes: ");
for (Integer netType : mUpstreamIfaceTypes) {
pw.println(" " + netType);
}
pw.println();
pw.println("Tether state:");
for (Object o : mIfaces.values()) {
pw.println(" " + o);
}
}
pw.println();
return;
|
private android.net.ConnectivityManager | getConnectivityManager()
return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
public java.lang.String[] | getErroredIfaces()
ArrayList<String> list = new ArrayList<String>();
synchronized (mPublicSync) {
Set keys = mIfaces.keySet();
for (Object key : keys) {
TetherInterfaceSM sm = mIfaces.get(key);
if (sm.isErrored()) {
list.add((String)key);
}
}
}
String[] retVal = new String[list.size()];
for (int i= 0; i< list.size(); i++) {
retVal[i] = list.get(i);
}
return retVal;
|
public int | getLastTetherError(java.lang.String iface)
TetherInterfaceSM sm = null;
synchronized (mPublicSync) {
sm = mIfaces.get(iface);
if (sm == null) {
Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface +
", ignoring");
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
}
return sm.getLastError();
}
|
public java.lang.String[] | getTetherableBluetoothRegexs()
return mTetherableBluetoothRegexs;
|
public java.lang.String[] | getTetherableIfaces()
ArrayList<String> list = new ArrayList<String>();
synchronized (mPublicSync) {
Set keys = mIfaces.keySet();
for (Object key : keys) {
TetherInterfaceSM sm = mIfaces.get(key);
if (sm.isAvailable()) {
list.add((String)key);
}
}
}
String[] retVal = new String[list.size()];
for (int i=0; i < list.size(); i++) {
retVal[i] = list.get(i);
}
return retVal;
|
public java.lang.String[] | getTetherableUsbRegexs()
return mTetherableUsbRegexs;
|
public java.lang.String[] | getTetherableWifiRegexs()
return mTetherableWifiRegexs;
|
public java.lang.String[] | getTetheredDhcpRanges()
return mDhcpRange;
|
public java.lang.String[] | getTetheredIfaces()
ArrayList<String> list = new ArrayList<String>();
synchronized (mPublicSync) {
Set keys = mIfaces.keySet();
for (Object key : keys) {
TetherInterfaceSM sm = mIfaces.get(key);
if (sm.isTethered()) {
list.add((String)key);
}
}
}
String[] retVal = new String[list.size()];
for (int i=0; i < list.size(); i++) {
retVal[i] = list.get(i);
}
return retVal;
|
public int[] | getUpstreamIfaceTypes()
int values[];
synchronized (mPublicSync) {
updateConfiguration(); // TODO - remove?
values = new int[mUpstreamIfaceTypes.size()];
Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator();
for (int i=0; i < mUpstreamIfaceTypes.size(); i++) {
values[i] = iterator.next();
}
}
return values;
|
public void | interfaceAdded(java.lang.String iface)
if (VDBG) Log.d(TAG, "interfaceAdded " + iface);
boolean found = false;
boolean usb = false;
synchronized (mPublicSync) {
if (isWifi(iface)) {
found = true;
}
if (isUsb(iface)) {
found = true;
usb = true;
}
if (isBluetooth(iface)) {
found = true;
}
if (found == false) {
if (VDBG) Log.d(TAG, iface + " is not a tetherable iface, ignoring");
return;
}
TetherInterfaceSM sm = mIfaces.get(iface);
if (sm != null) {
if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring");
return;
}
sm = new TetherInterfaceSM(iface, mLooper, usb);
mIfaces.put(iface, sm);
sm.start();
}
|
public void | interfaceLinkStateChanged(java.lang.String iface, boolean up)
if (VDBG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up);
interfaceStatusChanged(iface, up);
|
public void | interfaceRemoved(java.lang.String iface)
if (VDBG) Log.d(TAG, "interfaceRemoved " + iface);
synchronized (mPublicSync) {
TetherInterfaceSM sm = mIfaces.get(iface);
if (sm == null) {
if (VDBG) {
Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring");
}
return;
}
sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
mIfaces.remove(iface);
}
|
public void | interfaceStatusChanged(java.lang.String iface, boolean up)
if (VDBG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
boolean found = false;
boolean usb = false;
synchronized (mPublicSync) {
if (isWifi(iface)) {
found = true;
} else if (isUsb(iface)) {
found = true;
usb = true;
} else if (isBluetooth(iface)) {
found = true;
}
if (found == false) return;
TetherInterfaceSM sm = mIfaces.get(iface);
if (up) {
if (sm == null) {
sm = new TetherInterfaceSM(iface, mLooper, usb);
mIfaces.put(iface, sm);
sm.start();
}
} else {
if (isUsb(iface)) {
// ignore usb0 down after enabling RNDIS
// we will handle disconnect in interfaceRemoved instead
if (VDBG) Log.d(TAG, "ignore interface down for " + iface);
} else if (sm != null) {
sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
mIfaces.remove(iface);
}
}
}
|
public boolean | isBluetooth(java.lang.String iface)
synchronized (mPublicSync) {
for (String regex : mTetherableBluetoothRegexs) {
if (iface.matches(regex)) return true;
}
return false;
}
|
private boolean | isUsb(java.lang.String iface)
synchronized (mPublicSync) {
for (String regex : mTetherableUsbRegexs) {
if (iface.matches(regex)) return true;
}
return false;
}
|
public boolean | isWifi(java.lang.String iface)
synchronized (mPublicSync) {
for (String regex : mTetherableWifiRegexs) {
if (iface.matches(regex)) return true;
}
return false;
}
|
private void | sendTetherStateChangedBroadcast()
if (!getConnectivityManager().isTetheringSupported()) return;
ArrayList<String> availableList = new ArrayList<String>();
ArrayList<String> activeList = new ArrayList<String>();
ArrayList<String> erroredList = new ArrayList<String>();
boolean wifiTethered = false;
boolean usbTethered = false;
boolean bluetoothTethered = false;
synchronized (mPublicSync) {
Set ifaces = mIfaces.keySet();
for (Object iface : ifaces) {
TetherInterfaceSM sm = mIfaces.get(iface);
if (sm != null) {
if (sm.isErrored()) {
erroredList.add((String)iface);
} else if (sm.isAvailable()) {
availableList.add((String)iface);
} else if (sm.isTethered()) {
if (isUsb((String)iface)) {
usbTethered = true;
} else if (isWifi((String)iface)) {
wifiTethered = true;
} else if (isBluetooth((String)iface)) {
bluetoothTethered = true;
}
activeList.add((String)iface);
}
}
}
}
Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER,
availableList);
broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeList);
broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER,
erroredList);
mContext.sendStickyBroadcastAsUser(broadcast, UserHandle.ALL);
if (DBG) {
Log.d(TAG, "sendTetherStateChangedBroadcast " + availableList.size() + ", " +
activeList.size() + ", " + erroredList.size());
}
if (usbTethered) {
if (wifiTethered || bluetoothTethered) {
showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
} else {
showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_usb);
}
} else if (wifiTethered) {
if (bluetoothTethered) {
showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
} else {
/* We now have a status bar icon for WifiTethering, so drop the notification */
clearTetheredNotification();
}
} else if (bluetoothTethered) {
showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_bluetooth);
} else {
clearTetheredNotification();
}
|
public int | setUsbTethering(boolean enable)
if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
synchronized (mPublicSync) {
if (enable) {
if (mRndisEnabled) {
tetherUsb(true);
} else {
mUsbTetherRequested = true;
usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
}
} else {
tetherUsb(false);
if (mRndisEnabled) {
usbManager.setCurrentFunction(null, false);
}
mUsbTetherRequested = false;
}
}
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
private void | showTetheredNotification(int icon)
NotificationManager notificationManager =
(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
return;
}
if (mTetheredNotification != null) {
if (mTetheredNotification.icon == icon) {
return;
}
notificationManager.cancelAsUser(null, mTetheredNotification.icon,
UserHandle.ALL);
}
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0,
null, UserHandle.CURRENT);
Resources r = Resources.getSystem();
CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
CharSequence message = r.getText(com.android.internal.R.string.
tethered_notification_message);
if (mTetheredNotification == null) {
mTetheredNotification = new Notification();
mTetheredNotification.when = 0;
}
mTetheredNotification.icon = icon;
mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
mTetheredNotification.tickerText = title;
mTetheredNotification.visibility = Notification.VISIBILITY_PUBLIC;
mTetheredNotification.color = mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color);
mTetheredNotification.setLatestEventInfo(mContext, title, message, pi);
mTetheredNotification.category = Notification.CATEGORY_STATUS;
notificationManager.notifyAsUser(null, mTetheredNotification.icon,
mTetheredNotification, UserHandle.ALL);
|
public int | tether(java.lang.String iface)
if (DBG) Log.d(TAG, "Tethering " + iface);
TetherInterfaceSM sm = null;
synchronized (mPublicSync) {
sm = mIfaces.get(iface);
}
if (sm == null) {
Log.e(TAG, "Tried to Tether an unknown iface :" + iface + ", ignoring");
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
}
if (!sm.isAvailable() && !sm.isErrored()) {
Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring");
return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
}
sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED);
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
private void | tetherUsb(boolean enable)
if (VDBG) Log.d(TAG, "tetherUsb " + enable);
String[] ifaces = new String[0];
try {
ifaces = mNMService.listInterfaces();
} catch (Exception e) {
Log.e(TAG, "Error listing Interfaces", e);
return;
}
for (String iface : ifaces) {
if (isUsb(iface)) {
int result = (enable ? tether(iface) : untether(iface));
if (result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
return;
}
}
}
Log.e(TAG, "unable start or stop USB tethering");
|
public int | untether(java.lang.String iface)
if (DBG) Log.d(TAG, "Untethering " + iface);
TetherInterfaceSM sm = null;
synchronized (mPublicSync) {
sm = mIfaces.get(iface);
}
if (sm == null) {
Log.e(TAG, "Tried to Untether an unknown iface :" + iface + ", ignoring");
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
}
if (sm.isErrored()) {
Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring");
return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
}
sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED);
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
void | updateConfiguration()
String[] tetherableUsbRegexs = mContext.getResources().getStringArray(
com.android.internal.R.array.config_tether_usb_regexs);
String[] tetherableWifiRegexs = mContext.getResources().getStringArray(
com.android.internal.R.array.config_tether_wifi_regexs);
String[] tetherableBluetoothRegexs = mContext.getResources().getStringArray(
com.android.internal.R.array.config_tether_bluetooth_regexs);
int ifaceTypes[] = mContext.getResources().getIntArray(
com.android.internal.R.array.config_tether_upstream_types);
Collection<Integer> upstreamIfaceTypes = new ArrayList();
for (int i : ifaceTypes) {
upstreamIfaceTypes.add(new Integer(i));
}
synchronized (mPublicSync) {
mTetherableUsbRegexs = tetherableUsbRegexs;
mTetherableWifiRegexs = tetherableWifiRegexs;
mTetherableBluetoothRegexs = tetherableBluetoothRegexs;
mUpstreamIfaceTypes = upstreamIfaceTypes;
}
// check if the upstream type list needs to be modified due to secure-settings
checkDunRequired();
|