Skip to content

Commit

Permalink
Merge pull request #11 from Jinnrry/feature-v2.1
Browse files Browse the repository at this point in the history
Feature v2.1
  • Loading branch information
Jinnrry authored Aug 19, 2020
2 parents 0d0a22a + 528237d commit 2ea9670
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 284 deletions.
18 changes: 14 additions & 4 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
android:usesCleartextTraffic="true">
<service
android:name=".Service.Accessibility"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:enabled="true"
android:exported="true">
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
Expand All @@ -48,10 +48,20 @@
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import cn.xjiangwei.RobotHelper.Tools.Robot;
import fi.iki.elonen.NanoHTTPD;

import static android.support.v4.content.ContextCompat.getSystemService;

public class HttpServer extends NanoHTTPD {

Expand Down Expand Up @@ -63,15 +62,15 @@ public Response serve(IHTTPSession session) {
} else if (parms.containsKey("id")) {
ret = dumpHierarchyImpl(Accessibility.DOM.findAccessibilityNodeInfosByViewId(parms.get("id")), false).toString();
} else {
ret = dumpHierarchyImpl(new Node(Accessibility.DOM, 1440, 3120), false).toString();
ret = dumpHierarchyImpl(new Node(Accessibility.DOM, MainApplication.sceenWidth, MainApplication.sceenHeight), false).toString();
}
break;
case "/sceenSize":
ret = "{\"w\": " + MainApplication.sceenWidth + " , \"h\":" + MainApplication.sceenHeight + " }";
break;
case "/swipe":
try {
Robot.swipe(Float.parseFloat(parms.get("start_x")), Float.parseFloat(parms.get("start_y")), Float.parseFloat(parms.get("end_x")), Float.parseFloat(parms.get("end_y")), Float.parseFloat(parms.get("duration")));
Robot.swipe(Float.parseFloat(parms.get("start_x")), Float.parseFloat(parms.get("start_y")), Float.parseFloat(parms.get("end_x")), Float.parseFloat(parms.get("end_y")), Float.parseFloat(parms.get("duration")) * 1000);
ret = "{\"code\":200,\"msg\":\"success\"}";
} catch (Exception e) {
ret = "{\"code\":500,\"msg\":\"检查是否开启xposed\"}";
Expand Down Expand Up @@ -110,7 +109,7 @@ public Response serve(IHTTPSession session) {
public JSONArray dumpHierarchyImpl(List<AccessibilityNodeInfo> nodes, boolean onlyVisibleNode) {
JSONArray jsonArray = new JSONArray();
for (AccessibilityNodeInfo node : nodes) {
jsonArray.put(dumpHierarchyImpl(new Node(node, 3120, 1440), onlyVisibleNode));
jsonArray.put(dumpHierarchyImpl(new Node(node, MainApplication.sceenWidth, MainApplication.sceenHeight), onlyVisibleNode));
}

return jsonArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class Main {
public void start() {
sleep(5000); //点击开始后等待5秒后再执行,因为状态栏收起有动画时间,建议保留这行代码

//Robot.setExecType(Robot.ExecTypeXposed); //使用xposed权限执行模拟操作,建议优先使用此方式
//Robot.setExecType(Robot.ExecTypeAccessibillty); //使用安卓无障碍接口执行模拟操作


/**************************** 模板匹配demo *******************************/
InputStream is = null;
try {
Expand All @@ -56,7 +60,8 @@ public void start() {
e.printStackTrace();
}
bitmap = BitmapFactory.decodeStream(is);
String res = TessactOcr.img2string(bitmap, "chi_sim", "", "");

String res = TessactOcr.img2string(ScreenCaptureUtil.getScreenCap(0,0,200,30), "chi_sim", "", "");
MLog.info("文字识别结果:" + res);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,30 @@
import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.github.dfqin.grantor.PermissionListener;
import com.github.dfqin.grantor.PermissionsUtil;
import com.googlecode.tesseract.android.TessBaseAPI;
import com.lahm.library.EasyProtectorLib;
import com.lahm.library.EmulatorCheckCallback;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import cn.xjiangwei.RobotHelper.Accessibility.HttpServer;
import cn.xjiangwei.RobotHelper.Service.Accessibility;
import cn.xjiangwei.RobotHelper.Service.RunTime;
import cn.xjiangwei.RobotHelper.Tools.MLog;
import cn.xjiangwei.RobotHelper.Tools.Robot;
import cn.xjiangwei.RobotHelper.Tools.ScreenCaptureUtil;
import cn.xjiangwei.RobotHelper.Tools.ScreenCaptureUtilByMediaPro;
import cn.xjiangwei.RobotHelper.Tools.TessactOcr;
import cn.xjiangwei.RobotHelper.Tools.Toast;
Expand Down Expand Up @@ -132,27 +116,25 @@ public void start(View view) {
}



@Override
protected void onResume() {
super.onResume();
updateStatus();
}

private boolean checkXposedHook() {
return false;
}


public void openLog(View view) {

String file = Environment.getExternalStorageDirectory().toString() + "/RobotHelper.log";

String filePath = Environment.getExternalStorageDirectory().toString() + "/RobotHelper.log";
File file = new File(filePath);
Uri fileURI = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", file);
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(file)), "text/plain");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(fileURI, "text/plain");
startActivity(intent);
Intent.createChooser(intent, "请选择对应的软件打开该附件!");
} catch (ActivityNotFoundException e) {
Expand Down Expand Up @@ -183,9 +165,10 @@ private void updateStatus() {
TextView asStatus = (TextView) findViewById(R.id.accessibility_status);
TextView hsStatus = (TextView) findViewById(R.id.httpserver_status);

xpStatus.setText(checkXposedHook() ? "Xposed状态:已加载" : "Xposed状态:未加载");
asStatus.setText(Accessibility.DOM == null ? "Accessibility状态:未加载" : "Accessibility状态:已加载");
hsStatus.setText((RunTime.httpServer != null && RunTime.httpServer.runing) ? "HttpServer状态:已开启" : "HttpServer状态:未开启");
xpStatus.setText(mainApplication.checkXposedHook() ? "Xposed状态:已加载" : "Xposed状态:未加载");
asStatus.setText(mainApplication.checkAccessibilityService() ? "Accessibility状态:已加载" : "Accessibility状态:未加载");
hsStatus.setText(mainApplication.checkHttpServer() ? "HttpServer状态:已开启" : "HttpServer状态:未开启");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@

import android.app.Application;

import cn.xjiangwei.RobotHelper.Service.Accessibility;
import cn.xjiangwei.RobotHelper.Service.RunTime;


public class MainApplication extends Application {
public static int sceenWidth = 0;
public static int sceenHeight = 0;
public static int dpi;
private static String serverUrl = "http://192.168.199.241:8001/";
private static MainApplication instance;


public static MainApplication getInstance() {
return instance;
}

public static String getServerUrl() {
return serverUrl;
}

public static void setServerUrl(String serverUrl) {
MainApplication.serverUrl = serverUrl;
}


@Override
public void onCreate() {
Expand All @@ -39,4 +31,16 @@ public static int sceenSize() {
return 2;
}


public boolean checkXposedHook() {
return false;
}

public boolean checkAccessibilityService() {
return Accessibility.DOM != null;
}

public boolean checkHttpServer() {
return RunTime.httpServer != null && RunTime.httpServer.runing;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cn.xjiangwei.RobotHelper.Service;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
Expand All @@ -10,31 +14,22 @@

public class Accessibility extends AccessibilityService {


private static Accessibility instance;
public static AccessibilityNodeInfo DOM;



@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
DOM = getRootInActiveWindow();
public Accessibility() {
instance = this;
}

public static void logViewHierarchy(AccessibilityNodeInfo nodeInfo, final int depth) {

if (nodeInfo == null) return;

String spacerString = "";

for (int i = 0; i < depth; ++i) {
spacerString += '-';
}
//Log the info you care about here... I choce classname and view resource name, because they are simple, but interesting.
Log.d("TAG", spacerString + nodeInfo.getClassName() + " " + nodeInfo.getViewIdResourceName());
public static Accessibility getInstance(){
return instance;
}

for (int i = 0; i < nodeInfo.getChildCount(); ++i) {
logViewHierarchy(nodeInfo.getChild(i), depth + 1);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
DOM = getRootInActiveWindow();
}


Expand All @@ -44,4 +39,6 @@ public void onInterrupt() {
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cn.xjiangwei.RobotHelper.Tools.InputImp;

import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.RequiresApi;

import cn.xjiangwei.RobotHelper.Service.Accessibility;
import cn.xjiangwei.RobotHelper.Tools.Point;

@RequiresApi(api = Build.VERSION_CODES.N)
public class AccessibilityInput implements Input {


private static AccessibilityInput instance;

public static AccessibilityInput getInstance() {
if (instance == null) {
synchronized (AccessibilityInput.class) {
if (instance == null) {
instance = new AccessibilityInput();
}
}
}

return instance;
}


@Override
public void tap(int x, int y) {
GestureDescription.Builder builder = new GestureDescription.Builder();
Path path = new Path();
path.moveTo((float) x, (float) y);
path.lineTo((float) x, (float) y);
/**
* 参数path:笔画路径
* 参数startTime:时间 (以毫秒为单位),从手势开始到开始笔划的时间,非负数
* 参数duration:笔划经过路径的持续时间(以毫秒为单位),非负数
*/
builder.addStroke(new GestureDescription.StrokeDescription(path, 0, 50));
final GestureDescription build = builder.build();

Accessibility.getInstance().dispatchGesture(build, null, null);
}

@Override
public void tap(int x, int y, long delay) {
GestureDescription.Builder builder = new GestureDescription.Builder();
Path path = new Path();
path.moveTo((float) x, (float) y);
path.lineTo((float) x, (float) y);
/**
* 参数path:笔画路径
* 参数startTime:时间 (以毫秒为单位),从手势开始到开始笔划的时间,非负数
* 参数duration:笔划经过路径的持续时间(以毫秒为单位),非负数
*/
builder.addStroke(new GestureDescription.StrokeDescription(path, 1, delay));
final GestureDescription build = builder.build();
Accessibility.getInstance().dispatchGesture(build, null, null);
}

@Override
public void tap(Point p) {
tap(p.getX(), p.getY());
}

@Override
public void tap(Point p, long delay) {
tap(p.getX(), p.getY(), delay);
}

@Override
public void swipe(int x1, int y1, int x2, int y2, int duration) {
swipe((float) x1, (float) y1, (float) x2, (float) y2, duration);
}

@Override
public void swipe(float x1, float y1, float x2, float y2, float duration) {
GestureDescription.Builder builder = new GestureDescription.Builder();
Path path = new Path();
path.moveTo((float) x1, (float) y1);
path.lineTo((float) x2, (float) y2);
/**
* 参数path:笔画路径
* 参数startTime:时间 (以毫秒为单位),从手势开始到开始笔划的时间,非负数
* 参数duration:笔划经过路径的持续时间(以毫秒为单位),非负数
*/
builder.addStroke(new GestureDescription.StrokeDescription(path, 1, (long) duration));
final GestureDescription build = builder.build();
Accessibility.getInstance().dispatchGesture(build, null, null);
}

@Override
public void input(String str) {

}
}
Loading

0 comments on commit 2ea9670

Please sign in to comment.