安卓设备唯一标识解决方案,可完全替代移动安全联盟统一 SDK 闭源方案。包括国内手机厂商的开放匿名标识(OAID)、海外手机平台的安卓广告标识(AAID),另外也提供了 IMEI/MEID、AndroidID、WidevineID、PseudoID、GUID 等常见的设备标识的获取方法。

Overview

Android_CN_OAID

Release APK Gradle Package

安卓设备唯一标识解决方案,可作为移动安全联盟统一 SDK (miit_mdid_xxx.aar)的替代方案。本项目提供了国内各大手机厂商获取 OAID(开放匿名设备标识)及海外手机平台获取 AAID (安卓广告标识)的便携接口,另外也提供了 IMEI/MEID、AndroidID、WidevineID、PseudoID、GUID 等常见的设备标识的获取方法。

  • GitHub:https://github.com/gzu-liyujiang/Android_CN_OAID
  • 码云(GitEE):https://gitee.com/li_yu_jiang/Android_CN_OAID

接入指引

最新版本:jitpack更新日志 | JavaDoc

依赖配置

allprojects {
    repositories {
        maven { url 'https://www.jitpack.io' }
    }
}

4.0.0 以前的版本 不建议再使用,请尽快升级到最新版本。4.0.0 版本以后重新调整了与移动安全联盟 SDK 共存的方案 ,直接使用如下依赖即可:

dependencies {
    implementation 'com.github.gzu-liyujiang:Android_CN_OAID:
   
    '
   
}

4.1.1 开始默认加入了 READ_PHONE_STATEWRITE_SETTINGSWRITE_EXTERNAL_STORAGE 权限以便适配低版本安卓系统。 为** 遵循最小必要原则**保护用户隐私,若项目中没用到 IMEI 及 GUID,那么可酌情在 AndroidManifest.xml 中加入如下代码移除相关权限:

">
<manifest>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" tools:node="remove" />
manifest>

注意事项

代码示例

获取多个可能的设备标识,结合服务端引入拜占庭容错方案得到可靠的稳定的设备唯一标识:

  • 第一步:
    // 在`Application#onCreate`里初始化,注意APP合规性,若最终用户未同意隐私政策则不要调用
    @Override
    public void onCreate() {
        super.onCreate();
        if (privacyPolicyAgreed) {
            DeviceIdentifier.register(this);
        }
    }
  • 第二步:
         // 获取IMEI,只支持Android 10之前的系统,需要READ_PHONE_STATE权限,可能为空
        DeviceIdentifier.getIMEI(this);
        // 获取安卓ID,可能为空
        DeviceIdentifier.getAndroidID(this);
        // 获取数字版权管理ID,可能为空
        DeviceIdentifier.getWidevineID();
        // 获取伪造ID,根据硬件信息生成,不会为空,有大概率会重复
        DeviceIdentifier.getPseudoID();
        // 获取GUID,随机生成,不会为空
        DeviceIdentifier.getGUID(this);
        // 是否支持OAID/AAID
        DeviceID.supportedOAID(this);
        // 获取OAID/AAID,同步调用
        DeviceIdentifier.getOAID(this);
        // 获取OAID/AAID,异步回调
        DeviceID.getOAID(this, new IGetter() {
            @Override
            public void onOAIDGetComplete(String result) {
                // 不同厂商的OAID/AAID格式是不一样的,可进行MD5、SHA1之类的哈希运算统一
            }

            @Override
            public void onOAIDGetError(Exception error) {
                // 获取OAID/AAID失败
            }
        });

混淆规则

本库自带consumer-rules.pro如下混淆规则,不混淆厂商的相关接口及类。若通过远程依赖的方式引用,则无需进行额外配置:

-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.** { *; }
-keep interface repeackage.com.bun.lib.** { *; }
-keep class repeackage.com.heytap.openid.** { *; }
-keep interface repeackage.com.heytap.openid.** { *; }
-keep class repeackage.com.samsung.android.deviceidservice.** { *; }
-keep interface repeackage.com.samsung.android.deviceidservice.** { *; }
-keep class repeackage.com.zui.deviceidservice.** { *; }
-keep interface repeackage.com.zui.deviceidservice.** { *; }
-keep class repeackage.com.coolpad.deviceidsupport.** { *; }
-keep interface repeackage.com.coolpad.deviceidsupport.** { *; }
-keep class repeackage.com.android.creator.** { *; }
-keep interface repeackage.com.android.creator.** { *; }

支持情况

厂商或品牌 系统或框架
华为(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+

注:本项目的 OAID 获取接口主要参考北京数字联盟公开的代码以及逆向分析参考移动安全联盟的 SDK、HUAWEI Ads SDK、小米 DeviceId.jar、Google Play Services SDK 等。

效果预览

OAID(开放匿名设备标识符)

  • 华为手机 huawei
  • 荣耀手机 hono
  • 小米手机 xiaomi
  • 红米手机 redmi
  • 黑鲨手机 blackshark
  • 维沃手机 vivo_iqoo
  • 欧珀手机 oppo
  • 真我手机 realm
  • 三星手机 samsung
  • 魅族手机 meizu
  • 联想手机 lenovo
  • 一加手机 oneplus
  • 华硕手机 asus
  • 努比亚机 待验证
  • 酷派手机 待验证
  • 酷赛手机 待验证
  • 卓易手机 待验证

AAID(安卓广告标识符)

  • 谷歌手机 google
  • 中兴手机 zte
  • 摩托罗拉 motorola
  • 索尼手机 sony
  • 诺基亚机 nokia
  • HTC 手机 htc
  • LG 手机 lge

不支持 OAID 或 AAID

  • 用户关闭了广告标识符

disabled

  • 以下厂商或品牌手机截止2021年8月26日已验证尚不支持:
锤子(Smartisan)、360(360)、奇酷(QiKu)、海信(Hisense)、金立(Gionee)、
美图(Meitu)、糖果(SOAP)、格力(Gree)、朵唯(Doov)、优思(Uniscope)、
夏普(SHARP)、乐视(LeTV)、维图(VOTO)、宏碁(Acer)、TCL(TCL)、……

参考资料

OAID 是移动智能终端补充设备标识体系中的一员,官方定义为 Open Anonymous Device Identifier(开放匿名设备标识符), 华为称之为 Open Advertising ID (开放广告标识符),谷歌称之为 Android Advertising ID (安卓广告标识符)。

远程真机

许可协议

Copyright (c) 2019-2021 gzu-liyujiang <[email protected]>

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.
Comments
  • 华硕ROG 2

    华硕ROG 2

    08-19 09:56:17.177 E/MtaSDK.CaughtExp(28712): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.asus.msa.action.ACCESS_DID cmp=com.asus.msa.SupplementaryDID/.SupplementaryDIDService } 08-19 09:56:17.177 E/MtaSDK.CaughtExp(28712): at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1677) 08-19 09:56:17.177 E/MtaSDK.CaughtExp(28712): at android.app.ContextImpl.bindService(ContextImpl.java:1612) 08-19 09:56:17.177 E/MtaSDK.CaughtExp(28712): at android.content.ContextWrapper.bindService(ContextWrapper.java:705) 08-19 09:56:17.177 E/MtaSDK.CaughtExp(28712): at com.github.gzuliyujiang.oaid.impl.AsusDeviceIdImpl.doGet(AsusDeviceIdImpl.java:62)

    opened by echo6106 12
  • 关于华为,荣耀手机获取不到oaid

    关于华为,荣耀手机获取不到oaid

    isSupport-->true----->oaid--->00000000-0000-0000-0000-000000000000 支持获取oaid 但是获取到oaid 都为0的字符串 最后查到是因为用户设置了“匿名识别标识”为关闭 有没有什么办法可以曲线救国保证拿到相关的oaid

    opened by zhangxiaojin770 5
  • Crash at android 5.1(oppoR9m), caused by java.lang.NoSuchMethodError

    Crash at android 5.1(oppoR9m), caused by java.lang.NoSuchMethodError

    01-07 01:29:19.758 10455-10455/com.tongcheng.transport.flavor.dazhou E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tongcheng.transport.flavor.dazhou, PID: 10455 java.lang.NoSuchMethodError: No virtual method getMeid()Ljava/lang/String; in class Landroid/telephony/TelephonyManager; or its super classes (declaration of 'android.telephony.TelephonyManager' appears in /system/framework/framework.jar) at com.github.gzuliyujiang.oaid.DeviceID.getIMEI(DeviceID.java:182) at com.github.gzuliyujiang.oaid.DeviceID.getUniqueID(DeviceID.java:171) at com.github.gzuliyujiang.oaid.DeviceID.register(DeviceID.java:65)

    // Related project code about this issue
    @NonNull
    @SuppressWarnings("deprecation")
    @SuppressLint({"HardwareIds", "MissingPermission"})
    private static String getIMEI(Context context) {
        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String imei = tm.getImei();
            if (TextUtils.isEmpty(imei)) {
                imei = tm.getMeid();
            }
            return imei;
        } catch (Exception e) {
            OAIDLog.print(e);
            return "";
        }
    }
    

    Should catch Throwable,for some crash caused by java.lang.Error instead for java.land.Exception,both of them extends java.lang.Throwable

    And It is also need to replace Exception with Throwable for other method in your project because of android device compatibility problem

    opened by jadepeakpoet 3
  • 不同手机具有相同的clientIdMd5

    不同手机具有相同的clientIdMd5

    目前统计重复的有两个(线上实际用户统计)

    相关文章(文章中包含了我所碰到的两种类型错误,除此之外还有空值,null的情形,"null"字符串) 设备ID又一坑【抛砖引玉】 https://zhuanlan.zhihu.com/p/63708748

    IMEI变成0了 http://www.oneplusbbs.com/thread-4331675-1.html

    1 9f89c84a559f573636a47ff8daed0d33 md5前的源数据为00000000-0000-0000-0000-000000000000 大量存在于华为/荣耀手机中,应该是华为手机的广告标识符(idfa),占比极高,大概能占据华为手机用户的1/5

    2 cd9e459ea708a948d5c2f5a6ca8838cf md5前的源数据为0,推测位imei

    占比较少,存在于少量魅族和个别华为手机中,网络上有一加手机,小米手机案例,根据网络信息推测大概率为用户刷机所致

    这部分特殊数据可能需要做下过滤

    opened by jadepeakpoet 2
  • 三星手机获取 OAID 失败

    三星手机获取 OAID 失败

    java.lang.NoSuchMethodError: No interface method getID()Ljava/lang/String; in class Lcom/samsung/android/deviceidservice/IDeviceIdService; or its super classes (declaration of 'com.samsung.android.deviceidservice.IDeviceIdService' appears in /data/app/~~4ngdABdmkys3tE5ryKg_Ew==/com.fenbi.android.zebraenglish-SrHAAnAcAXBQ_WqLx-Djqw==/base.apk!classes4.dex) at com.github.gzuliyujiang.oaid.impl.SamsungImpl$1.onServiceConnected(SamsungImpl.java:72) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2084) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2116) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8462) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

    依赖了官方的 SDK

    bug 
    opened by callmepeanut 2
  • HuaweiImpl调用崩溃

    HuaweiImpl调用崩溃

    日志如下

        java.lang.IllegalArgumentException: Service not registered: com.github.gzuliyujiang.oaid.impl.HuaweiImpl$1@f4ac590
            at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1832)
            at android.app.ContextImpl.unbindService(ContextImpl.java:1880)
            at com.github.gzuliyujiang.oaid.impl.HuaweiImpl$1.onServiceConnected(HuaweiImpl.java:76)
            at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2037)
            at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2069)
            at android.os.Handler.handleCallback(Handler.java:900)
            at android.os.Handler.dispatchMessage(Handler.java:103)
            at android.os.Looper.loop(Looper.java:219)
            at android.app.ActivityThread.main(ActivityThread.java:8349)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
    

    报错代码为HuaweiImpl -> doGet -> onServiceConnected ->

    finally {
        context.unbindService(this);
    }
    
    opened by dakun666 2
  • 关于依赖

    关于依赖

    需要兼容所有手机下面依赖都要导入吗

    // 如果项目中已经使用了移动安全联盟的包 mdid_xxx.aar ,则可能需要取消相关有冲突的依赖项 //implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_ASUS:版本号' //华硕 //implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_BUN:版本号' //中兴、卓易 implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_HEYTAP:版本号' //欧珀、一加 //implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_SAMSUNG:版本号' //三星 implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_UODIS:版本号' //华为 implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_ZUI:版本号' //联想、摩托罗拉 implementation 'com.github.gzu-liyujiang.Android_CN_OAID:OAID_IMPL:版本号' //具体实现

    opened by zhudaihao 2
  • WidevineID唯一性

    WidevineID唯一性

        官方建议是WidevineID
       https://developer.android.com/training/articles/user-data-ids
       
       https://stackoverflow.com/questions/67396257
       从这个提问来看,唯一性可能有点问题
    
    • IMEI:Android 10+ 获取不到了;
    • AAID:系统需自带 Google Play Services 才支持,且用户可以在系统设置中重置;
    • OAID:基本上是国内知名厂商 Android 10+ 才支持,且用户可以在系统设置中重置;
    • AndroidID:可能为空;
    • PseudoID:可能重复;
    • GUID:Android 10+ 卸载APP后会丢失;
    • WidevineID:未经过验证,不知道可靠性如何;

    最好是通过服务端从以上标识中通过拜占庭容错方案得到可靠的设备唯一标识。不能使用服务端的话,综合来看 AndroidID 和 OAID 相对可靠一些吧,项目中我已经提供了一个getClientId/getClientIdMd5/getClientIdSha1获取客户端唯一标识,依次获取IMEI、AndroidID、OAID、WidevineID、GUID……

    Originally posted by @liyujiang-gzu in https://github.com/gzu-liyujiang/Android_CN_OAID/issues/28#issuecomment-858218231

    opened by fioogle 1
  • 这个混淆规则好像有问题,Google服务手机上获取OAID崩溃了

    这个混淆规则好像有问题,Google服务手机上获取OAID崩溃了

    这边发现混淆规则里面少了对Google的混淆,麻烦看一下,我这边手动新增了两个混淆: -keep class repeackage.com.google.android.gms.ads.identifier.internal.** { ; } -keep interface repeackage.com.google.android.gms.ads.identifier.internal.* { *; }

    opened by mrduank 1
  • 关于尝试移动安全联盟的接口去获取的判断问题

    关于尝试移动安全联盟的接口去获取的判断问题

    class MsaImpl implements IOAID { private final Context context;

    public MsaImpl(Context context) {
        this.context = context;
    }
    
    @Override
    public boolean supported() {
        if (context == null) {
            return false;
        }
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo("com.mdid.msa", 0);
            return pi != null;
        } catch (Exception e) {
            OAIDLog.print(e);
            return false;
        }
    }
    

    这里为何是判断是否存在包"com.mdid.msa",我往demo加了个oaid_1.0.25版本,试了几部手机都是返回不支持。

    opened by vivian688 15
Releases(4.2.4)
Owner
贵州山魈羡民
穿青人是不在中国56个民族之内的民族,被官方定性为“待定族称人口”。主要分布在贵州西北地区,人口将近百万,信仰五显,崇拜山魈,自称山魈人马。据道光《大定府志》记载,今穿青人在大清帝国时期称为“羡民”,与汉民、苗民、夷民并列。在民国时期及建国初,穿青人基本上统称“青族”,第一代身份证上记为青族,第二代身份证记为穿青人。
贵州山魈羡民
A simple Android app to demonstrate the use of Hover SDK for M-PESA Send Money while offline. This SDK does not require an internet connection, it automates USSD sessions in the background of an android application.

HoverSDKDemo Hover SDK is an Android SDK that lets mobile developers to add money features to the applications. This SDK does not require an internet

Joel Kanyi 9 Dec 21, 2022
StudyLive是anyRTC开发的示例项目,演示了如何通过anyRTC云服务,配合anyRTC RTC SDK、anyRTC RTM SDK、anyRTC播放插件,实现在线自习室的场景。

StudyLive 项目概述 StudyLive是anyRTC开发的示例项目,演示了如何通过anyRTC云服务,配合anyRTC RTC SDK、anyRTC RTM SDK,实现在线自习室的场景。 平台兼容 iOS 9 及以上。 Android 4.4 及以上 效果展示 上麦用户调用图 主持人的使

anyrtcIO 11 Oct 19, 2022
Sdk-android - SnapOdds Android SDK

Documentation For the full API documentation go to https://snapodds.github.io/sd

Snapodds 0 Jan 30, 2022
Unity-Android-SDK-Plugins - Android SDK/Library/Plugins (aar) for Unity Developers

Unity Android SDK Plugins Unity Android SDK Plugins is an Open Source project th

NNK 1 Aug 14, 2022
Segmenkt - The SegmenKT Kotlin SDK is a Kotlin-first SDK for Segment

SegmenKT Kotlin SDK The SegmenKT Kotlin SDK is a Kotlin-first SDK for Segment. I

UNiDAYS 0 Nov 25, 2022
Frogo SDK - SDK Core for Easy Development

SDK for anything your problem to make easier developing android apps

Frogobox 10 Dec 15, 2022
HubSpot Kotlin SDK 🧺 Implementation of HubSpot API for Java/Kotlin in tiny SDK

HubSpot Kotlin SDK ?? Implementation of HubSpot API for Java/Kotlin in tiny SDK

BOOM 3 Oct 27, 2022
Example application using Bugfender SDK in Android

Bugfender Android SDK SDK Installation Here are the main points to getting Bugfender working on your apps: Get an app key at bugfender.com Add Bugfend

Bugfender 37 Dec 7, 2022
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Applozic 659 May 14, 2022
Kommunicate.io Android Chat SDK for Customer Support

Kommunicate Android Chat SDK for Customer Support An Open Source Android Live Chat SDK for Customer Support Overview Kommunicate provides open source

Kommunicate 68 Jan 3, 2023
Configurable consent SDK for Android

Consent SDK for Android Obtaining explicit user consent regarding the gathering analytics data in an app, or with processing user’s personal data is a

Smartlook 81 Nov 11, 2022
Webtrekk Android SDK V5

Webtrekk Android SDK v5 Site | Docs | Support Webtrekk Android SDK is used to integrate Webtrekk tracking systems with your Android apps. Collect mean

Webtrekk GmbH 13 Apr 26, 2022
HorizontalListView is an Android ListView widget which scrolls in a horizontal manner (in contrast with the SDK-provided ListView which scrolls vertically).

HorizontalListView HorizontalListView is an Android ListView widget which scrolls in a horizontal manner (in contrast with the SDK-provided ListView w

MeetMe 722 Nov 10, 2022
Maps SDK for Android Utility Library

Maps SDK for Android Utility Library Description This open-source library contains utilities that are useful for a wide range of applications using th

Google Maps 3.4k Dec 30, 2022
andle is an Android tool help you sync dependencies, sdk or build tool version.

andle andle is an Android tool to help you sync dependencies, SDK or build tool version. Installation Simple install by pip: $ sudo pip install andle

Jintin 58 Sep 17, 2022
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

Jake Wharton 1.4k Dec 29, 2022
AWS SDK for Android. For more information, see our web site:

AWS SDK for Android For new projects, we recommend interacting with AWS using the Amplify Framework. The AWS SDK for Android is a collection of low-le

AWS Amplify 976 Dec 29, 2022
Countly Product Analytics Android SDK

Countly Android SDK We're hiring: Countly is looking for Android SDK developers, full stack devs, devops and growth hackers (remote work). Click this

Countly Team 648 Dec 23, 2022
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Applozic 659 May 14, 2022