Dying
This commit is contained in:
@@ -79,6 +79,9 @@ var clearConsole = function(){
|
||||
}
|
||||
|
||||
var shell = function(cmd, root){
|
||||
if(arguments.length == 1){
|
||||
return new com.stardust.scriptdroid.tool.Shell(context, arguments[0] ? 1 : 0);
|
||||
}
|
||||
root = root ? 1 : 0;
|
||||
return __runtime__.shell(cmd, root);
|
||||
}
|
||||
@@ -145,23 +148,23 @@ var longClick = function(a, b, c, d){
|
||||
}
|
||||
|
||||
|
||||
var scrollUp = function(a, b, c, d){
|
||||
var scrollDown = function(a, b, c, d){
|
||||
if(arguments.length == 0)
|
||||
return __runtime__.automator.scrollAllUp();
|
||||
return __runtime__.automator.scrollMaxForward();
|
||||
if(arguments.length == 1 && typeof a === 'number')
|
||||
return __runtime__.automator.scrollUp(a);
|
||||
return __runtime__.automator.scrollForward(a);
|
||||
return performAction(function(target){
|
||||
return __runtime__.automator.scrollUp(target);
|
||||
return __runtime__.automator.scrollForward(target);
|
||||
}, arguments);
|
||||
}
|
||||
|
||||
var scrollDown = function(a, b, c, d){
|
||||
var scrollUp = function(a, b, c, d){
|
||||
if(arguments.length == 0)
|
||||
return __runtime__.automator.scrollAllDown();
|
||||
return __runtime__.automator.scrollMaxBackward();
|
||||
if(arguments.length == 1 && typeof a === 'number')
|
||||
return __runtime__.automator.scrollDown(a);
|
||||
return __runtime__.automator.scrollBackward(a);
|
||||
return performAction(function(target){
|
||||
return __runtime__.automator.scrollDown(target);
|
||||
return __runtime__.automator.scrollBackward(target);
|
||||
}, arguments);
|
||||
}
|
||||
|
||||
@@ -180,18 +183,23 @@ var setClip = function(text){
|
||||
|
||||
|
||||
var Tap = function(x, y){
|
||||
return shell("input tap " + x + " " + y, true).code == 1;
|
||||
__runtime__.shellExecNotReturnResultWithRoot("input tap " + x + " " + y);
|
||||
}
|
||||
|
||||
var Swipe = function(x1, y1, x2, y2, duration){
|
||||
if(arguments.length == 5){
|
||||
return shell("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + duration, true).code == 1;
|
||||
__runtime__.shellExecNotReturnResultWithRoot("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + duration);
|
||||
}else{
|
||||
__runtime__.shellExecNotReturnResultWithRoot("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2);
|
||||
}
|
||||
return shell("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2, true).code == 1;
|
||||
}
|
||||
|
||||
var Screencap = function(path){
|
||||
__runtime__.shellExecNotReturnResultWithRoot("screencap -p " + path);
|
||||
}
|
||||
|
||||
var KeyCode = function(keyCode){
|
||||
return shell("input keyevent " + keyCode, true).code == 1;
|
||||
__runtime__.shellExecNotReturnResultWithRoot("input keyevent " + keyCode);
|
||||
}
|
||||
|
||||
var Home = function(){
|
||||
@@ -243,7 +251,7 @@ var Camera = function(){
|
||||
}
|
||||
|
||||
var Text = function(text){
|
||||
return shell("input text " + text, true).code == 1;
|
||||
__runtime__.shellExecNotReturnResultWithRoot("input text " + text);
|
||||
}
|
||||
|
||||
var selector = function(){
|
||||
@@ -290,7 +298,8 @@ var open = function(path, mode, encoding, bufferSize){
|
||||
}
|
||||
}
|
||||
|
||||
__importClassOld__(com.stardust.autojs.runtime.api.Shell);
|
||||
|
||||
//__importClassOld__(com.stardust.autojs.runtime.api.SlowShell);
|
||||
|
||||
var newInjectableWebClient = function(){
|
||||
return new com.stardust.autojs.runtime.api.InjectableWebClient(org.mozilla.javascript.Context.getCurrentContext(), __this__);
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.widget.Toast;
|
||||
import com.stardust.autojs.R;
|
||||
import com.stardust.autojs.engine.JavaScriptEngine;
|
||||
import com.stardust.autojs.rhino_android.AndroidClassLoader;
|
||||
import com.stardust.autojs.runtime.api.AbstractShell;
|
||||
import com.stardust.autojs.runtime.api.SlowShell;
|
||||
import com.stardust.autojs.runtime.simple_action.SimpleActionAutomator;
|
||||
import com.stardust.autojs.runtime.api.AppUtils;
|
||||
import com.stardust.autojs.runtime.api.Console;
|
||||
@@ -49,6 +51,8 @@ public class ScriptRuntime {
|
||||
@JavascriptField
|
||||
public AccessibilityInfoProvider info;
|
||||
|
||||
private AbstractShell mRootShell;
|
||||
|
||||
public ScriptRuntime(Context context, Console console, AccessibilityBridge accessibilityBridge) {
|
||||
mContext = context;
|
||||
mAccessibilityBridge = accessibilityBridge;
|
||||
@@ -88,6 +92,15 @@ public class ScriptRuntime {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@JavascriptInterface
|
||||
public void shellExecNotReturnResultWithRoot(String cmd){
|
||||
if(mRootShell == null){
|
||||
mRootShell = new SlowShell(true);
|
||||
}
|
||||
mRootShell.exec(cmd);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public Shell.CommandResult shell(String cmd, int root) {
|
||||
return Shell.execCommand(cmd, root != 0);
|
||||
@@ -96,7 +109,7 @@ public class ScriptRuntime {
|
||||
@JavascriptInterface
|
||||
public UiSelector selector(JavaScriptEngine engine) {
|
||||
AccessibilityNodeInfoAllocator allocator = (AccessibilityNodeInfoAllocator) engine.getTag("allocator");
|
||||
if(allocator == null){
|
||||
if (allocator == null) {
|
||||
allocator = new AccessibilityNodeInfoAllocator();
|
||||
engine.setTag("allocator", allocator);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/7.
|
||||
* Created by Stardust on 2017/4/24.
|
||||
*/
|
||||
|
||||
public class Shell extends com.stardust.util.Shell {
|
||||
public abstract class AbstractShell {
|
||||
|
||||
public Shell(boolean root) {
|
||||
super(root);
|
||||
public AbstractShell() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public void Tap(int x, int y) {
|
||||
execute("input tap " + x + " " + y);
|
||||
public AbstractShell(boolean root) {
|
||||
init(root ? "su" : "sh");
|
||||
}
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2) {
|
||||
execute("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2);
|
||||
}
|
||||
protected abstract void init(String initialCommand);
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2, long duration) {
|
||||
execute("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + duration);
|
||||
}
|
||||
public abstract void exec(String command);
|
||||
|
||||
public void KeyCode(int keyCode) {
|
||||
execute("input keyevent " + keyCode);
|
||||
exec("input keyevent " + keyCode);
|
||||
}
|
||||
|
||||
public void KeyCode(String keyCode) {
|
||||
execute("input keyevent " + keyCode);
|
||||
exec("input keyevent " + keyCode);
|
||||
}
|
||||
|
||||
public void Home() {
|
||||
@@ -79,7 +75,6 @@ public class Shell extends com.stardust.util.Shell {
|
||||
}
|
||||
|
||||
public void Text(String text) {
|
||||
execute("input text " + text);
|
||||
exec("input text " + text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
import com.stardust.util.Shell;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/7.
|
||||
*/
|
||||
|
||||
public class SlowShell extends AbstractShell {
|
||||
|
||||
private Shell mShell;
|
||||
|
||||
public SlowShell(boolean root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(String initialCommand) {
|
||||
mShell = new Shell(initialCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec(String command) {
|
||||
mShell.execute(command);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
|
||||
public class SimpleActionAutomator {
|
||||
|
||||
@Deprecated
|
||||
private static class PerformGlobalActionCommand extends AccessibilityEventCommandHost.AbstractCommand {
|
||||
|
||||
boolean result;
|
||||
@@ -91,22 +92,22 @@ public class SimpleActionAutomator {
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public boolean scrollUp(int i) {
|
||||
public boolean scrollBackward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, i));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public boolean scrollDown(int i) {
|
||||
public boolean scrollForward(int i) {
|
||||
return performAction(ActionFactory.createScrollAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, i));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public boolean scrollAllUp() {
|
||||
public boolean scrollMaxBackward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public boolean scrollAllDown() {
|
||||
public boolean scrollMaxForward() {
|
||||
return performAction(ActionFactory.createScrollMaxAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.stardust.autojs.script;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.stardust.autojs.rhino_android.RhinoAndroidHelper;
|
||||
import com.stardust.pio.PFile;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
|
||||
import org.mozilla.javascript.Function;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/12.
|
||||
*/
|
||||
|
||||
public class JsBeautifier {
|
||||
|
||||
public interface Callback {
|
||||
|
||||
void onSuccess(String beautifiedCode);
|
||||
|
||||
void onException(Exception e);
|
||||
}
|
||||
|
||||
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||
private Context mContext;
|
||||
private org.mozilla.javascript.Context mScriptContext;
|
||||
private Function mJsBeautifyFunction;
|
||||
private Scriptable mScriptable;
|
||||
private final String mBeautifyJsPath;
|
||||
|
||||
public JsBeautifier(Context context, String beautifyJsPath) {
|
||||
mContext = context;
|
||||
mBeautifyJsPath = beautifyJsPath;
|
||||
}
|
||||
|
||||
public void beautify(final String code, final Callback callback) {
|
||||
mExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
prepareIfNeeded();
|
||||
Object beautifiedCode = mJsBeautifyFunction.call(mScriptContext, mScriptable, mScriptable, new Object[]{code});
|
||||
callback.onSuccess(beautifiedCode.toString());
|
||||
} catch (Exception e) {
|
||||
callback.onException(e);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
mExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
prepareIfNeeded();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void prepareIfNeeded() {
|
||||
if (mScriptContext != null)
|
||||
return;
|
||||
RhinoAndroidHelper helper = new RhinoAndroidHelper(mContext);
|
||||
mScriptContext = helper.enterContext();
|
||||
compile();
|
||||
}
|
||||
|
||||
private void compile() {
|
||||
try {
|
||||
InputStream is = mContext.getAssets().open(mBeautifyJsPath);
|
||||
mScriptable = mScriptContext.initSafeStandardObjects();
|
||||
mJsBeautifyFunction = mScriptContext.compileFunction(mScriptable, PFile.read(is), "<js_beautify>", 1, null);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user