Skip to content

Commit

Permalink
支持荣耀手机原生的OAID实现 #73
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Dec 5, 2023
1 parent f2583a8 commit 90c3d6b
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 33 deletions.
49 changes: 28 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ dependencies {
本库自带`consumer-rules.pro`如下混淆规则,不混淆厂商的相关接口及类。若通过远程依赖的方式引用,则无需进行额外配置:

```proguard
# 本库模块专用的混淆规则(注:“repeackage”拼写是历史遗留问题)
-keep class repeackage.com.uodis.opendevice.aidl.** { *; }
-keep interface repeackage.com.uodis.opendevice.aidl.** { *; }
-keep class repeackage.com.asus.msa.SupplementaryDID.** { *; }
-keep interface repeackage.com.asus.msa.SupplementaryDID.** { *; }
-keep class repeackage.com.bun.lib.** { *; }
Expand All @@ -155,30 +158,33 @@ dependencies {
-keep interface repeackage.com.android.creator.** { *; }
-keep class repeackage.com.google.android.gms.ads.identifier.internal.** { *; }
-keep interface repeackage.com.google.android.gms.ads.identifier.internal.* { *; }
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }
-keep class repeackage.com.oplus.stdid.** {*; }
-keep interface repeackage.com.oplus.stdid.** {*; }
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }
-keep class com.hihonor.ads.** {*; }
-keep interface com.hihonor.ads.** {*; }
```

## 支持情况

| 厂商或品牌 | 系统或框架 |
| --------------------------------- | ------------------------------------------------------- |
| 华为(Huawei、Honor) | HMS Core 2.6.2+ 、Google Play Service 4.0+ |
| 小米(XiaoMi、Redmi、BlackShark) | MIUI 10.2+、Google Play Service 4.0+ |
| 维沃(VIVO、IQOO) | Funtouch OS 9+、OriginOS 1.0+、Google Play Service 4.0+ |
| 欧珀(OPPO、Realme) | ColorOS 7.0+、Google Play Service 4.0+ |
| 三星(Samsung) | Android 10+、Google Play Service 4.0+ |
| 联想(Lenovo) | ZUI 11.4+、Google Play Service 4.0+ |
| 华硕(ASUS) | Android 10+、Google Play Service 4.0+ |
| 魅族(Meizu) | Android 10+、Google Play Service 4.0+ |
| 一加(OnePlus) | Android 10+、Google Play Service 4.0+ |
| 努比亚(Nubia) | Android 10+、Google Play Service 4.0+ |
| 酷派(Coolpad) | CoolOS、Google Play Service 4.0+ |
| 酷赛(Coosea ) | Android 10+、Google Play Service 4.0+ |
| 卓易(Droi ) | Freeme OS、Google Play Service 4.0+ |
| 其他(ZTE、HTC、Motorola、……) | SSUI、Google Play Service 4.0+ |
| 厂商或品牌 | 系统或框架 |
|-----------------------------|-------------------------------------------------------|
| 华为(Huawei) | HMS Core 2.6.2+、Google Play Service 4.0+ |
| 荣耀(Honor) | Magic UI 4/5/6、MagicOS 7.0+、Google Play Service 4.0+ |
| 小米(XiaoMi、Redmi、BlackShark) | MIUI 10.2+、Google Play Service 4.0+ |
| 维沃(VIVO、IQOO) | Funtouch OS 9+、OriginOS 1.0+、Google Play Service 4.0+ |
| 欧珀(OPPO、Realme) | ColorOS 7.0+、Google Play Service 4.0+ |
| 三星(Samsung) | Android 10+、Google Play Service 4.0+ |
| 联想(Lenovo) | ZUI 11.4+、Google Play Service 4.0+ |
| 华硕(ASUS) | Android 10+、Google Play Service 4.0+ |
| 魅族(Meizu) | Android 10+、Google Play Service 4.0+ |
| 一加(OnePlus) | Android 10+、Google Play Service 4.0+ |
| 努比亚(Nubia) | Android 10+、Google Play Service 4.0+ |
| 酷派(Coolpad) | CoolOS、Google Play Service 4.0+ |
| 酷赛(Coosea ) | Android 10+、Google Play Service 4.0+ |
| 卓易(Droi ) | Freeme OS、Google Play Service 4.0+ |
| 其他(ZTE、HTC、Motorola、……) | SSUI、Google Play Service 4.0+ |

> 注:本项目的 OAID 获取接口主要参考北京数字联盟公开的代码以及逆向分析参考移动安全联盟的 SDK、HUAWEI Ads SDK、小米 DeviceId.jar、Google Play Services SDK 等。
Expand Down Expand Up @@ -240,7 +246,7 @@ OAID 是移动智能终端补充设备标识体系中的一员,官方定义为
- 谷歌官方文档 [使用标识符的最佳做法](https://developer.android.google.cn/training/articles/user-data-ids)
- [团体标准-移动智能终端补充设备标识规范-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)
- 华为 [广告标识服务](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/identifier-service-version-change-history-0000001050066927)
- 荣耀 [广告标识服务](https://developer.hihonor.com/cn/kitdoc?category=%E5%9F%BA%E7%A1%80%E6%9C%8D%E5%8A%A1&kitId=11030&navigation=guides&docId=update-instructions.md&token=)
- 荣耀 [广告标识服务](https://developer.hihonor.com/cn/kitdoc?kitId=11030&navigation=guides&docId=update-instructions.md&token=)
- 小米 [设备标识体系说明](https://dev.mi.com/console/doc/detail?pId=1821)
- 魅族 [移动智能终端补充设备标识](http://open-wiki.flyme.cn/doc-wiki/index#id?133)
- 维沃 [移动智能终端补充设备标识服务](https://dev.vivo.com.cn/documentCenter/doc/253)
Expand All @@ -253,9 +259,10 @@ OAID 是移动智能终端补充设备标识体系中的一员,官方定义为
## 远程真机

- 免费 [华为远程真机云调试](https://developer.huawei.com/consumer/cn/agconnect/cloud-adjust)
- 免费 [荣耀远程真机云调试](https://developer.hihonor.com/cn/doc/guides/100194)
- 免费 [小米云测平台远程真机租用](https://testit.miui.com/remote)
- 免费 [VIVO 云测平台远程真机](https://vcl.vivo.com.cn/#/machine/picking)
- 免费 [OPPO 云测平台远程真机](https://open.oppomobile.com/cloudmachine/device/list-plus)
- 免费 [维沃云测平台远程真机](https://vcl.vivo.com.cn/#/machine/picking)
- 免费 [欧珀云测平台远程真机](https://open.oppomobile.com/cloudmachine/device/list-plus)
- 免费 [三星远程开发测试平台真机调试](http://samsung.smarterapps.cn/index.php?app=home&mod=Index&act=samsung)
- 新人试用 ~~腾讯 WeTest 云真机调试、阿里 EMAS 移动测试远程真机、百度 MTC 远程真机调试、Testin 远程真机测试、AllTesting 真机测试~~

Expand Down
2 changes: 2 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ android {
dependencies {
// 华为的最新版本广告标识服务SDK,参阅 https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/identifier-service-version-change-history-0000001050066927
api "com.huawei.hms:ads-identifier:3.4.62.300"
// 荣耀的最新版本广告标识服务SDK,参阅 https://developer.hihonor.com/cn/kitdoc?kitId=11030&navigation=guides&docId=intergrate.md
api 'com.hihonor.mcs:ads-identifier:1.0.2.301'
}
6 changes: 4 additions & 2 deletions library/consumer-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
-keep interface repeackage.com.android.creator.** { *; }
-keep class repeackage.com.google.android.gms.ads.identifier.internal.** { *; }
-keep interface repeackage.com.google.android.gms.ads.identifier.internal.* { *; }
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }
-keep class repeackage.com.oplus.stdid.** {*; }
-keep interface repeackage.com.oplus.stdid.** {*; }
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }
-keep class com.hihonor.ads.** {*; }
-keep interface com.hihonor.ads.** {*; }
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static boolean isEmui() {
return !TextUtils.isEmpty(sysProperty("ro.build.version.emui", ""));
}

public static boolean isHonor() {
// 荣耀手机
return Build.BRAND.equalsIgnoreCase("HONOR");
}

public static boolean isOppo() {
// 欧珀手机、真我手机
return Build.MANUFACTURER.equalsIgnoreCase("OPPO") ||
Expand Down
101 changes: 101 additions & 0 deletions library/src/main/java/com/github/gzuliyujiang/oaid/impl/HonorImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2016-present. 贵州纳雍穿青人李裕江 and All Contributors.
*
* The software is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package com.github.gzuliyujiang.oaid.impl;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.github.gzuliyujiang.oaid.IGetter;
import com.github.gzuliyujiang.oaid.IOAID;
import com.github.gzuliyujiang.oaid.OAIDException;
import com.github.gzuliyujiang.oaid.OAIDLog;
import com.hihonor.ads.identifier.AdvertisingIdClient;

import java.util.concurrent.Executors;

/**
* 参阅荣耀官方 <a href="https://developer.hihonor.com/cn/kitdoc?kitId=11030&navigation=guides&docId=dev-overview.md&token=">HONOR Ads SDK</a>。
*
* @author 大定府羡民(1032694760@qq.com)
* @since 2023/12/04
*/
class HonorImpl implements IOAID {
private final Context context;
private final Handler uiHandler = new Handler(Looper.getMainLooper());

public HonorImpl(Context context) {
this.context = context;
}

@Override
public boolean supported() {
if (context == null) {
return false;
}
return AdvertisingIdClient.isAdvertisingIdAvailable(context);
}

@Override
public void doGet(final IGetter getter) {
if (context == null || getter == null) {
return;
}
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
runOnSubThread(getter);
}
});
}

private void runOnSubThread(IGetter getter) {
// 参阅 https://developer.hihonor.com/cn/kitdoc?kitId=11030&navigation=ref&docId=AdvertisingIdClient.md
try {
// 如果用户手机中,HMS Core(APK)版本在2.6.2以下,无法获取OAID,将抛出IOException。
final AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(context);
if (info == null) {
postOnMainThread(getter, new OAIDException("Advertising identifier info is null"));
return;
}
if (info.isLimit) {
// 实测在系统设置中关闭了广告标识符,将获取到固定的一大堆0
postOnMainThread(getter, new OAIDException("User has disabled advertising identifier"));
return;
}
postOnMainThread(getter, info.id);
} catch (Exception e) {
OAIDLog.print(e);
postOnMainThread(getter, new OAIDException(e));
}
}

private void postOnMainThread(final IGetter getter, final String oaid) {
uiHandler.post(new Runnable() {
@Override
public void run() {
getter.onOAIDGetComplete(oaid);
}
});
}

private void postOnMainThread(final IGetter getter, final OAIDException e) {
uiHandler.post(new Runnable() {
@Override
public void run() {
getter.onOAIDGetError(e);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,24 @@ public boolean supported() {
if (context == null) {
return false;
}
boolean ret = false;
try {
if (AdvertisingIdClient.isAdvertisingIdAvailable(context)) {
return true;
}
PackageManager pm = context.getPackageManager();
if (pm.getPackageInfo("com.huawei.hwid", 0) != null) {
ret = true;
} else if (pm.getPackageInfo("com.huawei.hwid.tv", 0) != null) {
ret = true;
} else {
ret = pm.getPackageInfo("com.huawei.hms", 0) != null;
return true;
}
if (pm.getPackageInfo("com.huawei.hwid.tv", 0) != null) {
return true;
}
if (pm.getPackageInfo("com.huawei.hms", 0) != null) {
return true;
}
} catch (Exception e) {
OAIDLog.print(e);
}
return ret;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@ private static IOAID createManufacturerImpl(Context context) {
if (OAIDRom.isASUS()) {
return new AsusImpl(context);
}
if (OAIDRom.isHonor()) {
HonorImpl honorImpl = new HonorImpl(context);
if (honorImpl.supported()) {
// 支持的话(Magic UI 4.0,5.0,6.0及MagicOS 7.0或以上)直接使用荣耀的实现,否则尝试华为的实现
return honorImpl;
}
}
if (OAIDRom.isHuawei() || OAIDRom.isEmui()) {
return new HuaweiImpl(context);
}
if (OAIDRom.isOppo() || OAIDRom.isOnePlus()) {
OppoImpl oppo = new OppoImpl(context);
if(oppo.supported()) {
if (oppo.supported()) {
return oppo;
}
else {
} else {
return new OppoExtImpl(context);
}
}
Expand Down

0 comments on commit 90c3d6b

Please sign in to comment.