Added: getPackageName, getActivityName
This commit is contained in:
Binary file not shown.
@@ -7,8 +7,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
versionCode 30
|
||||
versionName "1.17.0217"
|
||||
versionCode 31
|
||||
versionName "1.17.0221"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
||||
@@ -119,9 +119,17 @@ var clearConsole = function(){
|
||||
|
||||
var shell = function(cmd, root){
|
||||
root = root ? 1 : 0;
|
||||
droid.shell(cmd, root);
|
||||
return droid.shell(cmd, root);
|
||||
}
|
||||
|
||||
var getTexts = function(){
|
||||
return droid.getTexts();
|
||||
}
|
||||
|
||||
var getPackageName = function(){
|
||||
return droid.getPackageName();
|
||||
}
|
||||
|
||||
var getActivityName = function(){
|
||||
return droid.getActivityName();
|
||||
}
|
||||
@@ -167,10 +167,7 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
}
|
||||
|
||||
private <T> T performAction(Action action) {
|
||||
if (AccessibilityWatchDogService.getInstance() == null) {
|
||||
toast(App.getApp().getString(R.string.text_no_accessibility_permission));
|
||||
throw new ScriptStopException(App.getApp().getString(R.string.text_no_accessibility_permission));
|
||||
}
|
||||
ensureAccessibilityServiceEnable();
|
||||
ActionPerformAccessibilityDelegate.setAction(action);
|
||||
synchronized (mActionPerformLock) {
|
||||
try {
|
||||
@@ -183,6 +180,13 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
return (T) action.getResult();
|
||||
}
|
||||
|
||||
private void ensureAccessibilityServiceEnable() {
|
||||
if (AccessibilityWatchDogService.getInstance() == null) {
|
||||
toast(App.getApp().getString(R.string.text_no_accessibility_permission));
|
||||
throw new ScriptStopException(App.getApp().getString(R.string.text_no_accessibility_permission));
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getTexts() {
|
||||
return performAction(new GetTextAction());
|
||||
}
|
||||
@@ -206,8 +210,18 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
public void shell(String cmd, int root) {
|
||||
Shell.execCommand(cmd, root != 0);
|
||||
public String shell(String cmd, int root) {
|
||||
return Shell.execCommand(cmd, root != 0).toString();
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
ensureAccessibilityServiceEnable();
|
||||
return ActionPerformAccessibilityDelegate.getLatestPackage();
|
||||
}
|
||||
|
||||
public String getActivityName() {
|
||||
ensureAccessibilityServiceEnable();
|
||||
return ActionPerformAccessibilityDelegate.getLatestActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,6 +234,7 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
Thread.interrupted();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MaterialDialog.Builder dialog() {
|
||||
if (App.currentActivity() == null) {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.stardust.scriptdroid.droid.runtime.action;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.droid.runtime.DroidRuntime;
|
||||
import com.stardust.scriptdroid.service.AccessibilityDelegate;
|
||||
|
||||
@@ -20,6 +24,8 @@ public class ActionPerformAccessibilityDelegate implements AccessibilityDelegate
|
||||
public static final Action NO_ACTION = null;
|
||||
|
||||
private static Action action;
|
||||
private static String latestPackage, latestActivity;
|
||||
|
||||
|
||||
public static void setAction(Action action) {
|
||||
synchronized (ActionPerformAccessibilityDelegate.class) {
|
||||
@@ -27,8 +33,17 @@ public class ActionPerformAccessibilityDelegate implements AccessibilityDelegate
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static String getLatestPackage() {
|
||||
return latestPackage;
|
||||
}
|
||||
|
||||
public synchronized static String getLatestActivity() {
|
||||
return latestActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAccessibilityEvent(AccessibilityService service, AccessibilityEvent event) {
|
||||
setLatestComponent(event.getPackageName(), event.getClassName());
|
||||
if (action == NO_ACTION)
|
||||
return false;
|
||||
AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
@@ -54,4 +69,18 @@ public class ActionPerformAccessibilityDelegate implements AccessibilityDelegate
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized static void setLatestComponent(CharSequence latestPackage, CharSequence latestClass) {
|
||||
if (latestPackage == null)
|
||||
return;
|
||||
ActionPerformAccessibilityDelegate.latestPackage = latestPackage.toString();
|
||||
ComponentName componentName = new ComponentName(latestPackage.toString(), latestClass == null ? null : latestClass.toString());
|
||||
try {
|
||||
ActivityInfo activityInfo = App.getApp().getPackageManager().getActivityInfo(componentName, 0);
|
||||
ActionPerformAccessibilityDelegate.latestActivity = activityInfo.name;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class VolumeChangeListenService extends Service {
|
||||
private static WeakReference<VolumeChangeListenService> instance;
|
||||
|
||||
public static void stopServiceIfNeeded() {
|
||||
if (instance != null || instance.get() != null) {
|
||||
if (instance != null && instance.get() != null) {
|
||||
instance.get().stopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/20.
|
||||
*
|
||||
* <p>
|
||||
* 来自网络~~
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,12 @@ public class Shell {
|
||||
public int result = -1;
|
||||
public String errorMsg;
|
||||
public String successMsg;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return result + " | " + successMsg
|
||||
+ " | " + errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +48,7 @@ public class Shell {
|
||||
* @return
|
||||
*/
|
||||
public static CommandResult execCommand(String command, boolean isRoot) {
|
||||
String[] commands = {command};
|
||||
String[] commands = command.split("\n");
|
||||
return execCommand(commands, isRoot);
|
||||
}
|
||||
|
||||
@@ -85,8 +91,7 @@ public class Shell {
|
||||
while ((s = errorResult.readLine()) != null) errorMsg.append(s);
|
||||
commandResult.successMsg = successMsg.toString();
|
||||
commandResult.errorMsg = errorMsg.toString();
|
||||
Log.i(TAG, commandResult.result + " | " + commandResult.successMsg
|
||||
+ " | " + commandResult.errorMsg);
|
||||
Log.i(TAG, commandResult.toString());
|
||||
} catch (Exception e) {
|
||||
String errmsg = e.getMessage();
|
||||
if (errmsg != null) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.stardust.scriptdroid.ui.edit.completion;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jecelyin.editor.v2.core.widget.TextView;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
@@ -67,12 +66,10 @@ public class CodeCompletion implements TextWatcher {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
Log.v(TAG, "beforeTextChanged: s=" + s + " start=" + start + " count=" + count + " after=" + after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
Log.v(TAG, "onTextChanged: s=" + s + " start=" + start + " count=" + count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +101,7 @@ public class CodeCompletion implements TextWatcher {
|
||||
|
||||
private static final String[] KEYWORDS = {"arguments", "break", "case", "catch", "class", "continue", "default", "do", "else", "eval", "export", "false", "for", "function", "if", "import", "in", "int", "new", "null", "package", "return", "switch", "this", "throw", "throws", "true", "try", "typeof", "var", "volatile", "while", "with", "Array", "Date", "hasOwnProperty", "Infinity", "isFinite", "isNaN", "isPrototypeOf", "length", "Math", "NaN", "name", "Number", "Object", "prototype", "String", "toString", "undefined", "valueOf"};
|
||||
private static final int KEY_WORD_LENGTH_MAX = 15;
|
||||
private static final String[] FUNCTIONS = {"launchApp", "click", "longClick", "scrollUp", "scrollDown", "toast", "launch", "input", "notStopped", "shell", "importClass"};
|
||||
private static final String[] FUNCTIONS = {"toast", "launchPackage", "launch", "launchApp", "click", "longClick", "scrollUp", "scrollDown", "select", "focus", "paste", "input", "sleep", "isStopped", "notStopped", "log", "err", "openConsole", "clearConsole", "shell", "getTexts", "getPackageName", "getActivityName"};
|
||||
|
||||
private boolean searchCodeCompletion(String str) {
|
||||
Collection<CodeCompletionItem> c = searchWordCompletion(str);
|
||||
@@ -147,7 +144,7 @@ public class CodeCompletion implements TextWatcher {
|
||||
}
|
||||
|
||||
|
||||
private static final String[] DEFAULT_CODE_COMPLETIONS = new String[]{"=", "(", ")", ";", "{", "}", "\"", "!", "[", "]", ".", ","};
|
||||
private static final String[] DEFAULT_CODE_COMPLETIONS = new String[]{"=", "(", ")", ";", "{", "}", "\"", "!", "[", "]", "\\", ".", ", "};
|
||||
private static final List<CodeCompletionItem> DEFAULT_CODE_COMPLETION_LIST = new ArrayList<>();
|
||||
|
||||
static {
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
* `isStoppd` 若当前脚本处于停止状态时返回`true`, 否则返回`false`。
|
||||
* `shell(cmd, root=false)` 执行shell命令cmd, 其中参数root表示是否以root权限执行,默认为false。例如`shell("input keyevent 26", true); //锁屏`。
|
||||
* `getTexts()` 获取屏幕上的文字列表, 返回一个java.util.List<String>。例如:
|
||||
|
||||
* `getPackageName` 获取正在运行的应用包名
|
||||
* `getActivityName` 获取正在运行的Activity名称
|
||||
```
|
||||
launchApp("微信");
|
||||
while(!click("通讯录"));
|
||||
|
||||
Reference in New Issue
Block a user