### Install DroidBot with Pip Source: https://context7.com/honeynet/droidbot/llms.txt Installs DroidBot in development mode using pip. Verify the installation by running the help command. ```bash git clone https://github.com/honeynet/droidbot.git cd droidbot/ pip install -e . droidbot -h ``` -------------------------------- ### Initialize DroidMaster for Distributed Testing Source: https://context7.com/honeynet/droidbot/llms.txt Configure and start the DroidMaster instance for distributed testing using QEMU. ```python master = DroidMaster( app_path="/path/to/app.apk", is_emulator=True, output_dir="./distributed_output", policy_name="dfs_greedy", event_count=1000, event_interval=1, timeout=7200, qemu_hda="/path/to/android.qcow2", # QEMU disk image qemu_no_graphic=True, # Headless mode grant_perm=True ) # Start distributed testing master.start() ``` -------------------------------- ### DroidBot Class Initialization Source: https://context7.com/honeynet/droidbot/llms.txt Initializes and starts a DroidBot instance for automated testing pipelines. ```APIDOC ## DroidBot Initialization ### Description Creates and configures a DroidBot instance to automate Android application testing. ### Parameters - **app_path** (string) - Required - Path to the APK file. - **device_serial** (string) - Optional - Serial number of the target device. - **policy_name** (string) - Optional - Exploration policy (e.g., dfs_greedy, bfs_greedy). - **event_count** (int) - Optional - Maximum number of events to generate. - **timeout** (int) - Optional - Test duration in seconds. ### Request Example ```python droidbot = DroidBot(app_path="/path/to/app.apk", policy_name="dfs_greedy", event_count=1000) droidbot.start() ``` ``` -------------------------------- ### Install DroidBot with Pip Source: https://github.com/honeynet/droidbot/blob/master/README.md Clone the DroidBot repository and install it using pip. This command installs DroidBot and its dependencies. ```shell git clone https://github.com/honeynet/droidbot.git cd droidbot/ pip install -e . ``` -------------------------------- ### Initialize Device Class for Low-Level Control Source: https://context7.com/honeynet/droidbot/llms.txt Connect to an Android device using the Device class for low-level control. Includes setup, connection, device information retrieval, app management, screenshots, state inspection, and input event simulation. ```python from droidbot.device import Device from droidbot.app import App # Connect to a device device = Device( device_serial="emulator-5554", is_emulator=True, output_dir="./output", cv_mode=False, grant_perm=True ) # Setup and connect device.set_up() device.connect() # Get device information print(f"SDK Version: {device.get_sdk_version()}") print(f"Model: {device.get_model_number()}") print(f"Display: {device.get_width()}x{device.get_height()}") # Install and start an app app = App("/path/to/app.apk", output_dir="./output") device.install_app(app) device.start_app(app) # Take a screenshot screenshot_path = device.take_screenshot() # Get current state with view hierarchy current_state = device.get_current_state() print(f"Current activity: {current_state.foreground_activity}") print(f"Number of views: {len(current_state.views)}") # Perform touch operations device.view_touch(500, 800) # Touch at coordinates device.view_long_touch(500, 800, 2000) # Long touch for 2 seconds device.view_drag((100, 100), (500, 500), 1000) # Drag gesture device.key_press("BACK") # Press back button # Input text device.view_set_text("Hello World") # Cleanup device.uninstall_app(app) device.disconnect() device.tear_down() ``` -------------------------------- ### DroidBotScript for Login Flow Source: https://context7.com/honeynet/droidbot/llms.txt Example of a DroidBotScript in JSON format to automate a login process. It defines views, states, and operations for setting text and performing touch events. ```json { "views": { "login_email": { "resource_id": ".*email", "class": ".*EditText" }, "login_password": { "resource_id": ".*password", "class": ".*EditText" }, "login_button": { "resource_id": ".*next", "class": ".*Button" } }, "states": { "login_state": { "views": ["login_email", "login_password", "login_button"] } }, "operations": { "login_operation": [ { "event_type": "set_text", "target_view": "login_email", "text": "sample@email.com" }, { "event_type": "set_text", "target_view": "login_password", "text": "sample_password" }, { "event_type": "touch", "target_view": "login_button" } ] }, "main": { "login_state": ["login_operation"] } } ``` -------------------------------- ### Method Profiling Configuration Source: https://context7.com/honeynet/droidbot/llms.txt Enable method execution tracing for performance analysis using full or sampled modes. ```bash # Full method profiling droidbot -a app.apk -o output -use_method_profiling full # Sampled profiling (sampling rate in microseconds) droidbot -a app.apk -o output -use_method_profiling 1000 ``` -------------------------------- ### Initialize DroidBot with Full Configuration Source: https://context7.com/honeynet/droidbot/llms.txt Initialize DroidBot programmatically for integration into testing pipelines. Specify app path, device serial, output directory, policy, and various exploration parameters. ```python from droidbot import DroidBot # Initialize DroidBot with full configuration droidbot = DroidBot( app_path="/path/to/app.apk", device_serial="emulator-5554", # Optional: auto-detect if not specified is_emulator=True, output_dir="./test_output", policy_name="dfs_greedy", # Options: dfs_greedy, dfs_naive, bfs_greedy, bfs_naive, monkey, manual, none random_input=True, # Add randomness to exploration event_count=1000, # Maximum events to generate event_interval=1, # Seconds between events timeout=3600, # Test duration in seconds (-1 for unlimited) keep_app=False, # Keep app installed after testing keep_env=False, # Keep test environment (minicap, accessibility) cv_mode=False, # Use OpenCV for UI detection debug_mode=False, grant_perm=True, # Auto-grant permissions (Android 6.0+) script_path="./script.json", # Optional: custom script path humanoid=None, # Optional: Humanoid service address ignore_ad=True # Ignore ad views by resource_id ) # Start the test droidbot.start() ``` -------------------------------- ### View UTG Visualization Source: https://context7.com/honeynet/droidbot/llms.txt Serve the generated UTG visualization locally to view in a browser. ```bash # View UTG visualization cd output_dir python -m http.server 8000 # Open http://localhost:8000/index.html in browser ``` -------------------------------- ### Configure Computer Vision Mode Source: https://context7.com/honeynet/droidbot/llms.txt Enable OpenCV-based UI detection for applications lacking accessibility support. ```bash # Install OpenCV dependency pip install opencv-python # Run with CV mode enabled droidbot -a game.apk -o output -cv # CV mode requires output directory for screenshots droidbot -a game.apk -o output -cv -policy dfs_greedy ``` -------------------------------- ### Define and Send Input Events Source: https://context7.com/honeynet/droidbot/llms.txt Create various input events such as touches, swipes, scrolls, text input, and key presses, then dispatch them to the device. ```python long_touch = LongTouchEvent(x=500, y=800, duration=3000) # Swipe/drag event swipe = SwipeEvent( start_x=100, start_y=500, end_x=900, end_y=500, duration=500 ) # Scroll event with direction scroll = ScrollEvent( view=scrollable_view, direction="DOWN" # Options: UP, DOWN, LEFT, RIGHT ) # Text input event set_text = SetTextEvent(view=text_field_view, text="Hello World") # Key event back_key = KeyEvent(name="BACK") home_key = KeyEvent(name="HOME") menu_key = KeyEvent(name="MENU") # Intent event to start activity intent = Intent( prefix="start", action="android.intent.action.VIEW", data_uri="https://example.com" ) intent_event = IntentEvent(intent=intent) # Send events to device touch.send(device) scroll.send(device) ``` -------------------------------- ### Replay Recorded Test Sessions Source: https://context7.com/honeynet/droidbot/llms.txt Execute a previously recorded DroidBot test session using the replay policy. ```bash # Replay a previous test run droidbot -a app.apk -o new_output -replay_output ./previous_output -policy replay ``` -------------------------------- ### Analyze UI Transition Graph (UTG) Source: https://context7.com/honeynet/droidbot/llms.txt Access the UTG to retrieve graph statistics, check exploration status, and navigate between UI states. ```python from droidbot.utg import UTG # UTG is automatically created by UtgBasedInputPolicy # Access via input policy utg = input_policy.utg # Get graph statistics print(f"Total states: {len(utg.G.nodes())}") print(f"Total transitions: {utg.num_transitions}") print(f"Effective events: {utg.effective_event_count}") print(f"Reached activities: {len(utg.reached_activities)}") # Check if state/event is explored is_explored = utg.is_event_explored(event, current_state) is_state_explored = utg.is_state_explored(current_state) # Get navigation steps between states nav_steps = utg.get_navigation_steps(from_state, to_state) if nav_steps: for state, event in nav_steps: print(f"At {state.state_str}, do {event}") # Get reachable states from current state reachable = utg.get_reachable_states(current_state) ``` -------------------------------- ### Humanoid Integration for Input Generation Source: https://context7.com/honeynet/droidbot/llms.txt Configure DroidBot to use the Humanoid service for machine learning-based input generation. ```bash # Start with Humanoid service droidbot -a app.apk -o output -humanoid localhost:8080 ``` ```python # Humanoid integration in code droidbot = DroidBot( app_path="/path/to/app.apk", output_dir="./output", humanoid="localhost:8080" # Humanoid service address ) ``` -------------------------------- ### Use Different Exploration Policies Source: https://context7.com/honeynet/droidbot/llms.txt Commands to run DroidBot with various exploration policies, including different DFS and BFS strategies, monkey-style random testing, manual interaction, or no events. ```bash droidbot -a app.apk -o output -policy dfs_greedy ``` ```bash droidbot -a app.apk -o output -policy dfs_naive ``` ```bash droidbot -a app.apk -o output -policy bfs_greedy ``` ```bash droidbot -a app.apk -o output -policy bfs_naive ``` ```bash droidbot -a app.apk -o output -policy monkey ``` ```bash droidbot -a app.apk -o output -policy manual ``` ```bash droidbot -a app.apk -o output -policy none ``` -------------------------------- ### Distributed Testing Command Line Interface Source: https://context7.com/honeynet/droidbot/llms.txt Commands to initiate the master and worker nodes for distributed DroidBot execution. ```bash # Command line for distributed master droidbot -a app.apk -o output -distributed master \ -qemu_hda /path/to/android.qcow2 \ -qemu_no_graphic # Command line for distributed worker droidbot -a app.apk -o output -distributed worker \ -master http://localhost:8000/ ``` -------------------------------- ### Analyze Device State Source: https://context7.com/honeynet/droidbot/llms.txt Inspect the current UI hierarchy, activity stack, and available input events for the device. ```python # Get current device state state = device.get_current_state() # State properties print(f"State signature: {state.state_str}") print(f"Activity: {state.foreground_activity}") print(f"Activity stack: {state.activity_stack}") print(f"Background services: {state.background_services}") print(f"Screen size: {state.width}x{state.height}") # Access view hierarchy for view in state.views: print(f"Class: {view['class']}") print(f"Resource ID: {view.get('resource_id', 'N/A')}") print(f"Text: {view.get('text', '')}") print(f"Bounds: {view['bounds']}") print(f"Clickable: {view.get('clickable', False)}") print(f"Scrollable: {view.get('scrollable', False)}") # Get possible input events for current state possible_events = state.get_possible_input() for event in possible_events: print(f"Possible: {event}") # Save state to directory state.save2dir("./states") # Get text representation for LLM integration text_repr, activity, indexed_views = state.get_text_representation() print(text_repr) ``` -------------------------------- ### Initialize DroidMaster Source: https://context7.com/honeynet/droidbot/llms.txt Import the DroidMaster class for managing parallel testing across multiple emulator instances. ```python from droidbot.droidmaster import DroidMaster ``` -------------------------------- ### Run DroidBot with a Script Source: https://github.com/honeynet/droidbot/blob/master/README.md Use a JSON-formatted script to customize input for specific UI states during DroidBot analysis. This allows for more targeted testing. ```shell droidbot -a -o output_dir -script ``` -------------------------------- ### Run DroidBot with Humanoid Integration Source: https://github.com/honeynet/droidbot/blob/master/README.md Enable the -humanoid option to allow DroidBot to communicate with Humanoid for generating human-like test inputs. This can lead to more realistic test scenarios. ```shell droidbot -a -o output_dir -humanoid ``` -------------------------------- ### Run DroidBot with Custom Script Source: https://context7.com/honeynet/droidbot/llms.txt Command to execute DroidBot using a custom DroidBotScript file for automated UI interactions. ```bash droidbot -a app.apk -o output -script login_script.json ``` -------------------------------- ### Run DroidBot with Default Settings Source: https://context7.com/honeynet/droidbot/llms.txt Basic commands to run DroidBot on an Android app. Specify the APK path and output directory. Optionally, provide a device serial, grant permissions automatically, or indicate if running on an emulator. ```bash droidbot -a /path/to/app.apk -o output_dir ``` ```bash droidbot -a /path/to/app.apk -o output_dir -d emulator-5554 ``` ```bash droidbot -a /path/to/app.apk -o output_dir -grant_perm ``` ```bash droidbot -a /path/to/app.apk -o output_dir -is_emulator ``` -------------------------------- ### Device Class Control Source: https://context7.com/honeynet/droidbot/llms.txt Provides methods for low-level device interaction, including input events and app lifecycle management. ```APIDOC ## Device Control ### Description Allows programmatic control over an Android device, including gestures, key presses, and app management. ### Methods - **device.set_up()** - Initializes device environment. - **device.install_app(app)** - Installs the specified app. - **device.view_touch(x, y)** - Performs a touch event at coordinates. - **device.key_press(key)** - Simulates a hardware key press. - **device.take_screenshot()** - Captures the current device screen. ``` -------------------------------- ### Create DroidBot Input Events Source: https://context7.com/honeynet/droidbot/llms.txt Utilize DroidBot's input event classes for simulating user interactions. Includes TouchEvent, LongTouchEvent, SwipeEvent, ScrollEvent, SetTextEvent, KeyEvent, and IntentEvent. ```python from droidbot.input_event import ( TouchEvent, LongTouchEvent, SwipeEvent, ScrollEvent, SetTextEvent, KeyEvent, IntentEvent ) from droidbot.intent import Intent # Touch event at coordinates touch = TouchEvent(x=500, y=800) # Touch event targeting a view touch_view = TouchEvent(view=view_dict) # view_dict from device state ``` -------------------------------- ### Run DroidBot on an APK Source: https://github.com/honeynet/droidbot/blob/master/README.md Execute DroidBot to analyze an Android application. Specify the APK file path and the output directory. Use -d to specify a device if multiple are connected. ```shell droidbot -a -o output_dir ``` -------------------------------- ### Construct Android Intents Source: https://context7.com/honeynet/droidbot/llms.txt Generate various Android intents for activities, services, and broadcasts using the Intent class. ```python from droidbot.intent import Intent # Start an activity by component start_intent = Intent( prefix="start", suffix="com.example.app/com.example.app.MainActivity" ) # View intent with URI view_intent = Intent( prefix="start", action="android.intent.action.VIEW", data_uri="https://example.com" ) # Send SMS intent sms_intent = Intent( prefix="start", action="android.intent.action.SENDTO", data_uri="sms:1234567890", extra_string={"sms_body": "Hello from DroidBot"} ) # Call intent call_intent = Intent( prefix="start", action="android.intent.action.CALL", data_uri="tel:1234567890" ) # Broadcast intent broadcast_intent = Intent( prefix="broadcast", action="android.intent.action.BOOT_COMPLETED" ) # Add contact intent contact_intent = Intent( prefix="start", action="android.intent.action.INSERT", mime_type="vnd.android.cursor.dir/contact", extra_string={ "name": "Test User", "phone": "1234567890", "email": "test@example.com" } ) # Get command string cmd = start_intent.get_cmd() print(cmd) # "am start com.example.app/com.example.app.MainActivity" ``` -------------------------------- ### Analyze APK with App Class Source: https://context7.com/honeynet/droidbot/llms.txt Analyze APK files and extract metadata using the App class, which leverages Androguard. Retrieve package name, app name, main activity, permissions, activities, and SHA256 hash. ```python from droidbot.app import App # Load and analyze APK app = App("/path/to/app.apk", output_dir="./output") # Get app metadata print(f"Package name: {app.get_package_name()}") print(f"App name: {app.app_name}") print(f"Main activity: {app.get_main_activity()}") print(f"Permissions: {app.permissions}") print(f"Activities: {app.activities}") print(f"SHA256 hash: {app.hashes[2]}") # Get intents for app control start_intent = app.get_start_intent() stop_intent = app.get_stop_intent() # Get possible broadcast receivers broadcasts = app.get_possible_broadcasts() for broadcast in broadcasts: print(f"Broadcast: {broadcast}") ``` -------------------------------- ### Control Event Generation Source: https://context7.com/honeynet/droidbot/llms.txt Configure DroidBot's event generation by setting the event count, interval between events, and overall timeout. Options to add randomness and enable debug mode are also available. ```bash droidbot -a app.apk -o output -count 500 -interval 2 ``` ```bash droidbot -a app.apk -o output -timeout 3600 ``` ```bash droidbot -a app.apk -o output -random ``` ```bash droidbot -a app.apk -o output -debug ``` -------------------------------- ### Test Output Structure Source: https://context7.com/honeynet/droidbot/llms.txt Directory structure of the generated DroidBot test output. ```text output_dir/ ├── index.html # Interactive UTG viewer ├── utg.js # UTG graph data ├── states/ # Captured UI states │ ├── state_*.json # State JSON with view hierarchy │ └── screen_*.png # Screenshots ├── events/ # Event logs │ ├── event_*.json # Event details with before/after states │ └── event_trace_*.trace # Method traces (if profiling enabled) ├── views/ # Cropped view images ├── temp/ # Temporary files └── dumpsys_package_*.txt # Package info dump ``` -------------------------------- ### App Class Analysis Source: https://context7.com/honeynet/droidbot/llms.txt Analyzes APK files to extract metadata, permissions, and activity information. ```APIDOC ## App Analysis ### Description Uses Androguard to parse APK files and retrieve application details. ### Methods - **app.get_package_name()** - Returns the package name. - **app.get_main_activity()** - Returns the main entry activity. - **app.get_possible_broadcasts()** - Lists potential broadcast receivers. ``` -------------------------------- ### Define Probabilistic Script Operations Source: https://context7.com/honeynet/droidbot/llms.txt Define operations with specified probabilities for varied exploration. This JSON structure outlines views, states, operations, and the main execution flow with probabilities. ```json { "views": { "carousel": { "resource_id": ".*first_time_use_carousel" }, "skip_button": { "resource_id": ".*skip_welcome" } }, "states": { "welcome_state": { "views": ["carousel", "skip_button"] } }, "operations": { "swipe_operation": [ { "event_type": "scroll", "target_view": "carousel", "direction": "RIGHT" } ], "skip_operation": [ { "event_type": "touch", "target_view": "skip_button" } ] }, "main": { "welcome_state": [ {"op_id": "swipe_operation", "prob": 0.6}, {"op_id": "skip_operation", "prob": 0.2} ] } } ``` -------------------------------- ### Keep Environment During Multiple Runs Source: https://github.com/honeynet/droidbot/blob/master/README.md Use the -keep_env option to prevent DroidBot from re-installing the test environment for each app when testing a large number of applications. This can save time and resources. ```shell droidbot -a -o output_dir -keep_env ``` -------------------------------- ### Run DroidBot in CV Mode Source: https://github.com/honeynet/droidbot/blob/master/README.md Utilize the -cv option for apps that do not support view extraction through Accessibility, such as games built with Cocos2d or Unity3d. This mode may be helpful for analyzing such applications. ```shell droidbot -a -o output_dir -cv ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.