Make LocalSocket Closeable.
Enables usage of IoUtils.closeQuietly().
Change-Id: I91126297c1f235ae9da09f82d8f4f22db46558eb
diff --git a/api/current.txt b/api/current.txt
index 4b43318..6e0cd7c 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -12443,7 +12443,7 @@
method public android.net.LocalSocketAddress getLocalSocketAddress();
}
- public class LocalSocket {
+ public class LocalSocket implements java.io.Closeable {
ctor public LocalSocket();
method public void bind(android.net.LocalSocketAddress) throws java.io.IOException;
method public void close() throws java.io.IOException;
diff --git a/core/java/android/net/LocalSocket.java b/core/java/android/net/LocalSocket.java
index 34e0d9a..14a8094 100644
--- a/core/java/android/net/LocalSocket.java
+++ b/core/java/android/net/LocalSocket.java
@@ -16,6 +16,7 @@
package android.net;
+import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
@@ -26,7 +27,7 @@
* Creates a (non-server) socket in the UNIX-domain namespace. The interface
* here is not entirely unlike that of java.net.Socket
*/
-public class LocalSocket {
+public class LocalSocket implements Closeable {
private LocalSocketImpl impl;
private volatile boolean implCreated;
@@ -167,6 +168,7 @@
*
* @throws IOException
*/
+ @Override
public void close() throws IOException {
implCreateIfNeeded();
impl.close();
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index b12d597..d788eba 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -53,6 +53,8 @@
import java.nio.charset.Charsets;
import java.util.Arrays;
+import libcore.io.IoUtils;
+
/**
* @hide
*/
@@ -228,11 +230,7 @@
mConnection = connection;
mInterface = interfaze;
} catch (RuntimeException e) {
- try {
- tun.close();
- } catch (Exception ex) {
- // ignore
- }
+ IoUtils.closeQuietly(tun);
throw e;
}
Log.i(TAG, "Established by " + config.user + " on " + mInterface);
@@ -442,11 +440,7 @@
// We assume that everything is reset after stopping the daemons.
interrupt();
for (LocalSocket socket : mSockets) {
- try {
- socket.close();
- } catch (Exception e) {
- // ignore
- }
+ IoUtils.closeQuietly(socket);
}
}