• Android如何区别真机和模拟器


    一,native方式。

    通过c代码读取设备中的配置和硬件相关信息。

    1,diskstats

    获取闪存的分区状态信息。

    int fd = open(“/proc/diskstats”, O_RDONLY);

    bytes = read(fd, buf, bytes);

    区别:真机下都有mmcblk0分区,但是模拟器没有分区信息。

    2,mac地址。

    通过socket和ioctl读取mac地址。

    sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    ioctl(sockfd, SIOCGIFCONF, (char*)&ifc);

    ioctl(sockfd, SIOCGIFADDR, &ifr[i])

    ioctl(sockfd, SIOCGIFHWADDR, (char*)&ifr[i])

    区别:真机可以获取wlan0的ip和mac地址,模拟器只能获取eth0的ip和mac地址;

    3,有用的prop信息。

    __system_property_get(key, buf);

    区别: 模拟器没有ro.boot.serialno和ro.serialno属性,真机中为机器序列号。

    模拟器 ro.hardware属性为goldfish,真机为各自的型号。

    4,cpu信息。

    int fd = open(“/proc/cpuinfo”, O_RDONLY);

    bytes = read(fd, buf, bytes);

    区别:模拟器中cpuinfo的硬件为Goldfish。

    5,drivers

    int fd = open(“/proc/tty/drivers”, O_RDONLY);

    区别:模拟器中包含goldfish的驱动

    6,模拟器特有文件。

    int fd = open(“/dev/socket/qemud”, O_RDONLY);

    int fd = open(“/dev/qemu_pipe”, O_RDONLY);

    区别:模拟器专有的文件,真机中没有。

    二,传统的方式:

    通过Java层的代码获取,可以有以下方式:

    1,IMEI和IMSI

    IMEI  移动设备国际身份码。

    IMSI  IMSI国际移动用户识别码,储存在SIM卡中

    final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

    String imei = tm.getDeviceId();

    String imsi = tm.getSubscriberId();

    设备1:354273055927169 / null(无卡)

    设备2:862966024243759 / 460011040618938

    模拟器:000000000000000 / 310260000000000

    2,Serial序列号

    String serial = android.os.Build.SERIAL;

    设备1:4df78680771b117b

    设备2:OBAI5HDQZPDIRCQG

    模拟器:unknown

    3,android_id

    String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

    设备和模拟器都有,16位。

    4,Mac地址

    WifiManager wifimanage=(WifiManager)getSystemService(Context.WIFI_SERVICE);  WifiInfo wifiinfo= wifimanage.getConnectionInfo();

    设备1:88:32:9b:1e:49:20

    设备2:f8:a4:5f:fd:56:17

    模拟器:null

  • 相关阅读:
    mysql在第一次查询的时候很慢,第二次查询就比较快的原因?
    mysql的递归(使用函数)
    什么样的男人才是女人眼中最帅的男人
    面试题总结
    java的重载总结
    arduino读取GPIO数据
    electron+react项目改为typescript
    百度AI训练营笔记
    python读取文件出现ufeff问题
    大端小端
  • 原文地址:https://www.cnblogs.com/yxfcnbg/p/4918020.html
Copyright © 2020-2023  润新知