-
Notifications
You must be signed in to change notification settings - Fork 10
Send text using commands via simple cmds #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9ba1b32
updates to external_metadata.py for async and adding httpx dependancy
thomasm789 a558e10
fixes bugs in 64 ands 63
thomasm789 15df3fa
update default metadata
thomasm789 b20e500
further tweaks
thomasm789 74e8fd4
further tweaks
thomasm789 4709da4
adb poc
thomasm789 27ec593
update
thomasm789 1e2c497
merge from main
thomasm789 a7f53d2
update adb attempt
thomasm789 fe13f34
Merge remote-tracking branch 'origin/main' into android-adb
thomasm789 3ef5ba7
updates
thomasm789 17c2690
update
thomasm789 95ecaaf
lint
thomasm789 ced371e
isort
thomasm789 9573f72
update setupflow to allow for application list selection and if adb a…
thomasm789 ab015f7
testing
thomasm789 4ead16b
final commit - adding in apps configurator + adb + cleaning up adb ke…
thomasm789 fdefbfb
using idmapping if friendly names are already known + fixes
thomasm789 ca21a78
fixes
thomasm789 b0ae053
linting
thomasm789 2b621da
adding in requirements.txt
thomasm789 3739dd7
clean up
thomasm789 a799181
clean up
thomasm789 e35a2f8
replacing cache_root with config _get_data_root
thomasm789 f57eb1e
linting
thomasm789 447086e
adding send_text method
thomasm789 5044cd3
adding in simple commands for text entry via androidremote2
thomasm789 b76d49b
clean up
thomasm789 1a01857
add text backspace support
thomasm789 ca2c5d4
updating androidtv pem location to go into /certs folder
thomasm789 0f0f851
adding in enter
thomasm789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| """ | ||
| This module provides utilities for interacting with Android TVs via ADB (Android Debug Bridge). | ||
| It includes functions for managing ADB keys, connecting to devices, retrieving installed apps, | ||
| and verifying device authorization. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Dict, Optional | ||
|
|
||
| from adb_shell.adb_device_async import AdbDeviceTcpAsync | ||
| from adb_shell.auth.keygen import keygen | ||
| from adb_shell.auth.sign_pythonrsa import PythonRSASigner | ||
|
|
||
| ADB_CERTS_DIR = Path(os.environ.get("UC_CONFIG_HOME", "./config")) / "certs" | ||
| ADB_CERTS_DIR.mkdir(parents=True, exist_ok=True) | ||
|
|
||
|
|
||
| def get_adb_key_paths(device_id: str) -> tuple[Path, Path]: | ||
| """ | ||
| Return the paths to the private and public ADB keys for a given device. | ||
|
|
||
| Args: | ||
| device_id (str): The unique identifier for the device. | ||
|
|
||
| Returns: | ||
| tuple[Path, Path]: Paths to the private and public key files. | ||
| """ | ||
| priv = ADB_CERTS_DIR / f"adb_{device_id}" | ||
| pub = ADB_CERTS_DIR / f"adb_{device_id}.pub" | ||
| return priv, pub | ||
|
|
||
|
|
||
| def load_or_generate_adb_keys(device_id: str) -> PythonRSASigner: | ||
| """ | ||
| Ensure ADB RSA keys exist for the device and return the signer. | ||
|
|
||
| Args: | ||
| device_id (str): The unique identifier for the device. | ||
|
|
||
| Returns: | ||
| PythonRSASigner: The signer object for ADB authentication. | ||
| """ | ||
| priv_path, pub_path = get_adb_key_paths(device_id) | ||
|
|
||
| if not priv_path.exists() or not pub_path.exists(): | ||
| keygen(str(priv_path)) | ||
|
|
||
| with open(priv_path) as f: | ||
| priv = f.read() | ||
| with open(pub_path) as f: | ||
| pub = f.read() | ||
| return PythonRSASigner(pub, priv) | ||
|
|
||
|
|
||
| async def adb_connect(device_id: str, host: str, port: int = 5555) -> Optional[AdbDeviceTcpAsync]: | ||
| """ | ||
| Connect to an Android device via ADB. | ||
|
|
||
| Args: | ||
| device_id (str): The unique identifier for the device. | ||
| host (str): The IP address or hostname of the device. | ||
| port (int, optional): The port number for the ADB connection. Defaults to 5555. | ||
|
|
||
| Returns: | ||
| Optional[AdbDeviceTcpAsync]: The connected ADB device object, or None if the connection fails. | ||
| """ | ||
| signer = load_or_generate_adb_keys(device_id) | ||
| device = AdbDeviceTcpAsync(host, port, default_transport_timeout_s=9.0) | ||
|
|
||
| try: | ||
| await device.connect(rsa_keys=[signer], auth_timeout_s=20) | ||
| return device | ||
| except Exception as e: | ||
| print(f"ADB connection failed to {host}:{port} — {e}") | ||
| return None | ||
|
|
||
|
|
||
| async def get_installed_apps(device: AdbDeviceTcpAsync) -> Dict[str, Dict[str, str]]: | ||
| """ | ||
| Retrieve a list of installed non-system apps in a structured format. | ||
|
|
||
| Args: | ||
| device (AdbDeviceTcpAsync): The connected ADB device. | ||
|
|
||
| Returns: | ||
| Dict[str, Dict[str, str]]: A dictionary of app package names and their metadata. | ||
| """ | ||
| output = await device.shell("pm list packages -3 -e") | ||
| packages = sorted(line.replace("package:", "").strip() for line in output.splitlines()) | ||
| return {package: {"url": f"market://launch?id={package}"} for package in packages} | ||
|
|
||
|
|
||
| async def is_authorised(device: AdbDeviceTcpAsync) -> bool: | ||
| """ | ||
| Check if the connected device is authorized for ADB communication. | ||
|
|
||
| Args: | ||
| device (AdbDeviceTcpAsync): The connected ADB device. | ||
|
|
||
| Returns: | ||
| bool: True if the device is authorized, False otherwise. | ||
| """ | ||
| try: | ||
| result = await device.shell("echo ADB_OK") | ||
| return "ADB_OK" in result | ||
| except Exception: | ||
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be of type KeyPress IntEnum. Please enhance KeyPress with
TEXT = 5