fix executor issues by utilizing already present code

This commit is contained in:
f43nd1r 2019-02-09 02:16:46 +01:00
parent a445a97608
commit 6a2d8c587c
4 changed files with 14 additions and 31 deletions

View file

@ -27,6 +27,7 @@
<!-- Tasker -->
<uses-permission android:name="net.dinglisch.android.tasker.PERMISSION_RUN_TASKS"/>
<!-- TODO: add description -->
<permission
android:name="net.pierrox.lightning_launcher.USE_PLUGIN_SERVICE"
android:protectionLevel="dangerous"/>

View file

@ -3,7 +3,6 @@ package net.pierrox.lightning_launcher.util;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import com.faendir.rhino_android.RhinoAndroidHelper;
import net.pierrox.lightning_launcher.LLApp;
import net.pierrox.lightning_launcher.api.ScreenIdentity;
import net.pierrox.lightning_launcher.api.ScreenNotAvailableException;
@ -16,11 +15,6 @@ import net.pierrox.lightning_launcher.plugin.IPluginService;
import net.pierrox.lightning_launcher.plugin.IPluginService_Stub;
import net.pierrox.lightning_launcher.script.ScriptExecutor;
import net.pierrox.lightning_launcher.script.ScriptManager;
import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import static net.pierrox.lightning_launcher.script.ScriptExecutor.PROPERTY_EVENT_SCREEN;
/**
* @author lukas
@ -104,30 +98,6 @@ public class PluginService extends Service implements IPluginService {
throw new ScreenNotAvailableException();
}
ScriptExecutor executor = mEngine.getScriptExecutor();
if (executor.canRunScriptGlobally()) {
Scriptable scope = executor.prepareScriptScope();
org.mozilla.javascript.Context cx = RhinoAndroidHelper.prepareContext();
ScriptableObject.putProperty(scope, PROPERTY_EVENT_SCREEN, screen);
ScriptableObject.putProperty(scope, "ev_se", "DIRECT_PLUGIN");
ScriptableObject.putProperty(scope, "ev_d", null);
ScriptableObject.putProperty(scope, "ev_t", System.currentTimeMillis());
ScriptableObject.putProperty(scope, "ev_il", null);
ScriptableObject.putProperty(scope, "ev_iv", null);
try {
String script = "javascript:(function() {var _event = createEvent(ev_sc, ev_se, ev_d, ev_t, ev_il, ev_iv); var getEvent = function() { return _event;};\n" + code + "\n})();";
cx.setOptimizationLevel(-1);
org.mozilla.javascript.Script compiledScript = cx.compileString(script, null, 0, null);
if (compiledScript != null) {
return String.valueOf(compiledScript.exec(cx, scope));
}
} catch (RhinoException e) {
e.printStackTrace();
} finally {
// Exit from the context.
org.mozilla.javascript.Context.exit();
}
}
return null;
return String.valueOf(executor.runScriptAsFunction(screen, code, "", new Object[0], false, true));
}
}

View file

@ -17,6 +17,7 @@ public class Script extends JsonLoader {
public static final int TYPE_BUILTIN = 1;
public static final int TYPE_TARGET = 2;
public static final int TYPE_SET_VARIABLE = 3;
public static final int TYPE_IN_MEMORY = 4;
public static final int TARGET_NONE = -1;
public static final int TARGET_DESKTOP = 0;

View file

@ -671,7 +671,18 @@ public class ScriptExecutor {
if(!canRunScript(script)) {
return null;
}
return runScriptAsFunction(screen, script, parameters, arguments, allow_continuation, display_errors);
}
public Object runScriptAsFunction(Screen screen, String code, String parameters, Object[] arguments, boolean allow_continuation, boolean display_errors) {
if(!canRunScriptGlobally()) {
return null;
}
Script script = new Script(mEngine.getScriptManager(), Script.TYPE_IN_MEMORY, Script.NO_ID, null, code, null);
return runScriptAsFunction(screen, script, parameters, arguments, allow_continuation, display_errors);
}
private Object runScriptAsFunction(Screen screen, Script script, String parameters, Object[] arguments, boolean allow_continuation, boolean display_errors) {
mCurrentScript = script;
if(mCurrentScript != null && !mCurrentScript.hasFlag(Script.FLAG_DISABLED)) {
prepareScriptScope();