diff options
Diffstat (limited to 'services/java/com/android/server/ConnectivityService.java')
-rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 168 |
1 files changed, 118 insertions, 50 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 2348d76..0153613 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -97,7 +97,7 @@ import java.util.List; public class ConnectivityService extends IConnectivityManager.Stub { private static final boolean DBG = true; - private static final boolean VDBG = true; + private static final boolean VDBG = false; private static final String TAG = "ConnectivityService"; private static final boolean LOGD_RULES = false; @@ -867,7 +867,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { // javadoc from interface public int startUsingNetworkFeature(int networkType, String feature, IBinder binder) { - if (DBG) { + if (VDBG) { log("startUsingNetworkFeature for net " + networkType + ": " + feature); } enforceChangePermission(); @@ -933,17 +933,19 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (ni.isConnected() == true) { // add the pid-specific dns handleDnsConfigurationChange(usedNetworkType); - if (DBG) log("special network already active"); + if (VDBG) log("special network already active"); return Phone.APN_ALREADY_ACTIVE; } - if (DBG) log("special network already connecting"); + if (VDBG) log("special network already connecting"); return Phone.APN_REQUEST_STARTED; } // check if the radio in play can make another contact // assume if cannot for now - if (DBG) log("reconnecting to special network"); + if (DBG) { + log("startUsingNetworkFeature reconnecting to " + networkType + ": " + feature); + } network.reconnect(); return Phone.APN_REQUEST_STARTED; } else { @@ -985,7 +987,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { return stopUsingNetworkFeature(u, true); } else { // none found! - if (VDBG) log("ignoring stopUsingNetworkFeature - not a live request"); + if (VDBG) log("stopUsingNetworkFeature - not a live request, ignoring"); return 1; } } @@ -999,12 +1001,15 @@ public class ConnectivityService extends IConnectivityManager.Stub { NetworkStateTracker tracker = null; boolean callTeardown = false; // used to carry our decision outside of sync block - if (DBG) { - log("stopUsingNetworkFeature for net " + networkType + - ": " + feature); + if (VDBG) { + log("stopUsingNetworkFeature: net " + networkType + ": " + feature); } if (!ConnectivityManager.isNetworkTypeValid(networkType)) { + if (DBG) { + log("stopUsingNetworkFeature: net " + networkType + ": " + feature + + ", net is invalid"); + } return -1; } @@ -1013,7 +1018,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { synchronized(this) { // check if this process still has an outstanding start request if (!mFeatureUsers.contains(u)) { - if (DBG) log("ignoring - this process has no outstanding requests"); + if (VDBG) { + log("stopUsingNetworkFeature: this process has no outstanding requests" + + ", ignoring"); + } return 1; } u.unlinkDeathRecipient(); @@ -1028,7 +1036,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (ignoreDups == false) { for (FeatureUser x : mFeatureUsers) { if (x.isSameUser(u)) { - if (DBG) log("ignoring stopUsingNetworkFeature as dup is found"); + if (VDBG) log("stopUsingNetworkFeature: dup is found, ignoring"); return 1; } } @@ -1039,7 +1047,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { tracker = mNetTrackers[usedNetworkType]; if (tracker == null) { - if (DBG) log("ignoring - no known tracker for net type " + usedNetworkType); + if (DBG) { + log("stopUsingNetworkFeature: net " + networkType + ": " + feature + + " no known tracker for used net type " + usedNetworkType); + } return -1; } if (usedNetworkType != networkType) { @@ -1047,17 +1058,25 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetRequestersPids[usedNetworkType].remove(currentPid); reassessPidDns(pid, true); if (mNetRequestersPids[usedNetworkType].size() != 0) { - if (DBG) log("not tearing down special network - " + - "others still using it"); + if (VDBG) { + log("stopUsingNetworkFeature: net " + networkType + ": " + feature + + " others still using it"); + } return 1; } callTeardown = true; } else { - if (DBG) log("not a known feature - dropping"); + if (DBG) { + log("stopUsingNetworkFeature: net " + networkType + ": " + feature + + " not a known feature - dropping"); + } } } - if (DBG) log("Doing network teardown"); + if (callTeardown) { + if (DBG) { + log("stopUsingNetworkFeature: teardown net " + networkType + ": " + feature); + } tracker.teardown(); return 1; } else { @@ -1592,7 +1611,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { mInitialBroadcast = new Intent(intent); } intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - if (DBG) { + if (VDBG) { log("sendStickyBroadcast: action=" + intent.getAction()); } @@ -1604,7 +1623,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (delayMs <= 0) { sendStickyBroadcast(intent); } else { - if (DBG) { + if (VDBG) { log("sendStickyBroadcastDelayed: delayMs=" + delayMs + ", action=" + intent.getAction()); } @@ -1779,12 +1798,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } if (resetDns) { - if (DBG) log("resetting DNS cache for " + iface); + if (VDBG) log("resetting DNS cache for " + iface); try { mNetd.flushInterfaceDnsCache(iface); } catch (Exception e) { // never crash - catch them all - loge("Exception resetting dns cache: " + e); + if (DBG) loge("Exception resetting dns cache: " + e); } } } @@ -1840,12 +1859,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { // remove the default route unless somebody else has asked for it String ifaceName = newLp.getInterfaceName(); if (TextUtils.isEmpty(ifaceName) == false && mAddedRoutes.contains(r) == false) { - if (DBG) log("Removing " + r + " for interface " + ifaceName); + if (VDBG) log("Removing " + r + " for interface " + ifaceName); try { mNetd.removeRoute(ifaceName, r); } catch (Exception e) { // never crash - catch them all - loge("Exception trying to remove a route: " + e); + if (VDBG) loge("Exception trying to remove a route: " + e); } } } @@ -1955,7 +1974,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { Integer pid = (Integer)pids.get(j); if (pid.intValue() == myPid) { Collection<InetAddress> dnses = p.getDnses(); - writePidDns(dnses, myPid); + String proto = determineProto(p); + writePidDns(dnses, myPid, proto); if (doBump) { bumpDns(); } @@ -1965,6 +1985,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } // nothing found - delete + if (SystemProperties.get("net.dnsproto." + myPid).length() != 0) { + SystemProperties.set("net.dnsproto." + myPid, ""); + } for (int i = 1; ; i++) { String prop = "net.dns" + i + "." + myPid; if (SystemProperties.get(prop).length() == 0) { @@ -1978,7 +2001,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } // return true if results in a change - private boolean writePidDns(Collection <InetAddress> dnses, int pid) { + private boolean writePidDns(Collection <InetAddress> dnses, int pid, String proto) { int j = 1; boolean changed = false; for (InetAddress dns : dnses) { @@ -1988,6 +2011,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { SystemProperties.set("net.dns" + j++ + "." + pid, dns.getHostAddress()); } } + if (dnses.size() > 0 && (changed || !proto.equals(SystemProperties.get("net.dnsproto." + + pid)))) { + changed = true; + SystemProperties.set("net.dnsproto." + pid, proto); + } return changed; } @@ -2018,7 +2046,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { // Caller must grab mDnsLock. private boolean updateDns(String network, String iface, - Collection<InetAddress> dnses, String domains) { + Collection<InetAddress> dnses, String domains, String proto) { boolean changed = false; int last = 0; if (dnses.size() == 0 && mDefaultDns != null) { @@ -2054,12 +2082,17 @@ public class ConnectivityService extends IConnectivityManager.Stub { } mNumDnsEntries = last; + if (changed || !proto.equals(SystemProperties.get("net.dnsproto"))) { + changed = true; + SystemProperties.set("net.dnsproto", proto); + } + if (changed) { try { mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses)); mNetd.setDefaultInterfaceForDns(iface); } catch (Exception e) { - loge("exception setting default dns interface: " + e); + if (VDBG) loge("exception setting default dns interface: " + e); } } if (!domains.equals(SystemProperties.get("net.dns.search"))) { @@ -2077,11 +2110,14 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (p == null) return; Collection<InetAddress> dnses = p.getDnses(); boolean changed = false; + String proto = determineProto(p); + if (mNetConfigs[netType].isDefault()) { String network = nt.getNetworkInfo().getTypeName(); synchronized (mDnsLock) { if (!mDnsOverridden) { - changed = updateDns(network, p.getInterfaceName(), dnses, ""); + changed = updateDns(network, p.getInterfaceName(), dnses, "", + proto); } } } else { @@ -2089,19 +2125,41 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetd.setDnsServersForInterface(p.getInterfaceName(), NetworkUtils.makeStrings(dnses)); } catch (Exception e) { - loge("exception setting dns servers: " + e); + if (VDBG) loge("exception setting dns servers: " + e); } // set per-pid dns for attached secondary nets List pids = mNetRequestersPids[netType]; for (int y=0; y< pids.size(); y++) { Integer pid = (Integer)pids.get(y); - changed = writePidDns(dnses, pid.intValue()); + changed = writePidDns(dnses, pid.intValue(), proto); } } if (changed) bumpDns(); } } + private String determineProto(LinkProperties p) { + boolean v4 = false; + boolean v6 = false; + for (RouteInfo r : p.getRoutes()) { + if (r.getDestination().getAddress() instanceof Inet6Address) { + v6 = true; + } else { + v4 = true; + } + } + // secondary connections often don't have routes and we infer routes + // to the dns servers. Look at the dns addrs too + for (InetAddress i : p.getDnses()) { + if (i instanceof Inet6Address) { + v6 = true; + } else { + v4 = true; + } + } + return (v4 ? "v4" : "") + (v6 ? "v6" : ""); + } + private int getRestoreDefaultNetworkDelay(int networkType) { String restoreDefaultNetworkDelayStr = SystemProperties.get( NETWORK_RESTORE_DELAY_PROP_NAME); @@ -2194,9 +2252,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { int type = info.getType(); NetworkInfo.State state = info.getState(); - if (DBG) log("ConnectivityChange for " + + if (VDBG || (state == NetworkInfo.State.CONNECTED) || + (state == NetworkInfo.State.DISCONNECTED)) { + log("ConnectivityChange for " + info.getTypeName() + ": " + state + "/" + info.getDetailedState()); + } // Connectivity state changed: // [31-13] Reserved for future use @@ -2394,6 +2455,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { return mTethering.getTetheredIfaces(); } + @Override + public String[] getTetheredIfacePairs() { + enforceTetherAccessPermission(); + return mTethering.getTetheredIfacePairs(); + } + public String[] getTetheringErroredIfaces() { enforceTetherAccessPermission(); return mTethering.getErroredIfaces(); @@ -2452,23 +2519,24 @@ public class ConnectivityService extends IConnectivityManager.Stub { } private void handleInetConditionChange(int netType, int condition) { - if (DBG) { - log("Inet connectivity change, net=" + - netType + ", condition=" + condition + - ",mActiveDefaultNetwork=" + mActiveDefaultNetwork); - } if (mActiveDefaultNetwork == -1) { - if (DBG) log("no active default network - aborting"); + if (DBG) log("handleInetConditionChange: no active default network - ignore"); return; } if (mActiveDefaultNetwork != netType) { - if (DBG) log("given net not default - aborting"); + if (DBG) log("handleInetConditionChange: net=" + netType + + " != default=" + mActiveDefaultNetwork + " - ignore"); return; } + if (VDBG) { + log("handleInetConditionChange: net=" + + netType + ", condition=" + condition + + ",mActiveDefaultNetwork=" + mActiveDefaultNetwork); + } mDefaultInetCondition = condition; int delay; if (mInetConditionChangeInFlight == false) { - if (VDBG) log("starting a change hold"); + if (VDBG) log("handleInetConditionChange: starting a change hold"); // setup a new hold to debounce this if (mDefaultInetCondition > 50) { delay = Settings.Secure.getInt(mContext.getContentResolver(), @@ -2481,26 +2549,25 @@ public class ConnectivityService extends IConnectivityManager.Stub { mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END, mActiveDefaultNetwork, mDefaultConnectionSequence), delay); } else { - // we've set the new condition, when this hold ends that will get - // picked up - if (VDBG) log("currently in hold - not setting new end evt"); + // we've set the new condition, when this hold ends that will get picked up + if (VDBG) log("handleInetConditionChange: currently in hold - not setting new end evt"); } } private void handleInetConditionHoldEnd(int netType, int sequence) { - if (VDBG) { - log("Inet hold end, net=" + netType + - ", condition =" + mDefaultInetCondition + - ", published condition =" + mDefaultInetConditionPublished); + if (DBG) { + log("handleInetConditionHoldEnd: net=" + netType + + ", condition=" + mDefaultInetCondition + + ", published condition=" + mDefaultInetConditionPublished); } mInetConditionChangeInFlight = false; if (mActiveDefaultNetwork == -1) { - if (DBG) log("no active default network - aborting"); + if (DBG) log("handleInetConditionHoldEnd: no active default network - ignoring"); return; } if (mDefaultConnectionSequence != sequence) { - if (DBG) log("event hold for obsolete network - aborting"); + if (DBG) log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring"); return; } // TODO: Figure out why this optimization sometimes causes a @@ -2512,7 +2579,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { //} NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(); if (networkInfo.isConnected() == false) { - if (DBG) log("default network not connected - aborting"); + if (DBG) log("handleInetConditionHoldEnd: default network not connected - ignoring"); return; } mDefaultInetConditionPublished = mDefaultInetCondition; @@ -2590,7 +2657,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } if (VDBG) log("changing default proxy to " + proxy); - if ((proxy == null && mGlobalProxy == null) || proxy.equals(mGlobalProxy)) return; + + // global trumps default, if set, ignore this. if (mGlobalProxy != null) return; sendProxyBroadcast(proxy); } @@ -2813,7 +2881,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { // Apply DNS changes. boolean changed = false; synchronized (mDnsLock) { - changed = updateDns("VPN", "VPN", addresses, domains); + changed = updateDns("VPN", "VPN", addresses, domains, "v4"); mDnsOverridden = true; } if (changed) { |