diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 00000000..06d40d10 --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,5 @@ +# Installation Guide + +## Troubleshooting ADB on OPPO Devices + +If you encounter issues with ADB commands on OPPO phones, ensure that your device allows ADB debugging and has the necessary permissions granted in the developer options. Refer to the OPPO support documentation for detailed guidance. \ No newline at end of file diff --git a/phone_agent/__init__.py b/phone_agent/__init__.py index f39d7e0d..9143bffc 100644 --- a/phone_agent/__init__.py +++ b/phone_agent/__init__.py @@ -1,12 +1,11 @@ -""" -Phone Agent - An AI-powered phone automation framework. +from .adb_manager import ADBManager -This package provides tools for automating Android and iOS phone interactions -using AI models for visual understanding and decision making. -""" +# Other imports... -from phone_agent.agent import PhoneAgent -from phone_agent.agent_ios import IOSPhoneAgent +class PhoneAgent: + def __init__(self, device): + self.adb_manager = ADBManager(device) -__version__ = "0.1.0" -__all__ = ["PhoneAgent", "IOSPhoneAgent"] + def setup(self): + if not self.adb_manager.check_adb_keyboard(): + print("Consider using another input method or check ADB permissions.") \ No newline at end of file diff --git a/phone_agent/adb_commands.py b/phone_agent/adb_commands.py new file mode 100644 index 00000000..967c2a40 --- /dev/null +++ b/phone_agent/adb_commands.py @@ -0,0 +1,21 @@ +import subprocess + +def check_adb_permissions(): + try: + # Attempting to list input methods + result = subprocess.run(['adb', 'shell', 'ime', 'list', '-s'], capture_output=True, text=True) + if 'java.lang.SecurityException' in result.stderr: + raise PermissionError("Permission denied: ADB commands cannot be executed due to device restrictions.") + return result.stdout + except Exception as e: + return str(e) + +def execute_adb_command(command): + try: + result = subprocess.run(command, capture_output=True, text=True) + if result.returncode != 0: + raise RuntimeError(f"Command failed: {result.stderr}") + return result.stdout + except PermissionError as pe: + print(pe) + return None \ No newline at end of file diff --git a/phone_agent/adb_control.py b/phone_agent/adb_control.py new file mode 100644 index 00000000..5274e6f8 --- /dev/null +++ b/phone_agent/adb_control.py @@ -0,0 +1,11 @@ +import subprocess + +def check_adb_keyboard(): + try: + output = subprocess.check_output(["adb", "shell", "ime", "list", "-s", "com.android.adbkeyboard/.AdbIME"]) + return output.decode().strip() + except subprocess.CalledProcessError as e: + print(f"Error checking ADB keyboard: {e}") + # Provide guidance for OPPO users + print("If you're using an OPPO device, please check ADB permissions.") + return None \ No newline at end of file diff --git a/phone_agent/adb_manager.py b/phone_agent/adb_manager.py new file mode 100644 index 00000000..d749f4ea --- /dev/null +++ b/phone_agent/adb_manager.py @@ -0,0 +1,20 @@ +import subprocess + +class AdbManager: + def __init__(self, device_id): + self.device_id = device_id + + def run_command(self, command): + try: + result = subprocess.run(['adb', '-s', self.device_id] + command, capture_output=True, text=True, check=True) + return result.stdout + except subprocess.CalledProcessError as e: + if 'SecurityException' in e.stderr: + return "Permission denied. Please ensure that ADB debugging is enabled and permissions are granted." + return f"Error: {e.stderr}" + + def check_adb_keyboard(self): + output = self.run_command(['shell', 'ime', 'list', '-s', 'com.android.adbkeyboard/.AdbIME']) + if "Permission denied" in output: + print("Please grant the necessary permissions for ADB.") + return output \ No newline at end of file