# Android Automation & Interaction Standards

This document defines how the bot interacts with the Android OS and the Instagram UI.

## 1. No Fixed Coordinates
- **Never** hardcode `(x, y)` coordinates for clicks, swipes, or interactions.
- UI layouts change across devices (dpi, aspect ratios). All coordinates must be derived dynamically from the XML bounds of the target node.

## 2. Stealth & Interaction Physics (Bypass Bot Detection)
- **ABSOLUTE RULE:** You must **never** use raw, robotic input methods like `device.click()` or `device.swipe()`. Instagram will detect these mathematically perfect straight lines and constant speeds immediately and shadowban the account.
- **Mandatory Functions:** 
  - For clicking: Use `device.human_click(x, y)` which injects biological jitter and realistic touch down/up timings via sendevent.
  - For swiping: Use `device.human_swipe(start_x, start_y, end_x, end_y)` or `humanized_scroll()`. These utilize Bezier curves and variable acceleration (Dopamine Pacing Engine) to simulate human thumbs.
- **Micro-Delays:** Always inject `random_sleep()` between interactions to simulate human perception and reaction time. Never execute zero-delay sequential clicks.

## 3. UIAutomator2 / DeviceFacade
- All hardware interactions must go through the `DeviceFacade`.
- Do not instantiate raw `uiautomator2` connections deep in the business logic.
- If the app crashes or the connection drops, rely on the global error handling and recovery loops in `run.py` to restart the ADB server or the app.

## 4. Node Validation
- **Do not trust text matching alone.** Text can be user-generated (e.g., a bio saying "Follow me").
- Always validate the structural identity of a node using its `resource-id` or its hierarchical position within the XML tree to prevent malicious user-generated content from triggering bot actions.
