summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorPaul Jensen <pauljensen@google.com>2015-04-06 11:54:53 -0400
committerPaul Jensen <pauljensen@google.com>2015-04-08 07:46:49 -0400
commite75b9e355500b7c6a05e4d6ec54ef48835707caa (patch)
treea443bf1e6be90b96c9fe4b7a4d73c86c1a69d3fc /services
parent582b868c4466b25dd8a8e21c423b9180d25dac41 (diff)
downloadframeworks_base-e75b9e355500b7c6a05e4d6ec54ef48835707caa.zip
frameworks_base-e75b9e355500b7c6a05e4d6ec54ef48835707caa.tar.gz
frameworks_base-e75b9e355500b7c6a05e4d6ec54ef48835707caa.tar.bz2
Non-functional code cleanup of ConnectivityService.
1. Remove ConnectivityService.findConnectionTypeForIface() as this can be done just as easily with supported APIs now. 2. Avoid making copies of Network objects as this precludes reuse of Network internals (e.g. socket factory, connection pool). Change-Id: I52f92e35d769d8350471f485e408169608630082
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java33
-rw-r--r--services/core/java/com/android/server/connectivity/Vpn.java19
2 files changed, 21 insertions, 31 deletions
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index d9ef766..3103592 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -721,7 +721,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
info = new NetworkInfo(nai.networkInfo);
lp = new LinkProperties(nai.linkProperties);
nc = new NetworkCapabilities(nai.networkCapabilities);
- network = new Network(nai.network);
+ // Network objects are outwardly immutable so there is no point to duplicating.
+ // Duplicating also precludes sharing socket factories and connection pools.
+ network = nai.network;
subscriberId = (nai.networkMisc != null) ? nai.networkMisc.subscriberId : null;
}
info.setType(networkType);
@@ -789,7 +791,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
info = new NetworkInfo(nai.networkInfo);
lp = new LinkProperties(nai.linkProperties);
nc = new NetworkCapabilities(nai.networkCapabilities);
- network = new Network(nai.network);
+ // Network objects are outwardly immutable so there is no point to duplicating.
+ // Duplicating also precludes sharing socket factories and connection pools.
+ network = nai.network;
subscriberId = (nai.networkMisc != null) ? nai.networkMisc.subscriberId : null;
}
}
@@ -967,13 +971,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
@Override
public Network[] getAllNetworks() {
enforceAccessPermission();
- final ArrayList<Network> result = new ArrayList();
synchronized (mNetworkForNetId) {
+ final Network[] result = new Network[mNetworkForNetId.size()];
for (int i = 0; i < mNetworkForNetId.size(); i++) {
- result.add(new Network(mNetworkForNetId.valueAt(i).network));
+ result[i] = mNetworkForNetId.valueAt(i).network;
}
+ return result;
}
- return result.toArray(new Network[result.size()]);
}
private NetworkCapabilities getNetworkCapabilitiesAndValidation(NetworkAgentInfo nai) {
@@ -2860,23 +2864,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
- public int findConnectionTypeForIface(String iface) {
- enforceConnectivityInternalPermission();
-
- if (TextUtils.isEmpty(iface)) return ConnectivityManager.TYPE_NONE;
-
- synchronized(mNetworkForNetId) {
- for (int i = 0; i < mNetworkForNetId.size(); i++) {
- NetworkAgentInfo nai = mNetworkForNetId.valueAt(i);
- LinkProperties lp = nai.linkProperties;
- if (lp != null && iface.equals(lp.getInterfaceName()) && nai.networkInfo != null) {
- return nai.networkInfo.getType();
- }
- }
- }
- return ConnectivityManager.TYPE_NONE;
- }
-
@Override
public int checkMobileProvisioning(int suggestedTimeOutMs) {
// TODO: Remove? Any reason to trigger a provisioning check?
@@ -3130,7 +3117,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
loge("Starting user already has a VPN");
return;
}
- userVpn = new Vpn(mHandler.getLooper(), mContext, mNetd, this, userId);
+ userVpn = new Vpn(mHandler.getLooper(), mContext, mNetd, userId);
mVpns.put(userId, userVpn);
}
}
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 8533f69..0896955 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -69,6 +69,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.security.Credentials;
import android.security.KeyStore;
+import android.text.TextUtils;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
@@ -114,7 +115,6 @@ public class Vpn {
private LegacyVpnRunner mLegacyVpnRunner;
private PendingIntent mStatusIntent;
private volatile boolean mEnableTeardown = true;
- private final IConnectivityManager mConnService;
private final INetworkManagementService mNetd;
private VpnConfig mConfig;
private NetworkAgent mNetworkAgent;
@@ -130,10 +130,9 @@ public class Vpn {
private final int mUserHandle;
public Vpn(Looper looper, Context context, INetworkManagementService netService,
- IConnectivityManager connService, int userHandle) {
+ int userHandle) {
mContext = context;
mNetd = netService;
- mConnService = connService;
mUserHandle = userHandle;
mLooper = looper;
@@ -1086,11 +1085,15 @@ public class Vpn {
// registering
mOuterInterface = mConfig.interfaze;
- try {
- mOuterConnection.set(
- mConnService.findConnectionTypeForIface(mOuterInterface));
- } catch (Exception e) {
- mOuterConnection.set(ConnectivityManager.TYPE_NONE);
+ if (!TextUtils.isEmpty(mOuterInterface)) {
+ final ConnectivityManager cm = ConnectivityManager.from(mContext);
+ for (Network network : cm.getAllNetworks()) {
+ final LinkProperties lp = cm.getLinkProperties(network);
+ if (lp != null && mOuterInterface.equals(lp.getInterfaceName())) {
+ final NetworkInfo networkInfo = cm.getNetworkInfo(network);
+ if (networkInfo != null) mOuterConnection.set(networkInfo.getType());
+ }
+ }
}
IntentFilter filter = new IntentFilter();