From 0239fb720f75cb14b8a184d0769177a89d264b0a Mon Sep 17 00:00:00 2001 From: sarahzzhang Date: Thu, 21 Mar 2024 16:35:10 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B7=B7=E6=B7=86=E5=B8=A6=E6=9D=A5=E7=9A=84=E4=B8=8E=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=BA=93=E7=B1=BB=E5=90=8D=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9c04f04..c232916 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ android { release { minifyEnabled true buildConfigField("String", "VERSION_NAME", "\"${project.subVersionName}a\"") - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } From 3fbfb965279af3c3f65dc5fc834fdb5622fce54d Mon Sep 17 00:00:00 2001 From: sarahzzhang Date: Fri, 29 Mar 2024 17:35:44 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Datta=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8A=E6=8A=A5=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9ArespCode=E5=90=8C=E6=AD=A5=E6=9C=89=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E5=BF=85=E8=A6=81=E6=80=A7=EF=BC=8C=E5=90=A6=E5=88=99?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5disconnect=E6=96=AD=E8=81=94=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=95=B0=E6=8D=AE=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tencent/msdk/dns/report/AttaHelper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java index 2ac8af1..ee40314 100644 --- a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java +++ b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java @@ -50,7 +50,7 @@ public static Runnable report(final String carrier, public void run() { HttpURLConnection connection = null; try { - URL url = new URL(ATTA_URL + String path = ATTA_URL + "?attaid=" + ATTA_ID + "&token=" + ATTA_TOKEN + "&carrier=" + carrier @@ -80,8 +80,9 @@ public void run() { + "&count=" + count + "&ldns=" + ldns + "&hdns=" + hdns - + "&_dc=" + Math.random() - ); + + "&_dc=" + Math.random(); + path = path.replace(" ","_"); + URL url = new URL(path); DnsLog.d("开始Atta上报:" + url); connection = (HttpURLConnection) url.openConnection(); //设置请求方法 @@ -91,6 +92,8 @@ public void run() { //设置读取超时时间(毫秒) connection.setReadTimeout(2000); connection.connect(); + int respCode = connection.getResponseCode(); + DnsLog.d("Atta respCode:" + respCode); } catch (IOException e) { e.printStackTrace(); } finally { From 2d90a9dc9218d6e2b011f54043d10c541ce28290 Mon Sep 17 00:00:00 2001 From: sarahzzhang Date: Mon, 1 Apr 2024 10:22:01 +0800 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20=E8=B4=A8=E9=87=8F=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tencent/msdk/dns/report/AttaHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java index ee40314..2278be6 100644 --- a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java +++ b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java @@ -81,7 +81,7 @@ public void run() { + "&ldns=" + ldns + "&hdns=" + hdns + "&_dc=" + Math.random(); - path = path.replace(" ","_"); + path = path.replace(" ", "_"); URL url = new URL(path); DnsLog.d("开始Atta上报:" + url); connection = (HttpURLConnection) url.openConnection(); From 05632d4382412c0d3cf8e7d1a1ea2ab256ba8dfd Mon Sep 17 00:00:00 2001 From: sarahzzhang Date: Tue, 16 Apr 2024 20:08:11 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20SDK=E9=9B=86=E6=88=90=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E5=BC=8FBugly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../java/com/tencent/msdk/dns/DnsConfig.java | 21 ++++++++++++-- .../java/com/tencent/msdk/dns/DnsService.java | 11 ++++--- .../msdk/dns/base/bugly/SharedBugly.java | 29 +++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java diff --git a/build.gradle b/build.gradle index c232916..c584fa9 100644 --- a/build.gradle +++ b/build.gradle @@ -32,11 +32,13 @@ android { debug { minifyEnabled false buildConfigField("String", "VERSION_NAME", "\"${project.subVersionName}a\"") + buildConfigField("String", "BUGLY_ID", BUGLY_ID) } release { minifyEnabled true buildConfigField("String", "VERSION_NAME", "\"${project.subVersionName}a\"") + buildConfigField("String", "BUGLY_ID", BUGLY_ID) proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/src/main/java/com/tencent/msdk/dns/DnsConfig.java b/src/main/java/com/tencent/msdk/dns/DnsConfig.java index a3e9135..bdac595 100644 --- a/src/main/java/com/tencent/msdk/dns/DnsConfig.java +++ b/src/main/java/com/tencent/msdk/dns/DnsConfig.java @@ -62,13 +62,16 @@ public final class DnsConfig { public String routeIp; + public boolean experimentalBuglyEnable; + private DnsConfig(int logLevel, String appId, String userId, boolean initBuiltInReporters, String dnsId, String dnsKey, String token, int timeoutMills, Set protectedDomains, Set preLookupDomains, boolean enablePersistentCache, Set persistentCacheDomains, Set ipRankItems, String channel, boolean enableReport, boolean blockFirst, int customNetStack, DnsExecutors.ExecutorSupplier executorSupplier, ILookedUpListener lookedUpListener, List logNodes, List reporters, - boolean useExpiredIpEnable, boolean cachedIpEnable, String routeIp) { + boolean useExpiredIpEnable, boolean cachedIpEnable, String routeIp, + Boolean experimentalBuglyEnable) { this.logLevel = logLevel; this.appId = appId; this.userId = userId; @@ -91,6 +94,7 @@ private DnsConfig(int logLevel, String appId, String userId, boolean initBuiltIn this.useExpiredIpEnable = useExpiredIpEnable; this.cachedIpEnable = cachedIpEnable; this.routeIp = routeIp; + this.experimentalBuglyEnable = experimentalBuglyEnable; } boolean needProtect(/* @Nullable */String hostname) { @@ -134,6 +138,7 @@ public String toString() { + ", cachedIpEnable=" + cachedIpEnable + ", enableDomainServer=" + enableDomainServer + ", routeIp=" + routeIp + + ", experimentalBuglyEnable=" + experimentalBuglyEnable + '}'; } @@ -223,6 +228,7 @@ public static final class Builder { private boolean mUseExpiredIpEnable = false; private boolean mCachedIpEnable = false; private String mRouteIp = ""; + private boolean mExperimentalBuglyEnable = false; /** * 设置最低日志等级, 低于设置等级的日志不会输出 @@ -727,6 +733,17 @@ public Builder routeIp(String routeIp) { return this; } + /** + * 实验性参数,仅提供给内部特定团队使用,请勿随意启用。 + * + * @param buglyEnable + * @return + */ + public Builder setExperimentalBuglyEnable(Boolean buglyEnable) { + mExperimentalBuglyEnable = buglyEnable; + return this; + } + /** * 构建DnsConfig实例 * @@ -746,7 +763,7 @@ public DnsConfig build() { mTimeoutMills, mProtectedDomains, mPreLookupDomains, mEnablePersistentCache, mPersistentCacheDomains, mIpRankItems, mChannel, mEnableReport, mBlockFirst, mCustomNetStack, mExecutorSupplier, mLookedUpListener, mLogNodes, mReporters, mUseExpiredIpEnable, mCachedIpEnable, - mRouteIp); + mRouteIp, mExperimentalBuglyEnable); } } } diff --git a/src/main/java/com/tencent/msdk/dns/DnsService.java b/src/main/java/com/tencent/msdk/dns/DnsService.java index beb329a..f9355f7 100644 --- a/src/main/java/com/tencent/msdk/dns/DnsService.java +++ b/src/main/java/com/tencent/msdk/dns/DnsService.java @@ -3,6 +3,7 @@ import android.content.Context; import android.text.TextUtils; +import com.tencent.msdk.dns.base.bugly.SharedBugly; import com.tencent.msdk.dns.base.executor.DnsExecutors; import com.tencent.msdk.dns.base.lifecycle.ActivityLifecycleDetector; import com.tencent.msdk.dns.base.log.DnsLog; @@ -62,7 +63,7 @@ public static Context getAppContext() { * @throws IllegalArgumentException context为null时抛出 */ public static void init(Context context, /* @Nullable */DnsConfig config) { - try { + try { // NOTE: 参数检查不封装为通用方法, 是为了避免不必要的concat执行 if (null == context) { throw new IllegalArgumentException("context".concat(Const.NULL_POINTER_TIPS)); @@ -77,6 +78,8 @@ public static void init(Context context, /* @Nullable */DnsConfig config) { Context appContext = context.getApplicationContext(); sAppContext = appContext; sConfig = config; + // 集成共享式bugly + SharedBugly.init(appContext); // 底层配置获取 DnsExecutors.WORK.execute(new Runnable() { @Override @@ -106,9 +109,9 @@ public void run() { sInited = true; preLookupAndStartAsyncLookup(); - } catch (Exception e) { - DnsLog.w("DnsService.init failed: %s", e); - } + } catch (Exception e) { + DnsLog.w("DnsService.init failed: %s", e); + } } /** diff --git a/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java b/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java new file mode 100644 index 0000000..3a50bbe --- /dev/null +++ b/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java @@ -0,0 +1,29 @@ +package com.tencent.msdk.dns.base.bugly; + +import android.content.Context; +import android.content.SharedPreferences; + +import com.tencent.msdk.dns.BuildConfig; +import com.tencent.msdk.dns.DnsService; +import com.tencent.msdk.dns.base.log.DnsLog; + +public class SharedBugly { + private static String appId = BuildConfig.BUGLY_ID; + private static String appVersion = BuildConfig.VERSION_NAME; + + public static void init(Context context) { + try { + if (DnsService.getDnsConfig().experimentalBuglyEnable) { + SharedPreferences settings = context.getSharedPreferences("BuglySdkInfos", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = settings.edit(); + editor.putString(appId, appVersion);//必填信息 + editor.commit(); + DnsLog.d("shared bugly inited success"); + } else { + + } + } catch (Exception e) { + DnsLog.d("shared bugly inited error " + e); + } + } +} From 50cad7d0c69fcf7584a781f8982969a2af7f8c99 Mon Sep 17 00:00:00 2001 From: sarahzzhang Date: Wed, 17 Apr 2024 17:11:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E5=85=B3=E9=97=AD=E6=97=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BC=93=E5=AD=98=E9=97=AE=E9=A2=98=EF=BC=8C=E5=BD=BB?= =?UTF-8?q?=E5=BA=95=E5=85=B3=E6=8E=89=E5=85=B1=E4=BA=AB=E5=BC=8FBugly?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/msdk/dns/base/bugly/SharedBugly.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java b/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java index 3a50bbe..eb403ce 100644 --- a/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java +++ b/src/main/java/com/tencent/msdk/dns/base/bugly/SharedBugly.java @@ -14,13 +14,19 @@ public class SharedBugly { public static void init(Context context) { try { if (DnsService.getDnsConfig().experimentalBuglyEnable) { - SharedPreferences settings = context.getSharedPreferences("BuglySdkInfos", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = settings.edit(); - editor.putString(appId, appVersion);//必填信息 + SharedPreferences sharedPreferences = context.getSharedPreferences("BuglySdkInfos", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(appId, appVersion); //必填信息 editor.commit(); DnsLog.d("shared bugly inited success"); } else { - + SharedPreferences sharedPreferences = context.getSharedPreferences("BuglySdkInfos", + Context.MODE_PRIVATE); + if (sharedPreferences.contains(appId)) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.remove(appId); + editor.apply(); + } } } catch (Exception e) { DnsLog.d("shared bugly inited error " + e); From 404dbfd0675ab28193dc5e81ad52da8ad9197dea Mon Sep 17 00:00:00 2001 From: lemondark <743855454@qq.com> Date: Sun, 28 Apr 2024 17:33:45 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=E5=90=88=E8=A7=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E2=80=94=E2=80=94=E8=A7=A3=E6=9E=90=E8=A7=A3=E6=8E=A7=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=8E=A7=E5=88=B6=E6=89=8B=E6=9C=BA=E8=BF=90=E8=90=A5?= =?UTF-8?q?=E5=95=86=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96(=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E6=96=B0=E9=97=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/msdk/dns/report/AttaHelper.java | 6 ++++-- .../com/tencent/msdk/dns/report/ReportHelper.java | 15 +++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java index 2278be6..b4e060b 100644 --- a/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java +++ b/src/main/java/com/tencent/msdk/dns/report/AttaHelper.java @@ -4,6 +4,7 @@ import android.telephony.TelephonyManager; import com.tencent.msdk.dns.BuildConfig; +import com.tencent.msdk.dns.DnsService; import com.tencent.msdk.dns.base.log.DnsLog; import java.io.IOException; @@ -25,8 +26,7 @@ public class AttaHelper { private static final String SYSTEMVERSION = getSystemVersion(); private static final String SESSIONID = Session.getSessionId(); - public static Runnable report(final String carrier, - final String networkType, + public static Runnable report(final String networkType, final String dnsId, final String appId, final String encryptType, @@ -50,6 +50,8 @@ public static Runnable report(final String carrier, public void run() { HttpURLConnection connection = null; try { + // 获取手机卡运营商code + String carrier = getSimOperator(DnsService.getAppContext()); String path = ATTA_URL + "?attaid=" + ATTA_ID + "&token=" + ATTA_TOKEN diff --git a/src/main/java/com/tencent/msdk/dns/report/ReportHelper.java b/src/main/java/com/tencent/msdk/dns/report/ReportHelper.java index e3bc2ef..8b20f1a 100644 --- a/src/main/java/com/tencent/msdk/dns/report/ReportHelper.java +++ b/src/main/java/com/tencent/msdk/dns/report/ReportHelper.java @@ -7,7 +7,6 @@ import com.tencent.msdk.dns.BackupResolver; import com.tencent.msdk.dns.BuildConfig; import com.tencent.msdk.dns.DnsConfig; -import com.tencent.msdk.dns.DnsService; import com.tencent.msdk.dns.base.compat.CollectionCompat; import com.tencent.msdk.dns.base.lifecycle.ActivityLifecycleCallbacksWrapper; import com.tencent.msdk.dns.base.lifecycle.ActivityLifecycleDetector; @@ -187,8 +186,6 @@ private static void attaReportLookupEvent(String eventName, LookupResult lookupR StatisticsMerge statMerge = (StatisticsMerge) lookupResult.stat; BackupResolver backupInfo = BackupResolver.getInstance(); - // 获取手机卡运营商code - String carrierCode = AttaHelper.getSimOperator(DnsService.getAppContext()); // 获取当前dnsip String dnsIp = backupInfo.getDnsIp(); String reqType = AttaHelper.getReqType(statMerge.curNetStack); @@ -198,7 +195,7 @@ private static void attaReportLookupEvent(String eventName, LookupResult lookupR if (statMerge.restDnsStat.errorCode == 0) { // 请求成功后将ErrorCount置为0 backupInfo.setErrorCount(0); - MAIN.execute(AttaHelper.report(carrierCode, statMerge.netType, sDnsConfig.lookupExtra.bizId, + MAIN.execute(AttaHelper.report(statMerge.netType, sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, sDnsConfig.channel, eventName, System.currentTimeMillis(), dnsIp, statMerge.restDnsStat.costTimeMills, statMerge.localDnsStat.costTimeMills, statMerge.requestHostname, reqType, sDnsConfig.timeoutMills, statMerge.restDnsStat.ttl, @@ -212,7 +209,7 @@ private static void attaReportLookupEvent(String eventName, LookupResult lookupR || (Const.HTTPS_CHANNEL.equals(sDnsConfig.channel) && (statMerge.restDnsStat.errorCode == 1))) { // 解析失败,仅当达到最大失败次数满足切换IP时候上报 if (backupInfo.getCanReport(backupInfo.getErrorCount() + 1)) { - MAIN.execute(AttaHelper.report(carrierCode, statMerge.netType, sDnsConfig.lookupExtra.bizId, + MAIN.execute(AttaHelper.report(statMerge.netType, sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, sDnsConfig.channel, eventName, System.currentTimeMillis(), dnsIp, statMerge.restDnsStat.costTimeMills, statMerge.localDnsStat.costTimeMills, statMerge.requestHostname, reqType, sDnsConfig.timeoutMills, @@ -225,7 +222,7 @@ private static void attaReportLookupEvent(String eventName, LookupResult lookupR backupInfo.incrementErrorCount(); DnsLog.d("dnsip连接失败, 当前失败次数:" + backupInfo.getErrorCount()); } else { - MAIN.execute(AttaHelper.report(carrierCode, statMerge.netType, sDnsConfig.lookupExtra.bizId, + MAIN.execute(AttaHelper.report(statMerge.netType, sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, sDnsConfig.channel, eventName, System.currentTimeMillis(), dnsIp, statMerge.restDnsStat.costTimeMills, statMerge.localDnsStat.costTimeMills, statMerge.requestHostname, reqType, sDnsConfig.timeoutMills, statMerge.restDnsStat.ttl, @@ -249,20 +246,18 @@ private static void attaReportStatisticsEvent() { int errCount = (int) temp[1]; int curCount = (int) temp[2]; int spendAvg = (int) temp[0] / (errCount + curCount); - // 获取手机卡运营商code - String carrierCode = AttaHelper.getSimOperator(DnsService.getAppContext()); // 获取当前dnsip String dnsIp = BackupResolver.getInstance().getDnsIp(); if (errCount > 0) { // 为空的缓存统计项上报,解析结果不上报 - MAIN.execute(AttaHelper.report(carrierCode, "", sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, + MAIN.execute(AttaHelper.report("", sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, sDnsConfig.channel, ReportConst.LOOKUP_FROM_CACHED_EVENT_NAME, System.currentTimeMillis(), dnsIp, spendAvg, 0, item.getKey(), "", sDnsConfig.timeoutMills, null, 3, 0, true, errCount, null, null)); } if (curCount > 0) { // 有值的缓存统计项上报,解析结果不上报 - MAIN.execute(AttaHelper.report(carrierCode, "", sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, + MAIN.execute(AttaHelper.report( "", sDnsConfig.lookupExtra.bizId, sDnsConfig.appId, sDnsConfig.channel, ReportConst.LOOKUP_FROM_CACHED_EVENT_NAME, System.currentTimeMillis(), dnsIp, spendAvg, 0, item.getKey(), "", sDnsConfig.timeoutMills, null, 0, 0, true, curCount, null, null));