检测android模拟器的方法
下载LOFTER客户端
首先知道android os各个发布版本的code name:
Code name Version API level
(no code name) 1.0 API level 1
(no code name) 1.1 API level 2
Cupcake 1.5 API level 3, NDK 1
Donut 1.6 API level 4, NDK 2
Eclair 2.0 API level 5
Eclair 2.0.1 API level 6
Eclair 2.1 API level 7, NDK 3
Froyo 2.2.x API level 8, NDK 4
Gingerbread 2.3 - 2.3.2 API level 9, NDK 5
Gingerbread 2.3.3 - 2.3.7 API level 10
Honeycomb 3.0 API level 11
Honeycomb 3.1 API level 12, NDK 6
Honeycomb 3.2.x API level 13
Ice Cream Sandwich 4.0.1 - 4.0.2 API level 14, NDK 7
Ice Cream Sandwich 4.0.3 - 4.0.4 API level 15, NDK 8
Jelly Bean 4.1.x API level 16
Jelly Bean 4.2.x API level 17
模拟器中获取的操作系统code name为(Landroid/os/Build;->BRAND的值) "generic"
因此如果发现code name为"generic"则,为模拟器上运行!程序直接退出。
因此如果发现 Landroid/os/Build;->MODEL 为"sdk"则,为模拟器上运行!程序直接退出。
样例代码:
const-string v0, "phone"
invoke-virtual {p0, v0}, Lcom/xxx/LoadingActivity;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;
move-result-object v0
check-cast v0, Landroid/telephony/TelephonyManager;
invoke-virtual {v0}, Landroid/telephony/TelephonyManager;->getSubscriberId()Ljava/lang/String;
sget-object v0, Landroid/os/Build;->BRAND:Ljava/lang/String;
invoke-virtual {v0}, Ljava/lang/String;->toLowerCase()Ljava/lang/String;
move-result-object v0
const-string v1, "generic"
#v1=(Reference);
invoke-virtual {v0, v1}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I
move-result v0
#liyanzhong 修改值直接跳过
const/16 v0, -1
#v0=(Integer);
if-eq v0, v2, :cond_0
sget-object v0, Landroid/os/Build;->MODEL:Ljava/lang/String;
#v0=(Reference);
invoke-virtual {v0}, Ljava/lang/String;->toLowerCase()Ljava/lang/String;
move-result-object v0
const-string v1, "sdk"
invoke-virtual {v0, v1}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I
move-result v0
#v0=(Integer);
if-eq v0, v2, :cond_0
invoke-virtual {p0}, Lcom/xxx/LoadingActivity;->finish()V
:cond_0
iget-object v0, p0, Lcom/xxx/LoadingActivity;->b:Landroid/content/SharedPreferences;
#v0=(Reference);
invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;
...
...
...
【注】:以下信息可以被用来判断是否在模拟器上运行
模拟器输出的信息
C:\Users\dell>adb shell getprop
[ro.kernel.qemu]: [1]
[ro.hardware]: [goldfish]
[ro.build.tags]: [test-keys]
[ro.product.model]: [sdk]
[ro.product.brand]: [generic]
[ro.product.name]: [sdk]
[ro.product.device]: [generic]
[ro.product.board]: []
[ro.product.manufacturer]: [unknown]
[ro.board.platform]: []
[ro.build.product]: [generic]
[ro.build.fingerprint]: [generic/sdk/generic:2.3.1/GSI11/93351:eng/test-keys]
三星真机输出的信息
[ro.kernel.qemu]: [0]
[ro.hardware]: [SCH-I535]
[ro.build.tags]: [release-keys]
[ro.product.model]: [SCH-I535]
[ro.product.brand]: [Verizon]
[ro.product.name]: [d2vzw]
[ro.product.device]: [d2vzw]
[ro.product.board]: [MSM8960]
[ro.product.manufacturer]: [samsung]
[ro.board.platform]: [msm8960]
[ro.build.product]: [d2vzw]
[ro.build.fingerprint]: [Verizon/d2vzw/d2vzw:4.0.4/IMM76D/I535VRALG1:user/release-keys] |