Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu authored Apr 8, 2021
2 parents b358dec + 3366b57 commit f5fca59
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 3.0.2 - 2021/04/08

- 小米手机获取OAID问题 @andot PR#18
- 增加数字版权管理设备ID
- 增加各大手机厂商关于OAID的说明文档

## 3.0.1 - 2021/03/29

- 增加设备标识符统一格式为MD5或SHA1的方法
Expand Down
54 changes: 50 additions & 4 deletions OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/DeviceID.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.MediaDrm;
import android.media.UnsupportedSchemeException;
import android.os.Build;
import android.os.Process;
import android.provider.Settings;
Expand Down Expand Up @@ -68,21 +70,32 @@ public static void register(final Application application) {
String uniqueID = getUniqueID(application);
if (!TextUtils.isEmpty(uniqueID)) {
clientId = uniqueID;
OAIDLog.print("Client id is IMEI/MEID");
return;
}
getOAID(application, new IGetter() {
@Override
public void onOAIDGetComplete(@NonNull String result) {
clientId = result;
OAIDLog.print("Client id is OAID");
}

@Override
public void onOAIDGetError(@NonNull Throwable error) {
String id = getAndroidID(application);
if (TextUtils.isEmpty(id)) {
id = getGUID(application);
String id = DeviceID.getWidevineID(application);
if (!TextUtils.isEmpty(id)) {
clientId = id;
OAIDLog.print("Client id is WidevineID");
return;
}
clientId = id;
id = getAndroidID(application);
if (!TextUtils.isEmpty(id)) {
clientId = id;
OAIDLog.print("Client id is AndroidID");
return;
}
clientId = getGUID(application);
OAIDLog.print("Client id is GUID");
}
});
}
Expand Down Expand Up @@ -223,6 +236,39 @@ public static String getAndroidID(@NonNull Context context) {
return id == null ? "" : id;
}

/**
* 获取数字版权管理设备ID
*
* @param context 上下文
* @return WidevineID,可能为空
*/
@NonNull
public static String getWidevineID(@NonNull Context context) {
try {
//Widevine介绍:https://baike.baidu.com/item/Widevine/3613955
//参阅 https://stackoverflow.com/questions/16369818/how-to-get-crypto-scheme-uuid
//You can find some UUIDs in the https://github.com/google/ExoPlayer source code
//final UUID COMMON_PSSH_UUID = new UUID(0x1077EFECC0B24D02L, 0xACE33C1E52E2FB4BL);
//final UUID CLEARKEY_UUID = new UUID(0xE2719D58A985B3C9L, 0x781AB030AF78D30EL);
//final UUID WIDEVINE_UUID = new UUID(0xEDEF8BA979D64ACEL, 0xA3C827DCD51D21EDL);
//final UUID PLAYREADY_UUID = new UUID(0x9A04F07998404286L, 0xAB92E65BE0885F95L);
final UUID WIDEVINE_UUID = new UUID(0xEDEF8BA979D64ACEL, 0xA3C827DCD51D21EDL);
MediaDrm mediaDrm = new MediaDrm(WIDEVINE_UUID);
byte[] widevineId = mediaDrm.getPropertyByteArray(MediaDrm.PROPERTY_DEVICE_UNIQUE_ID);
if (widevineId == null) {
return "";
}
StringBuilder sb = new StringBuilder();
for (byte aByte : widevineId) {
sb.append(String.format("%02x", aByte));
}
return sb.toString();
} catch (UnsupportedSchemeException e) {
OAIDLog.print(e);
}
return "";
}

/**
* 通过取出ROM版本、制造商、CPU型号以及其他硬件信息来伪造设备标识
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,44 @@
import java.lang.reflect.Method;

/**
* 参阅 http://f4.market.xiaomi.com/download/MiPass/058fc4374ac89aea6dedd9dc03c60a5498241e0dd/DeviceId.jar
* 即 com.miui.deviceid.IdentifierManager
*
* @author 大定府羡民([email protected]
* @since 2020/5/30
*/
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class XiaomiImpl implements IOAID {
private final Context context;
private Class<?> idProvider;
private Class<?> idProviderClass;
private Object idProviderImpl;

@SuppressLint("PrivateApi")
public XiaomiImpl(Context context) {
this.context = context;
try {
idProvider = Class.forName("com.android.id.impl.IdProviderImpl");
idProviderClass = Class.forName("com.android.id.impl.IdProviderImpl");
idProviderImpl = idProviderClass.newInstance();
} catch (Throwable e) {
OAIDLog.print(e);
}
}

@Override
public boolean supported() {
return idProvider != null;
return idProviderImpl != null;
}

@Override
public void doGet(@NonNull final IGetter getter) {
if (idProvider == null) {
if (idProviderClass == null || idProviderImpl == null) {
getter.onOAIDGetError(new NullPointerException("Xiaomi IdProvider not exists"));
return;
}
try {
Method oaidMethod = idProvider.getMethod("getOAID", Context.class);
String did = invokeMethod(oaidMethod);
if (did != null && did.length() > 0) {
getter.onOAIDGetComplete(did);
String oaid = invokeMethod("getOAID");
if (oaid != null && oaid.length() > 0) {
getter.onOAIDGetComplete(oaid);
} else {
throw new RuntimeException("Xiaomi OAID get failed");
}
Expand All @@ -69,14 +73,13 @@ public void doGet(@NonNull final IGetter getter) {
}
}

private String invokeMethod(Method method) {
private String invokeMethod(String methodName) {
String result = null;
if (method != null) {
try {
result = (String) method.invoke(idProvider.newInstance(), context);
} catch (Throwable e) {
OAIDLog.print(e);
}
try {
Method method = idProviderClass.getMethod(methodName, Context.class);
result = (String) method.invoke(idProviderImpl, context);
} catch (Throwable e) {
OAIDLog.print(e);
}
return result;
}
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ dependencies {
builder.append(androidID);
}
builder.append("\n");
builder.append("WidevineID: ");
// 获取数字版权管理ID,可能为空
String widevineID = DeviceID.getWidevineID(this);
if (TextUtils.isEmpty(widevineID)) {
builder.append("WidevineID获取失败");
} else {
builder.append(widevineID);
}
builder.append("\n");
builder.append("PseudoID: ");
// 获取伪造ID,根据硬件信息生成,不会为空,有大概率会重复
builder.append(DeviceID.getPseudoID());
Expand Down Expand Up @@ -162,13 +171,17 @@ dependencies {

## 参考资料

OAID 即 Open Anonymous Identifier,开放匿名标识符,是移动智能终端补充设备标识体系中的一员。
OAID 即 Open Anonymous Device Identifier,开放匿名设备标识符,是移动智能终端补充设备标识体系中的一员。

- [移动安全联盟统一 SDK 下载](https://github.com/2tu/msa) (from http://www.msa-alliance.cn)。
- 谷歌官方文档 [使用标识符的最佳做法](https://developer.android.google.cn/training/articles/user-data-ids)
- [团体标准-移动智能终端补充设备标识规范-v20190516.pdf](http://www.msa-alliance.cn/login.jsp?url=%2Fcol.jsp%3Fid%3D120&errno=11&mid=634&fid=ABUIABA9GAAgpKaN6QUoq7em2QI)
- 华为官方文档 [《获取 OAID 信息(SDK 方式)》](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/identifier-service-obtaining-oaid-sdk-0000001050064988-V5)
- Flyme SDK [移动智能终端补充设备标识](http://open-wiki.flyme.cn/doc-wiki/index#id?133)
- [团体标准-移动智能终端补充设备标识规范-v20190516.pdf](https://swsdl.vivo.com.cn/appstore/developer/uploadfile/20191109/uohz59/%E5%9B%A2%E4%BD%93%E6%A0%87%E5%87%86-%E7%A7%BB%E5%8A%A8%E6%99%BA%E8%83%BD%E7%BB%88%E7%AB%AF%E8%A1%A5%E5%85%85%E8%AE%BE%E5%A4%87%E6%A0%87%E8%AF%86%E8%A7%84%E8%8C%83-v20190516.pdf)
- 华为 [《获取 OAID 信息(SDK 方式)》](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/identifier-service-obtaining-oaid-sdk-0000001050064988-V5)
- 小米 [设备标识体系说明](https://dev.mi.com/console/doc/detail?pId=1821)
- 魅族 [移动智能终端补充设备标识](http://open-wiki.flyme.cn/doc-wiki/index#id?133)
- VIVO [移动智能终端补充设备标识服务](https://dev.vivo.com.cn/documentCenter/doc/253)
- OPPO [移动智能终端补充设备标识体系](https://open.oppomobile.com/wiki/doc#id=10608)
- 三星 [适配指导 | Android Q Device ID权限变更](https://support-cn.samsung.com/App/DeveloperChina/notice/detail?noticeid=115)
- 北京数字联盟公开的获取各厂商 OAID 的简易代码:[Get_Oaid_CNAdid](https://github.com/shuzilm-open-source/Get_Oaid_CNAdid)
- 获取或生成设备唯一标识后,推荐参考“[一种 Android 移动设备构造 UDID 的方案](https://github.com/No89757/Udid) ”。
- StackOverFlow [Is there a unique Android device ID ?](https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/github/gzuliyujiang/demo/DemoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.app.Application;

import com.github.gzuliyujiang.oaid.DeviceID;
import com.github.gzuliyujiang.oaid.OAIDLog;

/**
* Created by liyujiang on 2020/5/20.
Expand All @@ -28,6 +29,7 @@ public class DemoApp extends Application {
@Override
public void onCreate() {
super.onCreate();
OAIDLog.enable();
DeviceID.register(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ private void obtainDeviceId() {
builder.append(androidID);
}
builder.append("\n");
builder.append("WidevineID: ");
// 获取数字版权管理ID,可能为空
String widevineID = DeviceID.getWidevineID(this);
if (TextUtils.isEmpty(widevineID)) {
builder.append("WidevineID获取失败");
} else {
builder.append(widevineID);
}
builder.append("\n");
builder.append("PseudoID: ");
// 获取伪造ID,根据硬件信息生成,不会为空,有大概率会重复
builder.append(DeviceID.getPseudoID());
Expand Down
4 changes: 3 additions & 1 deletion gradle/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

ext {

// Android 5.0
minSdkVersion = 21
targetSdkVersion = 29
// Android 11.0
targetSdkVersion = 30
compileSdkVersion = 30
buildToolsVersion = '30.0.0'
//启用x86架构支持(模拟器运行时需要)
Expand Down
83 changes: 44 additions & 39 deletions gradle/dependency.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,40 @@
ext {

library = [
logger : "com.orhanobut:logger:2.2.0",
immersionbar : "com.gyf.immersionbar:immersionbar:3.0.0",
toast : "com.hjq:toast:8.8",
xxpermissions : "com.hjq:xxpermissions:9.8",
photoview : "com.bm.photoview:library:1.4.1",
material : "com.google.android.material:material:1.2.0",
inline_activity_result : "com.github.florent37:inline-activity-result:1.0.4",
better_link_movement_method: "me.saket:better-link-movement-method:2.2.0",
glide : "com.github.bumptech.glide:glide:4.12.0",
picasso : "com.squareup.picasso:picasso:2.8",
universalimageloader : "com.nostra13.universalimageloader:universal-image-loader:1.9.5",
gson : "com.google.code.gson:gson:2.8.6",
fastjson : "com.alibaba:fastjson:1.2.70",
okgo : "com.lzy.net:okgo:3.0.4",
FastNetworking : "com.amitshekhar.android:android-networking:1.0.2",
PersistentCookieJar : "com.github.franmontiel:PersistentCookieJar:v1.0.1",
SmartRefreshKernel : "com.scwang.smart:refresh-layout-kernel:2.0.3",
SmartRefreshHeaderClassic : "com.scwang.smart:refresh-header-classics:2.0.3",
SmartRefreshHeaderMaterial : "com.scwang.smart:refresh-header-material:2.0.3",
SmartRefreshFooterClassic : "com.scwang.smart:refresh-footer-classics:2.0.3",
SmartRefreshFooterBall : "com.scwang.smart:refresh-footer-ball:2.0.3",
GifDrawable : "pl.droidsonroids.gif:android-gif-drawable:1.2.19",
FileDownloader : "com.liulishuo.filedownloader:library:1.7.7",
banner : "com.youth.banner:banner:2.1.0",
shapeofview : "com.github.florent37:shapeofview:1.3.2",
lcardview : "org.linwg1988:lcardview:1.5.4",
FlowLayoutManager : "com.github.1002326270xc:LayoutManager-FlowLayout:v1.8",
logger : "com.orhanobut:logger:2.2.0",
immersionbar : "com.gyf.immersionbar:immersionbar:3.0.0",
toast : "com.hjq:toast:8.8",
xxpermissions : "com.hjq:xxpermissions:9.8",
photoview : "com.bm.photoview:library:1.4.1",
material : "com.google.android.material:material:1.2.0",
inline_activity_result : "com.github.florent37:inline-activity-result:1.0.4",
glide : "com.github.bumptech.glide:glide:4.12.0",
picasso : "com.squareup.picasso:picasso:2.8",
universalimageloader : "com.nostra13.universalimageloader:universal-image-loader:1.9.5",
gson : "com.google.code.gson:gson:2.8.6",
fastjson : "com.alibaba:fastjson:1.2.70",
okgo : "com.lzy.net:okgo:3.0.4",
FastNetworking : "com.amitshekhar.android:android-networking:1.0.2",
PersistentCookieJar : "com.github.franmontiel:PersistentCookieJar:v1.0.1",
SmartRefreshKernel : "com.scwang.smart:refresh-layout-kernel:2.0.3",
SmartRefreshHeaderClassic : "com.scwang.smart:refresh-header-classics:2.0.3",
SmartRefreshHeaderMaterial: "com.scwang.smart:refresh-header-material:2.0.3",
SmartRefreshFooterClassic : "com.scwang.smart:refresh-footer-classics:2.0.3",
SmartRefreshFooterBall : "com.scwang.smart:refresh-footer-ball:2.0.3",
GifDrawable : "pl.droidsonroids.gif:android-gif-drawable:1.2.19",
FileDownloader : "com.liulishuo.filedownloader:library:1.7.7",
banner : "com.youth.banner:banner:2.1.0",
shapeofview : "com.github.florent37:shapeofview:1.4.7",
lcardview : "org.linwg1988:lcardview:1.5.4",
FlowLayoutManager : "com.github.1002326270xc:LayoutManager-FlowLayout:v1.8",
//noinspection GradleDependency 注意:zxing 3.4.0开始,扫码/二维码生成只支持API>=24,若要支持Android7.0以下则需降级到3.3.3版本
zxing : "com.google.zxing:core:3.3.3",
zxing : "com.google.zxing:core:3.3.3",
OAID_IMPL : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_IMPL:3.0.1",
OAID_ASUS : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_ASUS:3.0.1",
OAID_BUN : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_BUN:3.0.1",
OAID_SAMSUNG : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_SAMSUNG:3.0.1",
OAID_UODIS : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_UODIS:3.0.1",
OAID_ZUI : "com.github.gzu-liyujiang.Android_CN_OAID:OAID_ZUI:3.0.1",
]

androidxLibrary = [
Expand All @@ -56,6 +61,7 @@ ext {
recyclerview : "androidx.recyclerview:recyclerview:1.1.0",
recyclerview_selection: "androidx.recyclerview:recyclerview-selection:1.1.0",
webkit : "androidx.webkit:webkit:1.3.0",
exifinterface : "androidx.exifinterface:exifinterface:1.2.0",
documentfile : "androidx.documentfile:documentfile:1.0.1",
viewpager : "androidx.viewpager:viewpager:1.0.0",
viewpager2 : "androidx.viewpager2:viewpager2:1.0.0",
Expand Down Expand Up @@ -93,16 +99,15 @@ ext {

}

configurations {
all {
//此处可用于解决依赖冲突问题,参阅https://developer.android.google.cn/studio/build/dependencies#duplicate_classes
resolutionStrategy {
force androidxLibrary.core
force androidxLibrary.collection
force androidxLibrary.lifecycle
force androidxLibrary.fragment
force androidxLibrary.appcompat
force androidxLibrary.recyclerview
}
configurations.all {
resolutionStrategy {
//此处可用于解决依赖冲突问题,参阅 https://developer.android.google.cn/studio/build/dependencies#duplicate_classes
force androidxLibrary.annotation
force androidxLibrary.core
force androidxLibrary.collection
force androidxLibrary.lifecycle
force androidxLibrary.fragment
force androidxLibrary.appcompat
force androidxLibrary.recyclerview
}
}
15 changes: 12 additions & 3 deletions gradle/git.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ static def gitGitCommitNumber() {
static def getGitLatestTag() {
try {
// See https://www.jianshu.com/p/2ecfd791c464
def cmd = 'git describe --tags --always --dirty=_developing'
return cmd.execute().text.trim() ?: '1.0.0'
def cmd = 'git describe --tags --always'
def version = cmd.execute().text.trim() ?: '0.0.1'
if (version.indexOf('-') != -1) {
version = version.split('-')[0]
} else if (version.indexOf('.') == -1) {
version = "0.0.9"
}
if (!version.matches("\\d+\\.\\d+\\.\\d+")) {
System.err.println("版本号格式建议为:Major.Minor.Patch")
}
return version
} catch (ignored) {
return "error"
return "0.0.0"
}
}

Expand Down

0 comments on commit f5fca59

Please sign in to comment.