Commit Test
This commit is contained in:
@@ -85,8 +85,7 @@ public abstract class JavaScriptEngineManager {
|
||||
|
||||
void removeEngine(JavaScriptEngine engine) {
|
||||
synchronized (mEngines) {
|
||||
mEngines.remove(engine);
|
||||
if (mEngineLifecycleCallback != null) {
|
||||
if (mEngines.remove(engine) && mEngineLifecycleCallback != null) {
|
||||
mEngineLifecycleCallback.onEngineRemove(engine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.stardust.autojs.engine;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.autojs.rhino_android.AndroidContextFactory;
|
||||
import com.stardust.autojs.rhino_android.RhinoAndroidHelper;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.ScriptStopException;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
@@ -17,7 +17,6 @@ import org.mozilla.javascript.ScriptableObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
@@ -36,6 +35,7 @@ public class RhinoJavaScriptEngine implements JavaScriptEngine {
|
||||
private Thread mThread;
|
||||
private RhinoJavaScriptEngineManager mEngineManager;
|
||||
private Map<String, Object> mTags = new Hashtable<>();
|
||||
private boolean mDestroyed = false;
|
||||
|
||||
public RhinoJavaScriptEngine(RhinoJavaScriptEngineManager engineManager) {
|
||||
mEngineManager = engineManager;
|
||||
@@ -67,7 +67,7 @@ public class RhinoJavaScriptEngine implements JavaScriptEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public synchronized void destroy() {
|
||||
Context.exit();
|
||||
// TODO: 2017/4/6 XXX :在这里回收内存池并不好
|
||||
final AccessibilityNodeInfoAllocator allocator = (AccessibilityNodeInfoAllocator) getTag("allocator");
|
||||
@@ -75,6 +75,7 @@ public class RhinoJavaScriptEngine implements JavaScriptEngine {
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
// FIXME: 2017/4/28
|
||||
//allocator.recycleAll();
|
||||
}
|
||||
}, 1000);
|
||||
@@ -136,14 +137,13 @@ public class RhinoJavaScriptEngine implements JavaScriptEngine {
|
||||
@Override
|
||||
protected void observeInstructionCount(Context cx, int instructionCount) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
|
||||
Context.exit();
|
||||
throw new ScriptStopException(new InterruptedException());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context makeContext() {
|
||||
|
||||
Context cx = super.makeContext();
|
||||
cx.setInstructionObserverThreshold(10000);
|
||||
return cx;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/29.
|
||||
*/
|
||||
|
||||
public class AutomatorConfig {
|
||||
|
||||
private static boolean isUnintendedGuardEnabled = false;
|
||||
|
||||
|
||||
public static boolean isUnintendedGuardEnabled() {
|
||||
return isUnintendedGuardEnabled;
|
||||
}
|
||||
|
||||
public static void setIsUnintendedGuardEnabled(boolean isUnintendedGuardEnabled) {
|
||||
AutomatorConfig.isUnintendedGuardEnabled = isUnintendedGuardEnabled;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
@@ -87,7 +88,8 @@ public class UiSelector extends UiGlobalSelector {
|
||||
@JavascriptInterface
|
||||
public UiObjectCollection find() {
|
||||
ensureAccessibilityServiceEnabled();
|
||||
if (isRunningPackageSelf()) {
|
||||
if (AutomatorConfig.isUnintendedGuardEnabled() && isRunningPackageSelf()) {
|
||||
Log.d(TAG, "isSelfPackage return null");
|
||||
return null;
|
||||
}
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
@@ -105,7 +107,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
}
|
||||
|
||||
private boolean isRunningPackageSelf() {
|
||||
return DeveloperUtils.isRunningPackageSelf(mAccessibilityBridge.getInfoProvider().getLatestPackage());
|
||||
return DeveloperUtils.isSelfPackage(mAccessibilityBridge.getInfoProvider().getLatestPackage());
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +117,7 @@ public class UiSelector extends UiGlobalSelector {
|
||||
UiObjectCollection uiObjectCollection;
|
||||
do {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
Log.d(TAG, "Thread isInterrupted");
|
||||
throw new ScriptStopException(new InterruptedException());
|
||||
}
|
||||
uiObjectCollection = find();
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import com.stardust.autojs.runtime.AccessibilityBridge;
|
||||
import com.stardust.autojs.runtime.JavascriptInterface;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.api.AutomatorConfig;
|
||||
import com.stardust.automator.AccessibilityEventCommandHost;
|
||||
import com.stardust.automator.simple_action.SimpleAction;
|
||||
import com.stardust.automator.simple_action.ActionFactory;
|
||||
@@ -24,6 +25,8 @@ import com.stardust.view.accessibility.AccessibilityNodeInfoAllocator;
|
||||
|
||||
public class SimpleActionAutomator {
|
||||
|
||||
private static final String TAG = "SimpleActionAutomator";
|
||||
|
||||
@Deprecated
|
||||
private static class PerformGlobalActionCommand extends AccessibilityEventCommandHost.AbstractCommand {
|
||||
|
||||
@@ -185,7 +188,8 @@ public class SimpleActionAutomator {
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean performAction(SimpleAction simpleAction) {
|
||||
ensureAccessibilityServiceEnabled();
|
||||
if (isRunningPackageSelf()) {
|
||||
if (AutomatorConfig.isUnintendedGuardEnabled() && isRunningPackageSelf()) {
|
||||
Log.i(TAG, "performAction: running package is self. return false");
|
||||
return false;
|
||||
}
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
@@ -203,6 +207,6 @@ public class SimpleActionAutomator {
|
||||
}
|
||||
|
||||
private boolean isRunningPackageSelf() {
|
||||
return DeveloperUtils.isRunningPackageSelf(mAccessibilityBridge.getInfoProvider().getLatestPackage());
|
||||
return DeveloperUtils.isSelfPackage(mAccessibilityBridge.getInfoProvider().getLatestPackage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user