Skip to content

BasicFist/phone-ops

Phone Operations Project

Complete toolkit for managing and controlling your Android phone from your computer.

Current Device

  • Model: Google Pixel 7a
  • Android Version: 16
  • Serial: 2C161JEHN07969
  • IP Address: 192.168.1.13

Quick Start

# Add to PATH for easy access
export PATH="$HOME/LAB/projects/phone-ops/bin:$PATH"

# Launch phone control (scrcpy)
phone-control

# Get phone information
phone-info

# Take a screenshot
phone-screenshot

# Transfer files
phone-transfer pull /sdcard/DCIM/Camera/photo.jpg
phone-transfer push ~/file.pdf /sdcard/Download/

# Backup phone data
phone-backup

Directory Structure

phone-ops/
├── bin/                       # Executable scripts
│   ├── phone-connect          # Connection manager
│   ├── phone-setup-wifi       # WiFi setup helper
│   ├── phone-control          # Launch scrcpy
│   ├── phone-info             # Device information
│   ├── phone-screenshot       # Capture screenshots
│   ├── phone-transfer         # File transfer utility
│   ├── phone-backup           # Backup utility
│   ├── phone-organize         # File organization & cleanup
│   ├── phone-automate         # UI automation & flows
│   ├── phone-record           # Screen recording
│   ├── phone-input            # Text/key injection
│   ├── phone-monitor          # System monitoring
│   ├── phone-apps             # App management
│   ├── phone-test             # Automated testing
│   └── phone-security-scan    # Security analysis
├── backups/                   # Phone backups (timestamped)
├── screenshots/               # Screenshots & recordings
├── files/                     # Downloaded files
├── logs/                      # Operation logs
├── data/                      # General data storage
│   ├── apk-backups/           # APK backups
│   ├── test-results/          # Test outputs
│   ├── organization/          # File organization data
│   └── security-audit/        # Security scan results
├── phone-config.env           # Phone configuration
├── README.md                  # This file
├── QUICK-REFERENCE.md         # Quick command reference
├── SCRCPY-REFERENCE.md        # Complete scrcpy shortcuts
├── ADB-REFERENCE.md           # Complete ADB commands
├── AUTOMATION-COOKBOOK.md     # Automation recipes
├── OPTIMIZATION-GUIDE.md      # Performance & battery optimization
└── ORGANIZATION-GUIDE.md      # File organization & cleanup

Available Commands

Connection Management

phone-connect [wifi|usb|auto]

  • Manages connection to your phone
  • Auto-detects and connects via preferred method
  • Usage:
    phone-connect wifi    # Connect via WiFi
    phone-connect usb     # Connect via USB
    phone-connect auto    # Auto-detect (default)

phone-setup-wifi

  • One-time WiFi setup (requires USB initially)
  • Enables wireless ADB connection
  • Updates configuration file with phone IP
  • Usage:
    # Connect phone via USB first
    phone-setup-wifi
    # Now you can unplug USB cable

Phone Control

phone-control [scrcpy-options]

  • Launches scrcpy with automatic device selection
  • Supports all scrcpy command-line options
  • Usage:
    phone-control                    # Basic launch
    phone-control --turn-screen-off  # Launch with screen off
    phone-control --max-size 1920    # Limit resolution

Scrcpy Keyboard Shortcuts:

  • Ctrl+s - Switch phone screen off
  • Ctrl+o - Turn phone screen on
  • Ctrl+r - Rotate screen
  • Ctrl+n - Expand notifications
  • Ctrl+h - Home button
  • Ctrl+b - Back button
  • Ctrl+f - Fullscreen toggle

Information & Monitoring

phone-info

  • Displays comprehensive device information
  • Shows battery status, storage, network, display specs
  • Usage:
    phone-info

File Operations

phone-screenshot

  • Captures screenshot and saves locally
  • Auto-generates timestamped filename
  • Saves to screenshots/ directory
  • Usage:
    phone-screenshot
    # Returns: /home/miko/LAB/projects/phone-ops/screenshots/screenshot_20251002_131500.png

phone-transfer <command> [args]

  • Bidirectional file transfer
  • APK installation
  • Usage:
    # Send file to phone
    phone-transfer push ~/document.pdf /sdcard/Download/
    
    # Get file from phone
    phone-transfer pull /sdcard/DCIM/Camera/IMG_1234.jpg
    phone-transfer pull /sdcard/DCIM/Camera/IMG_1234.jpg ~/Pictures/
    
    # Install APK
    phone-transfer install ~/Downloads/app.apk

File Organization

phone-organize <command> [options]

  • Automated file organization and cleanup
  • Commands: scan, by-type, by-date, find-duplicates, remove-duplicates, disk-usage, clean-empty, all
  • Organizes Downloads, Documents, Pictures (excludes camera roll)
  • Usage:
    # Analyze current file distribution
    phone-organize scan
    
    # Organize files by type (PDF → Documents, MP3 → Music, etc.)
    phone-organize by-type --dry-run    # Preview first
    phone-organize by-type               # Apply
    
    # Organize Downloads by date (YYYY/MM folders)
    phone-organize by-date
    
    # Find duplicate files (size + MD5 hash)
    phone-organize find-duplicates
    
    # Show disk usage by folder
    phone-organize disk-usage
    
    # Remove empty directories
    phone-organize clean-empty
    
    # Full workflow (scan → organize → duplicates → cleanup)
    phone-organize all --dry-run

File Type Categories:

  • Documents: PDF, DOC, DOCX, TXT, EPUB, XLS, PPT
  • Pictures: JPG, PNG, GIF, WEBP (downloaded/screenshots only)
  • Music: MP3, M4A, FLAC, WAV, AAC
  • Movies: MP4, MKV, AVI, MOV, WEBM
  • Archives: ZIP, RAR, 7Z, APK, JAR
  • Code: JAVA, PY, JS, HTML, CSS, JSON

Note: Camera photos (/sdcard/DCIM/Camera/) are never touched.

Backup & Recovery

phone-backup

  • Creates timestamped backup of phone data
  • Backs up: Photos (DCIM), Downloads, Pictures
  • Saves installed apps list
  • Saves device information
  • Usage:
    phone-backup
    # Creates: backups/20251002_131500/

Automation & Testing

phone-automate <command>

  • UI automation and flow execution
  • Commands: tap, swipe, type, key, launch, flow
  • Usage:
    phone-automate tap 540 960
    phone-automate type "Hello World"
    phone-automate swipe up
    phone-automate flow ~/automation/login.txt

phone-record [options] [filename]

  • Enhanced screen recording with quality options
  • Options: --time, --bitrate, --size
  • Usage:
    phone-record demo.mp4
    phone-record --time 30 --bitrate 8M hq-demo.mp4

phone-input <command>

  • Text injection and key event simulation
  • Commands: text, key, tap, swipe, longpress
  • Usage:
    phone-input text "Hello World"
    phone-input key enter
    phone-input swipe up

phone-monitor <command>

  • Real-time system monitoring
  • Commands: battery, cpu, memory, network, app, logs, all
  • Usage:
    phone-monitor battery
    phone-monitor app com.example.app
    phone-monitor all --interval 2

phone-apps <command>

  • Comprehensive app management
  • Commands: list, info, install, batch-install, backup, backup-all, launch, stop, clear
  • Usage:
    phone-apps list 3rd
    phone-apps info com.android.chrome
    phone-apps batch-install ~/Downloads/apps/
    phone-apps backup-all

phone-test <command>

  • Automated UI testing
  • Commands: monkey, launch-test, ui-test, screenshot-compare, stress
  • Usage:
    phone-test monkey com.example.app 1000
    phone-test launch-test com.example.app 10
    phone-test stress com.example.app 300

System Optimization

phone-optimize <profile>

  • Apply optimization profiles for performance or battery life
  • Profiles: performance, battery, balanced, gaming, restore
  • Commands: status, cache-clear, bloat-list, monitor
  • Usage:
    phone-optimize performance      # Maximum speed
    phone-optimize battery          # Maximum battery life
    phone-optimize balanced         # Best of both
    phone-optimize gaming           # Gaming optimized
    phone-optimize status           # Show current settings
    phone-optimize cache-clear      # Free up space
    phone-optimize --dry-run battery # Preview changes

Configuration

Edit phone-config.env to customize settings:

PHONE_MODEL="Pixel 7a"
PHONE_MANUFACTURER="Google"
PHONE_ANDROID_VERSION="16"
PHONE_IP="192.168.1.13"
PHONE_PORT="5555"
PHONE_SERIAL="2C161JEHN07969"
PHONE_CONNECTION_TYPE="wifi"  # wifi or usb

Initial Setup

Prerequisites

  • ADB (Android Debug Bridge) - sudo dnf install android-tools
  • scrcpy - sudo dnf install scrcpy
  • Android phone with Developer Options enabled

Enable Developer Options

On your phone:

  1. Go to Settings → About phone
  2. Tap Build number 7 times
  3. Go back to Settings → Developer Options
  4. Enable USB debugging

First-Time WiFi Setup

# 1. Connect phone via USB
# 2. Accept USB debugging prompt on phone
# 3. Run WiFi setup
phone-setup-wifi

# 4. Unplug USB cable
# 5. Test connection
phone-connect wifi
phone-control

Troubleshooting

Phone Not Detected

# Check USB connection
adb devices

# Restart ADB server
adb kill-server
adb start-server
adb devices

WiFi Connection Lost

# Reconnect
phone-connect wifi

# Or setup again with USB
phone-setup-wifi

Update Phone IP Address

If your phone gets a new IP:

# Connect via USB temporarily
phone-connect usb

# Get new IP
adb shell ip route | grep -oP 'src \K[\d.]+'

# Update phone-config.env manually or run:
phone-setup-wifi

Advanced Usage

Custom scrcpy Settings

# High quality, lower latency
phone-control --bit-rate 8M --max-fps 60

# Portrait mode, smaller window
phone-control --max-size 1080 --rotation 0

# Audio forwarding (scrcpy 2.0+)
phone-control --audio-source=playback

# Record screen to file
phone-control --record=recording.mp4

Automation Examples

# Daily backup script
#!/bin/bash
phone-connect wifi && phone-backup

# Screenshot every 5 seconds
#!/bin/bash
while true; do
    phone-screenshot
    sleep 5
done

# Monitor battery
#!/bin/bash
watch -n 60 'phone-info | grep -A3 "Battery Status"'

Integration with LAB Workspace

This project integrates with the broader LAB workspace:

  • MCP Servers: Can use cloudflare-container to run Android automation scripts
  • Jupyter Notebooks: Analyze phone data exports
  • Perplexity: Research Android automation techniques

Security Notes

  • USB debugging grants significant device access
  • Only connect to trusted computers
  • Disable USB debugging when not needed
  • Use "Always allow" checkbox only on personal computers
  • WiFi debugging is less secure than USB - use on trusted networks only

Documentation

Reference Guides

External Resources

License

Personal use - Part of LAB workspace


Last Updated: 2025-10-02 Maintainer: Mickael Souedan

About

Mobile device operations toolkit

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages