#!/system/bin/sh
# CamSwapper VDM Privilege Module - Installation customization
# Sourced by KernelSU/Magisk installer after files are extracted.

SKIPUNZIP=0

# Set permissions
set_perm_recursive "$MODPATH/system" 0 0 0755 0644
set_perm "$MODPATH/system/priv-app/CamSwapper/CamSwapper.apk" 0 0 0644
set_perm "$MODPATH/system/etc/permissions/privapp-permissions-camswapper.xml" 0 0 0644
set_perm "$MODPATH/post-fs-data.sh" 0 0 0755
set_perm "$MODPATH/service.sh" 0 0 0755
set_perm "$MODPATH/uninstall.sh" 0 0 0755

# Remove user-installed version to avoid package conflict
if command -v pm >/dev/null 2>&1; then
    pm uninstall com.nothing.camera2magic 2>/dev/null && \
        ui_print "- Removed user-installed CamSwapper"
fi

ui_print ""
ui_print "  CamSwapper VDM Privilege Module"
ui_print "  ──────────────────────────────"
ui_print "  Installed CamSwapper as privileged system app"
ui_print "  Granted: REQUEST_COMPANION_PROFILE_APP_STREAMING"
ui_print "  Granted: REQUEST_COMPANION_SELF_MANAGED"
ui_print "  Granted: CREATE_VIRTUAL_DEVICE"
ui_print ""
ui_print "  After reboot:"
ui_print "    1. Open CamSwapper (it's now a system app)"
ui_print "    2. Grant CAMERA + POST_NOTIFICATIONS permissions"
ui_print "    3. Start virtual camera"
ui_print ""
