Skip to content

feat: add methods to close forward connections#196

Merged
codeskyblue merged 2 commits into
openatx:masterfrom
Yazan-Sharaya:forward_close
Oct 30, 2025
Merged

feat: add methods to close forward connections#196
codeskyblue merged 2 commits into
openatx:masterfrom
Yazan-Sharaya:forward_close

Conversation

@Yazan-Sharaya

Copy link
Copy Markdown
Contributor

This pull request introduces two new methods for device objects to close forwarded connections
as currently there is no way to kill forwards aside from killing the whole adb server (adb.server_kill()).
There are two new methods:

  • forward_close: close an existing forward connection
  • forward_close_all: close all open forwarded connections (device, not whole server).

Additionally, examples on how to forward connections and close them is added to the readme.

@codeskyblue

Copy link
Copy Markdown
Member

use forward_remove, forward_remove_all instead

@codeskyblue codeskyblue requested a review from Copilot October 30, 2025 09:10
@codecov

codecov Bot commented Oct 30, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.71%. Comparing base (7c43ec6) to head (d5e8530).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
adbutils/_device_base.py 18.18% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #196      +/-   ##
==========================================
- Coverage   34.80%   34.71%   -0.09%     
==========================================
  Files          17       17              
  Lines        2201     2212      +11     
  Branches      327      329       +2     
==========================================
+ Hits          766      768       +2     
- Misses       1390     1399       +9     
  Partials       45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds methods to close individual and all forwarded connections for Android devices, implementing functionality equivalent to adb forward --remove and adb forward --remove-all commands.

  • Added forward_close() method to remove a specific forwarded connection by local address
  • Added forward_close_all() method to remove all forwarded connections for a device
  • Updated README documentation with usage examples for the new methods and existing forward functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
adbutils/_device_base.py Implements forward_close() and forward_close_all() methods for managing forwarded connections
README.md Updated documentation to include examples for forward/close operations and corrected the section description

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread adbutils/_device_base.py

def forward_close_all(self) -> None:
"""Remove all forwarded network connections."""
self.open_transport("killforward-all").close()

Copilot AI Oct 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The forward_close_all method should use a context manager (with statement) for the connection cleanup, consistent with other methods in the codebase like forward_list, reverse, and reverse_list. This ensures proper resource cleanup even if an exception occurs.

Suggested change
self.open_transport("killforward-all").close()
with self.open_transport("killforward-all"):
pass

Copilot uses AI. Check for mistakes.
@codeskyblue codeskyblue merged commit 8d033f4 into openatx:master Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants