From 6d475970a200f162ba6845d25bb2a777bcaa611c Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Mon, 16 May 2016 16:19:07 -0700 Subject: [PATCH] Fix trivial warnings in Tethering.java Add some missing @Override annotations. Use template arguments to avoid explicit casting. Ignore unclosed IndentingPrintWriter in dump(). Bug: 28798823 Test: Compiles. Change-Id: I2cb6eb384ca23057c8059f4842b1c0d8248d03f8 --- .../server/connectivity/Tethering.java | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 1012f9aa031f1..7c1973697af72 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -227,7 +227,7 @@ public class Tethering extends BaseNetworkObserver { int ifaceTypes[] = mContext.getResources().getIntArray( com.android.internal.R.array.config_tether_upstream_types); - Collection upstreamIfaceTypes = new ArrayList(); + Collection upstreamIfaceTypes = new ArrayList<>(); for (int i : ifaceTypes) { upstreamIfaceTypes.add(new Integer(i)); } @@ -644,23 +644,23 @@ public class Tethering extends BaseNetworkObserver { boolean bluetoothTethered = false; synchronized (mPublicSync) { - Set ifaces = mIfaces.keySet(); - for (Object iface : ifaces) { + Set ifaces = mIfaces.keySet(); + for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); if (sm != null) { if (sm.isErrored()) { - erroredList.add((String)iface); + erroredList.add(iface); } else if (sm.isAvailable()) { - availableList.add((String)iface); + availableList.add(iface); } else if (sm.isTethered()) { - if (isUsb((String)iface)) { + if (isUsb(iface)) { usbTethered = true; - } else if (isWifi((String)iface)) { + } else if (isWifi(iface)) { wifiTethered = true; - } else if (isBluetooth((String)iface)) { + } else if (isBluetooth(iface)) { bluetoothTethered = true; } - activeList.add((String)iface); + activeList.add(iface); } } } @@ -952,11 +952,11 @@ public class Tethering extends BaseNetworkObserver { public String[] getTetheredIfaces() { ArrayList list = new ArrayList(); synchronized (mPublicSync) { - Set keys = mIfaces.keySet(); - for (Object key : keys) { + Set keys = mIfaces.keySet(); + for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); if (sm.isTethered()) { - list.add((String)key); + list.add(key); } } } @@ -970,11 +970,11 @@ public class Tethering extends BaseNetworkObserver { public String[] getTetherableIfaces() { ArrayList list = new ArrayList(); synchronized (mPublicSync) { - Set keys = mIfaces.keySet(); - for (Object key : keys) { + Set keys = mIfaces.keySet(); + for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); if (sm.isAvailable()) { - list.add((String)key); + list.add(key); } } } @@ -992,11 +992,11 @@ public class Tethering extends BaseNetworkObserver { public String[] getErroredIfaces() { ArrayList list = new ArrayList(); synchronized (mPublicSync) { - Set keys = mIfaces.keySet(); - for (Object key : keys) { + Set keys = mIfaces.keySet(); + for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); if (sm.isErrored()) { - list.add((String)key); + list.add(key); } } } @@ -1076,6 +1076,7 @@ public class Tethering extends BaseNetworkObserver { setInitialState(mInitialState); } + @Override public String toString() { String res = new String(); res += mIfaceName + " - "; @@ -1442,7 +1443,7 @@ public class Tethering extends BaseNetworkObserver { * could/should be moved here. */ class UpstreamNetworkMonitor { - final HashMap mNetworkMap = new HashMap(); + final HashMap mNetworkMap = new HashMap<>(); NetworkCallback mDefaultNetworkCallback; NetworkCallback mDunTetheringCallback; @@ -1520,12 +1521,6 @@ public class Tethering extends BaseNetworkObserver { static final int EVENT_UPSTREAM_LINKPROPERTIES_CHANGED = BASE_MASTER + 5; static final int EVENT_UPSTREAM_LOST = BASE_MASTER + 6; - // This indicates what a timeout event relates to. A state that - // sends itself a delayed timeout event and handles incoming timeout events - // should inc this when it is entered and whenever it sends a new timeout event. - // We do not flush the old ones. - private int mSequenceNumber; - private State mInitialState; private State mTetherModeAliveState; @@ -1845,17 +1840,17 @@ public class Tethering extends BaseNetworkObserver { config_mobile_hotspot_provision_app_no_ui).isEmpty() == false) { ArrayList tethered = new ArrayList(); synchronized (mPublicSync) { - Set ifaces = mIfaces.keySet(); - for (Object iface : ifaces) { + Set ifaces = mIfaces.keySet(); + for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); if (sm != null && sm.isTethered()) { - if (isUsb((String)iface)) { + if (isUsb(iface)) { tethered.add(new Integer( ConnectivityManager.TETHERING_USB)); - } else if (isWifi((String)iface)) { + } else if (isWifi(iface)) { tethered.add(new Integer( ConnectivityManager.TETHERING_WIFI)); - } else if (isBluetooth((String)iface)) { + } else if (isBluetooth(iface)) { tethered.add(new Integer( ConnectivityManager.TETHERING_BLUETOOTH)); } @@ -2080,9 +2075,11 @@ public class Tethering extends BaseNetworkObserver { } } + @Override public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { + // Binder.java closes the resource for us. + @SuppressWarnings("resource") final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); - if (mContext.checkCallingOrSelfPermission( android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump ConnectivityService.Tether " + @@ -2108,6 +2105,5 @@ public class Tethering extends BaseNetworkObserver { pw.decreaseIndent(); } pw.decreaseIndent(); - return; } }