Search in sources :

Example 1 with ScriptInterruptedException

use of com.stardust.autojs.runtime.exception.ScriptInterruptedException in project Auto.js by hyb1996.

the class UiSelector method findOne.

@ScriptInterface
public UiObject findOne(long timeout) {
    if (timeout == -1) {
        return untilFindOne();
    }
    UiObjectCollection uiObjectCollection = find();
    long start = SystemClock.uptimeMillis();
    while (uiObjectCollection.empty()) {
        if (Thread.currentThread().isInterrupted()) {
            throw new ScriptInterruptedException();
        }
        if (SystemClock.uptimeMillis() - start > timeout) {
            return null;
        }
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            throw new ScriptInterruptedException();
        }
        uiObjectCollection = find();
    }
    return uiObjectCollection.get(0);
}
Also used : UiObjectCollection(com.stardust.automator.UiObjectCollection) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) ScriptInterface(com.stardust.autojs.annotation.ScriptInterface)

Example 2 with ScriptInterruptedException

use of com.stardust.autojs.runtime.exception.ScriptInterruptedException in project Auto.js by hyb1996.

the class Floaty method window.

public JsFloatyWindow window(View view) {
    try {
        FloatingPermission.waitForPermissionGranted(view.getContext());
    } catch (InterruptedException e) {
        throw new ScriptInterruptedException();
    }
    JsFloatyWindow window = new JsFloatyWindow(view);
    addWindow(window);
    return window;
}
Also used : ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException)

Example 3 with ScriptInterruptedException

use of com.stardust.autojs.runtime.exception.ScriptInterruptedException in project Auto.js by hyb1996.

the class ProcessShell method execCommand.

public static Result execCommand(String[] commands, boolean isRoot) {
    Result commandResult = new Result();
    if (commands == null || commands.length == 0)
        throw new IllegalArgumentException("command is empty");
    Process process = null;
    DataOutputStream os = null;
    try {
        process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
        os = new DataOutputStream(process.getOutputStream());
        for (String command : commands) {
            if (command != null) {
                os.write(command.getBytes());
                os.writeBytes(COMMAND_LINE_END);
                os.flush();
            }
        }
        os.writeBytes(COMMAND_EXIT);
        os.flush();
        Log.d(TAG, "pid = " + ProcessUtils.getProcessPid(process));
        commandResult.code = process.waitFor();
        commandResult.result = readAll(process.getInputStream());
        commandResult.error = readAll(process.getErrorStream());
        Log.d(TAG, commandResult.toString());
    } catch (Exception e) {
        throw new ScriptInterruptedException(e);
    } finally {
        try {
            if (os != null)
                os.close();
            if (process != null) {
                process.getInputStream().close();
                process.getOutputStream().close();
            }
        } catch (IOException ignored) {
        }
        if (process != null) {
            process.destroy();
        }
    }
    return commandResult;
}
Also used : DataOutputStream(java.io.DataOutputStream) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) IOException(java.io.IOException) UncheckedIOException(com.stardust.pio.UncheckedIOException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) IOException(java.io.IOException) UncheckedIOException(com.stardust.pio.UncheckedIOException)

Example 4 with ScriptInterruptedException

use of com.stardust.autojs.runtime.exception.ScriptInterruptedException in project Auto.js by hyb1996.

the class RootAutomatorEngine method execute.

public void execute(String autoFile) {
    mExecutablePath = getExecutablePath(mContext);
    Log.d(LOG_TAG, "exec: " + autoFile);
    final String[] commands = { "chmod 755 " + mExecutablePath, // to run root_automator
    String.format("\"%s\" \"%s\" -d \"%s\" &", mExecutablePath, autoFile, mDeviceNameOrPath), // to print the root_automator pid
    "echo $!", // to exit su
    "exit", // to exit shell
    "exit" };
    try {
        mProcess = Runtime.getRuntime().exec("su");
        executeCommands(mProcess, commands);
        mPid = readPid(mProcess);
        mProcess.waitFor();
    } catch (IOException e) {
        throw new ScriptException(e);
    } catch (InterruptedException e) {
        throw new ScriptInterruptedException();
    } finally {
        mProcess.destroy();
        mProcess = null;
    }
}
Also used : ScriptException(com.stardust.autojs.runtime.exception.ScriptException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException) IOException(java.io.IOException) ScriptInterruptedException(com.stardust.autojs.runtime.exception.ScriptInterruptedException)

Aggregations

ScriptInterruptedException (com.stardust.autojs.runtime.exception.ScriptInterruptedException)4 IOException (java.io.IOException)2 ScriptInterface (com.stardust.autojs.annotation.ScriptInterface)1 ScriptException (com.stardust.autojs.runtime.exception.ScriptException)1 UiObjectCollection (com.stardust.automator.UiObjectCollection)1 UncheckedIOException (com.stardust.pio.UncheckedIOException)1 DataOutputStream (java.io.DataOutputStream)1