Skip to content

Latest commit

 

History

History
226 lines (181 loc) · 7.72 KB

File metadata and controls

226 lines (181 loc) · 7.72 KB

Summary: Enhanced Logging and Permission Handling

Overview

This PR addresses two key issues reported during testing:

  1. WiFi detection showing "not in range" when networks were actually present - Solved by adding comprehensive diagnostic logging
  2. "No permissions allowed" in Android Settings - Solved by implementing runtime permission requests

Changes Implemented

1. Enhanced WiFi Detection Logging (Commits 1c53eef, 635bb2c, e4300fa)

Problem: User reported WiFi networks weren't being detected even when in range, but logs provided minimal diagnostic information.

Solution: Added comprehensive logging throughout WiFi detection pipeline:

Initialization Logging

  • Android version, device model, manufacturer
  • WiFi enabled state at startup
  • System capabilities check

WiFi State Check Logging

  • Structured start/complete markers for each check cycle
  • Configured Home and OBD SSID display
  • Transmission mode verification
  • Check progress indicators

WiFi Scanning Details (isSSIDInRange)

  • Target SSID being searched for
  • WiFi enabled state before scanning
  • Scan start success/failure with Android version
  • Complete list of all detected SSIDs with signal strengths
  • Explicit "NOT found" message when target missing
  • Detailed permission/security exception handling

Example output:

DEBUG: === WiFi State Check Started ===
DEBUG: Configured Home SSID: 'MyHomeNetwork'
DEBUG: Scanning for WiFi SSID: 'MyHomeNetwork'
DEBUG: WiFi enabled: true
DEBUG: WiFi scan started: true (Android 33)
DEBUG: WiFi scan found 8 networks:
DEBUG:   - SSID: 'MyHomeNetwork' Signal: -45 dBm
DEBUG:   - SSID: 'NeighborWiFi' Signal: -72 dBm
DEBUG:   - SSID: 'OBDII' Signal: -38 dBm
INFO: Target WiFi found in range: 'MyHomeNetwork' (Signal: -45 dBm)

Connection State Logging (isConnectedToSSID)

  • Step-by-step connection verification
  • Network state and type information
  • Current SSID vs target comparison
  • Clear match/no-match indication

Transmission Logic Logging (shouldSendData)

  • All state variables at decision time
  • Mode-specific condition checks
  • Clear SEND/SKIP decisions with rationale

Network Connectivity Logging (hasInternetConnectivity)

  • Network availability details
  • Network type (WiFi/Mobile/None)
  • Connection state information

Documentation:

  • Created WIFI_DEBUGGING_GUIDE.md - 200+ lines of debugging instructions
  • Created LOGGING_IMPLEMENTATION_SUMMARY.md - Technical implementation details
  • Updated README troubleshooting section

2. Runtime Permission Handling (Commit e54e8c8)

Problem: App showed "No permissions allowed" in Android Settings because permissions weren't being requested at runtime (required on Android 6.0+).

Solution: Implemented comprehensive runtime permission request system:

Permission Request Flow

  • Automatic check on SettingsActivity launch
  • Explanation dialog before requesting permissions
  • Clear rationale for each permission
  • Graceful handling of denial with feature impact

Permissions Requested

  1. Location (ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION)

    • Required for WiFi scanning on Android 6.0+
    • Used for network detection and automatic switching
    • Prepares for future GPS location tracking feature
    • Not used to track location (explicitly stated)
  2. Notifications (POST_NOTIFICATIONS)

    • Required on Android 13+ for foreground service
    • Shows status indicators and connection updates

User Experience

Permission Explanation Dialog:

This app requires the following permissions:

Location:
- Scan for WiFi networks (required by Android)
- Detect when home network is in range
- Enable automatic WiFi switching
- Optional: Send vehicle location to Home Assistant

Note: Location is not tracked unless you explicitly enable the location tracking option.

Notifications:
- Display network status indicator
- Show connection/transmission status

On Grant:

All required permissions have been granted. The app can now:
- Scan for WiFi networks
- Detect home network proximity
- Enable automatic WiFi switching
- Display status notifications
- Optional: Track vehicle location (when enabled)

On Denial:

Some permissions were not granted. This will limit functionality:

Location Denied:
- WiFi network scanning disabled
- Cannot detect when home network is in range
- Automatic WiFi switching unavailable
- Location sensor feature unavailable

Notifications Denied:
- Status notifications may not appear
- Network indicator may not display

Technical Implementation

  • Added androidx.core:core:1.12.0 dependency for ActivityCompat
  • Permission check on Activity onCreate
  • Dialog-based explanation before system permission request
  • Handles grant/deny/never-ask-again states
  • Direct links to Android Settings for manual management
  • Android version checks (only request POST_NOTIFICATIONS on Android 13+)

Manifest Updates

  • Added POST_NOTIFICATIONS permission
  • Updated location permission comments to mention future GPS feature
  • All permissions properly documented

Documentation:

  • Created PERMISSIONS_GUIDE.md - Complete permission documentation
  • Updated README requirements section
  • Updated README troubleshooting section with permission steps

Impact

Debugging Improvements

Users can now diagnose WiFi detection issues by:

  1. Enabling logging in app settings
  2. Viewing detailed scan results showing all detected networks
  3. Comparing configured SSID with actual network names
  4. Identifying permission issues, scan throttling, or WiFi disabled state
  5. Understanding why transmission doesn't occur

Permission Issues Resolved

Users will now:

  1. See permission request on first app launch
  2. Understand why each permission is needed
  3. Have working WiFi scanning (if permission granted)
  4. Know what features are disabled if permissions denied
  5. Have easy access to manual permission management

Future Readiness

  • Location permission structure supports planned GPS feature
  • Permission explanation mentions vehicle location tracking
  • Framework in place for future permission needs

Testing Recommendations

WiFi Logging

  1. Enable logging and configure home WiFi SSID
  2. Wait for WiFi check cycle (30 seconds)
  3. View logs to verify networks are detected
  4. Compare scan results with actual network names
  5. Check for permission errors or throttling messages

Permission Handling

  1. Fresh install or clear app data
  2. Open app - should see permission dialog
  3. Grant permissions - should see confirmation
  4. Check Android Settings shows permissions granted
  5. Test WiFi scanning works with permissions
  6. Revoke permissions - should see limited functionality warning

Files Changed

Source Code

  • HomeAssistantPlugin.java - Enhanced logging throughout WiFi detection
  • SettingsActivity.java - Added runtime permission handling
  • build.gradle.module - Added androidx.core dependency
  • AndroidManifest.xml - Added POST_NOTIFICATIONS permission

Documentation

  • WIFI_DEBUGGING_GUIDE.md - NEW: WiFi detection debugging guide
  • LOGGING_IMPLEMENTATION_SUMMARY.md - NEW: Technical logging details
  • PERMISSIONS_GUIDE.md - NEW: Permission handling documentation
  • README.md - Updated with troubleshooting and requirements

Backward Compatibility

All changes are additive and backward compatible:

  • No API changes
  • No behavior changes when logging disabled
  • Permission requests are graceful (can be denied)
  • Works on Android 4.0.3+ (minSdk 15)
  • Runtime permissions only on Android 6.0+ (API 23+)
  • POST_NOTIFICATIONS only on Android 13+ (API 33+)

Statistics

  • Lines added: ~550
  • New log points: 40+
  • New files: 4 documentation files
  • Files modified: 4 source/config files
  • Commits: 5
  • Documentation: 600+ lines of comprehensive guides