Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from JoshuaYin/master
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
joshua.yin authored Feb 22, 2019
2 parents 5629dae + c4fd15f commit 7a24934
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 90 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,17 @@ public enum UCSdkStatus {
``` java
public enum UCNetStatus {
// 无网络连接
NET_STATUS_NOT_CONNECTED,
NET_STATUS_NOT_REACHABLE,

// WIFI网络
NET_STATUS_WIFI,

// 4G网络
NET_STATUS_4G,

// 3.5G网络
NET_STATUS_3_5G,

// 3G网络
NET_STATUS_3G,

// 2.5G网络
NET_STATUS_2_5G,

// 2G网络
NET_STATUS_2G,

Expand Down
56 changes: 28 additions & 28 deletions UNetAnalysisLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 26
versionCode 0
versionName "1.0"
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -54,37 +54,37 @@ class Utils {
}

String toJavaCodeString(String string) {
byte[] b = string.getBytes();
int c = b.length;
StringBuffer sb = new StringBuffer();
byte[] b = string.getBytes()
int c = b.length
StringBuffer sb = new StringBuffer()

sb.append("new Object(){");
sb.append("int t;");
sb.append("public String toString() {");
sb.append("byte[] buf = new byte[");
sb.append(c);
sb.append("];");
sb.append("new Object(){")
sb.append("int t;")
sb.append("public String toString() {")
sb.append("byte[] buf = new byte[")
sb.append(c)
sb.append("];")

for (int i = 0; i < c; ++i) {
int t = Utils.r.nextInt();
int f = Utils.r.nextInt(24) + 1;

t = (t & ~(0xff << f)) | (b[i] << f);

sb.append("t = ");
sb.append(t);
sb.append(";");
sb.append("buf[");
sb.append(i);
sb.append("] = (byte) (t >>> ");
sb.append(f);
sb.append(");");
int t = Utils.r.nextInt()
int f = Utils.r.nextInt(24) + 1

t = (t & ~(0xff << f)) | (b[i] << f)

sb.append("t = ")
sb.append(t)
sb.append(";")
sb.append("buf[")
sb.append(i)
sb.append("] = (byte) (t >>> ")
sb.append(f)
sb.append(");")
}

sb.append("return new String(buf);");
sb.append("}}.toString()");
sb.append("return new String(buf);")
sb.append("}}.toString()")

return sb.toString();
return sb.toString()
}

//task makeJar(type: Copy) {
Expand Down Expand Up @@ -122,7 +122,7 @@ task makeJar(dependsOn: ['clearJar', 'build', 'compileReleaseJavaWithJavac'], ty
// exclude "**/BuildConfig.class"
exclude "**/R.class"
exclude "android/**"
exclude { it.name.startsWith('R$'); }
exclude { it.name.startsWith('R$') }
//只导入资源路径集下的部分资源
// include "org/chaos/demo/jar/**/*.class"
//注: exclude include 支持可变长参数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
public class UCNetAnalysisManager {
private final String TAG = getClass().getSimpleName();

public static final String SDK_VERSION = String.format("Android/%s.%d", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE);
public static final String SDK_VERSION = String.format("Android/%s", BuildConfig.VERSION_NAME);
public static final int CUSTOM_IP_LIST_SIZE = 5;

private final int MAX_AUTO_COMMAND_TASK_SIZE = 2;
Expand Down Expand Up @@ -454,7 +454,7 @@ public void onReceive(Context context, Intent intent) {
if (mSdkListener != null)
mSdkListener.onNetworkStatusChanged(info);

if (info == null || info.getNetStatus() == UCNetStatus.NET_STATUS_NOT_CONNECTED)
if (info == null || info.getNetStatus() == UCNetStatus.NET_STATUS_NOT_REACHABLE)
return;
synchronized (flag) {
if (flag)
Expand All @@ -479,7 +479,6 @@ public void onResponse(Call<PublicIpBean> call, Response<PublicIpBean> response)
if (response == null || response.body() == null)
return;

JLog.D(TAG, "[ip info]:" + response.body());
mCurSrcIpInfo = response.body().getIpInfo();
mCurSrcIpInfo.setNetType(checkNetworkStatus().getNetStatus().getValue());
doGetIpList();
Expand Down Expand Up @@ -550,7 +549,7 @@ private boolean randomIpList(IpListBean bean) {
return false;

Collections.shuffle(bean.getInfo(), new Random(SystemClock.elapsedRealtime()));
Collections.shuffle(bean.getUrl(), new Random(SystemClock.elapsedRealtime()));

return true;
}

Expand Down Expand Up @@ -667,7 +666,7 @@ private void reportPing(PingResult result, boolean isCustomIp, List<String> repo

for (int i = 0, len = reportArrdCache.size(); i < len; i++) {
try {
Response<UCApiResponseBean<MessageBean>> response = mApiManager.apiReportPing(reportArrdCache.get(0), report, isCustomIp, mCurSrcIpInfo);
Response<UCApiResponseBean<MessageBean>> response = mApiManager.apiReportPing(reportArrdCache.get(i), report, isCustomIp, mCurSrcIpInfo);
JLog.D(TAG, "[response]:" + (response == null || response.body() == null ? "null" : response.body().toString()));
if (response != null && response.body() != null && response.body().getMeta() != null
&& response.body().getMeta().getCode() == 200)
Expand Down Expand Up @@ -763,7 +762,7 @@ private void reportTraceroute(TracerouteResult result, boolean isCustomIp, List<

for (int i = 0, len = reportArrdCache.size(); i < len; i++) {
try {
Response<UCApiResponseBean<MessageBean>> response = mApiManager.apiReportTraceroute(reportArrdCache.get(0), report, isCustomIp, mCurSrcIpInfo);
Response<UCApiResponseBean<MessageBean>> response = mApiManager.apiReportTraceroute(reportArrdCache.get(i), report, isCustomIp, mCurSrcIpInfo);
JLog.D(TAG, "[response]:" + (response == null || response.body() == null ? "null" : response.body().toString()));
if (response != null && response.body() != null && response.body().getMeta() != null
&& response.body().getMeta().getCode() == 200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
public class IpInfoBean {
@SerializedName("addr")
private String ip;
@SerializedName("cityName")
private String city_name;
@SerializedName("continentCode")
@SerializedName("city_name")
private String cityName;
@SerializedName("continent_code")
private String continentCode;
@SerializedName("country_code")
private String countryCode;
@SerializedName("country_name")
private String countryName;
@SerializedName("ispDomain")
private String isp_domain;
@SerializedName("isp_domain")
private String ispDomain;
@SerializedName("latitude")
private String latitude;
@SerializedName("longitude")
private String longitude;
@SerializedName("ownerDomain")
private String owner_domain;
@SerializedName("owner_domain")
private String ownerDomain;
@SerializedName("region_name")
private String regionName;
@SerializedName("timezone")
Expand All @@ -44,12 +44,12 @@ public void setIp(String ip) {
this.ip = ip;
}

public String getCity_name() {
return city_name;
public String getCityName() {
return cityName;
}

public void setCity_name(String city_name) {
this.city_name = city_name;
public void setCityName(String cityName) {
this.cityName = cityName;
}

public String getContinentCode() {
Expand All @@ -76,12 +76,12 @@ public void setCountryName(String countryName) {
this.countryName = countryName;
}

public String getIsp_domain() {
return isp_domain;
public String getIspDomain() {
return ispDomain;
}

public void setIsp_domain(String isp_domain) {
this.isp_domain = isp_domain;
public void setIspDomain(String ispDomain) {
this.ispDomain = ispDomain;
}

public String getLatitude() {
Expand All @@ -100,12 +100,12 @@ public void setLongitude(String longitude) {
this.longitude = longitude;
}

public String getOwner_domain() {
return owner_domain;
public String getOwnerDomain() {
return ownerDomain;
}

public void setOwner_domain(String owner_domain) {
this.owner_domain = owner_domain;
public void setOwnerDomain(String ownerDomain) {
this.ownerDomain = ownerDomain;
}

public String getRegionName() {
Expand Down Expand Up @@ -142,15 +142,15 @@ public void setNetType(String netType) {

protected String makeReportString() {
StringBuffer sb = new StringBuffer();
sb.append(String.format("ip=%s", ip));
sb.append(String.format(",region=%s", regionName));
sb.append(String.format(",country=%s", countryName));
sb.append(String.format(",city=%s", city_name));
sb.append(String.format(",isp=%s", isp_domain));
sb.append(String.format(",lon=%s", longitude));
sb.append(String.format(",lat=%s", latitude));
sb.append(String.format(",owner=%s", owner_domain));
sb.append(String.format(",net_type=%s", netType));
sb.append(String.format("ip=%s", (ip == null ? "" : ip)));
sb.append(String.format(",region=%s", (regionName == null ? "" : regionName)));
sb.append(String.format(",country=%s", (countryName == null ? "" : countryName)));
sb.append(String.format(",city=%s", (cityName == null ? "" : cityName)));
sb.append(String.format(",isp=%s", (ispDomain == null ? "" : ispDomain)));
sb.append(String.format(",lon=%s", (longitude == null ? "" : longitude)));
sb.append(String.format(",lat=%s", (latitude == null ? "" : latitude)));
sb.append(String.format(",owner=%s", (ownerDomain == null ? "" : ownerDomain)));
sb.append(String.format(",net_type=%s", (netType == null ? "" : netType)));
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setTTL(int TTL) {

protected String makeReportString() {
StringBuffer sb = new StringBuffer(super.makeReportString());
sb.append(String.format(",dst_ip=%s", dstIp));
sb.append(String.format(",dst_ip=%s", (dstIp == null ? "" : dstIp)));
sb.append(String.format(",TTL=%d", TTL));
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.ucloud.library.netanalysis.api.bean;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.ucloud.library.netanalysis.UCNetAnalysisManager;

import java.util.Locale;
import java.util.TimeZone;

/**
* Created by joshua on 2018/12/27 13:31.
* Company: UCloud
Expand All @@ -19,9 +20,17 @@ public class ReportTagBean {
protected final String sdkVersion = UCNetAnalysisManager.SDK_VERSION;
@SerializedName("cus")
protected int cus = 0;
@SerializedName("tz")
protected String timezone;

protected ReportTagBean(String appId) {
this.appId = appId;
try {
this.timezone = TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT, Locale.getDefault());
this.timezone = this.timezone.replace("GMT", "").replace(":", "");
} catch (Exception e) {
this.timezone = null;
}
}

public String getAppId() {
Expand All @@ -36,6 +45,10 @@ public int getPlatform() {
return platform;
}

public String getTimezone() {
return timezone;
}

public boolean isCustomIp() {
return cus > 0;
}
Expand All @@ -50,6 +63,7 @@ protected String makeReportString() {
sb.append(String.format(",platform=%d", platform));
sb.append(String.format(",s_ver=%s", sdkVersion));
sb.append(String.format(",cus=%d", cus));
sb.append(String.format(",tz=%s", (timezone == null ? "" : timezone)));
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -33,10 +34,32 @@ public void setTracerouteData(TracerouteDataBean tracerouteData) {

public static class ReportTracerouteData {
@SerializedName("route_info")
private List<TracerouteDataBean.RouteInfoBean> routeInfoList;
private transient List<TracerouteDataBean.RouteInfoBean> routeInfoList;
@SerializedName("route_list")
private List<String> routeList;
@SerializedName("delay_list")
private List<Integer> delayList;
@SerializedName("loss_list")
private List<Integer> lossList;

public ReportTracerouteData(List<TracerouteDataBean.RouteInfoBean> routeInfoList) {
this.routeInfoList = routeInfoList;
makeReportData();
}

private void makeReportData() {
routeList = new ArrayList<>();
delayList = new ArrayList<>();
lossList = new ArrayList<>();
if (routeInfoList == null || routeInfoList.isEmpty())
return;

for (int i = 0, len = routeInfoList.size(); i < len; i++) {
TracerouteDataBean.RouteInfoBean route = routeInfoList.get(i);
routeList.add(route.getRouteIp());
delayList.add(route.getDelay());
lossList.add(route.getLoss());
}
}

public List<TracerouteDataBean.RouteInfoBean> getRouteInfoList() {
Expand All @@ -45,6 +68,7 @@ public List<TracerouteDataBean.RouteInfoBean> getRouteInfoList() {

public void setRouteInfoList(List<TracerouteDataBean.RouteInfoBean> routeInfoList) {
this.routeInfoList = routeInfoList;
makeReportData();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void setDstIp(String dstIp) {

protected String makeReportString() {
StringBuffer sb = new StringBuffer(super.makeReportString());
sb.append(String.format(",dst_ip=%s", dstIp));
sb.append(String.format(",dst_ip=%s", (dstIp == null ? "" : dstIp)));
return sb.toString();
}

Expand Down
Loading

0 comments on commit 7a24934

Please sign in to comment.