Skip to content

Moksha89/virtual-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Virtual Android Emulator

Web-based virtual Android phone emulator with screen streaming and input forwarding.

🎯 Features

Phase 1: Core Infrastructure βœ…

  • βœ… Create virtual Android phones (Android 12)
  • βœ… Configurable RAM (2GB/4GB/8GB) and ROM (16GB/32GB/64GB)
  • βœ… Mobile phone screen size (1080x2340)
  • βœ… Touch/click input forwarding
  • βœ… Full Android OS functionality via redroid containers
  • βœ… RESTful API for instance management
  • βœ… Modern React UI with real-time updates

Phase 2: Real-Time Streaming βœ…

  • βœ… WebRTC screen streaming (real-time Android display in browser)
  • βœ… Camera streaming from browser to Android (v4l2loopback integration)
  • βœ… VoIP integration for calls/SMS via Twilio (eSIM simulation)
  • βœ… Bidirectional audio/video support

Phase 3: Multi-User & Admin Dashboard βœ…

  • βœ… Admin dashboard with full user management
  • βœ… User authentication (JWT with bcrypt)
  • βœ… Device assignment system (admin assigns devices to users)
  • βœ… Live monitoring grid (admin views all devices)
  • βœ… Role-based access control (admin/user roles)
  • βœ… User portal (users access only assigned devices)
  • βœ… Google apps pre-installed (Play Store, Gmail, Maps, etc.)
  • βœ… Full root access on all devices
  • βœ… Developer options enabled by default
  • βœ… Hardware buttons (volume, power, home, back, recent apps)

Phase 4: Production-Ready Deployment βœ…

  • βœ… Privacy-Focused Custom OS: Vanilla redroid/redroid:12.0.0-latest (pure AOSP)
    • No Google tracking or telemetry
    • Faster boot time and lower resource usage
    • Regular AOSP security updates
    • Users can sideload OpenGApps or microG if needed
  • βœ… Rate Limiting: 5 requests/minute on authentication endpoints (slowapi)
  • βœ… Comprehensive Logging: Request/error logging with timestamps to /tmp/virtual-android-backend.log
  • βœ… Health Check Endpoint: /api/health monitors database, Docker, disk space, instances
  • βœ… Database Backups: Daily automated backups with 7-day retention (cron: 2 AM daily)
  • βœ… Security Headers: X-Frame-Options, X-Content-Type-Options, HSTS, X-XSS-Protection, Referrer-Policy
  • βœ… Admin Password Enforcement: Startup warning for default password
  • βœ… Password Change API: Secure password change endpoint with validation

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User Browser  β”‚
β”‚  (React App)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTP/WebSocket
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  FastAPI Server β”‚
β”‚  - Instance Mgmtβ”‚
β”‚  - Input Forwardβ”‚
β”‚  - WebRTC Signalβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ Docker API
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Docker Engine  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚   β”‚  redroid  β”‚ β”‚
β”‚   β”‚ Container β”‚ β”‚
β”‚   β”‚ (Android) β”‚ β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Prerequisites

Server Requirements

  • OS: Ubuntu 22.04 LTS or newer (for Python 3.12 support)
  • CPU: 16+ cores recommended
  • RAM: 32GB+ (each instance uses 2-8GB)
  • Storage: 500GB+ SSD
  • Docker: Version 20.10 or newer

Development Machine

  • Python 3.12+
  • Node.js 18+
  • Docker (for local testing)

πŸš€ Quick Start

1. Server Setup

# SSH into your server
ssh administrator@YOUR_SERVER_IP

# Install Docker
sudo apt-get update
sudo apt-get install -y docker.io docker-compose
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker $USER

# Install Python 3.12 (Ubuntu 22.04+)
sudo apt-get install -y python3.12 python3.12-venv python3-pip

# Install Poetry
curl -sSL https://install.python-poetry.org | python3.12 -
export PATH="$HOME/.local/bin:$PATH"

# Pull redroid image
docker pull redroid/redroid:12.0.0-latest

# Setup v4l2loopback for future camera support
sudo apt-get install -y v4l2loopback-dkms
sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="VirtualCam"
echo "v4l2loopback" | sudo tee -a /etc/modules

2. Backend Deployment

# Copy backend to server
scp -r backend/ administrator@YOUR_SERVER_IP:~/virtual-android-backend/

# SSH to server
ssh administrator@YOUR_SERVER_IP

# Navigate to backend directory
cd ~/virtual-android-backend

# Update .env file
cat > .env << EOF
DOCKER_HOST=unix:///var/run/docker.sock
CORS_ORIGINS=*
EOF

# Install dependencies
poetry install

# Run backend
poetry run fastapi run app/main.py --host 0.0.0.0 --port 8000

Optional: Set up systemd service

sudo tee /etc/systemd/system/virtual-android-backend.service > /dev/null <<EOF
[Unit]
Description=Virtual Android Backend
After=network.target docker.service

[Service]
Type=simple
User=administrator
WorkingDirectory=/home/administrator/virtual-android-backend
ExecStart=/home/administrator/.local/bin/poetry run fastapi run app/main.py --host 0.0.0.0 --port 8000
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable virtual-android-backend
sudo systemctl start virtual-android-backend
sudo systemctl status virtual-android-backend

3. Frontend Deployment

# Update frontend .env with your backend URL
cd frontend
echo "VITE_BACKEND_URL=http://YOUR_SERVER_IP:8000" > .env

# Build frontend
npm install
npm run build

# Deploy dist/ folder to your hosting provider (Vercel, Netlify, etc.)
# Or serve with nginx on your server

πŸ§ͺ Local Development

Backend

cd backend

# Install dependencies
poetry install

# Update .env for local Docker
echo "DOCKER_HOST=unix:///var/run/docker.sock" > .env
echo "CORS_ORIGINS=*" >> .env

# Run development server
poetry run fastapi dev app/main.py --host 0.0.0.0 --port 8000

# API documentation available at http://localhost:8000/docs

Frontend

cd frontend

# Install dependencies
npm install

# Update .env for local backend
echo "VITE_BACKEND_URL=http://localhost:8000" > .env

# Run development server
npm run dev

# Frontend available at http://localhost:5173

πŸ“‘ API Endpoints

Instance Management

  • POST /api/instances - Create new Android instance

    {
      "ram_gb": 4,
      "rom_gb": 32
    }
  • GET /api/instances - List all instances

  • GET /api/instances/{instance_id} - Get instance details

  • DELETE /api/instances/{instance_id} - Delete instance

Input Control

  • POST /api/instances/{instance_id}/input - Send touch input
    {
      "x": 540,
      "y": 1170,
      "type": "tap"
    }

WebRTC Streaming

  • WS /api/instances/{instance_id}/webrtc - WebRTC signaling endpoint

πŸ› οΈ Technology Stack

Backend

  • FastAPI - Modern Python web framework
  • Docker SDK - Container management
  • redroid - Android in Docker
  • aiortc - WebRTC implementation
  • WebSockets - Real-time communication

Frontend

  • React 18 - UI framework
  • TypeScript - Type safety
  • Vite - Build tool
  • Tailwind CSS - Styling
  • shadcn/ui - Component library
  • Lucide React - Icons

Infrastructure

  • Docker - Containerization
  • redroid 12.0.0 - Android 12 containers
  • Ubuntu Server 20 LTS - Operating system

πŸ“ Environment Variables

Backend (.env)

DOCKER_HOST=unix:///var/run/docker.sock  # Local Docker
# OR
DOCKER_HOST=ssh://user@host              # Remote Docker (requires SSH keys)
CORS_ORIGINS=*                           # CORS configuration

Frontend (.env)

VITE_BACKEND_URL=http://localhost:8000   # Backend API URL

πŸ› Troubleshooting

Backend Issues

Docker connection errors:

  • Ensure Docker is running: sudo systemctl status docker
  • Check Docker socket permissions: sudo usermod -aG docker $USER
  • Verify DOCKER_HOST in .env is correct

Port already in use:

# Find process using port 8000
sudo lsof -i :8000

# Kill process
kill -9 <PID>

Frontend Issues

Can't connect to backend:

  • Verify backend is running
  • Check VITE_BACKEND_URL in frontend/.env
  • Ensure CORS is configured correctly in backend

Build errors:

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

πŸ” Security Considerations

  • Never commit .env files with credentials
  • Use SSH key-based authentication instead of passwords
  • Restrict CORS origins in production
  • Implement user authentication before public deployment
  • Use HTTPS for production deployments
  • Set up firewall rules to limit access

πŸ“Š Resource Management

Each Android instance uses:

  • RAM: 2-8GB (user configurable)
  • Storage: 16-64GB (user configurable)
  • CPU: ~2-4 cores per instance

With a 16-core, 32GB RAM server, you can support 5-8 concurrent instances.

πŸ” Production Deployment Guide

Production Features Overview

The Virtual Android Emulator is now 100% production-ready with:

  1. Privacy-Focused Android OS: Vanilla AOSP (no Google tracking/telemetry)
  2. Security: Rate limiting, JWT authentication, security headers, password enforcement
  3. Monitoring: Health checks, comprehensive logging, disk space monitoring
  4. Reliability: Database backups, systemd auto-restart, error handling
  5. Scalability: Multi-user support, device assignment, resource management

Production Server Configuration

Current Deployment: https://155.117.44.194/

Server Specifications:

  • OS: Ubuntu 24.04 LTS
  • CPU: 16 cores
  • RAM: 32GB (supports 5-8 concurrent devices)
  • Storage: 400GB SSD
  • Network: 500Mbps unmetered bandwidth

Health Monitoring

# Check system health
curl https://155.117.44.194/api/health

# View logs
ssh administrator@155.117.44.194
tail -f /tmp/virtual-android-backend.log

# Check database backups
ls -lh ~/virtual-android-backend/backups/

# Restart backend service
sudo systemctl restart virtual-android-backend
sudo systemctl status virtual-android-backend

Security Best Practices

  1. Change Default Admin Password:

    • Default credentials: admin/admin123
    • CHANGE IMMEDIATELY via admin dashboard or API
    • Endpoint: POST /api/auth/change-password
  2. Configure Secure JWT Secret:

    ssh administrator@155.117.44.194
    cd ~/virtual-android-backend
    python3 -c "import secrets; print(secrets.token_urlsafe(64))" >> .env
    sudo systemctl restart virtual-android-backend
  3. Monitor Logs Regularly:

    • Check /tmp/virtual-android-backend.log for suspicious activity
    • Rate limiting logs failed login attempts
  4. Database Backups:

    • Automated daily backups at 2 AM (cron)
    • 7-day retention policy
    • Manual backup: ~/virtual-android-backend/backup_database.sh
  5. Security Headers (already configured in nginx):

    • X-Frame-Options: SAMEORIGIN
    • X-Content-Type-Options: nosniff
    • X-XSS-Protection: 1; mode=block
    • Referrer-Policy: strict-origin-when-cross-origin
    • Strict-Transport-Security: max-age=31536000

Production Checklist

  • Vanilla AOSP for privacy/security
  • Rate limiting on auth endpoints
  • Health check endpoint implemented
  • Comprehensive logging enabled
  • Database backup script + cron job
  • Security headers configured
  • Admin password warning system
  • JWT authentication with bcrypt
  • HTTPS enabled with nginx
  • Systemd service with auto-restart

Admin Dashboard Access

URL: https://155.117.44.194/admin/login

Default Credentials (⚠️ CHANGE IMMEDIATELY):

  • Username: admin
  • Password: admin123

Admin Features:

  • Create and manage users
  • Create Android devices (2-8GB RAM, 16-64GB ROM)
  • Assign devices to specific users
  • Monitor all devices in real-time
  • View system health and logs

User Portal Access

URL: https://155.117.44.194/login

Users can:

  • Access only their assigned devices
  • View Android screen via WebRTC
  • Use hardware buttons (volume, power, home, back, recent apps)
  • Access camera (if permissions granted)
  • Full root access on devices
  • Developer options enabled

Vanilla AOSP Benefits

Why Vanilla Redroid?

After researching custom Android OS options (LineageOS, GrapheneOS, CalyxOS), vanilla redroid is the optimal choice because:

  1. Maximum Privacy:

    • Pure AOSP (Android Open Source Project)
    • Zero Google tracking or telemetry
    • No pre-installed Google apps or services
    • Users control what apps to install
  2. Better Performance:

    • Faster boot time (~30s vs ~60s with GApps)
    • Lower RAM usage (no Google services running)
    • Fewer background processes
  3. Security:

    • Regular AOSP security updates from redroid project
    • No third-party modifications
    • Official Docker image from redroid team
  4. Flexibility:

    • Users can sideload any apps they want
    • Can install OpenGApps or microG if needed
    • F-Droid and alternative app stores supported

Verified Features:

  • βœ… Boot time: ~30-60 seconds
  • βœ… Google packages: 0 (confirmed via pm list packages)
  • βœ… Root access: uid=0 (full root privileges)
  • βœ… Developer options: Enabled by default
  • βœ… ADB: Enabled and accessible
  • βœ… Hardware buttons: All 6 buttons working
  • βœ… WebRTC streaming: Real-time screen display

🚧 Known Limitations

  • Some Android apps may detect emulation
  • SQLite database has limited concurrency (upgrade to PostgreSQL for high traffic)
  • No persistent storage (instances reset on container restart)
  • Maximum ~5-8 concurrent devices per server (32GB RAM limit)

πŸ—ΊοΈ Future Enhancements

  • Persistent storage for Android instances
  • PostgreSQL migration for better concurrency
  • Multiple Android versions (13, 14, 15)
  • Kubernetes deployment for scalability
  • Auto-cleanup for idle instances
  • Advanced monitoring (Prometheus/Grafana)
  • GPU acceleration for better performance

πŸ“„ License

MIT License

πŸ‘₯ Credits

πŸ”— Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors