diff options
author | Steve Block <steveblock@google.com> | 2010-09-28 13:48:44 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-28 14:21:03 +0100 |
commit | 898bfbd865496855c3a6c792f9e0da011ae34854 (patch) | |
tree | c045d8d4689fade071f50e47c88264d585660d41 /tests/DumpRenderTree2/src | |
parent | 5c23ebadd48c8c3190878030a9974f1ff36b0419 (diff) | |
download | frameworks_base-898bfbd865496855c3a6c792f9e0da011ae34854.zip frameworks_base-898bfbd865496855c3a6c792f9e0da011ae34854.tar.gz frameworks_base-898bfbd865496855c3a6c792f9e0da011ae34854.tar.bz2 |
Prevent DumpRenderTree2 from crashing when the host server is not running
Bug: 3010758
Change-Id: I04a01634544d223d225b264827d3cf18be74e1e0
Diffstat (limited to 'tests/DumpRenderTree2/src')
3 files changed, 26 insertions, 29 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java index 086ff59..224509d 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java @@ -40,15 +40,10 @@ public class AdbUtils { * remote machine. This can be achieved by calling configureSocket() * * @return a socket that can be configured to link to remote machine + * @throws IOException */ - public static Socket createSocket() { - Socket socket = null; - try { - socket = new Socket(ADB_HOST, ADB_PORT); - } catch (IOException e) { - Log.e(LOG_TAG, "Creation failed.", e); - } - return socket; + public static Socket createSocket() throws IOException{ + return new Socket(ADB_HOST, ADB_PORT); } /** @@ -72,9 +67,9 @@ public class AdbUtils { outputStream.write(cmd.getBytes()); int read = inputStream.read(buf); if (read != ADB_RESPONSE_SIZE || !ADB_OK.equals(new String(buf))) { - Log.w(LOG_TAG, "adb cmd faild."); + Log.w(LOG_TAG, "adb cmd failed."); return false; } return true; } -}
\ No newline at end of file +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java index 4f01dae..f19cd41 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java @@ -93,7 +93,8 @@ public class ConnectionHandler { private OnFinishedCallback mOnFinishedCallback; - public ConnectionHandler(String remoteMachineIp, int port, Socket fromSocket, Socket toSocket) { + public ConnectionHandler(String remoteMachineIp, int port, Socket fromSocket, Socket toSocket) + throws IOException { mRemoteMachineIpAddress = remoteMachineIp; mPort = port; @@ -105,14 +106,12 @@ public class ConnectionHandler { mToSocketInputStream = mToSocket.getInputStream(); mFromSocketOutputStream = mFromSocket.getOutputStream(); mToSocketOutputStream = mToSocket.getOutputStream(); - if (!AdbUtils.configureConnection(mToSocketInputStream, mToSocketOutputStream, - mRemoteMachineIpAddress, mPort)) { - throw new IOException("Configuring socket failed!"); - } + AdbUtils.configureConnection(mToSocketInputStream, mToSocketOutputStream, + mRemoteMachineIpAddress, mPort); } catch (IOException e) { Log.e(LOG_TAG, "Unable to start ConnectionHandler", e); closeStreams(); - return; + throw e; } mFromToPipe = new SocketPipeThread(mFromSocketInputStream, mToSocketOutputStream); @@ -170,4 +169,4 @@ public class ConnectionHandler { } } } -}
\ No newline at end of file +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java index b361a89..ce22fa0 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java @@ -61,7 +61,6 @@ public class Forwarder extends Thread { public void run() { while (true) { Socket localSocket; - Socket remoteSocket; try { localSocket = mServerSocket.accept(); } catch (IOException e) { @@ -70,24 +69,28 @@ public class Forwarder extends Thread { break; } - remoteSocket = AdbUtils.createSocket(); - - if (remoteSocket == null) { + Socket remoteSocket = null; + final ConnectionHandler connectionHandler; + try { + remoteSocket = AdbUtils.createSocket(); + connectionHandler = new ConnectionHandler( + mRemoteMachineIpAddress, mPort, localSocket, remoteSocket); + } catch (IOException exception) { try { localSocket.close(); } catch (IOException e) { Log.e(LOG_TAG, "mPort=" + mPort, e); } - - Log.e(LOG_TAG, "run(): mPort= " + mPort + " Failed to start forwarding from " + - localSocket); + if (remoteSocket != null) { + try { + remoteSocket.close(); + } catch (IOException e) { + Log.e(LOG_TAG, "mPort=" + mPort, e); + } + } continue; } - final ConnectionHandler connectionHandler = - new ConnectionHandler(mRemoteMachineIpAddress, mPort, localSocket, - remoteSocket); - /** * We have to close the sockets after the ConnectionHandler finishes, so we * don't get "Too may open files" exception. We also remove the ConnectionHandler @@ -126,4 +129,4 @@ public class Forwarder extends Thread { Log.e(LOG_TAG, "mPort=" + mPort, e); } } -}
\ No newline at end of file +} |