From b8e86a1974c240fbe4e9f1298fe3129797b8459e Mon Sep 17 00:00:00 2001 From: lahm Date: Wed, 25 Jul 2018 15:52:20 +0800 Subject: [PATCH] support emulator check callback --- .../com/lahm/easyprotector/MainActivity.java | 10 ++++- .../lahm/library/EmulatorCheckCallback.java | 10 +++++ .../com/lahm/library/EmulatorCheckUtil.java | 45 ++++++++++--------- 3 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 library/src/main/java/com/lahm/library/EmulatorCheckCallback.java diff --git a/app/src/main/java/com/lahm/easyprotector/MainActivity.java b/app/src/main/java/com/lahm/easyprotector/MainActivity.java index c678cec..ad153a0 100644 --- a/app/src/main/java/com/lahm/easyprotector/MainActivity.java +++ b/app/src/main/java/com/lahm/easyprotector/MainActivity.java @@ -10,6 +10,8 @@ import android.widget.TextView; import com.lahm.library.EasyProtectorLib; +import com.lahm.library.EmulatorCheckCallback; +import com.lahm.library.EmulatorCheckUtil; import com.lahm.library.SecurityCheckUtil; import com.lahm.library.VirtualApkCheckUtil; @@ -63,8 +65,12 @@ protected void onCreate(Bundle savedInstanceState) { }); TextView emulator = findViewById(R.id.emulator); - emulator.setText(EasyProtectorLib.checkIsRunningInEmulator() ? - "isEmulator" : "not-emulator"); + emulator.setText(EmulatorCheckUtil.getSingleInstance().readSysProperty(new EmulatorCheckCallback() { + @Override + public void findEmulator(String emulatorInfo) { + System.out.println(emulatorInfo); + } + }) ? "isEmulator" : "not-emulator"); Button emptyFunc = findViewById(R.id.emptyFunc); emptyFunc.setOnClickListener(v -> play()); diff --git a/library/src/main/java/com/lahm/library/EmulatorCheckCallback.java b/library/src/main/java/com/lahm/library/EmulatorCheckCallback.java new file mode 100644 index 0000000..9d85118 --- /dev/null +++ b/library/src/main/java/com/lahm/library/EmulatorCheckCallback.java @@ -0,0 +1,10 @@ +package com.lahm.library; + +/** + * Project Name:EasyProtector + * Package Name:com.lahm.library + * Created by lahm on 2018/7/25 15:19 . + */ +public interface EmulatorCheckCallback { + void findEmulator(String emulatorInfo); +} diff --git a/library/src/main/java/com/lahm/library/EmulatorCheckUtil.java b/library/src/main/java/com/lahm/library/EmulatorCheckUtil.java index b9db4a6..a59c59a 100644 --- a/library/src/main/java/com/lahm/library/EmulatorCheckUtil.java +++ b/library/src/main/java/com/lahm/library/EmulatorCheckUtil.java @@ -37,11 +37,19 @@ public boolean readUidInfo() { return filter == null || filter.length() == 0; } + private EmulatorCheckCallback emulatorCheckCallback; + public boolean readSysProperty() { + return readSysProperty(null); + } + + public boolean readSysProperty(EmulatorCheckCallback callback) { + this.emulatorCheckCallback = callback; int suspectCount = 0; String baseBandVersion = CommandUtil.getSingleInstance().getProperty("gsm.version.baseband"); - if (TextUtils.isEmpty(baseBandVersion)) ++suspectCount; + if (TextUtils.isEmpty(baseBandVersion) | (baseBandVersion != null && baseBandVersion.contains("1.0.0.0"))) + ++suspectCount; String buildFlavor = CommandUtil.getSingleInstance().getProperty("ro.build.flavor"); if (TextUtils.isEmpty(buildFlavor) | (buildFlavor != null && buildFlavor.contains("vbox"))) @@ -63,29 +71,24 @@ public boolean readSysProperty() { String filter = CommandUtil.getSingleInstance().exec("cat /proc/self/cgroup"); if (TextUtils.isEmpty(filter)) ++suspectCount; + if (emulatorCheckCallback != null) { + StringBuffer stringBuffer = new StringBuffer("ceshi start|") + .append(baseBandVersion) + .append("|") + .append(buildFlavor) + .append("|") + .append(productBoard) + .append("|") + .append(boardPlatform) + .append("|") + .append(filter) + .append("|end"); + emulatorCheckCallback.findEmulator(stringBuffer.toString()); + emulatorCheckCallback = null; + } return suspectCount > 2; } - public String printSysProperty() { - String baseBandVersion = CommandUtil.getSingleInstance().getProperty("gsm.version.baseband"); - String buildFlavor = CommandUtil.getSingleInstance().getProperty("ro.build.flavor"); - String productBoard = CommandUtil.getSingleInstance().getProperty("ro.product.board"); - String boardPlatform = CommandUtil.getSingleInstance().getProperty("ro.board.platform"); - String filter = CommandUtil.getSingleInstance().exec("cat /proc/self/cgroup"); - StringBuffer stringBuffer = new StringBuffer("ceshi start|") - .append(baseBandVersion) - .append("|") - .append(buildFlavor) - .append("|") - .append(productBoard) - .append("|") - .append(boardPlatform) - .append("|") - .append(filter) - .append("|end"); - return stringBuffer.toString(); - } - public boolean hasGyroscopeSensor(Context context) { return getSystemSensor(context, Sensor.TYPE_GYROSCOPE); }