|
13 | 13 | import android.telephony.TelephonyManager;
|
14 | 14 | import android.text.TextUtils;
|
15 | 15 |
|
16 |
| -import androidx.annotation.RequiresApi; |
17 |
| -import androidx.annotation.RequiresPermission; |
18 |
| - |
| 16 | +import java.io.BufferedReader; |
19 | 17 | import java.io.File;
|
| 18 | +import java.io.IOException; |
| 19 | +import java.io.InputStreamReader; |
20 | 20 | import java.net.InetAddress;
|
21 | 21 | import java.net.NetworkInterface;
|
22 | 22 | import java.net.SocketException;
|
23 | 23 | import java.util.Enumeration;
|
24 | 24 | import java.util.UUID;
|
25 | 25 |
|
| 26 | +import androidx.annotation.RequiresApi; |
| 27 | +import androidx.annotation.RequiresPermission; |
| 28 | + |
26 | 29 | import static android.Manifest.permission.ACCESS_WIFI_STATE;
|
27 | 30 | import static android.Manifest.permission.CHANGE_WIFI_STATE;
|
28 | 31 | import static android.Manifest.permission.INTERNET;
|
@@ -382,13 +385,50 @@ public static boolean isEmulator() {
|
382 | 385 | intent.setAction(Intent.ACTION_DIAL);
|
383 | 386 | boolean checkDial = intent.resolveActivity(Utils.getApp().getPackageManager()) == null;
|
384 | 387 | if (checkDial) return true;
|
| 388 | + if (isEmulatorByCpu()) return true; |
385 | 389 |
|
386 | 390 | // boolean checkDebuggerConnected = Debug.isDebuggerConnected();
|
387 | 391 | // if (checkDebuggerConnected) return true;
|
388 | 392 |
|
389 | 393 | return false;
|
390 | 394 | }
|
391 | 395 |
|
| 396 | + /** |
| 397 | + * Returns whether is emulator by check cpu info. |
| 398 | + * by function of {@link #readCpuInfo}, obtain the device cpu information. |
| 399 | + * then compare whether it is intel or amd (because intel and amd are generally not mobile phone cpu), to determine whether it is a real mobile phone |
| 400 | + * |
| 401 | + * @return {@code true}: yes<br>{@code false}: no |
| 402 | + */ |
| 403 | + private static boolean isEmulatorByCpu() { |
| 404 | + String cpuInfo = readCpuInfo(); |
| 405 | + return cpuInfo.contains("intel") || cpuInfo.contains("amd"); |
| 406 | + } |
| 407 | + |
| 408 | + /** |
| 409 | + * Return Cpu information |
| 410 | + * |
| 411 | + * @return Cpu info |
| 412 | + */ |
| 413 | + private static String readCpuInfo() { |
| 414 | + String result = ""; |
| 415 | + try { |
| 416 | + String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; |
| 417 | + ProcessBuilder cmd = new ProcessBuilder(args); |
| 418 | + Process process = cmd.start(); |
| 419 | + StringBuilder sb = new StringBuilder(); |
| 420 | + String readLine; |
| 421 | + BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8")); |
| 422 | + while ((readLine = responseReader.readLine()) != null) { |
| 423 | + sb.append(readLine); |
| 424 | + } |
| 425 | + responseReader.close(); |
| 426 | + result = sb.toString().toLowerCase(); |
| 427 | + } catch (IOException ignored) { |
| 428 | + } |
| 429 | + return result; |
| 430 | + } |
| 431 | + |
392 | 432 | /**
|
393 | 433 | * Whether user has enabled development settings.
|
394 | 434 | *
|
|
0 commit comments