One, native way.
Read the configuration and hardware-related information in the device through the C code.
1,diskstats
Gets the partition state information for the Flash.
int fd = open ("/proc/diskstats", o_rdonly);
bytes = Read (fd, buf, bytes);
Difference: There are mmcblk0 partitions on the real machine, but the simulator has no partition information.
2,mac address.
Read the MAC address through the socket and the IOCTL.
SOCKFD = socket (af_inet, SOCK_DGRAM, 0);
IOCTL (SOCKFD, siocgifconf, (char*) &ifc);
IOCTL (SOCKFD, SIOCGIFADDR, &ifr[i])
IOCTL (SOCKFD, SIOCGIFHWADDR, (char*) &ifr[i])
Difference: The real machine can get Wlan0 IP and MAC address, the simulator can only get eth0 IP and MAC address;
3, useful prop information.
__system_property_get (key, BUF);
Difference: The simulator does not have the Ro.boot.serialno and Ro.serialno properties, the machine serial number in the real machine.
The simulator Ro.hardware property is goldfish and the real machine is the respective model.
4,CPU information.
int fd = open ("/proc/cpuinfo", o_rdonly);
bytes = Read (fd, buf, bytes);
Difference: The Cpuinfo hardware in the simulator is goldfish.
5,drivers
int fd = open ("/proc/tty/drivers", o_rdonly);
Difference: The simulator contains goldfish drivers
6, simulator-specific files.
int fd = open ("/dev/socket/qemud", o_rdonly);
int fd = open ("/dev/qemu_pipe", o_rdonly);
The difference: Emulator proprietary files, not in the real machine.
Two, the traditional way:
It can be obtained from Java layer code in the following ways:
1,imei and IMSI
IMEI Mobile Device International identification code.
IMSI IMSI International Mobile Subscriber ID, stored in SIM card
Final Telephonymanager TM = (Telephonymanager) getbasecontext (). Getsystemservice (Context.telephony_service);
String IMEI = Tm.getdeviceid ();
String IMSI = Tm.getsubscriberid ();
Device 1:354273055927169/null (no card)
Equipment 2:862966024243759/460011040618938
Simulator: 000000000000000/310260000000000
2,serial Serial Number
String serial = Android.os.Build.SERIAL;
Equipment 1:4df78680771b117b
Equipment 2:OBAI5HDQZPDIRCQG
Simulator: Unknown
3,android_id
String android_id = secure.getstring (Getcontentresolver (), secure.android_id);
Devices and simulators are available, 16-bit.
4,mac Address
Wifimanager wifimanage= (Wifimanager) Getsystemservice (Context.wifi_service); Wifiinfo wifiinfo= wifimanage.getconnectioninfo ();
Equipment 1:88:32:9B:1E:49:20
Equipment 2:f8:a4:5f:fd:56:17
Emulator: null
How Android distinguishes between real-computer and simulator