Files
fengtv/setup_home_launcher.sh
2026-06-18 10:28:37 +08:00

98 lines
3.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/system/bin/sh
# ============================================================
# FengTV - 设置为默认启动器(HOME桌面)
# 需要在 root 权限下执行(adb root 或 su
# ============================================================
PACKAGE="cn.flyzxf.FengTv"
ACTIVITY="cn.flyzxf.FengTv.MainActivity"
echo "============================================"
echo " FengTV 开机自启设置脚本"
echo "============================================"
echo ""
# 检查 root
if [ "$(id -u)" != "0" ]; then
echo "❌ 需要 root 权限!请用 adb root 或以 su 执行"
echo " 用法: adb root && adb shell < 此脚本"
echo " 或: 在终端模拟器中 su -c 'sh 此脚本'"
exit 1
fi
echo "✅ 已获得 root 权限"
# 方法1: 设置默认 HOME 启动器(最可靠)
echo ""
echo "📌 正在设置 FengTV 为默认启动器..."
# 清除旧的默认启动器设置
pm clear-defaults 2>/dev/null
# 将 FengTV 设置为默认 HOME
cmd package set-home-activity "$PACKAGE/$ACTIVITY" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ 已设置 FengTV 为默认桌面"
else
echo "⚠️ set-home-activity 失败,尝试备用方法..."
# 备用方法:直接修改系统设置
settings put secure default_input_method "$PACKAGE/$ACTIVITY" 2>/dev/null
# 对于 Android TV,使用 HOME 设置
if [ -d /data/system/users/0 ]; then
# 直接写入 role 管理器
pm grant "$PACKAGE" android.permission.SET_ACTIVITY_WATCHER 2>/dev/null
fi
echo "⚠️ 请手动设置:设置 → 应用 → 默认应用 → 桌面 → 选择 FengTV"
fi
# 方法2: 添加开机自启动白名单(针对小米/华为等国产系统)
echo ""
echo "📌 尝试添加开机自启动白名单..."
# 常见厂商白名单
for PROVIDER in "miui" "huawei" "oppo" "vivo" "oneplus" "smartisan" "meizu"; do
case "$PROVIDER" in
"miui")
# 小米 MIUI
settings put global power_supply_start_delay 0 2>/dev/null
appops set "$PACKAGE" AUTO_START allow 2>/dev/null
;;
"huawei")
# 华为 EMUI
settings put secure hw_auto_start_app_list "$PACKAGE" 2>/dev/null
;;
esac
done
# 方法3: 禁用系统的电池优化(防止杀后台)
echo ""
echo "📌 禁用电池优化..."
dumpsys deviceidle whitelist +"$PACKAGE" 2>/dev/null
pm grant "$PACKAGE" android.permission.DEVICE_POWER 2>/dev/null
appops set "$PACKAGE" RUN_ANY_IN_BACKGROUND allow 2>/dev/null
# 方法4: 对于 Android 8+,添加为持久化应用(需预置)
# 非系统应用可能不支持,但试试无害
echo ""
echo "📌 尝试注册为系统级自启应用..."
if [ -f /data/system/packages.xml ]; then
echo " 跳过(非系统分区操作)"
fi
echo ""
echo "============================================"
echo " ✅ 设置完成!"
echo "============================================"
echo ""
echo "重启电视后 FengTV 将自动启动"
echo ""
echo "如果仍然无法自启,请尝试:"
echo " 1. 在电视设置中关闭 FengTV 的"省电优化""
echo " 2. 将 FengTV 加入"受保护应用"列表"
echo " 3. 检查设置 → 应用 → 默认应用 → 桌面 → 选择 FengTV"
echo ""