|
|
@@ -3,6 +3,7 @@ package com.example.modifier;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.graphics.Rect;
|
|
|
+import android.os.Build;
|
|
|
import android.util.Log;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
@@ -10,7 +11,9 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -26,6 +29,8 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
|
|
|
private static final String TAG = "ModifierService";
|
|
|
|
|
|
+ public static final String NAME = BuildConfig.APPLICATION_ID + ".ModifierService";
|
|
|
+
|
|
|
private ScheduledExecutorService mExecutor = new ScheduledThreadPoolExecutor(8);
|
|
|
|
|
|
private Socket mSocket;
|
|
|
@@ -33,7 +38,9 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
public ModifierService() {
|
|
|
Log.i(TAG, "Creating ModifierService");
|
|
|
try {
|
|
|
- mSocket = IO.socket("http://192.168.6.215:3000");
|
|
|
+ IO.Options opts = new IO.Options();
|
|
|
+ opts.query = "device=" + Build.MANUFACTURER + " " + Build.MODEL;
|
|
|
+ mSocket = IO.socket("http://192.168.50.202:3000", opts);
|
|
|
mSocket.on("message", this);
|
|
|
mSocket.on(Socket.EVENT_CONNECT, args -> {
|
|
|
Log.i(TAG, "Connected to server");
|
|
|
@@ -48,7 +55,7 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
- } catch (URISyntaxException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -62,7 +69,6 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
|
|
|
@Override
|
|
|
public void onAccessibilityEvent(AccessibilityEvent event) {
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -87,7 +93,9 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
try {
|
|
|
Utils.runAsRoot(cmd);
|
|
|
|
|
|
+ Log.i(TAG, "Command executed successfully, waiting for app to open...");
|
|
|
mExecutor.schedule(() -> {
|
|
|
+ Log.i(TAG, "Getting root node...");
|
|
|
AccessibilityNodeInfo root = getRootInActiveWindow();
|
|
|
String packageName = root.getPackageName().toString();
|
|
|
String appName = null;
|
|
|
@@ -96,10 +104,11 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
|
|
|
appName = packageManager.getApplicationLabel(applicationInfo).toString();
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ Log.i(TAG, "App: " + appName + " (" + packageName + ")");
|
|
|
traverseNode(root);
|
|
|
- }, 2, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
+ }, 1, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -122,6 +131,15 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
node.getBoundsInScreen(rect);
|
|
|
map.put("bounds", rect);
|
|
|
|
|
|
+ String name = node.getViewIdResourceName();
|
|
|
+
|
|
|
+ if ("Compose:Draft:Send".equals(name)) {
|
|
|
+ Log.i(TAG, "Found send button Node: class=" + node.getClassName() + ", text=" + node.getText() + ", name=" + name);
|
|
|
+// node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
|
|
|
+ }
|
|
|
+
|
|
|
+ node.getViewIdResourceName();
|
|
|
+
|
|
|
if (node.getChildCount() != 0) {
|
|
|
List<Map<String, Object>> children = new ArrayList<>();
|
|
|
for (int i = 0; i < node.getChildCount(); i++) {
|