├── DeviceIdentify
├── app
│ ├── .gitignore
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── values
│ │ │ │ │ ├── strings.xml
│ │ │ │ │ ├── colors.xml
│ │ │ │ │ └── styles.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-anydpi-v26
│ │ │ │ │ ├── ic_launcher.xml
│ │ │ │ │ └── ic_launcher_round.xml
│ │ │ │ ├── layout
│ │ │ │ │ └── activity_main.xml
│ │ │ │ ├── drawable-v24
│ │ │ │ │ └── ic_launcher_foreground.xml
│ │ │ │ └── drawable
│ │ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── adnonstop
│ │ │ │ └── deviceidentify
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── DeviceUtils.java
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── adnonstop
│ │ │ │ └── deviceidentify
│ │ │ │ └── ExampleUnitTest.java
│ │ └── androidTest
│ │ │ └── java
│ │ │ └── com
│ │ │ └── adnonstop
│ │ │ └── deviceidentify
│ │ │ └── ExampleInstrumentedTest.java
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── .idea
│ ├── vcs.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ ├── gradle.xml
│ └── misc.xml
├── build.gradle
├── gradle.properties
├── gradlew.bat
├── 关于获取设备唯一性标识文档记录.txt
└── gradlew
└── README.md
/DeviceIdentify/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/DeviceIdentify/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidDevicesIdentifyAndAntiVirtualDevices
2 | 搜集Android设备唯一标识码,并且区分出真实设备和虚拟设备
3 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DeviceIdentify
3 |
4 |
--------------------------------------------------------------------------------
/DeviceIdentify/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/DeviceIdentify/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/DeviceIdentify/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminGao999/AndroidDevicesIdentifyAndAntiVirtualDevices/HEAD/DeviceIdentify/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/DeviceIdentify/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 23 14:23:26 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/DeviceIdentify/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/test/java/com/adnonstop/deviceidentify/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.adnonstop.deviceidentify;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/DeviceIdentify/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/DeviceIdentify/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/DeviceIdentify/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/DeviceIdentify/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/androidTest/java/com/adnonstop/deviceidentify/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.adnonstop.deviceidentify;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.adnonstop.deviceidentify", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.adnonstop.deviceidentify"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | }
29 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/java/com/adnonstop/deviceidentify/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.adnonstop.deviceidentify;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | private static final String TAG = "MainActivity";
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | Button btnDeviceIdentify = (Button) findViewById(R.id.btn_obtain_device_identify);
18 | btnDeviceIdentify.setOnClickListener(new View.OnClickListener() {
19 | @Override
20 | public void onClick(View v) {
21 |
22 |
23 | // String uniquePsuedoDeviceID = DeviceUtils.getUniquePsuedoDeviceID();
24 | //
25 | // Log.i(TAG, "onClick: uniquePsuedoDeviceID = " + uniquePsuedoDeviceID);
26 | //
27 | //// String uniqueID = UUID.randomUUID().toString();
28 | //// Log.i(TAG, "onClick: uniqueID = "+uniqueID);
29 | //
30 | //
31 | // String myUUID = DeviceUtils.getMyUUID(MainActivity.this);
32 | // Log.i(TAG, "onClick: myUUID = "+myUUID);
33 |
34 |
35 | // boolean isRealPhone = DeviceUtils.checkIsRealPhone();
36 | // Log.i(TAG, "onCreate: isRealPhone = " + isRealPhone);
37 |
38 | // Boolean notHasLightSensorManager = DeviceUtils.notHasLightSensorManager(MainActivity.this);
39 | // Log.i(TAG, "onClick: notHasLightSensorManager = " + notHasLightSensorManager);
40 |
41 | if (DeviceUtils.checkIsNotRealPhoneAccordingCpu()
42 | || DeviceUtils.notHasLightSensorManager(MainActivity.this)) {
43 | Log.i(TAG, "onClick: 虚拟机啦");
44 | } else {
45 |
46 | Log.i(TAG, "onClick: 真机啦");
47 | }
48 | }
49 | });
50 |
51 |
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/DeviceIdentify/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/DeviceIdentify/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/DeviceIdentify/关于获取设备唯一性标识文档记录.txt:
--------------------------------------------------------------------------------
1 | # 如何 抗虚拟设备?
2 |
3 | 唯一的办法就是识别出模拟器
4 | 那怎么识别一台设备是不是模拟器呢?
5 |
6 | https://stackoverflow.com/questions/1115413/android-emulator-vs-real-device
7 |
8 |
9 | android原生模拟器不支持带.so库的app
10 | 但是夜神模拟器支持
11 |
12 | anti virtual devices
13 | #### 读取cpu信息
14 | https://blog.csdn.net/rd_w_csdn/article/details/53841018
15 | https://blog.csdn.net/mengweiqi33/article/details/22796619
16 |
17 | https://blog.csdn.net/easkshark/article/details/70739735
18 |
19 | #### 具体识别方案
20 | https://blog.csdn.net/tianshuai4317618/article/details/78834683
21 |
22 | #### 读取设备的cpu架构
23 | http://allenfeng.com/2016/11/06/what-you-should-know-about-android-abi-and-so/
24 | shell@NX529J:/ $ getprop | grep abilist
25 | [ro.product.cpu.abi]: [arm64-v8a]
26 | [ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
27 | [ro.product.cpu.abilist64]: [arm64-v8a]
28 | [ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
29 |
30 | 使用API获取
31 | 使用Build.SUPPORTED_ABIS可以获取当前设备支持的ABI列表:
32 |
33 | import android.os.Build;
34 | String supportedAbis = Build.SUPPORTED_ABIS;
35 |
36 |
37 |
38 |
39 | # 如何做到设备唯一性标识呢?
40 |
41 |
42 |
43 |
44 | ## stack overflow
45 |
46 | https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
47 |
48 |
49 | ### Do Android devices have a unique ID, and if so, what is a simple way to access it using Java?
50 |
51 | #### 方案1
52 | Settings.Secure#ANDROID_ID returns the Android ID as an unique for each user 64-bit hex string.
53 |
54 | import android.provider.Settings.Secure;
55 | private String android_id = Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);
56 |
57 | 问题:
58 | It's known to be null sometimes, it's documented as "can change upon factory reset".
59 | Use at your own risk, and it can be easily changed on a rooted phone. – Seva Alekseyev Jun 23 '10 at 14:21
60 |
61 |
62 |
63 | #### 方案2
64 | final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
65 |
66 | final String tmDevice, tmSerial, androidId;
67 | tmDevice = "" + tm.getDeviceId();
68 | tmSerial = "" + tm.getSimSerialNumber();
69 | androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
70 |
71 | UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
72 | String deviceId = deviceUuid.toString();
73 |
74 |
75 |
76 |
77 | # UUID
78 | 通用唯一识别码(英语:Universally Unique Identifier,简称UUID)是一种软件建构的标准,
79 | 亦为开放软件基金会组织在分布式计算环境领域的一部分。
80 |
81 | UUID Version 1:基于时间的UUID
82 |
83 | 基于时间的UUID通过计算当前时间戳、随机数和机器MAC地址得到。
84 | 由于在算法中使用了MAC地址,这个版本的UUID可以保证在全球范围的唯一性。
85 | 但与此同时,使用MAC地址会带来安全性问题,这就是这个版本UUID受到批评的地方。
86 | 如果应用只是在局域网中使用,也可以使用退化的算法,以IP地址来代替MAC地址--Java的UUID往往是这样实现的(当然也考虑了获取MAC的难度)。
87 |
88 |
89 | UUID Version 3:基于名字的UUID(MD5)
90 |
91 | 基于名字的UUID通过计算名字和名字空间的MD5散列值得到。
92 | 这个版本的UUID保证了:相同名字空间中不同名字生成的UUID的唯一性;不同名字空间中的UUID的唯一性;
93 | 相同名字空间中相同名字的UUID重复生成是相同的。
94 |
95 |
96 | UUID Version 4:随机UUID
97 |
98 | 根据随机数,或者伪随机数生成UUID。这种UUID产生重复的概率是可以计算出来的,
99 | 但随机的东西就像是买彩票:你指望它发财是不可能的,但狗屎运通常会在不经意中到来。
100 |
101 |
102 | UUID Version 5:基于名字的UUID(SHA1)
103 |
104 | 和版本3的UUID算法类似,只是散列值计算使用SHA1(Secure Hash Algorithm 1)算法。
105 |
106 |
107 | UUID的应用
108 |
109 | 从UUID的不同版本可以看出,Version 1/2适合应用于分布式计算环境下,具有高度的唯一性;
110 | Version 3/5适合于一定范围内名字唯一,且需要或可能会重复生成UUID的环境下;
111 | 至于Version 4,我个人的建议是最好不用(虽然它是最简单最方便的)。
112 |
113 |
114 |
115 | 通常我们建议使用UUID来标识对象或持久化数据,但以下情况最好不使用UUID:
116 |
117 |
118 |
--------------------------------------------------------------------------------
/DeviceIdentify/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/DeviceIdentify/app/src/main/java/com/adnonstop/deviceidentify/DeviceUtils.java:
--------------------------------------------------------------------------------
1 | package com.adnonstop.deviceidentify;
2 |
3 | import android.Manifest;
4 | import android.bluetooth.BluetoothAdapter;
5 | import android.content.Context;
6 | import android.content.pm.PackageManager;
7 | import android.hardware.Sensor;
8 | import android.hardware.SensorManager;
9 | import android.os.Build;
10 | import android.provider.Settings;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v4.content.ContextCompat;
13 | import android.support.v7.app.AppCompatActivity;
14 | import android.telephony.TelephonyManager;
15 | import android.text.TextUtils;
16 | import android.util.Log;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.IOException;
20 | import java.io.InputStreamReader;
21 | import java.util.UUID;
22 |
23 | import static android.content.Context.SENSOR_SERVICE;
24 |
25 | /**
26 | * Created by admin on 2017/8/10.
27 | * 获取设备id
28 | */
29 |
30 | public class DeviceUtils {
31 | private static final String TAG = "DeviceUtils";
32 | public static final int REQUESTCODE_PERMISSION_READ_PHONE_STATE = 0x0001;
33 | private static final int REQUESTCODE_PERMISSION_BLUETOOTH = 0x0002;
34 |
35 |
36 | // public static String getAndroidID(Context context) {
37 | // return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
38 | // }
39 | //
40 | // public static String getPhoneInfo(Context context) {
41 | // TelephonyManager tm = (TelephonyManager) context
42 | // .getSystemService(Context.TELEPHONY_SERVICE);
43 | // return tm.getDeviceId();
44 | // }
45 |
46 |
47 | /**
48 | * Return pseudo unique ID
49 | *
50 | * @return ID
51 | */
52 | public static String getUniquePsuedoDeviceID() {
53 | // If all else fails, if the user does have lower than API 9 (lower
54 | // than Gingerbread), has reset their device or 'Secure.ANDROID_ID'
55 | // returns 'null', then simply the ID returned will be solely based
56 | // off their Android device information. This is where the collisions
57 | // can happen.
58 | // Thanks http://www.pocketmagic.net/?p=1662!
59 | // Try not to use DISPLAY, HOST or ID - these items could change.
60 | // If there are collisions, there will be overlapping data
61 | String m_szDevIDShort = "35" +
62 | (Build.BOARD.length() % 10) +
63 | (Build.BRAND.length() % 10) +
64 | (Build.CPU_ABI.length() % 10) +
65 | (Build.DEVICE.length() % 10) +
66 | (Build.MANUFACTURER.length() % 10) +
67 | (Build.MODEL.length() % 10) +
68 | (Build.PRODUCT.length() % 10);
69 | // Log.i("", "getUniquePsuedoDeviceID: "+m_szDevIDShort);
70 | // Thanks to @Roman SL!
71 | // http://stackoverflow.com/a/4789483/950427
72 | // Only devices with API >= 9 have android.os.Build.SERIAL
73 | // http://developer.android.com/reference/android/os/Build.html#SERIAL
74 | // If a user upgrades software or roots their device, there will be a duplicate entry
75 | String serial = null;
76 | try {
77 | serial = Build.class.getField("SERIAL").get(null).toString();
78 |
79 | // Go ahead and return the serial for api => 9
80 | return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
81 | } catch (Exception exception) {
82 | // String needs to be initialized
83 | serial = "serial"; // some value
84 | }
85 |
86 | // Thanks @Joe!
87 | // http://stackoverflow.com/a/2853253/950427
88 | // Finally, combine the values we have found by using the UUID class to create a unique identifier
89 | return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
90 | }
91 |
92 |
93 | public static String getMyUUID(AppCompatActivity context) {
94 | String uniqueId = null;
95 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
96 | != PackageManager.PERMISSION_GRANTED) {
97 | ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUESTCODE_PERMISSION_READ_PHONE_STATE);
98 | } else {
99 |
100 | TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
101 |
102 | String tmDevice, tmSerial, tmPhone, androidId;
103 |
104 | tmDevice = "" + tm.getDeviceId();
105 |
106 | tmSerial = "" + tm.getSimSerialNumber();
107 |
108 | androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
109 |
110 | UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
111 |
112 | uniqueId = deviceUuid.toString();
113 |
114 | // Log.i("debug", "uuid=" + uniqueId);
115 |
116 | return uniqueId;
117 |
118 | }
119 |
120 | return uniqueId;
121 | }
122 |
123 |
124 | /**
125 | * 判断是否存在光传感器来判断是否为模拟器
126 | * 部分真机也不存在温度和压力传感器。其余传感器模拟器也存在。
127 | *
128 | * @return true 为模拟器
129 | */
130 | public static Boolean notHasLightSensorManager(Context context) {
131 | SensorManager sensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE);
132 | Sensor sensor8 = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); //光
133 | if (null == sensor8) {
134 | return true;
135 | } else {
136 | return false;
137 | }
138 | }
139 |
140 | /**
141 | * 判断蓝牙是否有效来判断是否为模拟器
142 | *
143 | * @return true 为模拟器
144 | */
145 | public static boolean notHasBlueTooth(AppCompatActivity context) {
146 |
147 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
148 |
149 |
150 | ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.BLUETOOTH}, REQUESTCODE_PERMISSION_BLUETOOTH);
151 | } else {
152 |
153 | BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
154 | if (ba == null) {
155 | return true;
156 | } else {
157 | // 如果有蓝牙不一定是有效的。获取蓝牙名称,若为null 则默认为模拟器
158 | String name = ba.getName();
159 | if (TextUtils.isEmpty(name)) {
160 | return true;
161 | } else {
162 | return false;
163 | }
164 | }
165 | }
166 |
167 | return false;
168 | }
169 |
170 | /**
171 | * 根据部分特征参数设备信息来判断是否为模拟器
172 | *
173 | * @return true 为模拟器
174 | */
175 | public static boolean isFeatures() {
176 | return Build.FINGERPRINT.startsWith("generic")
177 | || Build.FINGERPRINT.toLowerCase().contains("vbox")
178 | || Build.FINGERPRINT.toLowerCase().contains("test-keys")
179 | || Build.MODEL.contains("google_sdk")
180 | || Build.MODEL.contains("Emulator")
181 | || Build.MODEL.contains("Android SDK built for x86")
182 | || Build.MANUFACTURER.contains("Genymotion")
183 | || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
184 | || "google_sdk".equals(Build.PRODUCT);
185 | }
186 |
187 | private static String readCpuInfo() {
188 | String result = "";
189 | try {
190 | String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
191 | ProcessBuilder cmd = new ProcessBuilder(args);
192 |
193 | Process process = cmd.start();
194 | StringBuffer sb = new StringBuffer();
195 | String readLine = "";
196 | BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
197 | while ((readLine = responseReader.readLine()) != null) {
198 | sb.append(readLine);
199 | }
200 | responseReader.close();
201 | result = sb.toString().toLowerCase();
202 | } catch (IOException ex) {
203 | }
204 | return result;
205 | }
206 |
207 | /**
208 | * 判断cpu是否为电脑来判断 模拟器
209 | *
210 | * @return true 为模拟器
211 | */
212 | public static boolean checkIsNotRealPhoneAccordingCpu() {
213 | String cpuInfo = readCpuInfo();
214 | if ((cpuInfo.contains("intel") || cpuInfo.contains("amd"))) {
215 | return true;
216 | }
217 | return false;
218 | }
219 |
220 | }
221 |
--------------------------------------------------------------------------------