From e8fd3292b1632b95d667a3a5d49ead767d8e3f9a Mon Sep 17 00:00:00 2001 From: andot Date: Thu, 8 Apr 2021 14:56:21 +0800 Subject: [PATCH 1/2] Remove getDefaultUDID --- .../com/github/gzuliyujiang/oaid/impl/XiaomiImpl.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/impl/XiaomiImpl.java b/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/impl/XiaomiImpl.java index aeaabc4..0104a41 100644 --- a/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/impl/XiaomiImpl.java +++ b/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/impl/XiaomiImpl.java @@ -55,16 +55,6 @@ public void doGet(@NonNull final IGetter getter) { getter.onOAIDGetError(new NullPointerException("Xiaomi IdProvider not exists")); return; } - try { - Method udidMethod = idProvider.getMethod("getDefaultUDID", Context.class); - String did = invokeMethod(udidMethod); - if (did != null && did.length() > 0) { - getter.onOAIDGetComplete(did); - return; - } - } catch (Throwable e) { - OAIDLog.print(e); - } try { Method oaidMethod = idProvider.getMethod("getOAID", Context.class); String did = invokeMethod(oaidMethod); From b358decd0837343770c87cf40041111efc7984de Mon Sep 17 00:00:00 2001 From: andot Date: Thu, 8 Apr 2021 15:10:37 +0800 Subject: [PATCH 2/2] Add supported method. --- .../github/gzuliyujiang/oaid/DeviceID.java | 84 ++++++++++++------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/DeviceID.java b/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/DeviceID.java index 0790a97..5294866 100644 --- a/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/DeviceID.java +++ b/OAID_IMPL/src/main/java/com/github/gzuliyujiang/oaid/DeviceID.java @@ -52,6 +52,7 @@ */ public final class DeviceID { private static String clientId; + private static IOAID oaid; private DeviceID() { super(); @@ -109,6 +110,40 @@ public static String getClientIdSHA1() { return clientId == null ? "" : calculateHash(clientId, "SHA-1"); } + private static IOAID getIOAID(@NonNull Context context) { + if (OAIDRom.isLenovo() || OAIDRom.isMotolora()) { + return new LenovoImpl(context); + } + if (OAIDRom.isMeizu()) { + return new MeizuImpl(context); + } + if (OAIDRom.isNubia()) { + return new NubiaImpl(context); + } + if (OAIDRom.isXiaomi() || OAIDRom.isBlackShark()) { + return new XiaomiImpl(context); + } + if (OAIDRom.isSamsung()) { + return new SamsungImpl(context); + } + if (OAIDRom.isVivo()) { + return new VivoImpl(context); + } + if (OAIDRom.isASUS()) { + return new AsusImpl(context); + } + if (OAIDRom.isHuawei()) { + return new HuaweiImpl(context); + } + if (OAIDRom.isOppo() || OAIDRom.isOnePlus()) { + return new OppoImpl(context); + } + if (OAIDRom.isZTE() || OAIDRom.isFreeme() || OAIDRom.isSSUI()) { + return new MsaImpl(context); + } + return new DefaultImpl(); + } + /** * 异步获取OAID * @@ -116,33 +151,24 @@ public static String getClientIdSHA1() { * @param getter 回调 */ public static void getOAID(@NonNull Context context, @NonNull IGetter getter) { - IOAID oaid; - if (OAIDRom.isLenovo() || OAIDRom.isMotolora()) { - oaid = new LenovoImpl(context); - } else if (OAIDRom.isMeizu()) { - oaid = new MeizuImpl(context); - } else if (OAIDRom.isNubia()) { - oaid = new NubiaImpl(context); - } else if (OAIDRom.isXiaomi() || OAIDRom.isBlackShark()) { - oaid = new XiaomiImpl(context); - } else if (OAIDRom.isSamsung()) { - oaid = new SamsungImpl(context); - } else if (OAIDRom.isVivo()) { - oaid = new VivoImpl(context); - } else if (OAIDRom.isASUS()) { - oaid = new AsusImpl(context); - } else if (OAIDRom.isHuawei()) { - oaid = new HuaweiImpl(context); - } else if (OAIDRom.isOppo() || OAIDRom.isOnePlus()) { - oaid = new OppoImpl(context); - } else if (OAIDRom.isZTE() || OAIDRom.isFreeme() || OAIDRom.isSSUI()) { - oaid = new MsaImpl(context); - } else { - oaid = new DefaultImpl(); + if (oaid == null) { + oaid = getIOAID(context); } oaid.doGet(getter); } + /** + * 判断是否支持OAID + * + * @param context 上下文 + */ + public static boolean supported(@NonNull Context context) { + if (oaid == null) { + oaid = getIOAID(context); + } + return oaid.supported(); + } + /** * 获取唯一设备标识 * @@ -157,9 +183,9 @@ public static String getUniqueID(@NonNull Context context) { // Android 10+ 不允许获取 IMEI、MEID 之类的设备唯一标识 return ""; } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - context.checkPermission(Manifest.permission.READ_PHONE_STATE, Process.myPid(), - Process.myUid()) != PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && context.checkPermission(Manifest.permission.READ_PHONE_STATE, Process.myPid(), + Process.myUid()) != PackageManager.PERMISSION_GRANTED) { // Android 6-9 需要申请电话权限才能获取设备唯一标识 return ""; } @@ -209,7 +235,7 @@ public static String getPseudoID() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sb.append(Arrays.deepToString(Build.SUPPORTED_ABIS).length() % 10); } else { - //noinspection deprecation + // noinspection deprecation sb.append(Build.CPU_ABI.length() % 10); } sb.append(Build.DEVICE.length() % 10); @@ -245,8 +271,8 @@ public static String getGUID(@NonNull Context context) { } /** - * 计算哈希值,算法可以是MD2、MD5、SHA-1、SHA-224、SHA-256、SHA-512等。 - * 支持的算法见 https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest + * 计算哈希值,算法可以是MD2、MD5、SHA-1、SHA-224、SHA-256、SHA-512等。 支持的算法见 + * https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest */ public static String calculateHash(String str, String algorithm) { try {