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);
}
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;
}
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;
}
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;
}
}
Aggregations