Opportunistic cleanup

Test: FrameworksNetTests NetworkStackTests
Change-Id: I370ad15fb0d8301f9720caf5296365c04aebeb62
This commit is contained in:
Chalard Jean
2019-09-26 18:03:47 +09:00
parent b96ef8f5c0
commit fbab6d4a26
2 changed files with 31 additions and 39 deletions

View File

@@ -495,7 +495,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
* arg1 = One of the NETWORK_TESTED_RESULT_* constants. * arg1 = One of the NETWORK_TESTED_RESULT_* constants.
* arg2 = NetID. * arg2 = NetID.
*/ */
public static final int EVENT_NETWORK_TESTED = 41; private static final int EVENT_NETWORK_TESTED = 41;
/** /**
* Event for NetworkMonitor/NetworkAgentInfo to inform ConnectivityService that the private DNS * Event for NetworkMonitor/NetworkAgentInfo to inform ConnectivityService that the private DNS
@@ -503,7 +503,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
* obj = PrivateDnsConfig * obj = PrivateDnsConfig
* arg2 = netid * arg2 = netid
*/ */
public static final int EVENT_PRIVATE_DNS_CONFIG_RESOLVED = 42; private static final int EVENT_PRIVATE_DNS_CONFIG_RESOLVED = 42;
/** /**
* Request ConnectivityService display provisioning notification. * Request ConnectivityService display provisioning notification.
@@ -511,12 +511,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
* arg2 = NetID. * arg2 = NetID.
* obj = Intent to be launched when notification selected by user, null if !arg1. * obj = Intent to be launched when notification selected by user, null if !arg1.
*/ */
public static final int EVENT_PROVISIONING_NOTIFICATION = 43; private static final int EVENT_PROVISIONING_NOTIFICATION = 43;
/** /**
* This event can handle dismissing notification by given network id. * This event can handle dismissing notification by given network id.
*/ */
public static final int EVENT_TIMEOUT_NOTIFICATION = 44; private static final int EVENT_TIMEOUT_NOTIFICATION = 44;
/** /**
* Used to specify whether a network should be used even if connectivity is partial. * Used to specify whether a network should be used even if connectivity is partial.
@@ -531,13 +531,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification * Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
* should be shown. * should be shown.
*/ */
public static final int PROVISIONING_NOTIFICATION_SHOW = 1; private static final int PROVISIONING_NOTIFICATION_SHOW = 1;
/** /**
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification * Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
* should be hidden. * should be hidden.
*/ */
public static final int PROVISIONING_NOTIFICATION_HIDE = 0; private static final int PROVISIONING_NOTIFICATION_HIDE = 0;
private static String eventName(int what) { private static String eventName(int what) {
return sMagicDecoderRing.get(what, Integer.toString(what)); return sMagicDecoderRing.get(what, Integer.toString(what));
@@ -1938,7 +1938,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
return mPolicyManagerInternal.isUidNetworkingBlocked(uid, uidRules, return NetworkPolicyManagerInternal.isUidNetworkingBlocked(uid, uidRules,
isNetworkMetered, isBackgroundRestricted); isNetworkMetered, isBackgroundRestricted);
} }
@@ -2204,7 +2204,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
final String iface = networkAgent.linkProperties.getInterfaceName(); final String iface = networkAgent.linkProperties.getInterfaceName();
final int timeout; final int timeout;
int type = ConnectivityManager.TYPE_NONE; final int type;
if (networkAgent.networkCapabilities.hasTransport( if (networkAgent.networkCapabilities.hasTransport(
NetworkCapabilities.TRANSPORT_CELLULAR)) { NetworkCapabilities.TRANSPORT_CELLULAR)) {
@@ -2219,11 +2219,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
15); 15);
type = ConnectivityManager.TYPE_WIFI; type = ConnectivityManager.TYPE_WIFI;
} else { } else {
// do not track any other networks return; // do not track any other networks
timeout = 0;
} }
if (timeout > 0 && iface != null && type != ConnectivityManager.TYPE_NONE) { if (timeout > 0 && iface != null) {
try { try {
mNMS.addIdleTimer(iface, timeout, type); mNMS.addIdleTimer(iface, timeout, type);
} catch (Exception e) { } catch (Exception e) {
@@ -2299,7 +2298,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
@VisibleForTesting @VisibleForTesting
protected static final String DEFAULT_TCP_BUFFER_SIZES = "4096,87380,110208,4096,16384,110208"; protected static final String DEFAULT_TCP_BUFFER_SIZES = "4096,87380,110208,4096,16384,110208";
private static final String DEFAULT_TCP_RWND_KEY = "net.tcp.default_init_rwnd";
private void updateTcpBufferSizes(String tcpBufferSizes) { private void updateTcpBufferSizes(String tcpBufferSizes) {
String[] values = null; String[] values = null;
@@ -2375,7 +2373,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
@Override @Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter writer,
@Nullable String[] args) {
PriorityDump.dump(mPriorityDumper, fd, writer, args); PriorityDump.dump(mPriorityDumper, fd, writer, args);
} }
@@ -2837,7 +2836,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
private NetworkMonitorCallbacks(NetworkAgentInfo nai) { private NetworkMonitorCallbacks(NetworkAgentInfo nai) {
mNetId = nai.network.netId; mNetId = nai.network.netId;
mNai = new AutodestructReference(nai); mNai = new AutodestructReference<>(nai);
} }
@Override @Override
@@ -4292,7 +4291,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
public void onChange(boolean selfChange, Uri uri) { public void onChange(boolean selfChange, Uri uri) {
final Integer what = mUriEventMap.get(uri); final Integer what = mUriEventMap.get(uri);
if (what != null) { if (what != null) {
mHandler.obtainMessage(what.intValue()).sendToTarget(); mHandler.obtainMessage(what).sendToTarget();
} else { } else {
loge("No matching event to send for URI=" + uri); loge("No matching event to send for URI=" + uri);
} }
@@ -4729,12 +4728,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
private static final String ATTR_MNC = "mnc"; private static final String ATTR_MNC = "mnc";
private String getProvisioningUrlBaseFromFile() { private String getProvisioningUrlBaseFromFile() {
FileReader fileReader = null; XmlPullParser parser;
XmlPullParser parser = null;
Configuration config = mContext.getResources().getConfiguration(); Configuration config = mContext.getResources().getConfiguration();
try { try (FileReader fileReader = new FileReader(mProvisioningUrlFile)) {
fileReader = new FileReader(mProvisioningUrlFile);
parser = Xml.newPullParser(); parser = Xml.newPullParser();
parser.setInput(fileReader); parser.setInput(fileReader);
XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS); XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
@@ -4769,12 +4766,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
loge("Xml parser exception reading Carrier Provisioning Urls file: " + e); loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
} catch (IOException e) { } catch (IOException e) {
loge("I/O exception reading Carrier Provisioning Urls file: " + e); loge("I/O exception reading Carrier Provisioning Urls file: " + e);
} finally {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {}
}
} }
return null; return null;
} }
@@ -5104,8 +5095,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
// This checks that the passed capabilities either do not request a specific SSID/SignalStrength // This checks that the passed capabilities either do not request a
// , or the calling app has permission to do so. // specific SSID/SignalStrength, or the calling app has permission to do so.
private void ensureSufficientPermissionsForRequest(NetworkCapabilities nc, private void ensureSufficientPermissionsForRequest(NetworkCapabilities nc,
int callerPid, int callerUid) { int callerPid, int callerUid) {
if (null != nc.getSSID() && !checkSettingsPermission(callerPid, callerUid)) { if (null != nc.getSSID() && !checkSettingsPermission(callerPid, callerUid)) {
@@ -5238,7 +5229,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
final int uid = Binder.getCallingUid(); final int uid = Binder.getCallingUid();
Integer uidReqs = mBandwidthRequests.get(uid); Integer uidReqs = mBandwidthRequests.get(uid);
if (uidReqs == null) { if (uidReqs == null) {
uidReqs = new Integer(0); uidReqs = 0;
} }
mBandwidthRequests.put(uid, ++uidReqs); mBandwidthRequests.put(uid, ++uidReqs);
} }
@@ -5572,7 +5563,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties newLp, private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties newLp,
LinkProperties oldLp) { @NonNull LinkProperties oldLp) {
int netId = networkAgent.network.netId; int netId = networkAgent.network.netId;
// The NetworkAgentInfo does not know whether clatd is running on its network or not, or // The NetworkAgentInfo does not know whether clatd is running on its network or not, or
@@ -5687,7 +5678,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/ */
private boolean updateRoutes(LinkProperties newLp, LinkProperties oldLp, int netId) { private boolean updateRoutes(LinkProperties newLp, LinkProperties oldLp, int netId) {
// Compare the route diff to determine which routes should be added and removed. // Compare the route diff to determine which routes should be added and removed.
CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>( CompareResult<RouteInfo> routeDiff = new CompareResult<>(
oldLp != null ? oldLp.getAllRoutes() : null, oldLp != null ? oldLp.getAllRoutes() : null,
newLp != null ? newLp.getAllRoutes() : null); newLp != null ? newLp.getAllRoutes() : null);
@@ -5706,7 +5697,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
for (RouteInfo route : routeDiff.added) { for (RouteInfo route : routeDiff.added) {
if (route.hasGateway() == false) continue; if (!route.hasGateway()) continue;
if (VDBG || DDBG) log("Adding Route [" + route + "] to network " + netId); if (VDBG || DDBG) log("Adding Route [" + route + "] to network " + netId);
try { try {
mNMS.addRoute(netId, route); mNMS.addRoute(netId, route);
@@ -5935,8 +5926,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
* 3. the VPN is fully-routed * 3. the VPN is fully-routed
* 4. the VPN interface is non-null * 4. the VPN interface is non-null
* *
* @See INetd#firewallAddUidInterfaceRules * @see INetd#firewallAddUidInterfaceRules
* @See INetd#firewallRemoveUidInterfaceRules * @see INetd#firewallRemoveUidInterfaceRules
*/ */
private boolean requiresVpnIsolation(@NonNull NetworkAgentInfo nai, NetworkCapabilities nc, private boolean requiresVpnIsolation(@NonNull NetworkAgentInfo nai, NetworkCapabilities nc,
LinkProperties lp) { LinkProperties lp) {
@@ -7051,9 +7042,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
@Override @Override
public void onShellCommand(FileDescriptor in, FileDescriptor out, public void onShellCommand(@NonNull FileDescriptor in, @NonNull FileDescriptor out,
FileDescriptor err, String[] args, ShellCallback callback, FileDescriptor err, @NonNull String[] args, ShellCallback callback,
ResultReceiver resultReceiver) { @NonNull ResultReceiver resultReceiver) {
(new ShellCmd()).exec(this, in, out, err, args, callback, resultReceiver); (new ShellCmd()).exec(this, in, out, err, args, callback, resultReceiver);
} }

View File

@@ -16,6 +16,7 @@
package com.android.server.connectivity; package com.android.server.connectivity;
import android.annotation.NonNull;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.IDnsResolver; import android.net.IDnsResolver;
import android.net.INetd; import android.net.INetd;
@@ -325,13 +326,13 @@ public class Nat464Xlat extends BaseNetworkObserver {
* This is necessary because the LinkProperties in mNetwork come from the transport layer, which * This is necessary because the LinkProperties in mNetwork come from the transport layer, which
* has no idea that 464xlat is running on top of it. * has no idea that 464xlat is running on top of it.
*/ */
public void fixupLinkProperties(LinkProperties oldLp, LinkProperties lp) { public void fixupLinkProperties(@NonNull LinkProperties oldLp, @NonNull LinkProperties lp) {
lp.setNat64Prefix(mNat64Prefix); lp.setNat64Prefix(mNat64Prefix);
if (!isRunning()) { if (!isRunning()) {
return; return;
} }
if (lp == null || lp.getAllInterfaceNames().contains(mIface)) { if (lp.getAllInterfaceNames().contains(mIface)) {
return; return;
} }
@@ -434,7 +435,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
@Override @Override
public void interfaceRemoved(String iface) { public void interfaceRemoved(String iface) {
mNetwork.handler().post(() -> { handleInterfaceRemoved(iface); }); mNetwork.handler().post(() -> handleInterfaceRemoved(iface));
} }
@Override @Override