11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | ## NetWorkDetection
2 |
3 | Android 网络诊断、网络检测库
4 | 基于[AndroidHttpCapture](https://github.com/JZ-Darkal/AndroidHttpCapture)改造,剔除了不需要的功能,更精简。
5 | 效果如下所示:
6 | ```java
7 | 开始诊断...
8 | 诊断时间:2020-06-11 14:20:09
9 | 应用code: 01
10 | 应用名称: NetworkDetection
11 | 应用版本: 1.0
12 | 机器类型: OnePlus:OnePlus:GM1910
13 | 系统版本: 10
14 | 机器ID: 5a121bc3a9547810
15 | 运营商: 中国电信
16 | ISOCountryCode: cn
17 | MobileCountryCode: 460
18 | MobileNetworkCode: 11
19 |
20 | 诊断域名 www.baidu.com...
21 | 当前是否联网: 已联网
22 | 当前联网类型: WIFI
23 | 本地IP: 10.1.150.157
24 | 本地网关: 10.1.150.1
25 | 本地DNS: 10.96.0.10,114.114.114.114
26 | 远端域名: www.baidu.com
27 | DNS解析结果: 112.80.248.75,112.80.248.76 (25ms)
28 |
29 | 开始TCP连接测试...
30 | Connect to host: 112.80.248.75...
31 | 1's time=17ms, 2's time=22ms, 3's time=15ms, 4's time=14ms, average=17ms
32 | Connect to host: 112.80.248.76...
33 | 1's time=16ms, 2's time=17ms, 3's time=17ms, 4's time=16ms, average=16ms
34 |
35 | 开始ping...
36 | ping...127.0.0.1
37 | 64bytes from 127.0.0.1: icmp_seq=#1 ttl=64 time=0.236ms
38 | 64bytes from 127.0.0.1: icmp_seq=#2 ttl=64 time=0.467ms
39 | 64bytes from 127.0.0.1: icmp_seq=#3 ttl=64 time=0.622ms
40 | 64bytes from 127.0.0.1: icmp_seq=#4 ttl=64 time=0.586ms
41 | ping本机IP...10.1.150.157
42 | 64bytes from 10.1.150.157: icmp_seq=#1 ttl=64 time=0.397ms
43 | 64bytes from 10.1.150.157: icmp_seq=#2 ttl=64 time=0.430ms
44 | 64bytes from 10.1.150.157: icmp_seq=#3 ttl=64 time=0.543ms
45 | 64bytes from 10.1.150.157: icmp_seq=#4 ttl=64 time=0.626ms
46 | ping本地网关...10.1.150.1
47 | 64bytes from 10.1.150.1: icmp_seq=#1 ttl=254 time=13.9ms
48 | 64bytes from 10.1.150.1: icmp_seq=#2 ttl=254 time=17.0ms
49 | 64bytes from 10.1.150.1: icmp_seq=#3 ttl=254 time=15.1ms
50 | 64bytes from 10.1.150.1: icmp_seq=#4 ttl=254 time=13.0ms
51 | ping本地DNS1...10.96.0.10
52 | ping: cannot resolve 10.96.0.10: Timeout
53 | ping本地DNS2...114.114.114.114
54 | 64bytes from 114.114.114.114: icmp_seq=#1 ttl=90 time=23.1ms
55 | 64bytes from 114.114.114.114: icmp_seq=#2 ttl=87 time=34.6ms
56 | 64bytes from 114.114.114.114: icmp_seq=#3 ttl=75 time=33.9ms
57 | 64bytes from 114.114.114.114: icmp_seq=#4 ttl=63 time=34.1ms
58 |
59 | 开始traceroute...
60 | 1?: [LOCALHOST] pmtu 1500
61 | 1: 10.1.150.1 4.795ms
62 | 1: 10.1.150.1 19.414ms
63 | 2: **********
64 | 3: 60.12.222.1 21.194ms
65 | 4: **********
66 | 5: **********
67 | 6: 221.12.35.101 25.570ms
68 | 7: **********
69 | 8: 221.6.1.254 24.447ms
70 | 9: 58.240.96.30 14.385ms
71 | 10: 182.61.216.0 15.139ms
72 | 11: **********
73 | 12: **********
74 | 13: **********
75 |
76 | 网络诊断结束
77 | ```
78 |
79 | ## Usage
80 | ### 添加依赖
81 | #### Step 1. Add the JitPack repository to your build file
82 | Add it in your root build.gradle at the end of repositories:
83 |
84 | ```java
85 | allprojects {
86 | repositories {
87 | ...
88 | maven { url 'https://jitpack.io' }
89 | }
90 | }
91 | ```
92 |
93 | #### Step 2. Add the dependency
94 |
95 | ```java
96 | dependencies {
97 | implementation 'com.github.EthanCo:NetWorkDetection:1.0.4'
98 | }
99 | ```
100 |
101 | ### 进行使用
102 | ```java
103 | traceTask = new TraceTask(MainActivity.this, "www.baidu.com", new TaskCallBack() {
104 | @Override
105 | public void onUpdated(String log) {
106 | //当诊断状态更新
107 | }
108 |
109 | @Override
110 | public void onFinish(String log) {
111 | //当诊断结束
112 | }
113 |
114 | @Override
115 | public void onFailed(Exception e) {
116 | //当诊断失败
117 | }
118 | });
119 | traceTask.doTask(); //进行诊断
120 | ```
121 |
122 | #### 可选方法
123 | ```java
124 | traceTask.setAppName("NetworkDetection"); //设置应用名称
125 | traceTask.setAppCode("01"); //设置AppCode
126 | traceTask.setDeviceId(deviceId); //设置设备ID
127 | traceTask.setAlwaysPing(false); //是否永远进行Ping,如果是false,则根据当前网络环境判断是否要Ping
128 | ```
129 |
130 | ### 添加混淆
131 |
132 | ```java
133 | -keep class com.netease.LDNetDiagnoService.**{*;}
134 | ```
135 |
136 | 感谢 [AndroidHttpCapture](https://github.com/JZ-Darkal/AndroidHttpCapture) | [LDNetDiagnoService](https://github.com/Lede-Inc/LDNetDiagnoService_Android)
137 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | applicationId "com.heiko.networkdetectionsample"
8 | minSdkVersion 21
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
20 | ndk { //设置支持的SO库架构,取交集
21 | //abiFilters "armeabi"
22 | abiFilters "armeabi"/*, "x86", "armeabi-v7a", "x86_64", "arm64-v8a"*/
23 | }
24 | }
25 | debug{
26 | ndk { //设置支持的SO库架构,取交集
27 | //abiFilters "armeabi"
28 | abiFilters "armeabi"/*, "x86", "armeabi-v7a", "x86_64", "arm64-v8a"*/
29 | }
30 | }
31 |
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | implementation 'androidx.appcompat:appcompat:1.1.0'
40 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
41 | testImplementation 'junit:junit:4.12'
42 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
44 | implementation project(path: ':networkdetection')
45 | }
46 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/heiko/networkdetectionsample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.heiko.networkdetectionsample;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.heiko.networkdetectionsample", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/heiko/networkdetectionsample/ClipboardUtils.java:
--------------------------------------------------------------------------------
1 | package com.heiko.networkdetectionsample;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.ClipData;
5 | import android.content.ClipboardManager;
6 | import android.content.Context;
7 | import android.os.Build;
8 |
9 | /**
10 | * 剪切板工具类
11 | */
12 | public class ClipboardUtils {
13 |
14 | /**
15 | * 复制到剪切板
16 | *
17 | * @param context
18 | * @param text
19 | */
20 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
21 | public static void copyToClipboard(Context context, String text) {
22 | ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
23 | clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
24 | }
25 |
26 | /**
27 | * 获取剪贴板指定Index的文本
28 | *
29 | * @param context
30 | * @param index
31 | * @return
32 | */
33 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
34 | public static String getText(Context context, int index) {
35 | ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
36 | ClipData clip = clipboard.getPrimaryClip();
37 | if (clip != null && clip.getItemCount() > index) {
38 | return String.valueOf(clip.getItemAt(index).coerceToText(context));
39 | }
40 | return null;
41 | }
42 |
43 | /**
44 | * 获取剪切板最后的文本
45 | *
46 | * @param context
47 | * @return
48 | */
49 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
50 | public static String getLatestText(Context context) {
51 | ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
52 | ClipData clip = clipboard.getPrimaryClip();
53 | if (clip != null && clip.getItemCount() > 0) {
54 | return String.valueOf(clip.getItemAt(0).coerceToText(context));
55 | }
56 | return null;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/heiko/networkdetectionsample/DeviceUtils.java:
--------------------------------------------------------------------------------
1 | package com.heiko.networkdetectionsample;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.provider.Settings;
7 |
8 | /**
9 | * Created by Darkal on 2016/9/21.
10 | */
11 |
12 | public class DeviceUtils {
13 | /**
14 | * 获取版本号
15 | *
16 | * @return 当前应用的版本号
17 | */
18 | public static String getVersion(Context context) {
19 | try {
20 | PackageManager manager = context.getPackageManager();
21 | PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
22 | return info.versionName;
23 | } catch (Exception e) {
24 | e.printStackTrace();
25 | return "";
26 | }
27 | }
28 |
29 | /**
30 | * 获取版本号
31 | *
32 | * @return 当前应用的版本号
33 | */
34 | public static int getVersionCode(Context context) {
35 | try {
36 | PackageManager manager = context.getPackageManager();
37 | PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
38 | return info.versionCode;
39 | } catch (Exception e) {
40 | e.printStackTrace();
41 | return 0;
42 | }
43 | }
44 |
45 | public static String getAndroidID(Context context) {
46 | String id = Settings.Secure.getString(
47 | context.getContentResolver(),
48 | Settings.Secure.ANDROID_ID
49 | );
50 | if ("9774d56d682e549c".equals(id)) return "";
51 | return id == null ? "" : id;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/heiko/networkdetectionsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.heiko.networkdetectionsample;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.EditText;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 | import androidx.appcompat.app.AlertDialog;
12 | import androidx.appcompat.app.AppCompatActivity;
13 |
14 | import com.heiko.network.detection.task.TaskCallBack;
15 | import com.heiko.network.detection.task.TraceTask;
16 |
17 | public class MainActivity extends AppCompatActivity implements TaskCallBack {
18 | Button traceButton;
19 | TextView resultTextView;
20 | EditText urlEditText;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | traceButton = findViewById(R.id.bt_trace);
28 | resultTextView = findViewById(R.id.tv_result);
29 | urlEditText = findViewById(R.id.et_url);
30 |
31 | traceButton.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | resultTextView.setText("");
35 | TraceTask traceTask = new TraceTask(getApplication(),
36 | urlEditText.getText() + "", MainActivity.this);
37 | traceTask.setAppVersion(DeviceUtils.getVersion(MainActivity.this));
38 | traceTask.setAppName("NetworkDetection");
39 | traceTask.setAppCode("01");
40 | traceTask.setDeviceId(DeviceUtils.getAndroidID(MainActivity.this));
41 | traceTask.setAlwaysPing(true); //是否永远进行Ping,如果是false,则根据当前网络环境判断是否要Ping
42 | traceTask.doTask();
43 | }
44 | });
45 | }
46 |
47 | @Override
48 | public void onUpdated(String log) {
49 | resultTextView.append(log);
50 | }
51 |
52 | @Override
53 | public void onFinish(String log) {
54 | new AlertDialog.Builder(this)
55 | .setTitle("诊断结束")
56 | .setMessage("可复制诊断信息到剪切板")
57 | .setCancelable(false)
58 | .setPositiveButton("复制", new DialogInterface.OnClickListener() {
59 | @Override
60 | public void onClick(DialogInterface dialog, int which) {
61 | String info = resultTextView.getText().toString();
62 | ClipboardUtils.copyToClipboard(MainActivity.this, info);
63 | Toast.makeText(getApplicationContext(), "复制诊断信息成功!", Toast.LENGTH_SHORT).show();
64 | }
65 | })
66 | .setNegativeButton("取消", null)
67 | .show();
68 | }
69 |
70 | @Override
71 | public void onFailed(Exception e) {
72 | resultTextView.append("诊断失败:" + e.getMessage());
73 | Toast.makeText(this, "诊断失败:" + e.getMessage(), Toast.LENGTH_SHORT).show();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
21 |
22 |
29 |
30 |
31 |
32 |
38 |
39 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | App网络检测工具
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/heiko/networkdetectionsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.heiko.networkdetectionsample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.6.3'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 |
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 20 10:19:17 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/network_detaction.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/network_detaction.jpg
--------------------------------------------------------------------------------
/networkdetection/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/networkdetection/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | group='com.github.EthanCo'
5 | android {
6 | compileSdkVersion 28
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.1.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34 | }
35 |
--------------------------------------------------------------------------------
/networkdetection/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EthanCo/NetWorkDetection/44bcb5a9603942504c63eea431260e640d6dbbb5/networkdetection/consumer-rules.pro
--------------------------------------------------------------------------------
/networkdetection/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/networkdetection/src/androidTest/java/com/heiko/network/detection/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.heiko.network.detection;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.heiko.network.detection.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/networkdetection/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/networkdetection/src/main/java/com/heiko/network/detection/task/BaseTask.java:
--------------------------------------------------------------------------------
1 | package com.heiko.network.detection.task;
2 |
3 | /**
4 | * Created by xuzhou on 2016/8/1.
5 | */
6 | public abstract class BaseTask {
7 | String url;
8 | String tag;
9 | TaskCallBack callBack;
10 |
11 | public BaseTask(String url, TaskCallBack callBack) {
12 | this.url = url;
13 | this.callBack = callBack;
14 | }
15 |
16 | public void doTask() {
17 | tag = System.currentTimeMillis() + "";
18 | // TraceTask运行于主线程
19 | if (this instanceof TraceTask) {
20 | getExecRunnable().run();
21 | } else {
22 | new Thread(getExecRunnable()).start();
23 | }
24 | }
25 |
26 | // public class updateResultRunnable implements Runnable {
27 | // String resultString;
28 | //
29 | // public updateResultRunnable(String resultString) {
30 | // this.resultString = resultString;
31 | // }
32 | //
33 | // @Override
34 | // public void run() {
35 | // /*if (resultTextView != null && resultTextView.getTag().equals(tag)) {
36 | // resultTextView.append(resultString);
37 | // resultTextView.requestFocus();
38 | // }*/
39 | // if (callBack != null) {
40 | // callBack.onUpdated(resultString);
41 | // }
42 | // }
43 | // }
44 |
45 | public abstract Runnable getExecRunnable();
46 | }
47 |
--------------------------------------------------------------------------------
/networkdetection/src/main/java/com/heiko/network/detection/task/TaskCallBack.java:
--------------------------------------------------------------------------------
1 | package com.heiko.network.detection.task;
2 |
3 | /**
4 | * Task 回调
5 | *
6 | * @author Heiko
7 | * @date 2020/5/20 0020
8 | */
9 | public interface TaskCallBack {
10 | void onUpdated(String log);
11 |
12 | void onFinish(String log);
13 |
14 | void onFailed(Exception e);
15 | }
16 |
--------------------------------------------------------------------------------
/networkdetection/src/main/java/com/heiko/network/detection/task/TraceTask.java:
--------------------------------------------------------------------------------
1 | package com.heiko.network.detection.task;
2 |
3 | import android.app.Application;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 |
7 | import com.netease.LDNetDiagnoService.LDNetDiagnoListener;
8 | import com.netease.LDNetDiagnoService.LDNetDiagnoService;
9 |
10 |
11 | /**
12 | * Created by xuzhou on 2016/8/1.
13 | */
14 | public class TraceTask extends BaseTask implements LDNetDiagnoListener {
15 | String url;
16 | Application context;
17 | private String appCode;
18 | private String appName;
19 | private String deviceId;
20 | private String appVersion;
21 | private boolean alwaysPing;
22 |
23 | private Handler handler = new Handler(Looper.getMainLooper());
24 |
25 | public void setAlwaysPing(boolean alwaysPing) {
26 | this.alwaysPing = alwaysPing;
27 | }
28 |
29 | public void setAppCode(String appCode) {
30 | this.appCode = appCode;
31 | }
32 |
33 | public void setAppName(String appName) {
34 | this.appName = appName;
35 | }
36 |
37 | public void setDeviceId(String deviceId) {
38 | this.deviceId = deviceId;
39 | }
40 |
41 | public void setAppVersion(String appVersion) {
42 | this.appVersion = appVersion;
43 | }
44 |
45 | public TraceTask(Application context, String url, TaskCallBack callBack) {
46 | super(url, callBack);
47 | this.context = context;
48 | this.url = url;
49 | }
50 |
51 | @Override
52 | public Runnable getExecRunnable() {
53 | return execRunnable;
54 | }
55 |
56 | public Runnable execRunnable = new Runnable() {
57 | @Override
58 | public void run() {
59 | try {
60 | LDNetDiagnoService _netDiagnoService = new LDNetDiagnoService(context,
61 | appCode, appName, appVersion, "",
62 | deviceId, url, "", "",
63 | "", "", alwaysPing, TraceTask.this);
64 | // 设置是否使用JNIC 完成traceroute
65 | _netDiagnoService.setIfUseJNICTrace(true);
66 | _netDiagnoService.execute();
67 | } catch (final Exception e) {
68 | if (callBack != null) {
69 | handler.post(new Runnable() {
70 | @Override
71 | public void run() {
72 | callBack.onFailed(e);
73 | }
74 | });
75 | }
76 | }
77 | }
78 | };
79 |
80 | @Override
81 | public void OnNetDiagnoFinished(final String log) {
82 | if (callBack != null) {
83 | handler.post(new Runnable() {
84 | @Override
85 | public void run() {
86 | callBack.onFinish(log);
87 | }
88 | });
89 | }
90 | }
91 |
92 | @Override
93 | public void OnNetDiagnoUpdated(final String log) {
94 | if (callBack != null) {
95 | handler.post(new Runnable() {
96 | @Override
97 | public void run() {
98 | callBack.onUpdated(log);
99 | }
100 | });
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/networkdetection/src/main/java/com/netease/LDNetDiagnoService/LDNetAsyncTaskEx.java:
--------------------------------------------------------------------------------
1 | package com.netease.LDNetDiagnoService;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Handler;
5 | import android.os.Message;
6 |
7 | import java.util.concurrent.Callable;
8 | import java.util.concurrent.CancellationException;
9 | import java.util.concurrent.ExecutionException;
10 | import java.util.concurrent.FutureTask;
11 | import java.util.concurrent.ThreadPoolExecutor;
12 |
13 | /**
14 | *
15 | * @author liujie
16 | *
17 | *
18 | * The most part is copied for {@link AsyncTask}.
19 | *
20 | * What's we do here is to control the executor and the core
21 | *
22 | * number of thread parallely.
23 | *
24 | *
25 | * Since Starting with HONEYCOMB, tasks are executed on a single thread
26 | *
27 | * to avoid common application errors caused by parallel execution.
28 | */
29 |
30 | public abstract class LDNetAsyncTaskEx {
31 | private static final int MESSAGE_POST_RESULT = 0x1;
32 | private static final int MESSAGE_POST_PROGRESS = 0x2;
33 | private static final int MESSAGE_POST_CANCEL = 0x3;
34 |
35 | private volatile Status mStatus = Status.PENDING;
36 |
37 | public enum Status {
38 | PENDING, RUNNING, FINISHED,
39 | }
40 |
41 | private static final LDNetInternalHandler sHandler = new LDNetInternalHandler();
42 | private final LDNetWorkerRunnable mWorker;
43 | private final FutureTask mFuture;
44 |
45 | // protected Hashtable mTaskCache = new
46 | // Hashtable();
47 |
48 | public LDNetAsyncTaskEx() {
49 | mWorker = new LDNetWorkerRunnable() {
50 | public Result call() throws Exception {
51 | // Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
52 | return doInBackground(mParams);
53 | }
54 | };
55 |
56 | mFuture = new FutureTask(mWorker) {
57 | @SuppressWarnings("unchecked")
58 | @Override
59 | protected void done() {
60 | Message message;
61 | Result result = null;
62 |
63 | try {
64 | result = get();
65 | } catch (InterruptedException e) {
66 | android.util.Log.w(this.getClass().getSimpleName(), e);
67 | } catch (ExecutionException e) {
68 | throw new RuntimeException(
69 | "An error occured while executing doInBackground()",
70 | e.getCause());
71 | } catch (CancellationException e) {
72 | message = sHandler.obtainMessage(MESSAGE_POST_CANCEL,
73 | new LDNetAsyncTaskResult(LDNetAsyncTaskEx.this,
74 | (Result[]) null));
75 | message.sendToTarget();
76 | return;
77 | } catch (Throwable t) {
78 | throw new RuntimeException(
79 | "An error occured while executing "
80 | + "doInBackground()", t);
81 | }
82 |
83 | message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
84 | new LDNetAsyncTaskResult(LDNetAsyncTaskEx.this, result));
85 | message.sendToTarget();
86 | }
87 | };
88 | }
89 |
90 | private static class LDNetInternalHandler extends Handler {
91 | @SuppressWarnings({ "rawtypes", "unchecked" })
92 | @Override
93 | public void handleMessage(Message msg) {
94 | LDNetAsyncTaskResult result = (LDNetAsyncTaskResult) msg.obj;
95 | switch (msg.what) {
96 | case MESSAGE_POST_RESULT:
97 | // There is only one result
98 | result.mTask.finish(result.mData[0]);
99 | break;
100 | case MESSAGE_POST_PROGRESS:
101 | result.mTask.onProgressUpdate(result.mData);
102 | break;
103 | case MESSAGE_POST_CANCEL:
104 | result.mTask.onCancelled();
105 | break;
106 | }
107 | }
108 | }
109 |
110 | public final Status getStatus() {
111 | return mStatus;
112 | }
113 |
114 | protected abstract Result doInBackground(Params... params);
115 | /**
116 | * 后台线程准备运行阶段
117 | */
118 | protected void onPreExecute() {
119 | }
120 |
121 | /**
122 | * 后台运行阶段,当前运行已经结束
123 | * @param result
124 | */
125 | protected void onPostExecute(Result result) {
126 | }
127 |
128 | /**
129 | * 进度更新阶段
130 | * @param values
131 | */
132 | protected void onProgressUpdate(Progress... values) {
133 | }
134 |
135 | /**
136 | * 取消运行
137 | */
138 | protected void onCancelled() {
139 | }
140 |
141 | public final boolean isCancelled() {
142 | return mFuture.isCancelled();
143 | }
144 |
145 | public final boolean cancel(boolean mayInterruptIfRunning) {
146 | return mFuture.cancel(mayInterruptIfRunning);
147 | }
148 |
149 | /**
150 | * 初始化运行阶段
151 | * @param params
152 | * @return
153 | */
154 | @SuppressWarnings("incomplete-switch")
155 | public final LDNetAsyncTaskEx execute(Params... params) {
156 | if (mStatus != Status.PENDING) {
157 | switch (mStatus) {
158 | case RUNNING:
159 | throw new IllegalStateException("Cannot execute task:"
160 | + " the task is already running.");
161 | case FINISHED:
162 | throw new IllegalStateException("Cannot execute task:"
163 | + " the task has already been executed "
164 | + "(a task can be executed only once)");
165 | }
166 | }
167 |
168 | mStatus = Status.RUNNING;
169 |
170 | onPreExecute();
171 |
172 | mWorker.mParams = params;
173 | ThreadPoolExecutor sExecutor = getThreadPoolExecutor();
174 | // ThreadPoolExecutor sExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,
175 | // MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue,
176 | // sThreadFactory);
177 | if (sExecutor != null) {
178 | sExecutor.execute(mFuture);
179 | return this;
180 | } else {
181 | return null;
182 | }
183 | }
184 |
185 | protected abstract ThreadPoolExecutor getThreadPoolExecutor();
186 |
187 | protected final void publishProgress(Progress... values) {
188 | sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
189 | new LDNetAsyncTaskResult