Skip to content

Commit

Permalink
support emulator check callback
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm committed Jul 25, 2018
1 parent bbaa94a commit b8e86a1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/lahm/easyprotector/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/lahm/library/EmulatorCheckCallback.java
Original file line number Diff line number Diff line change
@@ -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);
}
45 changes: 24 additions & 21 deletions library/src/main/java/com/lahm/library/EmulatorCheckUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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);
}
Expand Down

0 comments on commit b8e86a1

Please sign in to comment.