change simulator check method
This commit is contained in:
parent
c20f1c53bf
commit
6ff085d579
@ -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'
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
|
||||
<application>
|
||||
<activity android:name=".ui.DoricDevActivity" />
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user