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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ assignees: ''
- **Car Make/Model**: <!-- e.g., Audi A4 2021 -->

## Configuration
<!-- Paste your /sdcard/CarOS/config.env here (remove sensitive info) -->
<!-- Paste your /data/adb/caros/config.env here (remove sensitive info) -->
```bash
AUDI_BT_NAMES="Your Car"
AUDI_BT_MAC=""
Expand All @@ -39,7 +39,7 @@ ALLOW_BT_IN_WIRED=1

## Logs
<!-- IMPORTANT: Include logs or we can't help! -->
<!-- Run: adb shell cat /data/adb/modules/caros-switcher/log.txt -->
<!-- Run: adb shell cat /data/adb/caros/log.txt -->
```
Paste logs here
```
Expand Down
10 changes: 5 additions & 5 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CarOS Profile Switcher is a Magisk module for Android that automatically manages

#### Configuration Flow
1. Defaults defined in `caros_config.sh` (`DEFAULT_*` variables)
2. User config at `/sdcard/CarOS/config.env` (generated from defaults)
2. User config at `/data/adb/caros/config.env` (generated from defaults)
3. `apply_defaults()` ensures all variables have values

#### Service Loop
Expand Down Expand Up @@ -148,16 +148,16 @@ check_with_cache(){

### Path Conventions
- Module files: `/data/adb/modules/caros-switcher/`
- User config: `/sdcard/CarOS/config.env`
- Logs: `/data/adb/modules/caros-switcher/log.txt`
- State: `/data/adb/modules/caros-switcher/state.json`
- User config: `/data/adb/caros/config.env`
- Logs: `/data/adb/caros/log.txt`
- State: `/data/adb/caros/state.json`

## Testing & Validation

### Before Committing
1. Validate shell syntax: `bash -n script.sh`
2. Test on actual device (if possible)
3. Check logs for errors: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
3. Check logs for errors: `adb shell cat /data/adb/caros/log.txt`
4. Verify version consistency across files

### Log Analysis
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
2. Magisk → Modules → Installer depuis le stockage
3. Choisir le ZIP puis redémarrer

Configuration : \`/sdcard/CarOS/config.env\` (voir [EXAMPLES.md](https://github.com/${REPO}/blob/main/EXAMPLES.md)).
Configuration : \`/data/adb/caros/config.env\` (voir [EXAMPLES.md](https://github.com/${REPO}/blob/main/EXAMPLES.md)).

**Prérequis** : Magisk v20.4+, Android Auto, accès root.
EOT
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ All notable changes to CarOS Profile Switcher will be documented in this file.

## [Unreleased]

## [0.2.4] - 2026-11-14

### Added
- Carbox options: `ENABLE_WIRELESS_PROFILE` (0 for wired-only), `PARKING_MODE` (cut scans/location, force Doze while idle), `AUTO_SHUTDOWN_PCT` (shut down when idle, unplugged and low), `DISABLE_LOCKSCREEN`, `KEEP_BT_IN_IDLE`
- `grant_permissions.sh` exempts Android Auto, Maps and Waze from Doze/background limits
- The current profile is re-applied every 5 minutes, and the config is re-read live

### Changed
- Config moved to `/data/adb/caros/config.env` (root only); `/sdcard/CarOS/config.env` is still read as an optional override. Config files are parsed (whitelisted keys, never sourced), so an app can no longer run commands as root through the config
- Logs and state moved to `/data/adb/caros/`
- `post-fs-data.sh` is minimal; everything runs in `service.sh` after `sys.boot_completed`
- Wired detection uses USB accessory mode; Bluetooth detection no longer matches "disconnected"
- Charge limit only reduces current (never suspends charging) and restores original values
- Bluetooth/Wi-Fi/data use `svc` and `cmd wifi`; battery saver uses `cmd power set-mode`
- CPU limit is per cpufreq policy; screen off uses KEYCODE_SLEEP; Nova set through the HOME role
- Polling every 10 s (instead of 3 s) while idle
- The hotspot password is generated randomly when the config is created

### Fixed
- Idle profile ignored `DATA_OFF_OUTSIDE`
- Nova fallback overwrote the default keyboard
- Notification-listener list grew with invalid entries at every permission run
- Wi-Fi hotspot used an invalid security type
- Removed non-functional A2DP-sink system properties (feature is experimental and needs ROM support)


### 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
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ caros-profile-switcher/
1. Build the module: `./build.ps1` or `./build.sh`
2. Install via Magisk Manager
3. Reboot your device
4. Check logs: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
4. Check logs: `adb shell cat /data/adb/caros/log.txt`
5. Verify state changes work correctly

## 🔄 Release Process
Expand Down Expand Up @@ -133,24 +133,24 @@ git push origin main --tags
## 🐛 Debugging Tips

### Enable Verbose Logging
In `/sdcard/CarOS/config.env`:
In `/data/adb/caros/config.env`:
```bash
VERBOSE=1
```

### View Logs
```bash
# Full log
adb shell cat /data/adb/modules/caros-switcher/log.txt
adb shell cat /data/adb/caros/log.txt

# Last 50 lines
adb shell tail -n 50 /data/adb/modules/caros-switcher/log.txt
adb shell tail -n 50 /data/adb/caros/log.txt

# Follow in real-time
adb shell tail -f /data/adb/modules/caros-switcher/log.txt
adb shell tail -f /data/adb/caros/log.txt

# Check current state
adb shell cat /data/adb/modules/caros-switcher/state.json
adb shell cat /data/adb/caros/state.json
```

### Common Issues
Expand Down
6 changes: 3 additions & 3 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ VERBOSE=1 # Full logging
### Method 2: Check Logs
1. Enable verbose logging: `VERBOSE=1`
2. Connect to your car
3. View logs: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
3. View logs: `adb shell cat /data/adb/caros/log.txt`
4. Look for lines mentioning Bluetooth device names

### Method 3: Dumpsys (Advanced)
Expand Down Expand Up @@ -286,10 +286,10 @@ AUDI_BT_NAMES="Car \\(2024\\)"
```

### Testing Your Configuration
After editing `/sdcard/CarOS/config.env`:
After editing `/data/adb/caros/config.env`:
1. Don't need to reboot (config reloads automatically)
2. Connect to your car
3. Check logs: `adb shell tail -f /data/adb/modules/caros-switcher/log.txt`
3. Check logs: `adb shell tail -f /data/adb/caros/log.txt`
4. Should see "State change: IDLE -> WIRELESS" or "-> WIRED"

### Common Pitfalls
Expand Down
19 changes: 10 additions & 9 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Check these:
2. Android Auto app is installed
3. You've paired your car via Bluetooth
4. Module is enabled in Magisk Manager
5. Check logs: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
5. Check logs: `adb shell cat /data/adb/caros/log.txt`

### Where is the configuration file?
`/sdcard/CarOS/config.env`
`/data/adb/caros/config.env`

The module creates this automatically on first boot. You can edit it with any text editor.

Expand Down Expand Up @@ -188,7 +188,7 @@ Check:
4. Verify process name: `pidof com.google.android.projection.gearhead`

### Profiles not switching
1. Check logs: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
1. Check logs: `adb shell cat /data/adb/caros/log.txt`
2. Verify Bluetooth name matches: `AUDI_BT_NAMES="Your Car Name"`
3. Try MAC address matching instead
4. Ensure Android Auto is actually running (not just connected)
Expand Down Expand Up @@ -236,9 +236,10 @@ Yes, but changes will be lost on module updates. Better to:
### Where are the module files located?
```
/data/adb/modules/caros-switcher/ # Module directory
/data/adb/modules/caros-switcher/log.txt # Logs
/data/adb/modules/caros-switcher/state.json # Current state
/sdcard/CarOS/config.env # User configuration
/data/adb/caros/ # Config, logs, state
/data/adb/caros/log.txt # Logs
/data/adb/caros/state.json # Current state
/data/adb/caros/config.env # User configuration
```

### How do I uninstall?
Expand All @@ -247,7 +248,7 @@ Yes, but changes will be lost on module updates. Better to:
3. Tap **Remove** on CarOS Profile Switcher
4. Reboot

Configuration file at `/sdcard/CarOS/` will remain (delete manually if desired).
Configuration and logs in `/data/adb/caros/` (and an optional `/sdcard/CarOS/`) will remain (delete manually if desired).

### Can I pause the module temporarily?
Yes:
Expand Down Expand Up @@ -314,7 +315,7 @@ If issues occur, boot to recovery and disable/remove via Magisk.
### How do I report bugs?
1. Enable `VERBOSE=1` in config
2. Reproduce the issue
3. Collect logs: `adb shell cat /data/adb/modules/caros-switcher/log.txt`
3. Collect logs: `adb shell cat /data/adb/caros/log.txt`
4. Open a GitHub issue with logs and details

### Can I contribute?
Expand Down Expand Up @@ -343,5 +344,5 @@ Shell script (Bash/sh) - standard for Magisk modules.

**Remember:** Always include logs when asking for help!
```bash
adb shell cat /data/adb/modules/caros-switcher/log.txt
adb shell cat /data/adb/caros/log.txt
```
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A Magisk module for Android that automatically switches device profiles based on
- **🎵 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`
- User-configurable via `/data/adb/caros/config.env`
- Supports multiple car Bluetooth names (regex patterns)
- MAC address matching support
- Verbose logging for troubleshooting
Expand All @@ -46,7 +46,15 @@ A Magisk module for Android that automatically switches device profiles based on

## ⚙️ Configuration

After installation, edit the configuration file at `/sdcard/CarOS/config.env`:
The config is created at first boot in `/data/adb/caros/config.env` (readable by root only). For convenience, `/sdcard/CarOS/config.env` is read afterwards as an optional override: create it by hand and put only the keys you want to change. Only known `KEY=VALUE` keys are read; nothing in these files is executed. Changes are picked up within a few minutes without rebooting.

```powershell
# Edit from a PowerShell prompt with adb (rooted phone)
adb shell su -c "cat /data/adb/caros/config.env"
adb shell su -c "tail -n 50 /data/adb/caros/log.txt"
```

After installation, edit the configuration file at `/data/adb/caros/config.env`:

> 💡 **Quick Start**: See [EXAMPLES.md](EXAMPLES.md) for ready-to-use configurations for Audi, VW, BMW, Mercedes, and more!

Expand Down Expand Up @@ -86,7 +94,7 @@ ENABLE_WIFI_AUDIO_HOTSPOT=0 # WiFi hotspot for audio streaming (alternative to

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

# Verbose logging
VERBOSE=1
Expand Down Expand Up @@ -122,7 +130,7 @@ When enabled (`ENABLE_WIFI_AUDIO_HOTSPOT=1`), your CarOS device creates a WiFi h
```bash
ENABLE_WIFI_AUDIO_HOTSPOT=1
WIFI_AUDIO_HOTSPOT_SSID="CarOS-Audio"
WIFI_AUDIO_HOTSPOT_PASSWORD="caros123"
WIFI_AUDIO_HOTSPOT_PASSWORD="choose-a-password"
```
2. Connect your CarOS phone to car via USB
3. On the emitting phone:
Expand Down Expand Up @@ -241,12 +249,12 @@ echo "Release created: rel/CarOS_Profile_Switcher-v${VERSION}.zip"
### Check Logs
View module logs:
```bash
adb shell cat /data/adb/modules/caros-switcher/log.txt
adb shell cat /data/adb/caros/log.txt
```

### Check Current State
```bash
adb shell cat /data/adb/modules/caros-switcher/state.json
adb shell cat /data/adb/caros/state.json
```

### Common Issues
Expand Down Expand Up @@ -324,3 +332,24 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
---

**Note**: This module requires root access and modifies system behavior. Use at your own risk. Always test in a safe environment first.


## 🚙 Carbox setup (always-plugged old phone)

Suggested `config.env` for a phone that stays in the car and only does wired Android Auto:

```bash
ENABLE_WIRELESS_PROFILE=0 # wired only
KEEP_BT_IN_IDLE=0 # nothing needs Bluetooth when the car is off
DATA_OFF_OUTSIDE=1
KEEP_WIFI_IN_IDLE=0
PARKING_MODE=1 # no background scans/location, forced Doze while idle
AUTO_SHUTDOWN_PCT=10 # protect the battery if the car does not charge it
DISABLE_LOCKSCREEN=1 # only works with no PIN/pattern; security trade-off
IDLE_MAX_CPU_FREQ=1000000 # kHz, adapt to your SoC
```

Things the module cannot do from a shell script:
- **Power on when the car starts.** After a shutdown the phone must boot by itself when USB power returns. This depends on the device (some ROMs/bootloaders boot on charger insertion; others need `fastboot oem off-mode-charge 0` or similar). Test it on your phone.
- **Limit the battery to 80 %.** Use [ACC (Advanced Charging Controller)](https://github.com/VR-25/acc); this module deliberately never suspends charging.
- **Internet without a SIM.** Save the Wi-Fi of your main phone's hotspot and set `KEEP_WIFI_IN_WIRED=1`.
66 changes: 61 additions & 5 deletions caros_config.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/system/bin/sh
# === CarOS Profile Switcher Centralized Configuration v0.2.3 ===
# === CarOS Profile Switcher Centralized Configuration v0.2.4 ===
# This file contains all default configuration for the module
# It is sourced by post-fs-data.sh and service.sh to ensure consistency

Expand Down Expand Up @@ -54,16 +54,32 @@ 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"
# WiFi hotspot password for audio streaming (min 8 characters).
# Empty = a random password is generated when config.env is first created
DEFAULT_WIFI_AUDIO_HOTSPOT_PASSWORD=""

# Enable the WIRELESS profile (Bluetooth connected to the car + Android Auto running).
# Set to 0 for a wired-only "carbox" setup.
DEFAULT_ENABLE_WIRELESS_PROFILE=1

# Carbox / parking mode (applies in IDLE only; all best effort)
# 1 = cut background scans, location and force Doze while the car is off
DEFAULT_PARKING_MODE=0
# Shut the phone down when idle, unplugged and battery is below this % (0 = disabled)
DEFAULT_AUTO_SHUTDOWN_PCT=0
# Remove the lock screen at boot so Android Auto can start unattended (1 = enable).
# Only works if no PIN/pattern/password is set. Security trade-off: use with care.
DEFAULT_DISABLE_LOCKSCREEN=0

# Verbose logs
DEFAULT_VERBOSE=1

# Function to generate user configuration content
generate_user_config() {
# Random hotspot password so no weak default ships
WIFI_AUDIO_HOTSPOT_PASSWORD_GEN="$(tr -dc 'A-Za-z0-9' < /dev/urandom 2>/dev/null | head -c 12)"
cat <<EOF
# === CarOS Profile Switcher Configuration v0.2.3 ===
# === CarOS Profile Switcher Configuration v0.2.4 ===

# Multiple BT names possible, separated by | (regex), ex: "Audi|AUDI MMI|MyAudi"
AUDI_BT_NAMES="$DEFAULT_AUDI_BT_NAMES"
Expand Down Expand Up @@ -111,7 +127,17 @@ 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"
WIFI_AUDIO_HOTSPOT_PASSWORD="${WIFI_AUDIO_HOTSPOT_PASSWORD_GEN:-$DEFAULT_WIFI_AUDIO_HOTSPOT_PASSWORD}"

# Enable the WIRELESS profile (0 for a wired-only carbox setup)
ENABLE_WIRELESS_PROFILE=$DEFAULT_ENABLE_WIRELESS_PROFILE

# Carbox / parking mode (IDLE only, best effort)
PARKING_MODE=$DEFAULT_PARKING_MODE
# Shut down when idle, unplugged and below this battery % (0 = disabled)
AUTO_SHUTDOWN_PCT=$DEFAULT_AUTO_SHUTDOWN_PCT
# Remove the lock screen at boot (only works without PIN/pattern/password)
DISABLE_LOCKSCREEN=$DEFAULT_DISABLE_LOCKSCREEN

# Verbose logs
VERBOSE=$DEFAULT_VERBOSE
Expand All @@ -136,5 +162,35 @@ apply_defaults() {
: "${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}"
: "${ENABLE_WIRELESS_PROFILE:=$DEFAULT_ENABLE_WIRELESS_PROFILE}"
: "${PARKING_MODE:=$DEFAULT_PARKING_MODE}"
: "${AUTO_SHUTDOWN_PCT:=$DEFAULT_AUTO_SHUTDOWN_PCT}"
: "${DISABLE_LOCKSCREEN:=$DEFAULT_DISABLE_LOCKSCREEN}"
: "${VERBOSE:=$DEFAULT_VERBOSE}"

# Numeric options are written to sysfs / compared as numbers: reject anything else
case "$IDLE_MAX_CPU_FREQ" in *[!0-9]*) IDLE_MAX_CPU_FREQ="" ;; esac
case "$AUTO_SHUTDOWN_PCT" in ''|*[!0-9]*) AUTO_SHUTDOWN_PCT=0 ;; esac
}

# Config keys that load_config accepts (anything else in a config file is ignored)
CONFIG_KEYS="AUDI_BT_NAMES AUDI_BT_MAC ALLOW_BT_IN_WIRED DATA_OFF_OUTSIDE KEEP_DATA_IN_CAR IDLE_MAX_CPU_FREQ LIMIT_QUICK_CHARGE_WIRED SET_NOVA_DEFAULT KEEP_WIFI_IN_WIRED KEEP_WIFI_IN_IDLE KEEP_BT_IN_IDLE AUTO_GRANT_PERMISSIONS ENABLE_BT_AUDIO_SINK ENABLE_WIFI_AUDIO_HOTSPOT WIFI_AUDIO_HOTSPOT_SSID WIFI_AUDIO_HOTSPOT_PASSWORD ENABLE_WIRELESS_PROFILE PARKING_MODE AUTO_SHUTDOWN_PCT DISABLE_LOCKSCREEN VERBOSE"

# Safely load a KEY=VALUE config file WITHOUT sourcing it: the file may live on
# /sdcard (writable by any app) while this code runs as root. Only whitelisted keys
# are read, and values are assigned as data, never evaluated as shell code.
load_config() {
[ -f "$1" ] || return 1
while IFS='=' read -r _key _val || [ -n "$_key" ]; do
_key=${_key%$(printf '\r')}
case "$_key" in ''|'#'*) continue ;; esac
case " $CONFIG_KEYS " in *" $_key "*) ;; *) continue ;; esac
_val=${_val%$(printf '\r')}
case "$_val" in
\"*\") _val=${_val#\"}; _val=${_val%\"} ;;
\'*\') _val=${_val#\'}; _val=${_val%\'} ;;
esac
eval "$_key=\$_val"
done < "$1"
return 0
}
Loading
Loading