modularize init script
This commit is contained in:
@@ -86,7 +86,7 @@ public class RhinoJavaScriptEngineManager extends AbstractScriptEngineManager {
|
||||
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(getContext(), list);
|
||||
new RequireBuilder()
|
||||
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
|
||||
.setSandboxed(true)
|
||||
.setSandboxed(false)
|
||||
.createRequire(context, scope)
|
||||
.install(scope);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public abstract class AbstractScriptRuntime {
|
||||
public abstract void setClip(final String text);
|
||||
|
||||
@ScriptInterface
|
||||
public abstract void shellExecAsync(String cmd);
|
||||
public abstract AbstractShell getRootShell();
|
||||
|
||||
@ScriptInterface
|
||||
public abstract AbstractShell.Result shell(String cmd, int root);
|
||||
@@ -66,9 +66,6 @@ public abstract class AbstractScriptRuntime {
|
||||
@ScriptInterface
|
||||
public abstract void stop();
|
||||
|
||||
@ScriptInterface
|
||||
public abstract void SetScreenMetrics(int width, int height);
|
||||
|
||||
public abstract void ensureAccessibilityServiceEnabled();
|
||||
|
||||
public abstract void onStop();
|
||||
|
||||
@@ -117,9 +117,10 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
});
|
||||
}
|
||||
|
||||
public void shellExecAsync(String cmd) {
|
||||
@Override
|
||||
public AbstractShell getRootShell() {
|
||||
ensureRootShell();
|
||||
mRootShell.exec(cmd);
|
||||
return mRootShell;
|
||||
}
|
||||
|
||||
private void ensureRootShell() {
|
||||
@@ -137,7 +138,6 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
}
|
||||
|
||||
public UiSelector selector(ScriptEngine engine) {
|
||||
Intent intent;
|
||||
return new UiSelector(mAccessibilityBridge);
|
||||
}
|
||||
|
||||
@@ -163,12 +163,6 @@ public class ScriptRuntime extends AbstractScriptRuntime {
|
||||
Thread.interrupted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetScreenMetrics(int width, int height) {
|
||||
ensureRootShell();
|
||||
mRootShell.SetScreenMetrics(width, height);
|
||||
}
|
||||
|
||||
public void ensureAccessibilityServiceEnabled() {
|
||||
mAccessibilityBridge.ensureServiceEnabled();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class AbstractShell {
|
||||
|
||||
public AbstractShell(boolean root) {
|
||||
mRoot = root;
|
||||
init(root ? COMMAND_SU: COMMAND_SH);
|
||||
init(root ? COMMAND_SU : COMMAND_SH);
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
@@ -62,20 +62,20 @@ public abstract class AbstractShell {
|
||||
mTouchDevice = touchDevice;
|
||||
}
|
||||
|
||||
public void SendEvent(int type, int code, int value){
|
||||
public void SendEvent(int type, int code, int value) {
|
||||
SendEvent(mTouchDevice, type, code, value);
|
||||
}
|
||||
|
||||
public void SendEvent(int device, int type, int code, int value){
|
||||
public void SendEvent(int device, int type, int code, int value) {
|
||||
exec(TextUtils.join("", new Object[]{"sendevent /dev/input/event", device, " ", type, " ", code, " ", value}));
|
||||
}
|
||||
|
||||
public void SetScreenMetrics(int width, int height){
|
||||
public void SetScreenMetrics(int width, int height) {
|
||||
mScreenWidth = width;
|
||||
mScreenHeight = height;
|
||||
}
|
||||
|
||||
public void Touch(int x, int y){
|
||||
public void Touch(int x, int y) {
|
||||
TouchX(x);
|
||||
TouchY(y);
|
||||
}
|
||||
@@ -85,8 +85,10 @@ public abstract class AbstractShell {
|
||||
}
|
||||
|
||||
private int scaleX(int x) {
|
||||
if (mScreenWidth == 0)
|
||||
return x;
|
||||
int screenWidth = ScreenMetrics.getScreenWidth();
|
||||
if(screenWidth == mScreenWidth){
|
||||
if (screenWidth == mScreenWidth) {
|
||||
return x;
|
||||
}
|
||||
return x * screenWidth / mScreenWidth;
|
||||
@@ -97,13 +99,26 @@ public abstract class AbstractShell {
|
||||
}
|
||||
|
||||
private int scaleY(int y) {
|
||||
if (mScreenHeight == 0)
|
||||
return y;
|
||||
int screenHeight = ScreenMetrics.getScreenHeight();
|
||||
if(screenHeight == mScreenHeight){
|
||||
if (screenHeight == mScreenHeight) {
|
||||
return y;
|
||||
}
|
||||
return y * screenHeight / mScreenHeight;
|
||||
}
|
||||
|
||||
public void Tap(int x, int y) {
|
||||
exec("input tap " + scaleX(x) + " " + scaleY(y));
|
||||
}
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2) {
|
||||
exec(com.stardust.util.TextUtils.join(" ", "input", "tap", scaleX(x1), scaleY(y1), scaleX(x2), scaleY(y2)));
|
||||
}
|
||||
|
||||
public void Swipe(int x1, int y1, int x2, int y2, int time) {
|
||||
exec(com.stardust.util.TextUtils.join(" ", "input", "tap", scaleX(x1), scaleY(y1), scaleX(x2), scaleY(y2), time));
|
||||
}
|
||||
|
||||
public void KeyCode(int keyCode) {
|
||||
exec("input keyevent " + keyCode);
|
||||
@@ -161,9 +176,17 @@ public abstract class AbstractShell {
|
||||
KeyCode(27);
|
||||
}
|
||||
|
||||
public void Text(String text) {
|
||||
public void Input(String text) {
|
||||
exec("input text " + text);
|
||||
}
|
||||
|
||||
public void Screencap(String path) {
|
||||
exec("screencap -p " + path);
|
||||
}
|
||||
|
||||
public void Text(String text) {
|
||||
Input(text);
|
||||
}
|
||||
|
||||
public abstract void exitAndWaitFor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user