Quellcode durchsuchen

更新Oaid获取方式

zhipeng vor 2 Jahren
Ursprung
Commit
b6616bf19f

+ 8 - 1
common/build.gradle

@@ -25,9 +25,16 @@ android {
     }
 }
 
+configurations.all {
+    resolutionStrategy {
+        // don't cache changing modules at all
+        cacheChangingModulesFor 10, 'seconds'
+    }
+}
+
 dependencies {
     compileOnly 'androidx.annotation:annotation:+'
-    compileOnly "extension.oaid:oaid:1.0.23"
+    compileOnly "extra.common:oaid:1.0.0-SNAPSHOT"
     compileOnly 'com.google.android.gms:play-services-ads-identifier:+'
     compileOnly "com.tencent:mmkv:+"
 }

+ 2 - 2
common/config.gradle

@@ -1,4 +1,4 @@
 ext {
-    atmob_common_version_code = 201
-    atmob_common_version_name = "2.0.2-SNAPSHOT"
+    atmob_common_version_code = 202
+    atmob_common_version_name = "2.0.3-SNAPSHOT"
 }

+ 26 - 0
common/src/main/java/com/atmob/common/AtmobCommon.java

@@ -1,19 +1,45 @@
 package com.atmob.common;
 
 import android.app.Application;
+import android.content.Context;
 
 import com.atmob.common.logging.AtmobLog;
 import com.atmob.common.runtime.ActivityUtil;
 import com.atmob.common.runtime.ContextUtil;
+import com.atmob.oaid.OaidHelper;
 
 public class AtmobCommon {
+
+    private static final String TAG = "AtmobCommon";
+    private static boolean logEnable;
+
     private AtmobCommon() {
 
     }
 
     public static void init(Application application, boolean logEnable) {
+        AtmobCommon.logEnable = logEnable;
         AtmobLog.logEnable(logEnable);
         ContextUtil.init(application);
         ActivityUtil.init(application);
     }
+
+    public static void initAfterGrantedAgreement(Application application) {
+        initOaidHelper(application, logEnable);
+    }
+
+    private static void initOaidHelper(Application application, boolean logEnable) {
+        OaidHelper.init(application, logEnable);
+
+        try {
+            Class<?> oaidHelperClass = Class.forName("com.atmob.oaid.OaidHelper");
+            oaidHelperClass.getMethod("init", Context.class, boolean.class).invoke(null, application, logEnable);
+            Object versionCodeObj = oaidHelperClass.getMethod("getOaidVersionCode").invoke(null);
+            int versionCode = (int) (versionCodeObj == null ? -1 : versionCodeObj);
+
+            AtmobLog.d(TAG, "init OaidHelper, oaid versionCode: " + versionCode);
+        } catch (Exception ignore) {
+            AtmobLog.e(TAG, "init OaidHelper failed, if use oaid, please check oaid module is added and proguard config is correct.");
+        }
+    }
 }

+ 5 - 25
common/src/main/java/com/atmob/common/device/DeviceInfoUtil.java

@@ -15,7 +15,6 @@ import com.atmob.common.permission.PermissionUtil;
 import com.atmob.common.thread.ThreadPoolUtil;
 
 import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.util.HashMap;
 
 public class DeviceInfoUtil {
@@ -52,7 +51,7 @@ public class DeviceInfoUtil {
 
     @SuppressLint("HardwareIds")
     public static String getImei() {
-        if (!TextUtils.isEmpty(imei)) {
+        if (!TextUtils.isEmpty(imei) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
             return imei;
         }
         Context context = getContext();
@@ -76,7 +75,7 @@ public class DeviceInfoUtil {
     @SuppressLint("HardwareIds")
     public static String getSimImei(int slotIdx) {
         String imei = imeiCache.get(slotIdx);
-        if (!TextUtils.isEmpty(imei)) {
+        if (!TextUtils.isEmpty(imei) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
             return imei;
         }
         String imeiCache = KVUtils.getDefault().getString(Constants.KEY_IMEI_CACHE + slotIdx, null);
@@ -169,28 +168,9 @@ public class DeviceInfoUtil {
         }
         Context context = getContext();
         try {
-            Class<?> mdidSdkHelper = Class.forName("com.bun.miitmdid.core.MdidSdkHelper");
-            Class<?> iIdentifierListener = Class.forName("com.bun.miitmdid.interfaces.IIdentifierListener");
-            Method initSdk = mdidSdkHelper.getMethod("InitSdk", Context.class, boolean.class, iIdentifierListener);
-            Object identifierListener = Proxy.newProxyInstance(mdidSdkHelper.getClassLoader(), new Class[]{iIdentifierListener}, (proxy, method, args) -> {
-                if ("OnSupport".equals(method.getName())) {
-                    if (args.length == 2) {
-                        Object idSupplierObj = args[1];
-                        if (idSupplierObj != null) {
-                            Class<?> idSupplier = Class.forName("com.bun.miitmdid.interfaces.IdSupplier");
-                            Method isSupported = idSupplier.getMethod("isSupported");
-                            boolean isSupportedResult = (boolean) isSupported.invoke(idSupplierObj);
-                            if (isSupportedResult) {
-                                Method getOAID = idSupplier.getMethod("getOAID");
-                                oaid = (String) getOAID.invoke(idSupplierObj);
-                                KVUtils.getDefault().putString(Constants.KEY_OAID_CACHE, oaid);
-                            }
-                        }
-                    }
-                }
-                return null;
-            });
-            initSdk.invoke(null, context, true, identifierListener);
+            Class<?> oaidHelperClass = Class.forName("com.atmob.oaid.OaidHelper");
+            Method getOaid = oaidHelperClass.getMethod("getOaid", Context.class);
+            oaid = (String) getOaid.invoke(null, context);
         } catch (Exception e) {
             oaidEnable = false;
         }

+ 25 - 0
user/src/main/java/com/atmob/user/strategy/ChinaStrategy.java

@@ -3,6 +3,7 @@ package com.atmob.user.strategy;
 import com.atmob.common.device.DeviceInfoUtil;
 import com.atmob.common.device.IPUtil;
 import com.atmob.common.device.MacUtils;
+import com.atmob.user.AtmobUser;
 import com.atmob.user.sm.SmAntiFraudHelper;
 
 final class ChinaStrategy implements ComplianceStrategy {
@@ -26,11 +27,17 @@ final class ChinaStrategy implements ComplianceStrategy {
 
     @Override
     public String getMacCode() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return MacUtils.getMac();
     }
 
     @Override
     public String getWifiName() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return IPUtil.getWifiName();
     }
 
@@ -41,31 +48,49 @@ final class ChinaStrategy implements ComplianceStrategy {
 
     @Override
     public String getIPAddress() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return IPUtil.getIpV4();
     }
 
     @Override
     public String getAndroidId() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return DeviceInfoUtil.getAndroidId();
     }
 
     @Override
     public String getOaId() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return DeviceInfoUtil.getOaid();
     }
 
     @Override
     public String getImei() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return DeviceInfoUtil.getImei();
     }
 
     @Override
     public String getImei(int slotIndex) {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return DeviceInfoUtil.getSimImei(slotIndex);
     }
 
     @Override
     public String getSmDeviceId() {
+        if (!AtmobUser.isPolicyGranted()) {
+            return null;
+        }
         return SmAntiFraudHelper.getSmDeviceId();
     }