public <T> T talkToService(IDevice device, Communicator<T> communicator) throws IOException { try { device.createForward(mLocalPort, mPackageName, IDevice.DeviceUnixSocketNamespace.ABSTRACT); } catch (TimeoutException e) { throw new IOException(e); } catch (AdbCommandRejectedException e2) { throw new IOException(e2); } try { return talkToServiceWithinPortForward(communicator, mLocalPort); } finally { try { device.removeForward(mLocalPort, mPackageName, IDevice.DeviceUnixSocketNamespace.ABSTRACT); } catch (IOException | TimeoutException | AdbCommandRejectedException e) { // we don't worry that much about failures while removing port forwarding mLogger.warning("Exception while removing port forward: " + e); } } }
/** * Removes a port forwarding between a local and a remote port. * * @param localPort the local port to forward * @param remotePort the remote port. * @throws TimeoutException in case of timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws IOException in case of I/O error on the connection. */ @Override public void removeForward(int localPort, int remotePort) throws TimeoutException, AdbCommandRejectedException, IOException { device.removeForward(localPort, remotePort); }
/** * Removes an existing port forwarding between a local and a remote port. * * @param localPort the local port to forward * @param remoteSocketName the remote unix domain socket name. * @param namespace namespace in which the unix domain socket was created * @throws TimeoutException in case of timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws IOException in case of I/O error on the connection. */ @Override public void removeForward(int localPort, String remoteSocketName, DeviceUnixSocketNamespace namespace) throws TimeoutException, AdbCommandRejectedException, IOException { device.removeForward(localPort, remoteSocketName, namespace); }
@Override public void removePortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.removeForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ").", e); } }
@Override public void removePortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.removeForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ").", e); } }
@Override public void removePortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.removeForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ").", e); } }