add: auto() function and two mode of fetching rootInActiveWindow
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
|
||||
__runtime__.init();
|
||||
|
||||
if(__engine_name__ == "rhino"){
|
||||
__importClass__ = importClass;
|
||||
var importClass = function(pack){
|
||||
__importClass__ = importClass;
|
||||
var importClass = function(pack){
|
||||
if(typeof(pack) == "string"){
|
||||
__importClass__(Packages[pack]);
|
||||
}else{
|
||||
__importClass__(pack);
|
||||
}
|
||||
}
|
||||
var loadJar = function(path){
|
||||
}
|
||||
|
||||
var loadJar = function(path){
|
||||
__runtime__.loadJar(path);
|
||||
}
|
||||
}
|
||||
|
||||
__runtime__.bridges.setFunctionCaller(function(func, target, args){
|
||||
|
||||
@@ -97,12 +97,28 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
|
||||
automator.input = function(a, b){
|
||||
if(arguments.length == 1){
|
||||
return __runtime__.automator.appendText(__runtime__.automator.editable(-1), a);
|
||||
}else{
|
||||
return __runtime__.automator.appendText(__runtime__.automator.editable(a), b);
|
||||
}
|
||||
if(arguments.length == 1){
|
||||
return __runtime__.automator.appendText(__runtime__.automator.editable(-1), a);
|
||||
}else{
|
||||
return __runtime__.automator.appendText(__runtime__.automator.editable(a), b);
|
||||
}
|
||||
}
|
||||
|
||||
var modes = {
|
||||
"normal": 0,
|
||||
"fast": 1
|
||||
}
|
||||
|
||||
scope.auto = function(mode){
|
||||
if(mode){
|
||||
if(typeof(mode) !== "string"){
|
||||
throw new TypeError("mode should be a string");
|
||||
}
|
||||
mode = modes[mode.toLowerCase()];
|
||||
}
|
||||
mode = mode || 0;
|
||||
__runtime__.accessibilityBridge.setMode(mode);
|
||||
}
|
||||
|
||||
scope.__asGlobal__(__runtime__.automator, ['back', 'home', 'powerDialog', 'notifications', 'quickSettings', 'recents', 'splitScreen']);
|
||||
scope.__asGlobal__(automator, ['click', 'longClick', 'press', 'swipe', 'gesture', 'gestures', 'gestureAsync', 'gesturesAsync', 'scrollDown', 'scrollUp', 'input', 'setText']);
|
||||
|
||||
@@ -16,7 +16,8 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
|
||||
return function(){
|
||||
return __runtime__.selector(scope.__engine__);
|
||||
var s = __runtime__.selector(scope.__engine__);
|
||||
return s;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.stardust.autojs.runtime;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.CallSuper;
|
||||
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
@@ -24,6 +23,8 @@ import com.stardust.util.UiHandler;
|
||||
import com.stardust.view.accessibility.AccessibilityInfoProvider;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/4.
|
||||
@@ -61,16 +62,19 @@ public abstract class AbstractScriptRuntime {
|
||||
@ScriptVariable
|
||||
public Timers timers;
|
||||
|
||||
@ScriptVariable
|
||||
public AccessibilityBridge accessibilityBridge;
|
||||
|
||||
private Images images;
|
||||
|
||||
private UiHandler mUiHandler;
|
||||
private AccessibilityBridge mAccessibilityBridge;
|
||||
private static WeakReference<Context> applicationContext;
|
||||
private Map<String, Object> mProperties = new ConcurrentHashMap<>();
|
||||
|
||||
public AbstractScriptRuntime(UiHandler uiHandler, Console console, AccessibilityBridge bridge, AppUtils appUtils, ScreenCaptureRequester screenCaptureRequester) {
|
||||
this.app = appUtils;
|
||||
this.console = console;
|
||||
mAccessibilityBridge = bridge;
|
||||
accessibilityBridge = bridge;
|
||||
mUiHandler = uiHandler;
|
||||
this.automator = new SimpleActionAutomator(bridge, this);
|
||||
this.info = bridge.getInfoProvider();
|
||||
@@ -90,7 +94,7 @@ public abstract class AbstractScriptRuntime {
|
||||
if (loopers != null)
|
||||
throw new IllegalStateException("already initialized");
|
||||
loopers = new Loopers();
|
||||
events = new Events(mUiHandler.getContext(), mAccessibilityBridge, bridges, loopers);
|
||||
events = new Events(mUiHandler.getContext(), accessibilityBridge, bridges, loopers);
|
||||
timers = new Timers(bridges);
|
||||
}
|
||||
|
||||
@@ -158,5 +162,16 @@ public abstract class AbstractScriptRuntime {
|
||||
return images;
|
||||
}
|
||||
|
||||
public Object getProperty(String key) {
|
||||
return mProperties.get(key);
|
||||
}
|
||||
|
||||
public Object putProperty(String key, Object value) {
|
||||
return mProperties.put(key, value);
|
||||
}
|
||||
|
||||
public Object removeProperty(String key) {
|
||||
return mProperties.remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.stardust.autojs.runtime;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.view.accessibility.AccessibilityInfoProvider;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
@@ -9,15 +11,37 @@ import com.stardust.view.accessibility.AccessibilityService;
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
public interface AccessibilityBridge {
|
||||
public abstract class AccessibilityBridge {
|
||||
|
||||
void ensureServiceEnabled();
|
||||
public static final int MODE_NORMAL = 0;
|
||||
public static final int MODE_FAST = 1;
|
||||
|
||||
AccessibilityInfoProvider getInfoProvider();
|
||||
private int mMode = MODE_NORMAL;
|
||||
|
||||
|
||||
public abstract void ensureServiceEnabled();
|
||||
|
||||
|
||||
@Nullable
|
||||
AccessibilityService getService();
|
||||
public abstract AccessibilityService getService();
|
||||
|
||||
@Nullable
|
||||
public AccessibilityNodeInfo getRootInActiveWindow() {
|
||||
AccessibilityService service = getService();
|
||||
if (service == null)
|
||||
return null;
|
||||
if (mMode == MODE_FAST) {
|
||||
return service.fastRootInActiveWindow();
|
||||
}
|
||||
return service.getRootInActiveWindow();
|
||||
}
|
||||
|
||||
|
||||
public abstract AccessibilityInfoProvider getInfoProvider();
|
||||
|
||||
|
||||
public void setMode(int mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.stardust.automator.UiObjectCollection;
|
||||
import com.stardust.automator.filter.DfsFilter;
|
||||
import com.stardust.util.DeveloperUtils;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
|
||||
@@ -58,6 +59,8 @@ import static android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.
|
||||
|
||||
public class UiSelector extends UiGlobalSelector {
|
||||
|
||||
|
||||
|
||||
private static final String TAG = "UiSelector";
|
||||
|
||||
private AccessibilityBridge mAccessibilityBridge;
|
||||
@@ -80,16 +83,14 @@ public class UiSelector extends UiGlobalSelector {
|
||||
Log.d(TAG, "isSelfPackage return null");
|
||||
return UiObjectCollection.EMPTY;
|
||||
}
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
if (service != null) {
|
||||
AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
if (root != null) {
|
||||
return findOf(UiObject.createRoot(root, mAllocator));
|
||||
}
|
||||
AccessibilityNodeInfo root = mAccessibilityBridge.getRootInActiveWindow();
|
||||
if (root == null) {
|
||||
return UiObjectCollection.EMPTY;
|
||||
}
|
||||
return UiObjectCollection.EMPTY;
|
||||
return findOf(UiObject.createRoot(root, mAllocator));
|
||||
}
|
||||
|
||||
|
||||
private void ensureAccessibilityServiceEnabled() {
|
||||
mAccessibilityBridge.ensureServiceEnabled();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.accessibilityservice.GestureDescription;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
@@ -254,10 +255,7 @@ public class SimpleActionAutomator {
|
||||
Log.d(TAG, "performAction: running package is self. return false");
|
||||
return false;
|
||||
}
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
if (service == null)
|
||||
return false;
|
||||
AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
AccessibilityNodeInfo root = mAccessibilityBridge.getRootInActiveWindow();
|
||||
if (root == null)
|
||||
return false;
|
||||
Log.v(TAG, "performAction: " + simpleAction + " root = " + root);
|
||||
|
||||
Reference in New Issue
Block a user