#!/usr/bin/env bash
# [兼容入口] 卸载旧奥创 APK — 请优先使用：
#   bash sdk/scripts/clean_aochuang_device.sh --apply [-s SERIAL]
#   Skill：机擎/阿服/奥创真机清机/SKILL.md
# 本脚本仅卸两核心包，不含 xesd/Magisk/007 App。

set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ "${1:-}" == "--full" ]]; then
  shift
  exec bash "$SCRIPT_DIR/clean_aochuang_device.sh" --apply "$@"
fi
OCREAT_PACKAGES=(
  "org.xeslciw.manager"   # XESlciw 框架管理
  "top.zzz.vivwxjz"       # 微信 Hook 模块
)
KEEP_PACKAGE="com.system.cloudservice"  # 新工作程序，不卸载

ADB="${ADB:-adb}"
if [[ -n "$1" ]]; then
  ADB="adb -s $1"
fi

echo "=== 卸载旧奥创 APK（保留 $KEEP_PACKAGE）==="
echo "设备: $($ADB devices -l | grep -v 'List' | grep device | head -1 || echo '未指定，使用默认')"
echo ""

for pkg in "${OCREAT_PACKAGES[@]}"; do
  if $ADB shell pm list packages 2>/dev/null | grep -q "^package:$pkg"; then
    echo "卸载: $pkg"
    $ADB uninstall "$pkg" || echo "  (卸载失败或需手动确认)"
  else
    echo "跳过(未安装): $pkg"
  fi
done

echo ""
echo "完成。新工作程序 $KEEP_PACKAGE 未动。"
