Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to CarOS Profile Switcher will be documented in this file.

## [Unreleased]

### Added
- **🎵 Audio Streaming Feature**: Stream audio from another device to car speakers via two methods:
- **Bluetooth A2DP Sink** (`ENABLE_BT_AUDIO_SINK`): Receive audio via Bluetooth
- May not work if Bluetooth is used for car audio even in wired mode
- Device becomes discoverable for pairing
- Automatic A2DP sink mode configuration
- **WiFi Hotspot** (`ENABLE_WIFI_AUDIO_HOTSPOT`): Create WiFi hotspot for audio streaming
- Recommended alternative when Bluetooth is occupied by car
- Works in WIRED mode when WiFi is not used by car
- Configurable SSID and password
- Requires audio streaming app on emitting device (SoundWire, AudioRelay, etc.)
- Both methods only work in WIRED mode (USB connection)
- Automatically disable in IDLE mode to save battery
- Comprehensive documentation in README.md, EXAMPLES.md, and FAQ.md

### Planned
- Improved error handling in service.sh

Expand Down
47 changes: 46 additions & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ IDLE_MAX_CPU_FREQ="1516800" # Throttle CPU to ~1.5GHz
LIMIT_QUICK_CHARGE_WIRED=1 # Limit charging
SET_NOVA_DEFAULT=1
KEEP_WIFI_IN_WIRED=0 # Turn off WiFi
KEEP_WIFI_IN_IDLE=0 # Turn off WiFi when idle
KEEP_WIFI_IN_IDLE=1
AUTO_GRANT_PERMISSIONS=1
ENABLE_BT_AUDIO_SINK=0 # Disable to save battery
VERBOSE=0 # Reduce logging overhead
```

Expand All @@ -132,6 +134,49 @@ LIMIT_QUICK_CHARGE_WIRED=0 # Allow fast charging
SET_NOVA_DEFAULT=1
KEEP_WIFI_IN_WIRED=1 # Keep WiFi on
KEEP_WIFI_IN_IDLE=1 # Keep WiFi on
AUTO_GRANT_PERMISSIONS=1
ENABLE_BT_AUDIO_SINK=0
VERBOSE=1
```

### Audio Streaming via Bluetooth
```bash
# Enable receiving audio from another phone via Bluetooth
# Note: May not work if Bluetooth is used for car audio even in wired mode
AUDI_BT_NAMES="Your Car"
AUDI_BT_MAC=""
ALLOW_BT_IN_WIRED=1 # Must keep BT on for audio streaming
DATA_OFF_OUTSIDE=1
KEEP_DATA_IN_CAR=1
IDLE_MAX_CPU_FREQ=""
LIMIT_QUICK_CHARGE_WIRED=1
SET_NOVA_DEFAULT=1
KEEP_WIFI_IN_WIRED=0
KEEP_WIFI_IN_IDLE=1
AUTO_GRANT_PERMISSIONS=1
ENABLE_BT_AUDIO_SINK=1 # Enable Bluetooth audio sink mode
ENABLE_WIFI_AUDIO_HOTSPOT=0
VERBOSE=1
```

### Audio Streaming via WiFi Hotspot (Recommended)
```bash
# Enable WiFi hotspot for audio streaming (works even if BT used for car audio)
AUDI_BT_NAMES="Your Car"
AUDI_BT_MAC=""
ALLOW_BT_IN_WIRED=1
DATA_OFF_OUTSIDE=1
KEEP_DATA_IN_CAR=1
IDLE_MAX_CPU_FREQ=""
LIMIT_QUICK_CHARGE_WIRED=1
SET_NOVA_DEFAULT=1
KEEP_WIFI_IN_WIRED=1 # WiFi must be on for hotspot
KEEP_WIFI_IN_IDLE=1
AUTO_GRANT_PERMISSIONS=1
ENABLE_BT_AUDIO_SINK=0
ENABLE_WIFI_AUDIO_HOTSPOT=1 # Enable WiFi hotspot for audio streaming
WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"
WIFI_AUDIO_HOTSPOT_PASSWORD="caros123"
VERBOSE=1
```

Expand Down
46 changes: 46 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,52 @@ In wired mode, the module tries to reduce fast charging to prevent phone overhea
### Does Nova Launcher need to be installed?
No. If `SET_NOVA_DEFAULT=1` but Nova isn't installed, the module just skips this step. No errors.

### How does audio streaming work?
CarOS supports two methods for streaming audio from another phone:

**Method 1: Bluetooth A2DP Sink**
When `ENABLE_BT_AUDIO_SINK=1`, your CarOS phone becomes discoverable and can receive audio from another phone via Bluetooth.

**Limitation:** May not work if Bluetooth is already used for car audio/calls, even in wired mode.

**Method 2: WiFi Hotspot (Recommended)**
When `ENABLE_WIFI_AUDIO_HOTSPOT=1`, your CarOS device creates a WiFi hotspot that other devices can connect to for streaming audio.

**Advantages:** Works even when Bluetooth is used by the car. Requires an audio streaming app on the emitting phone.

**To use WiFi hotspot:**
1. Enable in config: `ENABLE_WIFI_AUDIO_HOTSPOT=1`
2. Set SSID and password: `WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"`
3. Connect to car via USB (wired mode)
4. Emitting phone connects to WiFi hotspot
5. Use audio streaming app (SoundWire, AudioRelay, etc.)

### Does Bluetooth audio sink work on all devices?
No, it's device-dependent. Some Android devices don't support A2DP sink mode. Additionally, even in wired mode, many cars use Bluetooth for audio and phone calls, which prevents the phone from acting as an A2DP sink simultaneously.

**If Bluetooth doesn't work:** Use the WiFi hotspot method instead (`ENABLE_WIFI_AUDIO_HOTSPOT=1`).

### Why isn't my phone discoverable for Bluetooth audio?
If `ENABLE_BT_AUDIO_SINK=1` but your phone isn't discoverable:
1. **Bluetooth may be in use by the car** - Even in wired mode, many cars use Bluetooth for audio/calls
2. **Try WiFi hotspot instead** - Set `ENABLE_WIFI_AUDIO_HOTSPOT=1`
3. Check that you're in WIRED mode (USB connection)
4. Look for "BT Audio Sink" messages in logs
5. Your device may not support A2DP sink mode

### Can I use audio streaming in IDLE mode?
No, both features are automatically disabled in IDLE mode to save battery. They only work when connected to your car in WIRED mode.

### Can I use audio streaming in WIRELESS mode?
No, in wireless mode both Bluetooth and WiFi are typically used by the car for Android Auto connection. The audio streaming features only work in WIRED mode where the car connection is via USB.

### What audio streaming apps work with WiFi hotspot?
Popular options include:
- **SoundWire** (free) - Low latency audio streaming
- **AudioRelay** (free) - WiFi/USB audio streaming
- **AirMusic** - DLNA/UPnP streaming
- Any app that supports streaming to a WiFi network

---

## Troubleshooting
Expand Down
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A Magisk module for Android that automatically switches device profiles based on
- **Battery Saver**: Automatically enable when not in car
- **Nova Launcher**: Set as default launcher automatically
- **🔔 Auto Permissions**: Automatically grants notification and location permissions to Android Auto, Waze, Google Maps, and Nova Launcher
- **🎵 Audio Streaming**: Stream audio from another device to car speakers via Bluetooth A2DP sink or WiFi hotspot

### Configuration
- User-configurable via `/sdcard/CarOS/config.env`
Expand Down Expand Up @@ -79,10 +80,68 @@ KEEP_WIFI_IN_IDLE=1 # Keep WiFi on when idle
# Automatic permission management
AUTO_GRANT_PERMISSIONS=1 # Auto-grant notifications & location to AA, Waze, Maps

# Audio streaming options (choose one or both based on what works for your setup)
ENABLE_BT_AUDIO_SINK=0 # Bluetooth A2DP sink (may not work if BT used for car audio)
ENABLE_WIFI_AUDIO_HOTSPOT=0 # WiFi hotspot for audio streaming (alternative to BT)

# WiFi hotspot settings (if using WiFi audio streaming)
WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"
WIFI_AUDIO_HOTSPOT_PASSWORD="caros123"

# Verbose logging
VERBOSE=1
```

## 🎵 Audio Streaming Feature

Stream audio from another phone to your car speakers via Bluetooth or WiFi. Two methods available:

### Method 1: Bluetooth A2DP Sink
When enabled (`ENABLE_BT_AUDIO_SINK=1`), your CarOS device can receive audio from another phone via Bluetooth.

**Limitation:** May not work if Bluetooth is already used for car audio/calls (even in wired mode).

**How to use:**
1. Enable in config: `ENABLE_BT_AUDIO_SINK=1`
2. Connect your CarOS phone to car via USB
3. On the emitting phone:
- Go to Bluetooth settings
- Find and pair with your CarOS device
- Connect and play music

### Method 2: WiFi Hotspot (Recommended Alternative)
When enabled (`ENABLE_WIFI_AUDIO_HOTSPOT=1`), your CarOS device creates a WiFi hotspot that other devices can connect to for streaming audio.

**Advantages:**
- ✓ Works even if Bluetooth is used for car audio
- ✓ Higher quality audio streaming
- ✓ Can work in WIRED mode when WiFi is not used by the car

**How to use:**
1. Enable in config:
```bash
ENABLE_WIFI_AUDIO_HOTSPOT=1
WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"
WIFI_AUDIO_HOTSPOT_PASSWORD="caros123"
```
2. Connect your CarOS phone to car via USB
3. On the emitting phone:
- Connect to the WiFi hotspot (SSID: CarOS-Audio)
- Use an audio streaming app (e.g., SoundWire, AudioRelay, etc.)
- Stream audio to CarOS device

### Use Cases
- Stream music from a passenger's phone to your car speakers
- Multiple people can share music during the drive
- Alternative to passing phone cables around

### Important Notes
- **Both methods work in WIRED mode only** (USB connection to car)
- Does NOT work in WIRELESS mode (both Bluetooth and WiFi may be used by car)
- Automatically disabled when IDLE to save battery
- WiFi hotspot method requires an audio streaming app on the emitting phone
- Bluetooth method may not work on all devices (A2DP sink support required)

## 📝 How It Works

1. **Boot**: The module starts automatically via `service.sh`
Expand Down
31 changes: 31 additions & 0 deletions caros_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ DEFAULT_KEEP_WIFI_IN_IDLE=0
# Automatically grants necessary permissions for Android Auto, Waze, Maps, etc.
DEFAULT_AUTO_GRANT_PERMISSIONS=1

# Bluetooth audio streaming (enable device as A2DP sink to receive audio from another phone)
# When enabled, the phone becomes discoverable and can receive audio from another device
# Note: May not work if Bluetooth is used for car audio even in wired mode
DEFAULT_ENABLE_BT_AUDIO_SINK=0

# WiFi hotspot for audio streaming (alternative to Bluetooth)
# Creates a WiFi hotspot that other devices can connect to for streaming audio
# Works when WiFi is not used by the car (typically in wired mode)
DEFAULT_ENABLE_WIFI_AUDIO_HOTSPOT=0

# WiFi hotspot SSID for audio streaming
DEFAULT_WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"

# WiFi hotspot password for audio streaming (min 8 characters)
DEFAULT_WIFI_AUDIO_HOTSPOT_PASSWORD="caros123"

# Verbose logs
DEFAULT_VERBOSE=1

Expand Down Expand Up @@ -80,6 +96,17 @@ KEEP_WIFI_IN_IDLE=$DEFAULT_KEEP_WIFI_IN_IDLE
# Automatic permission management (notifications and location)
AUTO_GRANT_PERMISSIONS=$DEFAULT_AUTO_GRANT_PERMISSIONS

# Bluetooth audio streaming (enable device as A2DP sink to receive audio from another phone)
# Note: May not work if Bluetooth is used for car audio even in wired mode
ENABLE_BT_AUDIO_SINK=$DEFAULT_ENABLE_BT_AUDIO_SINK

# WiFi hotspot for audio streaming (alternative to Bluetooth)
ENABLE_WIFI_AUDIO_HOTSPOT=$DEFAULT_ENABLE_WIFI_AUDIO_HOTSPOT

# WiFi hotspot SSID and password
WIFI_AUDIO_HOTSPOT_SSID="$DEFAULT_WIFI_AUDIO_HOTSPOT_SSID"
WIFI_AUDIO_HOTSPOT_PASSWORD="$DEFAULT_WIFI_AUDIO_HOTSPOT_PASSWORD"

# Verbose logs
VERBOSE=$DEFAULT_VERBOSE
EOF
Expand All @@ -98,5 +125,9 @@ apply_defaults() {
: "${KEEP_WIFI_IN_WIRED:=$DEFAULT_KEEP_WIFI_IN_WIRED}"
: "${KEEP_WIFI_IN_IDLE:=$DEFAULT_KEEP_WIFI_IN_IDLE}"
: "${AUTO_GRANT_PERMISSIONS:=$DEFAULT_AUTO_GRANT_PERMISSIONS}"
: "${ENABLE_BT_AUDIO_SINK:=$DEFAULT_ENABLE_BT_AUDIO_SINK}"
: "${ENABLE_WIFI_AUDIO_HOTSPOT:=$DEFAULT_ENABLE_WIFI_AUDIO_HOTSPOT}"
: "${WIFI_AUDIO_HOTSPOT_SSID:=$DEFAULT_WIFI_AUDIO_HOTSPOT_SSID}"
: "${WIFI_AUDIO_HOTSPOT_PASSWORD:=$DEFAULT_WIFI_AUDIO_HOTSPOT_PASSWORD}"
: "${VERBOSE:=$DEFAULT_VERBOSE}"
}
27 changes: 27 additions & 0 deletions grant_permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ grant_location_permission() {
appops set "$package" FINE_LOCATION allow 2>/dev/null
}

# Grant Bluetooth permissions for audio sink functionality
grant_bluetooth_audio_permissions() {
# Check if Bluetooth audio sink is enabled
if [ "$ENABLE_BT_AUDIO_SINK" != "1" ]; then
return 0
fi

log "Granting Bluetooth audio permissions for A2DP sink mode"

# Grant system-level Bluetooth permissions (Android 12+)
pm grant com.android.bluetooth android.permission.BLUETOOTH_CONNECT 2>/dev/null
pm grant com.android.bluetooth android.permission.BLUETOOTH_SCAN 2>/dev/null
pm grant com.android.bluetooth android.permission.BLUETOOTH_ADVERTISE 2>/dev/null

# Grant audio permissions
pm grant com.android.bluetooth android.permission.MODIFY_AUDIO_SETTINGS 2>/dev/null
pm grant com.android.bluetooth android.permission.RECORD_AUDIO 2>/dev/null

# Set app ops for Bluetooth
appops set com.android.bluetooth BLUETOOTH_SCAN allow 2>/dev/null
appops set com.android.bluetooth BLUETOOTH_CONNECT allow 2>/dev/null
appops set com.android.bluetooth BLUETOOTH_ADVERTISE allow 2>/dev/null
}

# Main execution
log "Starting permission grants..."

Expand All @@ -93,4 +117,7 @@ for app in "${LOCATION_APPS[@]}"; do
grant_location_permission "$app"
done

# Grant Bluetooth audio permissions
grant_bluetooth_audio_permissions

log "Permission grants completed"
Loading