|
@@ -1,20 +1,28 @@
|
|
|
package com.example.modifier;
|
|
package com.example.modifier;
|
|
|
|
|
|
|
|
|
|
+import android.accessibilityservice.AccessibilityServiceInfo;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.ApplicationInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
+import android.graphics.PixelFormat;
|
|
|
import android.graphics.Rect;
|
|
import android.graphics.Rect;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
+import android.view.Gravity;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.WindowManager;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
|
+import android.widget.FrameLayout;
|
|
|
|
|
+import android.widget.ImageButton;
|
|
|
|
|
|
|
|
|
|
+import androidx.appcompat.view.ContextThemeWrapper;
|
|
|
|
|
+
|
|
|
|
|
+import com.example.modifier.databinding.FloatingWindowBinding;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
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.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -36,12 +44,15 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
|
|
|
|
|
private Socket mSocket;
|
|
private Socket mSocket;
|
|
|
|
|
|
|
|
|
|
+ private boolean canSend = false;
|
|
|
|
|
+ private FloatingWindowBinding binding;
|
|
|
|
|
+
|
|
|
public ModifierService() {
|
|
public ModifierService() {
|
|
|
Log.i(TAG, "Creating ModifierService");
|
|
Log.i(TAG, "Creating ModifierService");
|
|
|
try {
|
|
try {
|
|
|
IO.Options opts = new IO.Options();
|
|
IO.Options opts = new IO.Options();
|
|
|
- opts.query = "device=" + Build.MANUFACTURER + " " + Build.MODEL;
|
|
|
|
|
- mSocket = IO.socket("http://192.168.50.202:3000", opts);
|
|
|
|
|
|
|
+ opts.query = "model=" + Build.MANUFACTURER + " " + Build.MODEL + "&name=" + Build.DEVICE + "&id=" + Utils.getUniqueID();
|
|
|
|
|
+ mSocket = IO.socket("http://192.168.6.215:3000", opts);
|
|
|
mSocket.on("message", this);
|
|
mSocket.on("message", this);
|
|
|
mSocket.on(Socket.EVENT_CONNECT, args -> {
|
|
mSocket.on(Socket.EVENT_CONNECT, args -> {
|
|
|
Log.i(TAG, "Connected to server");
|
|
Log.i(TAG, "Connected to server");
|
|
@@ -65,6 +76,7 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
public void onCreate() {
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
super.onCreate();
|
|
|
Log.i(TAG, "Starting ModifierService");
|
|
Log.i(TAG, "Starting ModifierService");
|
|
|
|
|
+ canSend = getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE).getBoolean("canSend", false);
|
|
|
mSocket.connect();
|
|
mSocket.connect();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -150,4 +162,59 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
}
|
|
}
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onServiceConnected() {
|
|
|
|
|
+ super.onServiceConnected();
|
|
|
|
|
+
|
|
|
|
|
+ AccessibilityServiceInfo info = new AccessibilityServiceInfo();
|
|
|
|
|
+ info.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED |
|
|
|
|
|
+ AccessibilityEvent.TYPE_VIEW_FOCUSED |
|
|
|
|
|
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
|
|
|
|
+ info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
|
|
|
|
|
+ info.notificationTimeout = 100;
|
|
|
|
|
+ this.setServiceInfo(info);
|
|
|
|
|
+
|
|
|
|
|
+ WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
|
|
+ FrameLayout mLayout = new FrameLayout(this);
|
|
|
|
|
+ WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
|
|
|
|
+ layoutParams.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
|
|
|
|
|
+ layoutParams.format = PixelFormat.TRANSLUCENT;
|
|
|
|
|
+ layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
|
+ layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
|
+ layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
|
+ layoutParams.x = 0;
|
|
|
|
|
+ layoutParams.y = 400;
|
|
|
|
|
+ layoutParams.gravity = Gravity.START | Gravity.TOP;
|
|
|
|
|
+ ContextThemeWrapper newContext = new ContextThemeWrapper(getApplicationContext(), R.style.Theme_Modifier);
|
|
|
|
|
+ LayoutInflater inflater = LayoutInflater.from(newContext);
|
|
|
|
|
+ binding = FloatingWindowBinding.inflate(inflater, mLayout, true);
|
|
|
|
|
+ windowManager.addView(mLayout, layoutParams);
|
|
|
|
|
+
|
|
|
|
|
+ binding.swConnect.setChecked(true);
|
|
|
|
|
+ binding.swConnect.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
|
+ if (isChecked) {
|
|
|
|
|
+ mSocket.connect();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mSocket.disconnect();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ binding.swSend.setChecked(canSend);
|
|
|
|
|
+ binding.swSend.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
|
+ getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE).edit().putBoolean("canSend", isChecked).apply();
|
|
|
|
|
+ canSend = isChecked;
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ try {
|
|
|
|
|
+ json.put("action", "updateDevice");
|
|
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
|
|
+ data.put("canSend", isChecked);
|
|
|
|
|
+ json.put("data", data);
|
|
|
|
|
+ mSocket.emit("message", json);
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|