Skip to content

Commit 9c5c659

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Make LocalSocket Closeable." into jb-mr1-dev
2 parents fe33a09 + 065b299 commit 9c5c659

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
@@ -12446,7 +12446,7 @@ package android.net {
1244612446
method public android.net.LocalSocketAddress getLocalSocketAddress();
1244712447
}
1244812448

12449-
public class LocalSocket {
12449+
public class LocalSocket implements java.io.Closeable {
1245012450
ctor public LocalSocket();
1245112451
method public void bind(android.net.LocalSocketAddress) throws java.io.IOException;
1245212452
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)