Android recognizes the emulator and determines whether it is an emulator or a real machine

Preface

For android developers, the simulator is a development tool, but for users, probably 薅羊毛, 找漏洞of making money.

Regardless of whether it is 活动风控or 内容保护wait for other starting points, it may be required to identify Android模拟器or even prohibit simulator login or subsequent operations.

Do a brief discussion today.

principle

Recognition of the principle of the simulator, in fact, is to find 模拟器and 真机differences, but these differences are reflected in what it, such as operators, phone cards, Bluetooth, various sensors, and so on.

But now the simulator is more and more powerful, and can be simulated 不同品牌in 不同型号the 不同版本mobile phone, and Bluetooth, you can call.

Is it a headache? If you are not careful, you will misjudge. So now there is a scheme on the market that is based on the number of differences between the 容错机制simulator and the real machine. For example, if there are more than 3 differences between the simulator and the real machine, it is judged as a simulation Device.

But in fact, some old versions of mobile phones are not even as advanced as the simulator...So the fault-tolerant mechanism can also add differentiated treatment of users, and individual users do not detect and so on.

Prohibit the simulator to install apk

The general cpu architecture of x86the simulator is the same, we can build.gradleremove x86the support in it.

        ndk {
            // 设置支持的SO库架构
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }

Of course, some mobile phones may also be x86, which is a misjudgment, because there is no more complete solution at present, so the above-mentioned 容错机制is more important.

Just removing the x86 support is not enough, because some simulators are not x86 architectures, so we still need to further find out the difference between the simulator and the real machine.

Of course, it is not necessary to prohibit it, just identify it.

Code recognition

Here is also mentioned in the principle, to determine whether there are multiple judgments such as Bluetooth, serial number, sensor, cpu architecture, etc.

Recommend a library here: CacheEmulatorChecker

The call is also relatively simple, just one line of code:

       val emulator = EmulatorDetectUtil.isEmulator(this)
        if (emulator) {
            ToastUtils.show(this, "检测到您的设备可能为模拟器", Toast.LENGTH_LONG)
        }

verification

Prohibited to add code recognition program, currently verified simulator:

  • Happy Simulator
  • Blue Stack Simulator
  • Night God Simulator
  • Everyday Simulator
  • Tencent Mobile Games Assistant
  • Lightning simulator
  • MUMU simulator
  • Master Lu mobile phone simulation master

And mainstream models of various mainstream mobile phone brands, test ok

At last

At present, there is still no complete and open solution, so in order to avoid misjudgment, it is still necessary to implement related fault tolerance mechanisms according to your own business, such as adding a field to the user whether to judge, and then judge if necessary, otherwise Let it go.

At the end, if you have a better method, welcome to discuss.

Guess you like

Origin blog.csdn.net/yechaoa/article/details/108800001