A simple, reliable script that extends AFWall+ with Work Profile support and automatic sorting by custom app names.
- Rooted Android device (Magisk/KernelSU/SuperSU)
- AFWall+ installed with root granted
- Work Profile exists (via Island, Shelter, or native Dual Apps)
- ADB on computer for initial setup
-
Connect device with ADB debugging enabled
-
Create directories and push files:
# Create config directory (user accessible)
adb shell "mkdir -p /sdcard/afw/"
# Create script directory with root
adb shell "su -c 'mkdir -p /data/local/afw/'"
# Push script to temp location first
adb push afw.sh /sdcard/afw/afw.sh.tmp
# Move to final location with root permissions
adb shell "su -c 'cp /sdcard/afw/afw.sh.tmp /data/local/afw/afw.sh'"
adb shell "su -c 'chmod 755 /data/local/afw/afw.sh'"
adb shell "rm /sdcard/afw/afw.sh.tmp"
# Push config file
adb push uid.txt /sdcard/afw/uid.txt-
Configure AFWall+:
- Open AFWall+ โ Menu (โฎ) โ Set custom script
- Enter exactly:
nohup /data/local/afw/afw.sh > /dev/null 2>&1 & - Tap OK to save
-
Initial run:
- Tap Apply in AFWall+ (this triggers the script)
- Check Android logs for "afwall_custom_script" tag to verify
You MUST tap "Apply" in AFWall+ after editing uid.txt! The script only runs when AFWall+ triggers it. Changes to uid.txt alone do nothing until you:
- Edit
/sdcard/afw/uid.txt - Save the file
- Open AFWall+ and tap Apply
For easy one-tap editing, create a shortcut to uid.txt:
- See HOWTO.md for detailed instructions
- Works with X-plore, MiXplorer, Solid Explorer, Total Commander
- Edit uid.txt with one tap!
com.spotify.music Spotify Music Player
The script auto-detects the UID and sorts by "Spotify Music Player"
1010444 My Special App
The script auto-detects the package name
1010444 com.spotify.music Spotify Premium
Format: UID PACKAGE CUSTOM_NAME
Everything after the package name is the custom name
See HOWTO.md for complete instructions:
- App Manager method (visual, easy)
- ADB commands (batch operations)
- On-device terminal (quick checks)
- Apps are automatically sorted alphabetically by your custom names
- Case-insensitive sorting (A=a, B=b, etc.)
- Happens every time the script runs
- No configuration needed - it just works!
- Automatic detection of
-wflag support - Waits for lock (up to 5 seconds) when supported
- Prevents errors like "Another app is currently holding the xtables lock"
- Works on old and new Android versions
- See HOWTO.md for details
Before sorting:
com.zzz.app Zebra App
com.aaa.app Apple App
com.mmm.app Mango App
After sorting (automatic):
com.aaa.app Apple App
com.mmm.app Mango App
com.zzz.app Zebra App
debug=0 # Line 1: Production mode
recalculate=0 # Line 2: Normal operation
# Your apps (will be auto-sorted)
com.spotify.music Spotify Music
com.android.chrome Chrome Browser
com.whatsapp WhatsApp Messenger
| Line | Setting | Values | Description |
|---|---|---|---|
| 1 | debug |
0 or 1 |
Enable verbose logging |
| 2 | recalculate |
0 or 1 |
Force UID refresh (for migrations) |
- HOWTO.md - Detailed how-to guide covering:
- Creating homescreen shortcuts for easy editing
- Finding UIDs and package names
- Troubleshooting xtables lock issues
- QUICK_REFERENCE.md - Quick command reference
- CHANGELOG.md - Version history and changes
When moving to a new device, UIDs change but package names don't:
-
Backup old device:
adb pull /sdcard/afw/uid.txt uid_backup.txt
-
Setup new device: Install script
-
Restore file:
adb push uid_backup.txt /sdcard/afw/uid.txt
-
Enable recalculation: Set line 2 to
recalculate=1 -
Apply: Tap Apply in AFWall+ to refresh all UIDs
-
Automatic reset: Script sets
recalculate=0after completion
Nothing happens after editing uid.txt:
- Did you tap Apply in AFWall+? (Required!)
- Check logs:
adb shell "logcat -d | grep afwall_custom"
xtables lock errors:
- v1.1 fixes this automatically with
-wflag - See HOWTO.md for details
Apps not blocked/allowed:
# Enable debug mode:
# Change line 1 to: debug=1
# Then tap Apply and check outputVerify Work Profile:
adb shell "pm list users"
# Should show: UserInfo{10:Work Profile:30}- Parse uid.txt into memory
- Augment missing UIDs/packages via
pmcommand - Recalculate UIDs if migration mode enabled
- Sort entries alphabetically by custom name
- Apply iptables rules (with
-wflag support) - Write sorted, complete data back to file
- File locking prevents concurrent writes
- Atomic operations prevent partial writes
- UID validation prevents invalid iptables commands
- xtables lock handling prevents lock conflicts
- Silent operation in production mode
- Parse: ~40ms
- Augment: ~200ms (depends on pm lookups)
- Sort: ~2-5ms
- Apply rules: ~500ms
- Total: ~750ms (typical config with 20 apps)
- Script location: Keep in
/data/local/afw/(root-protected) - Configuration: Stored in
/sdcard/afw/for easy editing - Permissions: Script requires root for iptables access
- Validation: All UIDs verified before use
debug=0
recalculate=0
com.android.chrome Chrome
com.spotify.music Spotify
debug=0
recalculate=0
# Apps (will be sorted automatically)
com.android.chrome Chrome Browser
com.whatsapp WhatsApp Messenger
com.spotify.music Spotify Music
com.slack Slack for Work
com.zoom.videomeetings Zoom
debug=1
recalculate=0
com.android.chrome Chrome
com.spotify.music Spotify
- NEW: Automatic sorting by custom name
- NEW: xtables lock fix with
-wflag support - Alphabetical, case-insensitive sorting
- Automatic compatibility detection
- No configuration needed
- Basic Work Profile support (user 10)
- Dynamic UID/package name resolution
- Debug and recalculate modes
- File locking mechanism
- IPv4 and IPv6 support
- Logs: Check
logcatfor tag "afwall_custom_script" - Debug: Enable
debug=1for detailed output - Script location:
/data/local/afw/afw.sh - Config location:
/sdcard/afw/uid.txt - How-to guide: See HOWTO.md for detailed instructions
This project is released under the MIT License. Use, modify, and distribute freely.
Version 1.1 - Automatic sorting by custom name + xtables lock fix