Skip to content

Commit 065b299

Browse files
committed
Make LocalSocket Closeable.
Enables usage of IoUtils.closeQuietly(). Change-Id: I91126297c1f235ae9da09f82d8f4f22db46558eb
1 parent 187019c commit 065b299

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12443,7 +12443,7 @@ package android.net {
1244312443
method public android.net.LocalSocketAddress getLocalSocketAddress();
1244412444
}
1244512445

12446-
public class LocalSocket {
12446+
public class LocalSocket implements java.io.Closeable {
1244712447
ctor public LocalSocket();
1244812448
method public void bind(android.net.LocalSocketAddress) throws java.io.IOException;
1244912449
method public void close() throws java.io.IOException;

core/java/android/net/LocalSocket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.net;
1818

19+
import java.io.Closeable;
1920
import java.io.FileDescriptor;
2021
import java.io.IOException;
2122
import java.io.InputStream;
@@ -26,7 +27,7 @@
2627
* Creates a (non-server) socket in the UNIX-domain namespace. The interface
2728
* here is not entirely unlike that of java.net.Socket
2829
*/
29-
public class LocalSocket {
30+
public class LocalSocket implements Closeable {
3031

3132
private LocalSocketImpl impl;
3233
private volatile boolean implCreated;
@@ -167,6 +168,7 @@ public OutputStream getOutputStream() throws IOException {
167168
*
168169
* @throws IOException
169170
*/
171+
@Override
170172
public void close() throws IOException {
171173
implCreateIfNeeded();
172174
impl.close();

services/java/com/android/server/connectivity/Vpn.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import java.nio.charset.Charsets;
5454
import java.util.Arrays;
5555

56+
import libcore.io.IoUtils;
57+
5658
/**
5759
* @hide
5860
*/
@@ -228,11 +230,7 @@ public synchronized ParcelFileDescriptor establish(VpnConfig config) {
228230
mConnection = connection;
229231
mInterface = interfaze;
230232
} catch (RuntimeException e) {
231-
try {
232-
tun.close();
233-
} catch (Exception ex) {
234-
// ignore
235-
}
233+
IoUtils.closeQuietly(tun);
236234
throw e;
237235
}
238236
Log.i(TAG, "Established by " + config.user + " on " + mInterface);
@@ -442,11 +440,7 @@ public void exit() {
442440
// We assume that everything is reset after stopping the daemons.
443441
interrupt();
444442
for (LocalSocket socket : mSockets) {
445-
try {
446-
socket.close();
447-
} catch (Exception e) {
448-
// ignore
449-
}
443+
IoUtils.closeQuietly(socket);
450444
}
451445
}
452446

0 commit comments

Comments
 (0)