diff --git a/doric-android/devkit/build.gradle b/doric-android/devkit/build.gradle index d02d4741..a67bc207 100644 --- a/doric-android/devkit/build.gradle +++ b/doric-android/devkit/build.gradle @@ -35,7 +35,6 @@ dependencies { implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.3.7' implementation "io.reactivex.rxjava2:rxjava:2.2.15" api 'org.greenrobot:eventbus:3.1.1' - implementation 'com.lahm.library:easy-protector-release:1.1.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/doric-android/devkit/src/main/AndroidManifest.xml b/doric-android/devkit/src/main/AndroidManifest.xml index a9b13be5..6a6b118b 100644 --- a/doric-android/devkit/src/main/AndroidManifest.xml +++ b/doric-android/devkit/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ + diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java index 9b694e25..d17045dd 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java @@ -2,14 +2,9 @@ package pub.doric.devkit; import android.content.Intent; -import com.lahm.library.EasyProtectorLib; -import com.lahm.library.EmulatorCheckCallback; - -import org.greenrobot.eventbus.EventBus; - import pub.doric.Doric; -import pub.doric.devkit.event.EOFExceptionEvent; import pub.doric.devkit.ui.DoricDevActivity; +import pub.doric.devkit.util.SimulatorUtil; public class DoricDev { private static class Inner { @@ -17,12 +12,7 @@ public class DoricDev { } private DoricDev() { - DevKit.isRunningInEmulator = EasyProtectorLib.checkIsRunningInEmulator(Doric.application(), new EmulatorCheckCallback() { - @Override - public void findEmulator(String emulatorInfo) { - System.out.println(emulatorInfo); - } - }); + DevKit.isRunningInEmulator = SimulatorUtil.isSimulator(Doric.application()); } public static DoricDev getInstance() { diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/util/SimulatorUtil.java b/doric-android/devkit/src/main/java/pub/doric/devkit/util/SimulatorUtil.java new file mode 100644 index 00000000..5b0e5b87 --- /dev/null +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/util/SimulatorUtil.java @@ -0,0 +1,94 @@ +package pub.doric.devkit.util; + +import android.bluetooth.BluetoothAdapter; +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorManager; +import android.os.Build; +import android.text.TextUtils; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +public class SimulatorUtil { + public static boolean isSimulator(Context context) { + return notHasBlueTooth() + || notHasLightSensorManager(context) + || isFeatures() + || checkIsNotRealPhone() + || checkPipes(); + } + + private static boolean notHasBlueTooth() { + BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter(); + if (ba == null) { + return true; + } else { + String name = ba.getName(); + return TextUtils.isEmpty(name); + } + } + + private static boolean notHasLightSensorManager(Context context) { + SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + Sensor sensor8 = null; + if (sensorManager != null) { + sensor8 = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); + } + return null == sensor8; + } + + private static boolean isFeatures() { + return Build.FINGERPRINT.startsWith("generic") + || Build.FINGERPRINT.toLowerCase().contains("vbox") + || Build.FINGERPRINT.toLowerCase().contains("test-keys") + || Build.MODEL.contains("google_sdk") + || Build.MODEL.contains("Emulator") + || Build.MODEL.contains("Android SDK built for x86") + || Build.MANUFACTURER.contains("Genymotion") + || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) + || "google_sdk".equals(Build.PRODUCT); + } + + private static boolean checkIsNotRealPhone() { + String cpuInfo = readCpuInfo(); + return (cpuInfo.contains("intel") || cpuInfo.contains("amd")); + } + + private static String readCpuInfo() { + String result = ""; + try { + String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; + ProcessBuilder cmd = new ProcessBuilder(args); + + Process process = cmd.start(); + StringBuilder sb = new StringBuilder(); + String readLine; + BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8")); + while ((readLine = responseReader.readLine()) != null) { + sb.append(readLine); + } + responseReader.close(); + result = sb.toString().toLowerCase(); + } catch (IOException ignored) { + } + return result; + } + + private static String[] known_pipes = {"/dev/socket/qemud", "/dev/qemu_pipe"}; + + private static boolean checkPipes() { + for (String pipes : known_pipes) { + File qemu_socket = new File(pipes); + if (qemu_socket.exists()) { + Log.v("Result:", "Find pipes!"); + return true; + } + } + Log.i("Result:", "Not Find pipes!"); + return false; + } +}