@@ -72,7 +72,7 @@ public class NetUtils {
72
72
/**
73
73
* 预计多少秒后刷新dns列表
74
74
*/
75
- private static final int TIMERD_DNS_REFRESH = 120 ;
75
+ private static final int TIMERD_DNS_REFRESH = 240 ;
76
76
77
77
/**
78
78
* 建议自己去ping一个自己的服务地址
@@ -321,24 +321,31 @@ private static String[] getConvertDns() {
321
321
* 2小时刷新一次可用的dns列表
322
322
*/
323
323
public static boolean reloadDnsPing () {
324
- long beforeTime = BaseIotUtils .instance ().dnsRefreshTime ;
325
- if (beforeTime <= 0 ) {
326
- //如果没有记录过时间 那么证明第一次加载DNS列表
327
- BaseIotUtils .instance ().dnsRefreshTime = System .currentTimeMillis ();//记录这一次操作的时间
328
- //如果在通过的列表中 有网络正常通过的那么直接返回true ,因为的重新加载的列表中会对所有的列表做检测
329
- return tryRefreshDns ();
330
- } else {
331
- long nowTime = System .currentTimeMillis () / 1000 ;
332
- long diffNum = nowTime - (beforeTime / 1000 );
333
- if (diffNum > TIMERD_DNS_REFRESH ) {//大于两小时刷新一次 7200秒等于2小时
334
- KLog .d ("reloadDnsList() time >> " + TIMERD_DNS_REFRESH + " diffNum >> " + diffNum );
324
+ //先判断本机是否网络API返回正常
325
+ if (getNetWorkType () != NETWORK_NO ) {
326
+ long beforeTime = BaseIotUtils .instance ().dnsRefreshTime ;
327
+ if (beforeTime > 1 ) {
328
+ //如果没有记录过时间 那么证明第一次加载DNS列表
335
329
BaseIotUtils .instance ().dnsRefreshTime = System .currentTimeMillis ();//记录这一次操作的时间
336
330
//如果在通过的列表中 有网络正常通过的那么直接返回true ,因为的重新加载的列表中会对所有的列表做检测
337
331
return tryRefreshDns ();
332
+ } else {
333
+ long nowTime = System .currentTimeMillis () / 1000 ;
334
+ long diffNum = nowTime - (beforeTime / 1000 );
335
+ if (diffNum > TIMERD_DNS_REFRESH ) {//大于两小时刷新一次 7200秒等于2小时
336
+ KLog .d ("reloadDnsList() time >> " + TIMERD_DNS_REFRESH + " diffNum >> " + diffNum );
337
+ BaseIotUtils .instance ().dnsRefreshTime = System .currentTimeMillis ();//记录这一次操作的时间
338
+ //如果在通过的列表中 有网络正常通过的那么直接返回true ,因为的重新加载的列表中会对所有的列表做检测
339
+ return tryRefreshDns ();
340
+ }
338
341
}
342
+ //即使在上面经过刷新dns列表的情况下都没有ping那么还有这次
343
+ return checkNetWork (TypeDataUtils .getRandomList (getConvertDns (), 3 ), 1 , 1 );
344
+ } else {
345
+ //由于网络出现问题 重置下一次刷新时间
346
+ BaseIotUtils .instance ().dnsRefreshTime = 0 ;
347
+ return false ;
339
348
}
340
- //即使在上面经过刷新dns列表的情况下都没有ping那么还有这次
341
- return checkNetWork (TypeDataUtils .getRandomList (getConvertDns (), 3 ), 1 , 1 );
342
349
}
343
350
344
351
/**
0 commit comments