8000 Feature/network info by eamon831 · Pull Request #120 · mobile-next/mobile-mcp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/network info #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eamon831
Copy link

🎯 Overview

Adds comprehensive network connectivity detection to mobile-mcp, providing real-time network information across Android devices, iOS devices, and iOS simulators through a unified getNetworkInfo() API.

✨ Features Added

  • Cross-platform network detection with consistent NetworkInfo interface
  • Real-time connectivity status with internet reachability testing
  • Detailed network information including SSID, signal strength, and connection type
  • MCP tool integration via mobile_get_network_info command
  • Robust error handling with graceful fallbacks

🧪 Use Cases

  • Network-dependent test automation - Verify connectivity before running tests that require internet
  • Internet connectivity test cases - Validate app behavior under different network conditions
  • Connection type testing - Test app functionality on WiFi vs cellular vs offline modes
  • Network reliability testing - Monitor connection stability during long-running test suites
  • Cross-platform network validation - Ensure consistent network behavior across Android and iOS

🔧 Implementation Details

Android Implementation:

  • Detects WiFi, cellular, and unknown connection types
  • Extracts SSID and RSSI from dumpsys connectivity
  • Tests internet connectivity via ping to 8.8.8.8
  • Provides carrier information for cellular connections

iOS Device Implementation:

  • Uses go-ios for device communication (WebDriverAgent-independent)
  • Attempts to retrieve WiFi details via go-ios wifi info
  • Falls back to basic connectivity detection when detailed info unavailable

iOS Simulator Implementation:

  • Uses host machine connectivity (simulators share host network)
  • Direct ping testing for accurate connectivity status
  • No external dependencies required

📊 API Interface

interface NetworkInfo {
    type: "wifi" | "cellular" | "none" | "unknown";
    isConnected: boolean;
    networkName?: string;
    signalStrength?: number;
}

🧪 Testing

  • ✅ Unit tests added for all platforms
  • ✅ Real device testing validated on Android emulator and physical devices
  • ✅ iOS simulator connectivity detection verified
  • ✅ Cross-platform compatibility confirmed
  • Internet connectivity test scenarios validated across different network states
  • Testing confirmed with Cursor AI integration - MCP tools working seamlessly in development environment

💡 Technical Highlights

  • WebDriverAgent-independent network detection for better reliability
  • Helper method architecture consistent with existing codebase patterns
  • Graceful degradation when detailed network info unavailable
  • Timeout handling and proper error propagation
  • Useful for automated testing against various internet connectivity scenarios
  • Cursor AI compatible - Tested and validated in Cursor development workflow

🔧 Usage Examples

# Via MCP - Perfect for test case validation (Cursor AI tested)
mobile_get_network_info

# Response examples for different test scenarios
{"type": "wifi", "isConnected": true, "networkName": "MyWiFi", "signalStrength": -45}
{"type": "cellular", "isConnected": true, "networkName": "Verizon"}
{"type": "none", "isConnected": false}  # Perfect for offline testing

🛠️ Breaking Changes

None - This is a new feature addition.

📋 Checklist

  • Tests added and passing
  • Documentation updated (via code comments)
  • Cross-platform compatibility verified
  • Error handling implemented
  • Code style consistent with existing patterns
  • ESLint passes
  • TypeScript compilation successful
  • Internet connectivity test cases validated
  • Cursor AI integration tested and confirmed working

Ready for review and merge! Particularly useful for testing applications against various internet connectivity scenarios. Fully tested and validated with Cursor AI development environment. 🚀

eamon831 added 4 commits June 24, 2025 16:24
- Add NetworkInfo interface with type, connection status, network name, and signal strength
- Implement Android network info using ping connectivity test
- Implement iOS network info using go-ios info command with fallback
- Implement iPhone Simulator network info with host connectivity assumption
- Register mobile_get_network_info MCP tool for cross-platform network status
- Add comprehensive error handling and logging for network operations
- Add comprehensive network info testing to validate return types and values
- Test network info structure (type, isConnected, optional fields)
- Validate network type enum values (wifi, cellular, none, unknown)
- Ensure cross-platform compatibility and consistent behavior
- Tests pass successfully on Android and iPhone Simulator
- Move local helper functions to private class methods
- Consistent with existing patterns like isAscii(), getUiAutomatorDump()
- Applied across Android, iOS, and iPhone Simulator implementations
- No functional changes, only style alignment
- Replace simctl spawn ping with direct host ping command
- iOS simulators use host network, so check host connectivity directly
- Fixes false negative where simulator showed 'none' despite working internet
- Now correctly detects wifi/connected state matching actual connectivity
- Network info feature complete across all platforms
@gmegidish
Copy link
Contributor

@eamon831 this is an excellent pull request! thank you so much!! 🤯 💯 . I'll review the code later today/tomorrow and after manually testing, let's merge this!!! thank you!!!

@@ -310,14 +349,117 @@ export class AndroidRobot implements Robot {

// disable auto-rotation prior to setting the orientation
this.adb("shell", "settings", "put", "system", "accelerometer_rotation", "0");
this.adb("shell", "content", "insert", "--uri", "content://settings/system", "--bind", "name:s:user_rotation", "--bind", `value:i:${orientationValue}`);
this.adb(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is most of the PR just re-formatting :(
why is it modifying these lines?

}
}

private async getWifiInfo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code is copy-pasted entirely from android.ts, no?

}
}

private parseWifiInfo(info: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the response type?

assert.ok(typeof networkInfo.isConnected === "boolean");

// type should be one of the valid network types
const validTypes = ["wifi", "cellular", "none", "unknown"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this test assert not only the type? cause these should be enforced by typescript. but maybe assert that all simulators return a specific type (is it wifi?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0