Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能够正常使用的脚本使用定时任务后工作异常 #225

Open
MisterZakary opened this issue Feb 20, 2024 · 0 comments
Open

能够正常使用的脚本使用定时任务后工作异常 #225

MisterZakary opened this issue Feb 20, 2024 · 0 comments

Comments

@MisterZakary
Copy link

非常感谢作者的无私奉献,为了让软件更好,现将遇到的相关问题提出。

环境说明:
系统:miui13 已经root
autojs6:6.5.0版本,给予root权限以及除shizuku外的所有权限

都是锁屏后定时运行,脚本第一步打开无障碍服务,代码如下:

/**
 * @description: 免root打开无障碍服务(需adb授权,重启手机不失效)
 * @param:  {string} [package]:需要开启免Root无障碍服务的包名,默认是Autojs6
 * @return: null
 */
baseLib._自动启用无障碍服务 = function(package){
    //默认设置为Autojs6
    var package     = typeof(package)!=="undefined" ? package : "org.autojs.autojs6";

    importClass(android.content.Context);
    importClass(android.provider.Settings);
    try {
        var enabledServices = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        log('当前已启用的辅助服务\n', enabledServices);

        var Services = enabledServices + ":" + package + "/com.stardust.autojs.core.accessibility.AccessibilityService";
        Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, Services);
        Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, '1');
        
        toastLog("成功开启" + package + "的免Root无障碍辅助服务");
    } catch (error) {
        //授权方法:开启usb调试并使用adb工具连接手机,执行 adb shell pm grant org.autojs.autojspro android.permission.WRITE_SECURE_SETTING
        toastLog("\n请确保已给予 WRITE_SECURE_SETTINGS 权限\n\n授权代码已复制,请使用adb工具连接手机执行(重启不失效)\n\n", error);
        setClip("adb shell pm grant " + package + " android.permission.WRITE_SECURE_SETTINGS");
    }
    auto.waitFor();
}

然后解锁屏幕,代码如下

/**
 * @description: 屏幕解锁功能
 * @param:
 *  {数组}passWord:存储密码的一维数组
 *  {string}info:主屏上的APP名字用以确认是否解锁完成
 * @return:
 *  {bool} true:表示解锁成功
 *  {bool} false:表示解锁失败
 */
baseLib._解锁锁屏密码 = function(passWord,info) {
    if(!device.isScreenOn() || desc("快捷方式").exists()){
        device.wakeUp();
        sleep(5000);
        //向上滑动解锁
        swipe(500, 1000, 500, 30, 1200);
       sleep(2000);

        //密码解锁
        var index;
        for (index in passWord){
            desc(passWord[index]).findOne().click();
            sleep(2000);
        }
        sleep(3000);
        if(text(info).exists()){
            baseLib._输出调试信息("解锁成功");
            return true
        }
        else{
            baseLib._输出调试信息("解锁失败或者["+info+"]不在主屏上");
            return false
        }
    }
    return true;
}

接下来就是正常的打开app,执行相关操作。问题就是手动运行脚本正常,一旦定时运行脚本就开始胡乱操作。

希望能够提升后台运行以及定时运行问题解决的优先级,有较多的脚本都是在晚上睡觉的时候通过脚本来操作 。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant