├── README.md
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── layout
│ │ │ │ ├── download_fragment_layout.xml
│ │ │ │ ├── download_list_item.xml
│ │ │ │ ├── home_layout.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── values-zh-rCN
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── ghost
│ │ │ │ └── thunder
│ │ │ │ ├── ui
│ │ │ │ ├── UserFragment.java
│ │ │ │ ├── DownLoadListFragment.java
│ │ │ │ └── HomeFragment.java
│ │ │ │ ├── data
│ │ │ │ ├── DownLoadDataBaseColumns.java
│ │ │ │ ├── DownLoadDataBase.java
│ │ │ │ └── DownLoadDBUtil.java
│ │ │ │ ├── download
│ │ │ │ ├── DownLoadProgressListener.java
│ │ │ │ └── DownLoadUtil.java
│ │ │ │ ├── utils
│ │ │ │ ├── UrlUtils.java
│ │ │ │ ├── UrlType.java
│ │ │ │ ├── FragmentUtils.java
│ │ │ │ ├── LogPrinter.java
│ │ │ │ └── StorageUtils.java
│ │ │ │ ├── adapter
│ │ │ │ ├── MyPageAdapter.java
│ │ │ │ └── DownLoadListAdapter.java
│ │ │ │ ├── MyApp.java
│ │ │ │ └── app
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── PermissionActivity.java
│ │ │ │ └── BaseActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── ghost
│ │ │ └── thunder
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── ghost
│ │ └── thunder
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── thunder
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── jniLibs
│ │ │ └── armeabi
│ │ │ │ ├── libxl_stat.so
│ │ │ │ ├── libxluagc.so
│ │ │ │ └── libxl_thunder_sdk.so
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── xunlei
│ │ │ │ └── downloadlib
│ │ │ │ ├── parameter
│ │ │ │ ├── XLTaskLocalUrl.java
│ │ │ │ ├── MaxDownloadSpeedParam.java
│ │ │ │ ├── GetDownloadLibVersion.java
│ │ │ │ ├── XLSessionInfo.java
│ │ │ │ ├── GetDownloadHead.java
│ │ │ │ ├── GetTaskId.java
│ │ │ │ ├── BtSubTaskDetail.java
│ │ │ │ ├── BtIndexSet.java
│ │ │ │ ├── BtTaskStatus.java
│ │ │ │ ├── GetFileName.java
│ │ │ │ ├── UrlQuickInfo.java
│ │ │ │ ├── ThunderUrlInfo.java
│ │ │ │ ├── XLProductInfo.java
│ │ │ │ ├── XLTaskInfoEx.java
│ │ │ │ ├── TorrentFileInfo.java
│ │ │ │ ├── InitParam.java
│ │ │ │ ├── MagnetTaskParam.java
│ │ │ │ ├── TorrentInfo.java
│ │ │ │ ├── ServerResourceParam.java
│ │ │ │ ├── EmuleTaskParam.java
│ │ │ │ ├── BtTaskParam.java
│ │ │ │ ├── CIDTaskParam.java
│ │ │ │ ├── P2spTaskParam.java
│ │ │ │ ├── PeerResourceParam.java
│ │ │ │ ├── XLTaskInfo.java
│ │ │ │ ├── ErrorCodeToMsg.java
│ │ │ │ └── XLConstant.java
│ │ │ │ ├── BlockingItem.java
│ │ │ │ ├── android
│ │ │ │ ├── LogLevel.java
│ │ │ │ ├── XLLog.java
│ │ │ │ ├── LogConfig.java
│ │ │ │ ├── XLLogInternal.java
│ │ │ │ └── XLUtil.java
│ │ │ │ ├── Daemon.java
│ │ │ │ ├── LinuxFileCommand.java
│ │ │ │ ├── XLAppKeyChecker.java
│ │ │ │ ├── XLLoader.java
│ │ │ │ └── XLTaskHelper.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── ghost
│ │ │ └── thunder
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── ghost
│ │ └── thunder
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── runConfigurations.xml
├── compiler.xml
├── modules.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
└── LICENSE
/README.md:
--------------------------------------------------------------------------------
1 | # BtPlayer
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/thunder/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':thunder'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BtPlayer
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/thunder/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | thunder
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/thunder/src/main/jniLibs/armeabi/libxl_stat.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxl_stat.so
--------------------------------------------------------------------------------
/thunder/src/main/jniLibs/armeabi/libxluagc.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxluagc.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/thunder/src/main/jniLibs/armeabi/libxl_thunder_sdk.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxl_thunder_sdk.so
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskLocalUrl.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class XLTaskLocalUrl {
4 | public String mStrUrl;
5 | }
6 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/MaxDownloadSpeedParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class MaxDownloadSpeedParam {
4 | public long mSpeed;
5 | }
6 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/GetDownloadLibVersion.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class GetDownloadLibVersion {
4 | public String mVersion = null;
5 | }
6 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLSessionInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class XLSessionInfo {
4 | public long mSendByte;
5 | public long mStartTime;
6 | }
7 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/GetDownloadHead.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class GetDownloadHead {
4 | public String mHttpResponse = null;
5 | public int mHttpState = -1;
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/ui/UserFragment.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.ui;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | /**
6 | * Created by wyt on 2018/8/9.
7 | */
8 |
9 | public class UserFragment extends Fragment {
10 | }
11 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/GetTaskId.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class GetTaskId {
4 | private long mTaskId;
5 |
6 | public long getTaskId() {
7 | return this.mTaskId;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/BtSubTaskDetail.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class BtSubTaskDetail {
4 | public int mFileIndex;
5 | public boolean mIsSelect;
6 | public XLTaskInfo mTaskInfo = new XLTaskInfo();
7 | }
8 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/BtIndexSet.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class BtIndexSet {
4 | public int[] mIndexSet;
5 |
6 | public BtIndexSet(int i) {
7 | this.mIndexSet = new int[i];
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/BtTaskStatus.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class BtTaskStatus {
4 | public int[] mStatus;
5 |
6 | public BtTaskStatus(int i) {
7 | this.mStatus = new int[i];
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/GetFileName.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class GetFileName {
4 | private String mFileName;
5 |
6 | public String getFileName() {
7 | return this.mFileName;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 09 19:25:00 CST 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/UrlQuickInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class UrlQuickInfo {
4 | public String mContentType;
5 | public String mFileNameAdvice;
6 | public long mFileSize;
7 | public int mState;
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #CCCCCC
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 57dp
5 |
6 | 15sp
7 |
8 | 18sp
9 |
10 | 21sp
11 |
12 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/ThunderUrlInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class ThunderUrlInfo {
4 | public String mUrl;
5 |
6 | public ThunderUrlInfo() {
7 | }
8 |
9 | public ThunderUrlInfo(String str) {
10 | this.mUrl = str;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLProductInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class XLProductInfo {
4 | public String mProductKey;
5 | public String mProductName;
6 |
7 | public XLProductInfo(String str, String str2) {
8 | this.mProductKey = str;
9 | this.mProductName = str2;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskInfoEx.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class XLTaskInfoEx {
4 | public int mErrorCode;
5 | public int mInfoLen;
6 | public int mOriginResState;
7 | public int mP2pAbandonTotal;
8 | public int mP2pUsedTotal;
9 | public int mP2sAbandonTotal;
10 | public int mP2sUsedTotal;
11 | public long mTaskId;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/download_fragment_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ghost/thunder/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/thunder/src/test/java/com/ghost/thunder/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder;
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() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/data/DownLoadDataBaseColumns.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.data;
2 |
3 | /**
4 | * Created by yuntao.wei on 2018/8/15.
5 | * github:https://github.com/YuntaoWei
6 | * blog:http://blog.csdn.net/qq_17541215
7 | */
8 |
9 | public class DownLoadDataBaseColumns {
10 |
11 | public static final String ID = "_id";
12 | public static final String NAME = "file_name";
13 | public static final String SAVE_PATH = "_path";
14 | public static final String URL = "_url";
15 | public static final String PROGRESS = "_progress";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/download/DownLoadProgressListener.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.download;
2 |
3 | /**
4 | * Created by yuntao.wei on 2018/8/9.
5 | * github:https://github.com/YuntaoWei
6 | * blog:http://blog.csdn.net/qq_17541215
7 | */
8 |
9 | public interface DownLoadProgressListener {
10 |
11 | void onProgressChange(String totalSize, String downloadedSize, String downSpeed);
12 |
13 | void onProgressChangeRealSize(long totalSize, long downloadedSize, long downSpeed);
14 |
15 | void onDonwloadEnd(String filePath);
16 |
17 | void onTaskStart(String fileName);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/utils/UrlUtils.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.utils;
2 |
3 | /**
4 | * Created by yuntao.wei on 2018/8/9.
5 | * github:https://github.com/YuntaoWei
6 | * blog:http://blog.csdn.net/qq_17541215
7 | */
8 |
9 | public class UrlUtils {
10 |
11 | public static boolean isValidUrl(String url) {
12 | if (url.startsWith(UrlType.TYPE_THUNDER_URL))
13 | return true;
14 | else if(url.startsWith(UrlType.TYPE_MAGNET_URL))
15 | return true;
16 | else if(url.endsWith(UrlType.TYPE_TORRENT_FILE))
17 | return true;
18 |
19 | return false;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | "BtPlayer"
5 |
6 | "请输入thunder/magnet/ftp/torrent链接"
7 |
8 | "无法解析这种类型的链接"
9 |
10 | "开始下载"
11 |
12 | "添加torrent"
13 |
14 | "主页"
15 |
16 | "下载列表"
17 |
18 | "用户"
19 |
20 | "请输入链接再进行下载"
21 |
22 | "解析异常"
23 |
24 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class TorrentFileInfo {
4 | public int mFileIndex;
5 | public String mFileName;
6 | public long mFileSize;
7 | public int mRealIndex;
8 | public String mSubPath;
9 | public String playUrl;
10 | public String hash;
11 |
12 | @Override
13 | public String toString() {
14 | return "File index : " + mFileIndex + "\n"
15 | + "File name : " + mFileName + "\n"
16 | + "File size : " + mFileSize + "\n"
17 | + "Real index : " + mRealIndex + "\n"
18 | + "Sub path : " + mSubPath + "\n"
19 | + "Play url : " + playUrl + "\n"
20 | + "hash value : " + hash;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/thunder/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/adapter/MyPageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by wyt on 2018/8/9.
11 | */
12 |
13 | public class MyPageAdapter extends FragmentPagerAdapter {
14 |
15 | private List fragments;
16 |
17 | public MyPageAdapter(FragmentManager fm) {
18 | super(fm);
19 | }
20 |
21 | public void setFragment(List fragments) {
22 | this.fragments = fragments;
23 | }
24 |
25 | @Override
26 | public Fragment getItem(int position) {
27 | return fragments.get(position);
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | return fragments.size();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ghost/thunder/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ghost.thunder", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/thunder/src/androidTest/java/com/ghost/thunder/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ghost.thunder.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/InitParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class InitParam {
4 | public String mAppKey;
5 | public String mAppVersion;
6 | public int mPermissionLevel;
7 | public String mStatCfgSavePath;
8 | public String mStatSavePath;
9 |
10 | public InitParam(String str, String str2, String str3, String str4, int i) {
11 | this.mAppKey = str;
12 | this.mAppVersion = str2;
13 | this.mStatSavePath = str3;
14 | this.mStatCfgSavePath = str4;
15 | this.mPermissionLevel = i;
16 | }
17 |
18 | public InitParam() {
19 | }
20 |
21 | public boolean checkMemberVar() {
22 | if (this.mAppKey == null || this.mAppVersion == null || this.mStatSavePath == null || this.mStatCfgSavePath == null) {
23 | return false;
24 | }
25 | return true;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Thu Aug 09 14:04:18 CST 2018
16 | systemProp.http.proxyHost=mirrors.neusoft.edu.cn
17 | org.gradle.jvmargs=-Xmx1536m
18 | systemProp.http.proxyPort=80
19 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/MagnetTaskParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class MagnetTaskParam {
4 | public String mFileName;
5 | public String mFilePath;
6 | public String mUrl;
7 |
8 | public MagnetTaskParam(String str, String str2, String str3) {
9 | this.mFileName = str;
10 | this.mFilePath = str2;
11 | this.mUrl = str3;
12 | }
13 |
14 | public MagnetTaskParam() {
15 | }
16 |
17 | public void setUrl(String str) {
18 | this.mUrl = str;
19 | }
20 |
21 | public void setFileName(String str) {
22 | this.mFileName = str;
23 | }
24 |
25 | public void setFilePath(String str) {
26 | this.mFilePath = str;
27 | }
28 |
29 |
30 |
31 | public boolean checkMemberVar() {
32 | if (this.mFileName == null || this.mFilePath == null || this.mUrl == null) {
33 | return false;
34 | }
35 | return true;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/thunder/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:25.3.1'
29 | compile 'io.reactivex:rxandroid:1.1.0'
30 | compile 'io.reactivex:rxjava:1.1.0'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/thunder/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class TorrentInfo {
4 | public int mFileCount;
5 | public String mInfoHash;
6 | public boolean mIsMultiFiles;
7 | public String mMultiFileBaseFolder;
8 | public TorrentFileInfo[] mSubFileInfo;
9 |
10 | @Override
11 | public String toString() {
12 | StringBuilder childFileInfo = new StringBuilder();
13 | childFileInfo.append("[");
14 | for (TorrentFileInfo info : mSubFileInfo
15 | ) {
16 | childFileInfo.append(info.toString() + "\n");
17 | childFileInfo.append("------------------------");
18 | }
19 | childFileInfo.append("]");
20 |
21 | return "file count : " + mFileCount + "\n"
22 | + "Info Hash : " + mInfoHash + "\n"
23 | + "is muti files : " + mIsMultiFiles + "\n"
24 | + "muti file base folder : " + mMultiFileBaseFolder + "\n"
25 | + childFileInfo.toString();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder;
2 |
3 | import android.app.Application;
4 | import android.content.pm.PackageManager;
5 | import android.util.Log;
6 |
7 | /**
8 | * Created by oceanzhang on 2017/9/28.
9 | */
10 |
11 | public class MyApp extends Application {
12 |
13 | public static MyApp instance = null;
14 |
15 | @Override
16 | public void onCreate() {
17 | super.onCreate();
18 | instance = this;
19 | }
20 |
21 | public static MyApp appInstance() {
22 | return instance;
23 | }
24 |
25 | @Override
26 | public String getPackageName() {
27 | if (Log.getStackTraceString(new Throwable()).contains("com.xunlei.downloadlib")) {
28 | return "com.xunlei.downloadprovider";
29 | }
30 | return super.getPackageName();
31 | }
32 |
33 | @Override
34 | public PackageManager getPackageManager() {
35 | if (Log.getStackTraceString(new Throwable()).contains("com.xunlei.downloadlib")) {
36 | return new DelegateApplicationPackageManager(super.getPackageManager());
37 | }
38 | return super.getPackageManager();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.ghost.thunder.demo"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':thunder')
31 |
32 | implementation 'com.jakewharton:butterknife:8.8.1'
33 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
34 | }
35 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/ServerResourceParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class ServerResourceParam {
4 | public String mCookie;
5 | public String mRefUrl;
6 | public int mResType;
7 | public int mStrategy;
8 | public String mUrl;
9 |
10 | public ServerResourceParam(String str, String str2, String str3, int i, int i2) {
11 | this.mUrl = str;
12 | this.mRefUrl = str2;
13 | this.mCookie = str3;
14 | this.mResType = i;
15 | this.mStrategy = i2;
16 | }
17 |
18 | public void setUrl(String str) {
19 | this.mUrl = str;
20 | }
21 |
22 | public void setRefUrl(String str) {
23 | this.mRefUrl = str;
24 | }
25 |
26 | public void setCookie(String str) {
27 | this.mCookie = str;
28 | }
29 |
30 | public void setRestype(int i) {
31 | this.mResType = i;
32 | }
33 |
34 | public void setStrategy(int i) {
35 | this.mStrategy = i;
36 | }
37 |
38 | public boolean checkMemberVar() {
39 | if (this.mUrl == null || this.mRefUrl == null || this.mCookie == null) {
40 | return false;
41 | }
42 | return true;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/EmuleTaskParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class EmuleTaskParam {
4 | public int mCreateMode;
5 | public String mFileName;
6 | public String mFilePath;
7 | public int mSeqId;
8 | public String mUrl;
9 |
10 | public EmuleTaskParam() {
11 | }
12 |
13 | public EmuleTaskParam(String str, String str2, String str3, int i, int i2) {
14 | this.mFileName = str;
15 | this.mFilePath = str2;
16 | this.mUrl = str3;
17 | this.mCreateMode = i;
18 | this.mSeqId = i2;
19 | }
20 |
21 | public void setFileName(String str) {
22 | this.mFileName = str;
23 | }
24 |
25 | public void setFilePath(String str) {
26 | this.mFilePath = str;
27 | }
28 |
29 | public void setUrl(String str) {
30 | this.mUrl = str;
31 | }
32 |
33 | public void setCreateMode(int i) {
34 | this.mCreateMode = i;
35 | }
36 |
37 | public void setSeqId(int i) {
38 | this.mSeqId = i;
39 | }
40 |
41 | public boolean checkMemberVar() {
42 | if (this.mFileName == null || this.mFilePath == null || this.mUrl == null) {
43 | return false;
44 | }
45 | return true;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/BtTaskParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class BtTaskParam {
4 | public int mCreateMode;
5 | public String mFilePath;
6 | public int mMaxConcurrent;
7 | public int mSeqId;
8 | public String mTorrentPath;
9 |
10 | public BtTaskParam() {
11 | }
12 |
13 | public BtTaskParam(String str, String str2, int i, int i2, int i3) {
14 | this.mTorrentPath = str;
15 | this.mFilePath = str2;
16 | this.mMaxConcurrent = i;
17 | this.mCreateMode = i2;
18 | this.mSeqId = i3;
19 | }
20 |
21 | public void setTorrentPath(String str) {
22 | this.mTorrentPath = str;
23 | }
24 |
25 | public void setFilePath(String str) {
26 | this.mFilePath = str;
27 | }
28 |
29 | public void setMaxConcurrent(int i) {
30 | this.mMaxConcurrent = i;
31 | }
32 |
33 | public void setCreateMode(int i) {
34 | this.mCreateMode = i;
35 | }
36 |
37 | public void setSeqId(int i) {
38 | this.mSeqId = i;
39 | }
40 |
41 | public boolean checkMemberVar() {
42 | if (this.mTorrentPath == null || this.mFilePath == null) {
43 | return false;
44 | }
45 | return true;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.app;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.ghost.thunder.demo.R;
6 | import com.ghost.thunder.utils.FragmentUtils;
7 |
8 | import butterknife.OnClick;
9 |
10 | public class MainActivity extends BaseActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | }
16 |
17 | @OnClick(R.id.btn_home)
18 | public void onHomeButtonClicked() {
19 | if(currentType == FragmentUtils.TYPE_HOME)
20 | return;
21 |
22 | changePage(FragmentUtils.TYPE_HOME);
23 | }
24 |
25 | @OnClick(R.id.btn_download_list)
26 | public void onDownloadListButtonClicked() {
27 | if(currentType == FragmentUtils.TYPE_FILE_LIST)
28 | return;
29 |
30 | changePage(FragmentUtils.TYPE_FILE_LIST);
31 | }
32 |
33 | @OnClick(R.id.btn_user)
34 | public void onUserButtonClicked() {
35 | if(currentType == FragmentUtils.TYPE_USER)
36 | return;
37 |
38 | changePage(FragmentUtils.TYPE_USER);
39 | }
40 |
41 | public void changePage(int type) {
42 | currentType = type;
43 | FragmentUtils.getFragment(type);
44 |
45 | changeButtonStyle(type);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/data/DownLoadDataBase.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.data;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | /**
8 | * Created by yuntao.wei on 2018/8/15.
9 | * github:https://github.com/YuntaoWei
10 | * blog:http://blog.csdn.net/qq_17541215
11 | */
12 |
13 | public class DownLoadDataBase extends SQLiteOpenHelper {
14 |
15 | private static final String DB_NAME = "download.db";
16 | public static final String DOWNLOAD_TABLE_NAME = "download";
17 |
18 | public DownLoadDataBase(Context context) {
19 | super(context, DB_NAME, null, 1);
20 | }
21 |
22 | @Override
23 | public void onCreate(SQLiteDatabase db) {
24 | String createTableSQL = "create table "+ DOWNLOAD_TABLE_NAME +" (" +
25 | DownLoadDataBaseColumns.ID + " integer primary key autoincrement,"+
26 | DownLoadDataBaseColumns.NAME + " varchar(40),"+
27 | DownLoadDataBaseColumns.SAVE_PATH + " varchar(50),"+
28 | DownLoadDataBaseColumns.URL + " varchar(50),"+
29 | DownLoadDataBaseColumns.PROGRESS + " integer"+
30 | ")";
31 | db.execSQL(createTableSQL);
32 | }
33 |
34 | @Override
35 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/utils/UrlType.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.utils;
2 |
3 | /**
4 | * Created by yuntao.wei on 2018/8/9.
5 | * github:https://github.com/YuntaoWei
6 | * blog:http://blog.csdn.net/qq_17541215
7 | */
8 |
9 | public class UrlType {
10 |
11 | public static final String TYPE_THUNDER_URL = "thunder://";
12 | public static final String TYPE_THUNDER_URL_1 = "ed2k://";
13 |
14 |
15 | public static final String TYPE_MAGNET_URL = "magnet:?";
16 |
17 | public static final String TYPE_TORRENT_FILE = ".torrent";
18 |
19 | public static final String TYPE_FTP_URL = "ftp://";
20 |
21 | public static final String TYPE_HTTP_URL = "http://";
22 |
23 | public static final String TYPE_HTTPS_URL = "https://";
24 |
25 | public static boolean isMagnetUrl(String url) {
26 | return url.startsWith(TYPE_MAGNET_URL);
27 | }
28 |
29 | public static boolean isThunderUrl(String url) {
30 | return url.startsWith(TYPE_THUNDER_URL) || url.startsWith(TYPE_THUNDER_URL_1);
31 | }
32 |
33 | public static boolean isTorrentUrl(String url) {
34 | return url.endsWith(TYPE_TORRENT_FILE);
35 | }
36 |
37 | public static boolean isFTPUrl(String url) {
38 | return url.startsWith(TYPE_FTP_URL);
39 | }
40 |
41 | public static boolean isHttpOrHttpsUrl(String url) {
42 | return url.startsWith(TYPE_HTTP_URL) || url.startsWith(TYPE_HTTPS_URL);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/download_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
19 |
20 |
26 |
27 |
33 |
34 |
35 |
36 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/BlockingItem.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import java.util.concurrent.TimeUnit;
4 | import java.util.concurrent.locks.Condition;
5 | import java.util.concurrent.locks.Lock;
6 | import java.util.concurrent.locks.ReentrantLock;
7 |
8 | public class BlockingItem {
9 | final Lock lock = new ReentrantLock();
10 | final Condition notEmpty = lock.newCondition();
11 |
12 | private volatile T item;
13 |
14 | public void put(T x) {
15 | lock.lock();
16 | try {
17 | item = x;
18 | if (x != null)
19 | notEmpty.signal();
20 | } finally {
21 | lock.unlock();
22 | }
23 | }
24 |
25 | public T take() throws InterruptedException {
26 | lock.lock();
27 | try {
28 | while (item == null)
29 | notEmpty.await();
30 | T t = item;
31 | item = null;
32 | return t;
33 | } finally {
34 | lock.unlock();
35 | }
36 | }
37 |
38 | public T tryTake(long waitMs) throws InterruptedException {
39 | lock.lock();
40 | try {
41 | while (item == null)
42 | if (!notEmpty.await(waitMs, TimeUnit.MILLISECONDS))
43 | return null;
44 | T t = item;
45 | item = null;
46 | return t;
47 | } finally {
48 | lock.unlock();
49 | }
50 | }
51 |
52 | public T peek() {
53 | return item;
54 | }
55 | }
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/android/LogLevel.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.android;
2 |
3 |
4 | /* compiled from: XLLog */
5 | enum LogLevel {
6 | LOG_LEVEL_VERBOSE(2),
7 | LOG_LEVEL_DEBUG(3),
8 | LOG_LEVEL_INFO(4),
9 | LOG_LEVEL_WARN(5),
10 | LOG_LEVEL_ERROR(6);
11 |
12 | private final int logLevel;
13 |
14 | private LogLevel(int i) {
15 | this.logLevel = i;
16 | }
17 |
18 | static LogLevel parseLevel(String str) {
19 | if (str.equals("e") || str.equals("error")) {
20 | return LOG_LEVEL_ERROR;
21 | }
22 | if (str.equals("w") || str.equals("warn")) {
23 | return LOG_LEVEL_WARN;
24 | }
25 | if (str.equals("i") || str.equals("info")) {
26 | return LOG_LEVEL_INFO;
27 | }
28 | if (str.equals("d") || str.equals("debug")) {
29 | return LOG_LEVEL_DEBUG;
30 | }
31 | return LOG_LEVEL_VERBOSE;
32 | }
33 |
34 | public final int getValue() {
35 | return this.logLevel;
36 | }
37 |
38 | public final String toString() {
39 | return toString(true);
40 | }
41 |
42 | public final String toString(boolean z) {
43 | switch (this) {
44 | case LOG_LEVEL_DEBUG:
45 | return z ? "D" : "DEBUG";
46 | case LOG_LEVEL_INFO:
47 | return z ? "I" : "INFO";
48 | case LOG_LEVEL_WARN:
49 | return z ? "W" : "WARN";
50 | case LOG_LEVEL_ERROR:
51 | return z ? "E" : "ERROR";
52 | default:
53 | if (z) {
54 | return "V";
55 | }
56 | return "VERBOSE";
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/CIDTaskParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class CIDTaskParam {
4 | public String mBcid;
5 | public String mCid;
6 | public int mCreateMode;
7 | public String mFileName;
8 | public String mFilePath;
9 | public long mFileSize;
10 | public String mGcid;
11 | public int mSeqId;
12 |
13 | public CIDTaskParam(String str, String str2, String str3, String str4, String str5, long j, int i, int i2) {
14 | this.mCid = str;
15 | this.mGcid = str2;
16 | this.mBcid = str3;
17 | this.mFilePath = str4;
18 | this.mFileName = str5;
19 | this.mFileSize = j;
20 | this.mCreateMode = i;
21 | this.mSeqId = i2;
22 | }
23 |
24 | public void setCid(String str) {
25 | this.mCid = str;
26 | }
27 |
28 | public void setGcid(String str) {
29 | this.mGcid = str;
30 | }
31 |
32 | public void setBcid(String str) {
33 | this.mBcid = str;
34 | }
35 |
36 | public void setFilePath(String str) {
37 | this.mFilePath = str;
38 | }
39 |
40 | public void setFileName(String str) {
41 | this.mFileName = str;
42 | }
43 |
44 | public void setFileSize(long j) {
45 | this.mFileSize = j;
46 | }
47 |
48 | public void setCreateMode(int i) {
49 | this.mCreateMode = i;
50 | }
51 |
52 | public void setSeqId(int i) {
53 | this.mSeqId = i;
54 | }
55 |
56 | public boolean checkMemberVar() {
57 | if (this.mCid == null || this.mGcid == null || this.mBcid == null || this.mFilePath == null || this.mFileName == null) {
58 | return false;
59 | }
60 | return true;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/utils/FragmentUtils.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.utils;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import com.ghost.thunder.ui.DownLoadListFragment;
6 | import com.ghost.thunder.ui.HomeFragment;
7 | import com.ghost.thunder.ui.UserFragment;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.WeakHashMap;
12 |
13 | /**
14 | * Created by wyt on 2018/8/9.
15 | */
16 |
17 | public class FragmentUtils {
18 |
19 | public static final int TYPE_HOME = 1;
20 | public static final int TYPE_FILE_LIST = 2;
21 | public static final int TYPE_USER = 3;
22 |
23 | private static WeakHashMap fragments = new WeakHashMap<>();
24 |
25 | public static Fragment getFragment(int type) {
26 | Fragment fragment = fragments.get("fragment:" + type);
27 | if(fragment != null) {
28 | return fragment;
29 | }
30 |
31 | switch (type) {
32 |
33 | case TYPE_HOME :
34 | fragment = new HomeFragment();
35 | break;
36 |
37 | case TYPE_FILE_LIST :
38 | fragment = new DownLoadListFragment();
39 | break;
40 |
41 | case TYPE_USER :
42 | fragment = new UserFragment();
43 | break;
44 |
45 | }
46 |
47 | if(fragment != null) {
48 | fragments.put("fragment:" + type, fragment);
49 | return fragment;
50 | }
51 |
52 | return null;
53 | }
54 |
55 | public static List getAllFragment() {
56 | List fragments = new ArrayList<>();
57 | fragments.add(getFragment(TYPE_HOME));
58 | fragments.add(getFragment(TYPE_FILE_LIST));
59 | fragments.add(getFragment(TYPE_USER));
60 | return fragments;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/Daemon.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import android.os.Looper;
4 |
5 | /**
6 | * 常驻的后台线程,用于处理一个消息循环
7 | *
8 | * 一般用于处理运算密集型任务、磁盘IO任务等执行时间小于1秒的任务
9 | *
10 | */
11 | public class Daemon {
12 | private static volatile boolean shouldStop;
13 | private static Thread thread = null;
14 | private static Looper looper = null;
15 |
16 | public static synchronized void start() {
17 | if (thread == null) {
18 | final BlockingItem bl = new BlockingItem();
19 | thread = new Thread(new Runnable() {
20 | @Override
21 | public void run() {
22 | Looper.prepare();
23 | Looper l = Looper.myLooper();
24 | bl.put(l);
25 |
26 | while (!shouldStop) {
27 | try {
28 | Looper.loop();
29 | } catch (Exception e) {
30 | }
31 | }
32 | }
33 | }, "daemon");
34 |
35 | shouldStop = false;
36 | thread.start();
37 | try {
38 | looper = bl.take();
39 | } catch (InterruptedException e) {
40 | }
41 | }
42 | }
43 |
44 | public static synchronized void stop() {
45 | shouldStop = true;
46 |
47 | if (thread != null && looper != null) {
48 | looper.quit();
49 | try {
50 | thread.join();
51 | } catch (Exception e) {
52 | }
53 | thread = null;
54 | looper = null;
55 | }
56 | }
57 |
58 | public static Looper looper() {
59 | if (looper == null) {
60 | start();
61 | }
62 | return looper == null ? Looper.getMainLooper() : looper;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/home_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
20 |
21 |
30 |
31 |
40 |
41 |
42 |
43 |
49 |
50 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/P2spTaskParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class P2spTaskParam {
4 | public String mCookie;
5 | public int mCreateMode;
6 | public String mFileName;
7 | public String mFilePath;
8 | public String mPass;
9 | public String mRefUrl;
10 | public int mSeqId;
11 | public String mUrl;
12 | public String mUser;
13 |
14 | public P2spTaskParam() {
15 | }
16 |
17 | public P2spTaskParam(String str, String str2, String str3, String str4, String str5, String str6, String str7, int i, int i2) {
18 | this.mFileName = str;
19 | this.mFilePath = str2;
20 | this.mUrl = str3;
21 | this.mCookie = str4;
22 | this.mRefUrl = str5;
23 | this.mUser = str6;
24 | this.mPass = str7;
25 | this.mCreateMode = i;
26 | this.mSeqId = i2;
27 | }
28 |
29 | public void setUrl(String str) {
30 | this.mUrl = str;
31 | }
32 |
33 | public void setFileName(String str) {
34 | this.mFileName = str;
35 | }
36 |
37 | public void setFilePath(String str) {
38 | this.mFilePath = str;
39 | }
40 |
41 | public void setCookie(String str) {
42 | this.mCookie = str;
43 | }
44 |
45 | public void setRefUrl(String str) {
46 | this.mRefUrl = str;
47 | }
48 |
49 | public void setUser(String str) {
50 | this.mUser = str;
51 | }
52 |
53 | public void setPass(String str) {
54 | this.mPass = str;
55 | }
56 |
57 | public void setCreateMode(int i) {
58 | this.mCreateMode = i;
59 | }
60 |
61 | public void setSeqId(int i) {
62 | this.mSeqId = i;
63 | }
64 |
65 | public boolean checkMemberVar() {
66 | if (this.mFileName == null || this.mFilePath == null || this.mUrl == null || this.mCookie == null || this.mRefUrl == null || this.mUser == null || this.mPass == null) {
67 | return false;
68 | }
69 | return true;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/adapter/DownLoadListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.adapter;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.support.v4.widget.CursorAdapter;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.ghost.thunder.demo.R;
12 |
13 | /**
14 | * Created by yuntao.wei on 2018/8/15.
15 | * github:https://github.com/YuntaoWei
16 | * blog:http://blog.csdn.net/qq_17541215
17 | */
18 |
19 | public class DownLoadListAdapter extends CursorAdapter {
20 |
21 | private LayoutInflater mInflater;
22 |
23 | public DownLoadListAdapter(Context context, Cursor c, boolean autoRequery) {
24 | super(context, c, autoRequery);
25 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
26 | }
27 |
28 | @Override
29 | public View newView(Context context, Cursor cursor, ViewGroup parent) {
30 | View v = mInflater.inflate(R.layout.download_list_item, null);
31 | ViewHolder vh = new ViewHolder();
32 | vh.tvFileName = (TextView)v.findViewById(R.id.filename);
33 | vh.tvProgress = (TextView)v.findViewById(R.id.progress);
34 | vh.tvSpeed = (TextView)v.findViewById(R.id.speed);
35 | vh.tvPath = (TextView)v.findViewById(R.id.path);
36 |
37 | v.setTag(vh);
38 | return v;
39 | }
40 |
41 | @Override
42 | public void bindView(View view, Context context, Cursor cursor) {
43 | ViewHolder vh = (ViewHolder) view.getTag();
44 | vh.tvFileName.setText(cursor.getString(1));
45 | vh.tvProgress.setText(cursor.getInt(4));
46 | vh.tvSpeed.setText("0");
47 | vh.tvPath.setText(cursor.getString(2));
48 | }
49 |
50 | class ViewHolder {
51 |
52 | public TextView tvFileName;
53 |
54 | public TextView tvProgress;
55 |
56 | public TextView tvSpeed;
57 |
58 | public TextView tvPath;
59 |
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/utils/LogPrinter.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by wyt on 2018/8/9.
7 | */
8 |
9 | public class LogPrinter {
10 |
11 | private static final int LOG_E_LEVEL = 5;
12 | private static final int LOG_D_LEVEL = 4;
13 | private static final int LOG_W_LEVEL = 3;
14 | private static final int LOG_I_LEVEL = 2;
15 | private static final int LOG_V_LEVEL = 1;
16 |
17 | private static final int LOG_DEFAULT_LEVEL = 2;
18 |
19 | public static void i(String tag, String msg) {
20 | if(LOG_I_LEVEL >= LOG_DEFAULT_LEVEL)
21 | Log.i(tag, msg);
22 | }
23 |
24 | public static void i_with_trace(String tag, String msg) {
25 | i(tag, msg + "\n" + Log.getStackTraceString(new Throwable()));
26 | }
27 |
28 | public static void w(String tag, String msg) {
29 | if(LOG_W_LEVEL >= LOG_DEFAULT_LEVEL)
30 | Log.w(tag, msg);
31 | }
32 |
33 | public static void w_with_trace(String tag, String msg) {
34 | w(tag, msg + "\n" + Log.getStackTraceString(new Throwable()));
35 | }
36 |
37 | public static void d(String tag, String msg) {
38 | if(LOG_D_LEVEL >= LOG_DEFAULT_LEVEL)
39 | Log.d(tag, msg);
40 | }
41 |
42 | public static void d_with_trace(String tag, String msg) {
43 | d(tag, msg + "\n" + Log.getStackTraceString(new Throwable()));
44 | }
45 |
46 | public static void e(String tag, String msg) {
47 | if(LOG_E_LEVEL >= LOG_DEFAULT_LEVEL)
48 | Log.e(tag, msg);
49 | }
50 |
51 | public static void e_with_trace(String tag, String msg) {
52 | e(tag, msg + "\n" + Log.getStackTraceString(new Throwable()));
53 | }
54 |
55 | public static void v(String tag, String msg) {
56 | if(LOG_V_LEVEL >= LOG_DEFAULT_LEVEL)
57 | Log.v(tag, msg);
58 | }
59 |
60 | public static void v_with_trace(String tag, String msg) {
61 | v(tag, msg + "\n" + Log.getStackTraceString(new Throwable()));
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/PeerResourceParam.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class PeerResourceParam {
4 | public int mCapabilityFlag;
5 | public int mInternalIp;
6 | public String mJmpKey;
7 | public String mPeerId;
8 | public int mResLevel;
9 | public int mResPriority;
10 | public int mResType;
11 | public int mTcpPort;
12 | public int mUdpPort;
13 | public long mUserId;
14 | public String mVipCdnAuth;
15 |
16 | public PeerResourceParam(String str, long j, String str2, String str3, int i, int i2, int i3, int i4, int i5, int i6, int i7) {
17 | this.mPeerId = str;
18 | this.mUserId = j;
19 | this.mJmpKey = str2;
20 | this.mVipCdnAuth = str3;
21 | this.mInternalIp = i;
22 | this.mTcpPort = i2;
23 | this.mUdpPort = i3;
24 | this.mResLevel = i4;
25 | this.mResPriority = i5;
26 | this.mCapabilityFlag = i6;
27 | this.mResType = i7;
28 | }
29 |
30 | public void setPeerId(String str) {
31 | this.mPeerId = str;
32 | }
33 |
34 | public void setUserId(long j) {
35 | this.mUserId = j;
36 | }
37 |
38 | public void setJmpKey(String str) {
39 | this.mJmpKey = str;
40 | }
41 |
42 | public void setVipCdnAuth(String str) {
43 | this.mVipCdnAuth = str;
44 | }
45 |
46 | public void setInternalIp(int i) {
47 | this.mInternalIp = i;
48 | }
49 |
50 | public void setTcpPort(int i) {
51 | this.mTcpPort = i;
52 | }
53 |
54 | public void setUdpPort(int i) {
55 | this.mUdpPort = i;
56 | }
57 |
58 | public void setResLevel(int i) {
59 | this.mResLevel = i;
60 | }
61 |
62 | public void setResPriority(int i) {
63 | this.mResPriority = i;
64 | }
65 |
66 | public void setCapabilityFlag(int i) {
67 | this.mCapabilityFlag = i;
68 | }
69 |
70 | public void setResType(int i) {
71 | this.mResType = i;
72 | }
73 |
74 | public boolean checkMemberVar() {
75 | if (this.mPeerId == null || this.mJmpKey == null || this.mVipCdnAuth == null) {
76 | return false;
77 | }
78 | return true;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/app/PermissionActivity.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.app;
2 |
3 | import android.Manifest;
4 | import android.content.pm.PackageManager;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.support.v7.app.AppCompatActivity;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by wyt on 2018/8/9.
16 | */
17 |
18 | public class PermissionActivity extends AppCompatActivity {
19 |
20 | boolean hasPermission = false;
21 | private static final int REQUEST_CODE = 0x1;
22 |
23 | private static String[] PERMISSIONS = {
24 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
25 | Manifest.permission.READ_EXTERNAL_STORAGE,
26 | Manifest.permission.INTERNET
27 | };
28 |
29 | @Override
30 | protected void onCreate(@Nullable Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
33 | hasPermission = grantAllPermission();
34 | } else {
35 | hasPermission = true;
36 | }
37 | }
38 |
39 | private boolean grantAllPermission() {
40 | ArrayList permission = new ArrayList<>();
41 | for (String p : PERMISSIONS
42 | ) {
43 | if(PackageManager.PERMISSION_GRANTED != checkSelfPermission(p)) {
44 | permission.add(p);
45 | }
46 | }
47 |
48 | if(permission.size() == 0)
49 | return true;
50 |
51 | grantPermission(permission);
52 | return false;
53 | }
54 |
55 | private void grantPermission(List permissions) {
56 | String[] needRequestPermissions = new String[permissions.size()];
57 | permissions.toArray(needRequestPermissions);
58 | requestPermissions(needRequestPermissions, REQUEST_CODE);
59 | }
60 |
61 | @Override
62 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
63 | for (int i : grantResults
64 | ) {
65 | if(i != PackageManager.PERMISSION_GRANTED) {
66 | onGotPermissionFailure();
67 | return;
68 | }
69 | }
70 |
71 | onGotPermissionSuccess();
72 | }
73 |
74 | void onGotPermissionSuccess() {}
75 |
76 | void onGotPermissionFailure() {}
77 |
78 | void showPermissionTips() {
79 |
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/ui/DownLoadListFragment.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.ui;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ListView;
12 |
13 | import com.ghost.thunder.adapter.DownLoadListAdapter;
14 | import com.ghost.thunder.app.MainActivity;
15 | import com.ghost.thunder.data.DownLoadDBUtil;
16 | import com.ghost.thunder.demo.R;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 | import butterknife.Unbinder;
21 |
22 | /**
23 | * Created by wyt on 2018/8/9.
24 | */
25 |
26 | public class DownLoadListFragment extends Fragment {
27 |
28 | private DownLoadDBUtil downLoadDBUtil;
29 |
30 | private Unbinder unbinder;
31 |
32 | MainActivity mainActivity;
33 |
34 | @BindView(R.id.download_list)
35 | ListView downloadList;
36 |
37 | DownLoadListAdapter mAdapter;
38 |
39 | @Override
40 | public void onAttach(Context context) {
41 | super.onAttach(context);
42 | mainActivity = (MainActivity) context;
43 | }
44 |
45 | @Override
46 | public void onCreate(@Nullable Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | init();
49 | }
50 |
51 | private void init() {
52 | downLoadDBUtil = DownLoadDBUtil.getInstance(getContext());
53 | }
54 |
55 | @Nullable
56 | @Override
57 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
58 | View v = inflater.inflate(R.layout.download_fragment_layout, null);
59 | unbinder = ButterKnife.bind(this, v);
60 | return v;
61 | }
62 |
63 | @Override
64 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
65 | super.onViewCreated(view, savedInstanceState);
66 | initView();
67 | }
68 |
69 | private void initView() {
70 | Cursor c = downLoadDBUtil.queryAll();
71 | mAdapter = new DownLoadListAdapter(getContext(), c, false);
72 | downloadList.setAdapter(mAdapter);
73 | }
74 |
75 | @Override
76 | public void onDestroyView() {
77 | super.onDestroyView();
78 | unbinder.unbind();
79 | }
80 |
81 | @Override
82 | public void onDestroy() {
83 | super.onDestroy();
84 | release();
85 | }
86 |
87 | private void release() {
88 | downLoadDBUtil.release();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/app/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.app;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.ViewPager;
5 | import android.support.v7.widget.Toolbar;
6 | import android.widget.Button;
7 |
8 | import com.ghost.thunder.adapter.MyPageAdapter;
9 | import com.ghost.thunder.demo.R;
10 | import com.ghost.thunder.utils.FragmentUtils;
11 |
12 | import butterknife.BindView;
13 | import butterknife.ButterKnife;
14 | import butterknife.Unbinder;
15 |
16 | /**
17 | * Created by yuntao.wei on 2018/8/9.
18 | * github:https://github.com/YuntaoWei
19 | * blog:http://blog.csdn.net/qq_17541215
20 | */
21 |
22 | public class BaseActivity extends PermissionActivity {
23 |
24 | static final String TAG = "BaseActivity";
25 |
26 | @BindView(R.id.top_tool)
27 | Toolbar topTool;
28 |
29 | @BindView(R.id.view_pager)
30 | ViewPager viewPager;
31 |
32 | @BindView(R.id.btn_home)
33 | Button btnHome;
34 |
35 | @BindView(R.id.btn_download_list)
36 | Button btnList;
37 |
38 | @BindView(R.id.btn_user)
39 | Button btnUser;
40 |
41 | int currentType;
42 | MyPageAdapter pageAdapter;
43 |
44 | private Unbinder unbinder;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_main);
50 | if(hasPermission) {
51 | init();
52 | initView();
53 | }
54 | }
55 |
56 | private void init() {
57 | unbinder = ButterKnife.bind(this);
58 | }
59 |
60 | private void initView() {
61 | setSupportActionBar(topTool);
62 |
63 | pageAdapter = new MyPageAdapter(getSupportFragmentManager());
64 | pageAdapter.setFragment(FragmentUtils.getAllFragment());
65 | viewPager.setAdapter(pageAdapter);
66 | viewPager.setCurrentItem(0);
67 | }
68 |
69 | protected void changeButtonStyle(int type) {
70 | switch (type) {
71 |
72 | case FragmentUtils.TYPE_HOME :
73 |
74 | break;
75 |
76 | case FragmentUtils.TYPE_FILE_LIST :
77 |
78 | break;
79 |
80 | case FragmentUtils.TYPE_USER :
81 |
82 | break;
83 |
84 | }
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | super.onDestroy();
90 | unbinder.unbind();
91 | }
92 |
93 | void onGotPermissionSuccess() {
94 | init();
95 | initView();
96 | }
97 |
98 | void onGotPermissionFailure() {
99 | showPermissionTips();
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/data/DownLoadDBUtil.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.data;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 |
8 | /**
9 | * Created by yuntao.wei on 2018/8/15.
10 | * github:https://github.com/YuntaoWei
11 | * blog:http://blog.csdn.net/qq_17541215
12 | */
13 |
14 | public class DownLoadDBUtil {
15 |
16 | private static DownLoadDBUtil mInstance;
17 | private DownLoadDataBase dataBase;
18 | private SQLiteDatabase db;
19 |
20 | private DownLoadDBUtil(Context ctx) {
21 | dataBase = new DownLoadDataBase(ctx);
22 | }
23 |
24 | public static DownLoadDBUtil getInstance(Context ctx) {
25 | if(mInstance == null)
26 | mInstance = new DownLoadDBUtil(ctx);
27 |
28 | return mInstance;
29 | }
30 |
31 | private void checkEnvironment() {
32 | if(db == null)
33 | db = dataBase.getWritableDatabase();
34 | }
35 |
36 | public long insert(ContentValues values) {
37 | checkEnvironment();
38 | return db.insert(DownLoadDataBase.DOWNLOAD_TABLE_NAME, null, values);
39 | }
40 |
41 | public int deleteById(int id) {
42 | checkEnvironment();
43 | return db.delete(DownLoadDataBase.DOWNLOAD_TABLE_NAME,
44 | DownLoadDataBaseColumns.ID +" = " + id, null);
45 | }
46 |
47 | public int deleteByName(String name) {
48 | checkEnvironment();
49 | return db.delete(DownLoadDataBase.DOWNLOAD_TABLE_NAME,
50 | DownLoadDataBaseColumns.NAME + " = " + name, null);
51 | }
52 |
53 | public int updateById(int id, ContentValues cv) {
54 | checkEnvironment();
55 | return db.update(DownLoadDataBase.DOWNLOAD_TABLE_NAME, cv,
56 | DownLoadDataBaseColumns.ID + "=" + id, null);
57 | }
58 |
59 | public int updateByName(String name, ContentValues cv) {
60 | checkEnvironment();
61 | return db.update(DownLoadDataBase.DOWNLOAD_TABLE_NAME, cv,
62 | DownLoadDataBaseColumns.NAME + "=" + name, null);
63 | }
64 |
65 | public Cursor queryAll() {
66 | checkEnvironment();
67 | return db.query(DownLoadDataBase.DOWNLOAD_TABLE_NAME,
68 | null, null, null, null, null, null);
69 | }
70 |
71 | public Cursor rawQuery(String sql, String[] args) {
72 | checkEnvironment();
73 | return db.rawQuery(sql, args);
74 | }
75 |
76 | public void execSql(String sql) {
77 | checkEnvironment();
78 | db.execSQL(sql);
79 | }
80 |
81 | public void release() {
82 | if(db != null)
83 | db.close();
84 | db = null;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
19 |
20 |
26 |
27 |
32 |
33 |
45 |
46 |
58 |
59 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/LinuxFileCommand.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * File operators. Like: delete, create, move...
7 | * Use linux shell to implement these operators.
8 | * So, only for linux like operator system.
9 | * All return the execute process, and if the requested program can not be executed,
10 | * may throws IOException.
11 | * And all files or diretorys String parameters are absolute path.
12 | * The return new {@code Process} object that represents the native process.
13 | * */
14 | public class LinuxFileCommand {
15 | public final Runtime shell;
16 | //private static final int c = 0;
17 | /**
18 | * Constructor. /data/busybox/
19 | * @param
20 | * */
21 | public LinuxFileCommand(Runtime runtime) {
22 | // TODO Auto-generated constructor stub
23 | shell = runtime;
24 | }
25 |
26 | /** Delete {@code file} file, nerver prompt*/
27 | public final Process deleteFile(String file) throws IOException{
28 | String[] cmds = {"rm", file};
29 | return shell.exec(cmds);
30 | }
31 |
32 | public final Process delete(String file) throws IOException {
33 | String[] cmds = {"rm", "-r", file};
34 | return shell.exec(cmds);
35 | }
36 |
37 | public final Process deleteMult(String[] cmds) throws IOException{
38 | return shell.exec(cmds);
39 | }
40 |
41 | /** Delete {@code dire} directory, nerver prompt*/
42 | public final Process deleteDirectory(String dire) throws IOException{
43 | String[] cmds = {"rm", "-r", dire};
44 | return shell.exec(cmds);
45 | }
46 |
47 | /** Create {@code file} file, if file has already exist, update the
48 | * file access and modification time to current time.
49 | * @throws IOException
50 | * */
51 | public final Process createFile(String file) throws IOException {
52 | String[] cmds = {"touch", file};
53 | return shell.exec(cmds);
54 | }
55 |
56 | /** Create directory. If parent path is not existed, also create parent directory
57 | * @throws IOException */
58 | public final Process createDirectory(String dire) throws IOException{
59 | String[] cmds = {"mkdir", dire};
60 | return shell.exec(cmds);
61 | }
62 |
63 | /** Move or rename(if they in the same directory) file or directory
64 | * @throws IOException */
65 | public final Process moveFile(String src, String dir) throws IOException{
66 | String[] cmds = {"mv", src, dir};
67 | return shell.exec(cmds);
68 | }
69 |
70 | /** Copy file
71 | * @throws IOException */
72 | public final Process copyFile(String src, String dir) throws IOException{
73 | String[] cmds = {"cp", "-r", src, dir};
74 | return shell.exec(cmds);
75 | }
76 |
77 | /**`
78 | * File soft Link
79 | * @throws IOException
80 | * */
81 | public final Process linkFile(String src, String dir) throws IOException{
82 | String[] cmds = {"ln", "-l", src, dir};
83 | return shell.exec(cmds);
84 | }
85 |
86 |
87 | public final Process du_s(String file) throws IOException{
88 | String[] cmds = {"du", "-s", file};
89 | return shell.exec(cmds);
90 | }
91 |
92 | public final Process ls_lhd(String file) throws IOException{
93 | String[] cmds = {"ls", "-l", file};
94 | return shell.exec(cmds);
95 | }
96 |
97 | public final Process ls_Directory(String directory) throws IOException{
98 | if (directory.equals("/"))
99 | directory = "";
100 | String[] cmds = {"ls", "-a", directory};
101 | return shell.exec(cmds);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/android/XLLog.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.android;
2 |
3 | import android.os.Environment;
4 | import android.util.Log;
5 | import java.io.File;
6 |
7 | public class XLLog {
8 | private static LogConfig mLogConfig = null;
9 | private static XLLogInternal mXLLogInternal;
10 |
11 | @Deprecated
12 | public static boolean init(String str) {
13 | return init();
14 | }
15 |
16 | public static synchronized boolean init() {
17 | synchronized (XLLog.class) {
18 | if (mLogConfig == null) {
19 | File file = new File(Environment.getExternalStorageDirectory().getPath(), "xunlei_ds_log.ini");
20 | if (file.exists()) {
21 | LogConfig logConfig = new LogConfig(file.getPath());
22 | mLogConfig = logConfig;
23 | if (logConfig.canLogToFile()) {
24 | mXLLogInternal = new XLLogInternal(mLogConfig);
25 | }
26 | }
27 | }
28 | }
29 | return true;
30 | }
31 |
32 | public static void i(String str, String str2) {
33 | log(LogLevel.LOG_LEVEL_INFO, str, str2);
34 | }
35 |
36 | public static void d(String str, String str2) {
37 | log(LogLevel.LOG_LEVEL_DEBUG, str, str2);
38 | }
39 |
40 | public static void w(String str, String str2) {
41 | log(LogLevel.LOG_LEVEL_WARN, str, str2);
42 | }
43 |
44 | public static void e(String str, String str2) {
45 | log(LogLevel.LOG_LEVEL_ERROR, str, str2);
46 | }
47 |
48 | public static void w(String str, String str2, Throwable th) {
49 | log(LogLevel.LOG_LEVEL_WARN, str, str2 + ": " + th);
50 | }
51 |
52 | public static void v(String str, String str2) {
53 | d(str, str2);
54 | }
55 |
56 | public static void wtf(String str, String str2, Throwable th) {
57 | log(LogLevel.LOG_LEVEL_WARN, str, str2 + ": " + th);
58 | }
59 |
60 | public static boolean canbeLog(LogLevel logLevel) {
61 | return mXLLogInternal != null;
62 | }
63 |
64 | static void log(LogLevel logLevel, String str, String str2) {
65 | Object obj = null;
66 | if (logLevel == LogLevel.LOG_LEVEL_ERROR || (mLogConfig != null && mLogConfig.canLogToLogCat())) {
67 | obj = 1;
68 | }
69 | if (obj != null || mXLLogInternal != null) {
70 | String formatMessage = formatMessage(logLevel, str, str2);
71 | if (obj != null) {
72 | Log.println(logLevel.getValue(), str, formatMessage);
73 | }
74 | if (mXLLogInternal != null) {
75 | mXLLogInternal.log(logLevel, str, formatMessage);
76 | }
77 | }
78 | }
79 |
80 | public static void printStackTrace(Throwable th) {
81 | if (mXLLogInternal != null) {
82 | mXLLogInternal.printStackTrace(th);
83 | }
84 | }
85 |
86 | private static String formatMessage(LogLevel logLevel, String str, String str2) {
87 | StringBuilder stringBuilder = new StringBuilder(str2 + "\t");
88 | try {
89 | StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
90 | if (stackTrace.length > 5) {
91 | StackTraceElement stackTraceElement = stackTrace[5];
92 | stringBuilder.append("[" + stackTraceElement.getFileName() + ":");
93 | stringBuilder.append(stackTraceElement.getLineNumber() + "]");
94 | } else {
95 | stringBuilder.append("[stack=" + stackTrace.length + "]");
96 | }
97 | } catch (Exception e) {
98 | }
99 | return stringBuilder.toString();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/android/LogConfig.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.android;
2 |
3 | import android.text.TextUtils;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /* compiled from: XLLog */
10 | final class LogConfig {
11 | private final int mDestinationType;
12 | final String mFileName;
13 | final LogLevel mLevel;
14 | final String mLogDir;
15 | final long mLogSize;
16 |
17 | public LogConfig(String str) {
18 | Map parseConfigFile = parseConfigFile(str);
19 | long parseLong = Long.parseLong(getOrDefault(parseConfigFile, "LOG_FILE_SIZE", "0"));
20 | if (parseLong == 0) {
21 | parseLong = 20971520;
22 | }
23 | this.mLogSize = parseLong;
24 | this.mLevel = LogLevel.parseLevel(getOrDefault(parseConfigFile, "LOG_LEVEL", "").toLowerCase());
25 | this.mFileName = getOrDefault(parseConfigFile, "LOG_FILE", "");
26 | this.mLogDir = getOrDefault(parseConfigFile, "LOG_DIR", "");
27 | if (TextUtils.isEmpty(this.mFileName) || TextUtils.isEmpty(this.mLogDir)) {
28 | this.mDestinationType = 0;
29 | return;
30 | }
31 | int parseInt = Integer.parseInt(getOrDefault(parseConfigFile, "LOG_DESTINATION_TYPE", "0"));
32 | if (parseInt > 0) {
33 | this.mDestinationType = parseInt;
34 | } else {
35 | this.mDestinationType = 3;
36 | }
37 | }
38 |
39 | public final boolean canLogToFile() {
40 | return (this.mDestinationType & 1) > 0;
41 | }
42 |
43 | public final boolean canLogToLogCat() {
44 | return (this.mDestinationType & 2) > 0;
45 | }
46 |
47 | private String getOrDefault(Map map, String str, String str2) {
48 | String str3 = (String) map.get(str);
49 | return str3 == null ? str2 : str3;
50 | }
51 |
52 | private Map parseConfigFile(String str) {
53 | File file = new File(str);
54 | Map hashMap = new HashMap();
55 | if (file.exists()) {
56 | try {
57 | FileInputStream fileInputStream = new FileInputStream(file);
58 | String str2 = "";
59 | StringBuilder stringBuilder = new StringBuilder();
60 | StringBuilder stringBuilder2 = new StringBuilder();
61 | while (true) {
62 | int read = fileInputStream.read();
63 | if (read != -1) {
64 | if (stringBuilder.length() == 0 && read == 35) {
65 | do {
66 | read = fileInputStream.read();
67 | if (read == -1 || read == 13) {
68 | break;
69 | }
70 | } while (read != 10);
71 | } else if (!(read == 32 || read == 9)) {
72 | if (read == 61) {
73 | str2 = stringBuilder.toString();
74 | } else if (read == 10 || read == 13) {
75 | if (stringBuilder.length() != 0) {
76 | hashMap.put(str2, stringBuilder2.toString());
77 | str2 = "";
78 | stringBuilder = new StringBuilder();
79 | stringBuilder2 = new StringBuilder();
80 | }
81 | } else if (str2.length() == 0) {
82 | stringBuilder.append((char) read);
83 | } else {
84 | stringBuilder2.append((char) read);
85 | }
86 | }
87 | } else {
88 | break;
89 | }
90 | }
91 | fileInputStream.close();
92 | } catch (Exception e) {
93 | e.printStackTrace();
94 | }
95 | }
96 | return hashMap;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskInfo.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.os.Parcelable.Creator;
6 |
7 | public class XLTaskInfo implements Parcelable {
8 | public static final Creator CREATOR = new Creator() {
9 | public final XLTaskInfo createFromParcel(Parcel parcel) {
10 | return new XLTaskInfo(parcel);
11 | }
12 |
13 | public final XLTaskInfo[] newArray(int i) {
14 | return new XLTaskInfo[i];
15 | }
16 | };
17 | public int mAddedHighSourceState;
18 | public int mAdditionalResCount;
19 | public long mAdditionalResDCDNBytes;
20 | public long mAdditionalResDCDNSpeed;
21 | public long mAdditionalResPeerBytes;
22 | public long mAdditionalResPeerSpeed;
23 | public int mAdditionalResType;
24 | public long mAdditionalResVipRecvBytes;
25 | public long mAdditionalResVipSpeed;
26 | public String mCid;
27 | public long mDownloadSize;
28 | public long mDownloadSpeed;
29 | public int mErrorCode;
30 | public String mFileName;
31 | public long mFileSize;
32 | public String mGcid;
33 | public int mInfoLen;
34 | public long mOriginRecvBytes;
35 | public long mOriginSpeed;
36 | public long mP2PRecvBytes;
37 | public long mP2PSpeed;
38 | public long mP2SRecvBytes;
39 | public long mP2SSpeed;
40 | public int mQueryIndexStatus;
41 | public long mTaskId;
42 | public int mTaskStatus;
43 |
44 | public int describeContents() {
45 | return 0;
46 | }
47 |
48 | public void writeToParcel(Parcel parcel, int i) {
49 | parcel.writeLong(this.mTaskId);
50 | parcel.writeString(this.mFileName);
51 | parcel.writeInt(this.mInfoLen);
52 | parcel.writeInt(this.mTaskStatus);
53 | parcel.writeInt(this.mErrorCode);
54 | parcel.writeLong(this.mFileSize);
55 | parcel.writeLong(this.mDownloadSize);
56 | parcel.writeLong(this.mDownloadSpeed);
57 | parcel.writeInt(this.mQueryIndexStatus);
58 | parcel.writeString(this.mCid);
59 | parcel.writeString(this.mGcid);
60 | parcel.writeLong(this.mOriginSpeed);
61 | parcel.writeLong(this.mOriginRecvBytes);
62 | parcel.writeLong(this.mP2SSpeed);
63 | parcel.writeLong(this.mP2SRecvBytes);
64 | parcel.writeLong(this.mP2PSpeed);
65 | parcel.writeLong(this.mP2PRecvBytes);
66 | parcel.writeInt(this.mAdditionalResCount);
67 | parcel.writeInt(this.mAdditionalResType);
68 | parcel.writeLong(this.mAdditionalResVipSpeed);
69 | parcel.writeLong(this.mAdditionalResVipRecvBytes);
70 | parcel.writeLong(this.mAdditionalResPeerSpeed);
71 | parcel.writeLong(this.mAdditionalResPeerBytes);
72 | }
73 |
74 | public XLTaskInfo() {
75 | }
76 |
77 | public XLTaskInfo(Parcel parcel) {
78 | this.mTaskId = parcel.readLong();
79 | this.mFileName = parcel.readString();
80 | this.mInfoLen = parcel.readInt();
81 | this.mTaskStatus = parcel.readInt();
82 | this.mErrorCode = parcel.readInt();
83 | this.mFileSize = parcel.readLong();
84 | this.mDownloadSize = parcel.readLong();
85 | this.mDownloadSpeed = parcel.readLong();
86 | this.mQueryIndexStatus = parcel.readInt();
87 | this.mCid = parcel.readString();
88 | this.mGcid = parcel.readString();
89 | this.mOriginSpeed = parcel.readLong();
90 | this.mOriginRecvBytes = parcel.readLong();
91 | this.mP2SSpeed = parcel.readLong();
92 | this.mP2SRecvBytes = parcel.readLong();
93 | this.mP2PSpeed = parcel.readLong();
94 | this.mP2PRecvBytes = parcel.readLong();
95 | this.mAdditionalResCount = parcel.readInt();
96 | this.mAdditionalResType = parcel.readInt();
97 | this.mAdditionalResVipSpeed = parcel.readLong();
98 | this.mAdditionalResVipRecvBytes = parcel.readLong();
99 | this.mAdditionalResPeerSpeed = parcel.readLong();
100 | this.mAdditionalResPeerBytes = parcel.readLong();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/utils/StorageUtils.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.os.Environment;
6 | import android.text.TextUtils;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.File;
10 | import java.io.FileInputStream;
11 | import java.io.FileNotFoundException;
12 | import java.io.IOException;
13 | import java.io.InputStreamReader;
14 |
15 | /**
16 | * Created by yuntao.wei on 2018/8/9.
17 | * github:https://github.com/YuntaoWei
18 | * blog:http://blog.csdn.net/qq_17541215
19 | */
20 |
21 | public class StorageUtils {
22 |
23 | private static final String TAG = "StorageUtils";
24 |
25 | private static final String DEFAULT_PATH = File.separator + "BtPlayer" + File.separator + "download";
26 | private static final String STORAGE_PREF_FILE_NAME = "storage";
27 | private static final String PATH = "path";
28 |
29 | public static String getDefaultSavePath(Context ctx) {
30 | SharedPreferences sp = ctx.getSharedPreferences(STORAGE_PREF_FILE_NAME, Context.MODE_PRIVATE);
31 | String path = sp.getString(PATH, null);
32 | if(!TextUtils.isEmpty(path)) {
33 | return path;
34 | }
35 |
36 | File f = new File(Environment.getExternalStorageDirectory().toString() + DEFAULT_PATH);
37 | if(!f.exists()) {
38 | if(!f.mkdirs()) {
39 | return Environment.getExternalStorageDirectory().toString() + File.separator;
40 | }
41 |
42 | }
43 |
44 | return Environment.getExternalStorageDirectory().toString() + DEFAULT_PATH;
45 | }
46 |
47 | public static boolean changeSavePath(Context ctx, String path) {
48 | File f = new File(path);
49 |
50 | if(!f.exists()) {
51 | if(!f.mkdirs()) {
52 | return false;
53 | }
54 | }
55 |
56 | SharedPreferences sp = ctx.getSharedPreferences(STORAGE_PREF_FILE_NAME, Context.MODE_PRIVATE);
57 | sp.edit().putString(PATH, path).apply();
58 |
59 | return true;
60 | }
61 |
62 | public static String convertFileSize(long size) {
63 | long kb = 1024;
64 | long mb = kb * 1024;
65 | long gb = mb * 1024;
66 |
67 | if (size >= gb) {
68 | return String.format("%.1f GB", (float) size / gb);
69 | } else if (size >= mb) {
70 | float f = (float) size / mb;
71 | return String.format(f > 100 ? "%.0f M" : "%.1f M", f);
72 | } else if (size >= kb) {
73 | float f = (float) size / kb;
74 | return String.format(f > 100 ? "%.0f K" : "%.1f K", f);
75 | } else
76 | return String.format("%d B", size);
77 | }
78 |
79 | public static boolean isTorrentFile(String path) {
80 | File f = new File(path);
81 | BufferedReader br = null;
82 | if(f.exists()) {
83 | try {
84 | br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
85 | String msg = br.readLine();
86 | LogPrinter.i(TAG, "isTorrentFile : " + path + " \n" + msg);
87 | if(!TextUtils.isEmpty(msg) && msg.contains("//tracker")) {
88 | return true;
89 | }
90 | } catch (FileNotFoundException e) {
91 | e.printStackTrace();
92 | } catch (IOException e) {
93 | e.printStackTrace();
94 | } finally {
95 | if(br != null) {
96 | try {
97 | br.close();
98 | } catch (IOException e) {
99 | e.printStackTrace();
100 | }
101 | br = null;
102 | }
103 | }
104 | }
105 |
106 | return false;
107 | }
108 |
109 | public static boolean isCanPlay(long totalSize, long downloadSize) {
110 | if(totalSize <= 0)
111 | return false;
112 |
113 | float rate = (downloadSize * 1.0f) / (totalSize * 1.0f);
114 |
115 | if(downloadSize >= 1024 * 1024 * 50 || rate > 0.5f) {
116 | return true;
117 | }
118 |
119 | return false;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/android/XLLogInternal.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.android;
2 |
3 | import android.os.Environment;
4 | import android.os.Handler;
5 | import android.os.HandlerThread;
6 | import java.io.BufferedWriter;
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.FileWriter;
10 | import java.io.IOException;
11 | import java.io.PrintWriter;
12 | import java.io.Writer;
13 | import java.text.SimpleDateFormat;
14 | import java.util.Date;
15 |
16 | /* compiled from: XLLog */
17 | final class XLLogInternal {
18 | private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
19 | private File mFile;
20 | private final Handler mHandler;
21 | private final LogConfig mLogConfig;
22 | private int mNext;
23 | private int mRun;
24 |
25 | XLLogInternal(LogConfig logConfig) {
26 | this.mLogConfig = logConfig;
27 | HandlerThread handlerThread = new HandlerThread("DownloadLib-XLLog");
28 | handlerThread.start();
29 | this.mHandler = new Handler(handlerThread.getLooper());
30 | }
31 |
32 | final void log(final LogLevel logLevel, final String str, String str2) {
33 | final String appendHeader = appendHeader(logLevel, str, str2);
34 | if (logLevel.getValue() >= this.mLogConfig.mLevel.getValue() && this.mLogConfig.canLogToFile()) {
35 | this.mHandler.post(new Runnable() {
36 | public void run() {
37 | XLLogInternal.this.logfile(logLevel, str, appendHeader);
38 | }
39 | });
40 | }
41 | }
42 |
43 | public final void printStackTrace(final Throwable th) {
44 | this.mHandler.post(new Runnable() {
45 | public void run() {
46 | try {
47 | Writer fileWriter = new FileWriter(XLLogInternal.this.getLogFile(), true);
48 | Writer bufferedWriter = new BufferedWriter(fileWriter);
49 | th.printStackTrace(new PrintWriter(bufferedWriter));
50 | bufferedWriter.write("\n");
51 | bufferedWriter.close();
52 | fileWriter.close();
53 | } catch (IOException e) {
54 | e.printStackTrace();
55 | }
56 | }
57 | });
58 | }
59 |
60 | private static String appendHeader(LogLevel logLevel, String str, String str2) {
61 | StringBuilder stringBuilder = new StringBuilder();
62 | stringBuilder.append(DATEFORMAT.format(new Date()) + ": " + logLevel.toString());
63 | stringBuilder.append("/" + str + "(" + Thread.currentThread().getId() + "):\t");
64 | stringBuilder.append(str2);
65 | stringBuilder.append("\r\n");
66 | return stringBuilder.toString();
67 | }
68 |
69 | private void logfile(LogLevel logLevel, String str, String str2) {
70 | try {
71 | Writer fileWriter = new FileWriter(getLogFile(), true);
72 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
73 | bufferedWriter.write(str2);
74 | bufferedWriter.newLine();
75 | bufferedWriter.close();
76 | fileWriter.close();
77 | } catch (Exception e) {
78 | }
79 | }
80 |
81 | private File getLogFile() {
82 | if ("mounted".equalsIgnoreCase(Environment.getExternalStorageState())) {
83 | File file = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + this.mLogConfig.mLogDir);
84 | if (!file.exists()) {
85 | file.mkdirs();
86 | }
87 | while (this.mFile == null) {
88 | this.mFile = new File(file.getPath() + File.separator + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".R" + this.mRun + ".0." + this.mLogConfig.mFileName);
89 | if (!this.mFile.exists()) {
90 | break;
91 | }
92 | this.mRun++;
93 | this.mFile = null;
94 | }
95 | if (getLogFileSize() >= this.mLogConfig.mLogSize) {
96 | this.mNext++;
97 | this.mFile = new File(file.getPath() + File.separator + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".R" + this.mRun + "." + this.mNext + "." + this.mLogConfig.mFileName);
98 | this.mFile.delete();
99 | }
100 | }
101 | return this.mFile;
102 | }
103 |
104 | private long getLogFileSize() {
105 | long j = -1;
106 | if (this.mFile == null) {
107 | return -1;
108 | }
109 | try {
110 | FileInputStream fileInputStream = new FileInputStream(this.mFile);
111 | j = (long) fileInputStream.available();
112 | fileInputStream.close();
113 | return j;
114 | } catch (Exception e) {
115 | return j;
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/ui/HomeFragment.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.ui;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.text.TextUtils;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 | import android.widget.VideoView;
15 |
16 | import com.ghost.thunder.app.MainActivity;
17 | import com.ghost.thunder.demo.R;
18 | import com.ghost.thunder.download.DownLoadProgressListener;
19 | import com.ghost.thunder.download.DownLoadUtil;
20 | import com.ghost.thunder.utils.LogPrinter;
21 | import com.ghost.thunder.utils.StorageUtils;
22 | import com.ghost.thunder.utils.UrlType;
23 | import com.ghost.thunder.utils.UrlUtils;
24 |
25 | import butterknife.BindView;
26 | import butterknife.ButterKnife;
27 | import butterknife.OnClick;
28 | import butterknife.Unbinder;
29 |
30 | /**
31 | * Created by wyt on 2018/8/9.
32 | */
33 |
34 | public class HomeFragment extends Fragment implements DownLoadProgressListener {
35 |
36 | private static final String TAG = "HomeFragment";
37 |
38 | private Unbinder unbinder;
39 |
40 | @BindView(R.id.et_url)
41 | EditText etUrl;
42 |
43 | @BindView(R.id.btn_download)
44 | Button btnDownload;
45 |
46 | @BindView(R.id.btn_select_file)
47 | Button btnSelectFile;
48 |
49 | DownLoadUtil downLoadUtil;
50 |
51 | MainActivity mainActivity;
52 |
53 | @BindView(R.id.video_view)
54 | VideoView mVideoView;
55 |
56 | boolean canPlay = false;
57 |
58 | boolean isTorrent = false;
59 |
60 | @Override
61 | public void onAttach(Context context) {
62 | super.onAttach(context);
63 | mainActivity = (MainActivity) context;
64 | }
65 |
66 | @Nullable
67 | @Override
68 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
69 | View v = inflater.inflate(R.layout.home_layout, null);
70 | unbinder = ButterKnife.bind(this, v);
71 | return v;
72 | }
73 |
74 | @Override
75 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
76 | super.onViewCreated(view, savedInstanceState);
77 | }
78 |
79 | @OnClick(R.id.btn_download)
80 | public void onDonwloadButtonClicked() {
81 | String url = etUrl.getText().toString();
82 | LogPrinter.i(TAG, "onDonwloadButtonClicked : " + url);
83 | if(TextUtils.isEmpty(url)) {
84 | Toast.makeText(getContext(), R.string.url_is_null, Toast.LENGTH_SHORT).show();
85 | return;
86 | }
87 |
88 | if(!UrlUtils.isValidUrl(url)) {
89 | Toast.makeText(getContext(), R.string.url_format_error, Toast.LENGTH_SHORT).show();
90 | return;
91 | }
92 |
93 | startDownloadTask(url);
94 | }
95 |
96 | @OnClick(R.id.btn_select_file)
97 | public void startSelectTorrentFile() {
98 | if(canPlay) {
99 | LogPrinter.i(TAG, "can play!");
100 | } else {
101 | LogPrinter.i(TAG, "can not play!");
102 | }
103 | }
104 |
105 | private void checkDonwloadUtil() {
106 | if(downLoadUtil == null)
107 | downLoadUtil = DownLoadUtil.getInstance(getContext().getApplicationContext());
108 | }
109 |
110 | private void startDownloadTask(String url) {
111 | checkDonwloadUtil();
112 | try {
113 | downLoadUtil.getTaskInfo(url);
114 |
115 | downLoadUtil.startDownLoad(url, this);
116 | LogPrinter.i(TAG, "url is valid");
117 | } catch (Exception e) {
118 | e.printStackTrace();
119 | Toast.makeText(getContext(), R.string.task_error, Toast.LENGTH_SHORT).show();
120 | }
121 | }
122 |
123 | @Override
124 | public void onDestroyView() {
125 | super.onDestroyView();
126 | unbinder.unbind();
127 | }
128 |
129 | @Override
130 | public void onDestroy() {
131 | super.onDestroy();
132 | if(downLoadUtil != null) {
133 | downLoadUtil.stopTask();
134 | }
135 | }
136 |
137 | @Override
138 | public void onProgressChange(String totalSize, String downloadedSize, String downSpeed) {
139 | LogPrinter.i(TAG, "onProgressChange : " + totalSize + " " +
140 | downloadedSize + " " + downSpeed + " " + Thread.currentThread().getName());
141 | }
142 |
143 | @Override
144 | public void onProgressChangeRealSize(long totalSize, long downloadedSize, long downSpeed) {
145 | if(StorageUtils.isCanPlay(totalSize, downloadedSize))
146 | canPlay = true;
147 | else
148 | canPlay = false;
149 | }
150 |
151 | @Override
152 | public void onDonwloadEnd(String filePath) {
153 | LogPrinter.i(TAG, "onDonwloadEnd -- > end file : " +
154 | filePath + " currentThread : " + Thread.currentThread().getName());
155 | if(StorageUtils.isTorrentFile(filePath)) {
156 | LogPrinter.i(TAG,"onDonwloadEnd is a torrent file, start new torrent task!");
157 | startDownloadTask(filePath);
158 | } else {
159 | LogPrinter.i(TAG,"onDonwloadEnd success");
160 | }
161 | }
162 |
163 | @Override
164 | public void onTaskStart(String fileName) {
165 | LogPrinter.i(TAG, "OnTaskStart : " + fileName);
166 | if(UrlType.isTorrentUrl(fileName)) {
167 | isTorrent = true;
168 | } else {
169 | isTorrent = false;
170 | }
171 |
172 | }
173 |
174 | }
175 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/XLAppKeyChecker.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import android.content.Context;
4 | import android.util.Base64;
5 | import com.xunlei.downloadlib.android.XLLog;
6 | import com.xunlei.downloadlib.android.XLUtil;
7 | import java.io.UnsupportedEncodingException;
8 | import java.text.ParseException;
9 | import java.text.SimpleDateFormat;
10 | import java.util.Calendar;
11 | import java.util.Date;
12 | import java.util.Locale;
13 |
14 | public class XLAppKeyChecker {
15 | private static final byte APPTYPE_PRODUCT = (byte) 1;
16 | private static final String TAG = "XLAppKeyChecker";
17 | private short mAppId = (short) 0;
18 | private String mAppKey = "";
19 | private Context mContext = null;
20 | private String mPackageName = "";
21 |
22 | private class AppKeyEntity {
23 | private String MD5;
24 | private RawItemsEntity mItemsEntity;
25 | private String mRawItems;
26 |
27 | private AppKeyEntity() {
28 | this.mRawItems = "";
29 | this.MD5 = "";
30 | this.mItemsEntity = null;
31 | }
32 |
33 | public RawItemsEntity getmItemsEntity() {
34 | return this.mItemsEntity;
35 | }
36 |
37 | public void setmItemsEntity(RawItemsEntity rawItemsEntity) {
38 | this.mItemsEntity = rawItemsEntity;
39 | }
40 |
41 | public String getMD5() {
42 | return this.MD5;
43 | }
44 |
45 | public void setMD5(String str) {
46 | this.MD5 = str;
47 | }
48 |
49 | public String getmRawItems() {
50 | return this.mRawItems;
51 | }
52 |
53 | public void setmRawItems(String str) {
54 | this.mRawItems = str;
55 | }
56 | }
57 |
58 | public class KeyFormateException extends Exception {
59 | private static final long serialVersionUID = 13923744320L;
60 |
61 | public KeyFormateException(String str) {
62 | super(str);
63 | }
64 | }
65 |
66 | private class RawItemsEntity {
67 | private short mAppId;
68 | private Date mExpired;
69 |
70 | private RawItemsEntity() {
71 | this.mAppId = (short) 0;
72 | this.mExpired = null;
73 | }
74 |
75 | public short getAppId() {
76 | return this.mAppId;
77 | }
78 |
79 | public void setAppId(short s) {
80 | this.mAppId = s;
81 | }
82 |
83 | public Date getExpired() {
84 | return this.mExpired;
85 | }
86 |
87 | public void setExpired(Date date) {
88 | this.mExpired = date;
89 | }
90 | }
91 |
92 | public XLAppKeyChecker(Context context, String str) {
93 | this.mContext = context;
94 | this.mAppKey = str;
95 | }
96 |
97 | public boolean verify() {
98 | try {
99 | AppKeyEntity keyEntity = getKeyEntity();
100 | this.mPackageName = "com.xunlei.downloadprovider";
101 | if (!verifyAppKeyMD5(keyEntity, this.mPackageName)) {
102 | XLLog.i(TAG, "appkey MD5 invalid.");
103 | return false;
104 | } else if (!verifyAppKeyExpired(keyEntity)) {
105 | return true;
106 | } else {
107 | XLLog.i(TAG, "appkey expired.");
108 | return false;
109 | }
110 | } catch (KeyFormateException e) {
111 | return false;
112 | }
113 | }
114 |
115 | private boolean verifyAppKeyMD5(AppKeyEntity appKeyEntity, String str) {
116 | String str2 = appKeyEntity.getmRawItems() + ";" + str;
117 | XLLog.i(TAG, "totalContent:" + str2);
118 | str2 = XLUtil.getMd5(str2).toLowerCase().replace('b', '^').replace('9', 'b');
119 | XLLog.i(TAG, "keyEntity getMD5 MD5:" + appKeyEntity.getMD5());
120 | if (str2.compareTo(appKeyEntity.getMD5()) == 0) {
121 | return true;
122 | }
123 | return false;
124 | }
125 |
126 | private boolean verifyAppKeyExpired(AppKeyEntity appKeyEntity) {
127 | Date expired = appKeyEntity.getmItemsEntity().getExpired();
128 | if (expired == null) {
129 | return false;
130 | }
131 | return expired.before(Calendar.getInstance().getTime());
132 | }
133 |
134 | public String getSoAppKey() {
135 | return XLUtil.generateAppKey("com.xunlei.downloadprovider", this.mAppId, (byte) 1);
136 | }
137 |
138 | private AppKeyEntity getKeyEntity() throws KeyFormateException {
139 | String[] split = this.mAppKey.split("==");
140 | if (split.length != 2) {
141 | XLLog.i(TAG, "keyPair length invalid");
142 | throw new KeyFormateException("error");
143 | }
144 | AppKeyEntity appKeyEntity = new AppKeyEntity();
145 | appKeyEntity.setMD5(split[1]);
146 | try {
147 | String replace = split[0].replace('^', '=');
148 | String str = new String(Base64.decode(replace.substring(2, replace.length() - 2), 0), "UTF-8");
149 | appKeyEntity.setmRawItems(str);
150 | XLLog.i(TAG, "items:" + str);
151 | appKeyEntity.setmItemsEntity(getRawItemsEntity(str));
152 | return appKeyEntity;
153 | } catch (UnsupportedEncodingException e) {
154 | throw new KeyFormateException("error");
155 | }
156 | }
157 |
158 | private RawItemsEntity getRawItemsEntity(String str) throws KeyFormateException {
159 | String[] split = str.split(";");
160 | RawItemsEntity rawItemsEntity = new RawItemsEntity();
161 | if (split.length <= 0 || split.length > 2) {
162 | throw new KeyFormateException("raw item length invalid.");
163 | }
164 | try {
165 | this.mAppId = Short.parseShort(split[0]);
166 | rawItemsEntity.setAppId(this.mAppId);
167 | if (split.length == 2) {
168 | try {
169 | rawItemsEntity.setExpired(new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(split[1]));
170 | } catch (ParseException e) {
171 | throw new KeyFormateException("expired field formate error.");
172 | }
173 | }
174 | return rawItemsEntity;
175 | } catch (NumberFormatException e2) {
176 | XLLog.i(TAG, "appId invalid");
177 | e2.printStackTrace();
178 | throw new KeyFormateException("app id format error.");
179 | }
180 | }
181 | }
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/XLLoader.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import android.content.Context;
4 |
5 | import com.xunlei.downloadlib.parameter.BtIndexSet;
6 | import com.xunlei.downloadlib.parameter.BtSubTaskDetail;
7 | import com.xunlei.downloadlib.parameter.BtTaskStatus;
8 | import com.xunlei.downloadlib.parameter.GetDownloadHead;
9 | import com.xunlei.downloadlib.parameter.GetDownloadLibVersion;
10 | import com.xunlei.downloadlib.parameter.GetFileName;
11 | import com.xunlei.downloadlib.parameter.GetTaskId;
12 | import com.xunlei.downloadlib.parameter.MaxDownloadSpeedParam;
13 | import com.xunlei.downloadlib.parameter.ThunderUrlInfo;
14 | import com.xunlei.downloadlib.parameter.TorrentInfo;
15 | import com.xunlei.downloadlib.parameter.UrlQuickInfo;
16 | import com.xunlei.downloadlib.parameter.XLSessionInfo;
17 | import com.xunlei.downloadlib.parameter.XLTaskInfo;
18 | import com.xunlei.downloadlib.parameter.XLTaskInfoEx;
19 | import com.xunlei.downloadlib.parameter.XLTaskLocalUrl;
20 |
21 | class XLLoader {
22 | private static final String TAG = "XLLoader";
23 |
24 | public native int addPeerResource(long j, String str, long j2, String str2, String str3, int i, int i2, int i3, int i4, int i5, int i6, int i7);
25 |
26 | public native int addServerResource(long j, String str, String str2, String str3, int i, int i2);
27 |
28 | public native int btAddPeerResource(long j, int i, String str, long j2, String str2, String str3, int i2, int i3, int i4, int i5, int i6, int i7, int i8);
29 |
30 | public native int btAddServerResource(long j, int i, String str, String str2, String str3, int i2, int i3);
31 |
32 | public native int btRemoveAddedResource(long j, int i, int i2);
33 |
34 | public native int clearTaskFile(String str);
35 |
36 | public native int createBtMagnetTask(String str, String str2, String str3, GetTaskId getTaskId);
37 |
38 | public native int createBtTask(String str, String str2, int i, int i2, int i3, GetTaskId getTaskId);
39 |
40 | public native int createCIDTask(String str, String str2, String str3, String str4, String str5, long j, int i, int i2, GetTaskId getTaskId);
41 |
42 | public native int createEmuleTask(String str, String str2, String str3, int i, int i2, GetTaskId getTaskId);
43 |
44 | public native int createP2spTask(String str, String str2, String str3, String str4, String str5, String str6, String str7, int i, int i2, GetTaskId getTaskId);
45 |
46 | public native int createShortVideoTask(String str, String str2, String str3, String str4, int i, int i2, int i3, GetTaskId getTaskId);
47 |
48 | public native int deselectBtSubTask(long j, BtIndexSet btIndexSet);
49 |
50 | public native int enterPrefetchMode(long j);
51 |
52 | public native int getBtSubTaskInfo(long j, int i, BtSubTaskDetail btSubTaskDetail);
53 |
54 | public native int getBtSubTaskStatus(long j, BtTaskStatus btTaskStatus, int i, int i2);
55 |
56 | public native int getDownloadHeader(long j, GetDownloadHead getDownloadHead);
57 |
58 | public native int getDownloadLibVersion(GetDownloadLibVersion getDownloadLibVersion);
59 |
60 | public native int getFileNameFromUrl(String str, GetFileName getFileName);
61 |
62 | public native int getLocalUrl(String str, XLTaskLocalUrl xLTaskLocalUrl);
63 |
64 | public native int getMaxDownloadSpeed(MaxDownloadSpeedParam maxDownloadSpeedParam);
65 |
66 | public native int getNameFromUrl(String str, String str2);
67 |
68 | public native int getSessionInfoByUrl(String str, XLSessionInfo xLSessionInfo);
69 |
70 |
71 | public native int getTaskInfo(long j, int i, XLTaskInfo xLTaskInfo);
72 |
73 | public native int getTaskInfoEx(long j, XLTaskInfoEx xLTaskInfoEx);
74 |
75 | public native int getTorrentInfo(String str, TorrentInfo torrentInfo);
76 |
77 | public native int getUrlQuickInfo(long j, UrlQuickInfo urlQuickInfo);
78 |
79 | public native int init(Context context, String str, String str2, String str3, String str4, String str5, String str6, int i, int i2);
80 |
81 | public native boolean isLogTurnOn();
82 |
83 | public native int notifyNetWorkType(int i);
84 |
85 | public native int parserThunderUrl(String str, ThunderUrlInfo thunderUrlInfo);
86 |
87 | public native int playShortVideoBegin(long j);
88 |
89 | public native int releaseTask(long j);
90 |
91 | public native int removeAddedServerResource(long j, int i);
92 |
93 | public native int requeryIndex(long j);
94 |
95 | public native int selectBtSubTask(long j, BtIndexSet btIndexSet);
96 |
97 | public native int setBtPriorSubTask(long j, int i);
98 |
99 | public native int setDownloadTaskOrigin(long j, String str);
100 |
101 | public native int setFileName(long j, String str);
102 |
103 | public native int setHttpHeaderProperty(long j, String str, String str2);
104 |
105 | public native int setImei(String str);
106 |
107 | public native int setLocalProperty(String str, String str2);
108 |
109 | public native int setMac(String str);
110 |
111 | public native int setMiUiVersion(String str);
112 |
113 | public native int setNotifyNetWorkCarrier(int i);
114 |
115 | public native int setNotifyWifiBSSID(String str);
116 |
117 | public native int setOriginUserAgent(long j, String str);
118 |
119 | public native int setReleaseLog(int i, String str, int i2, int i3);
120 |
121 | public native int setSpeedLimit(long j, long j2);
122 |
123 | public native int setStatReportSwitch(boolean z);
124 |
125 | public native int setTaskAllowUseResource(long j, int i);
126 |
127 | public native int setTaskAppInfo(long j, String str, String str2, String str3);
128 |
129 | public native int setTaskGsState(long j, int i, int i2);
130 |
131 | public native int setTaskLxState(long j, int i, int i2);
132 |
133 | public native int setTaskUid(long j, int i);
134 |
135 | public native int setUserId(String str);
136 |
137 | public native int startDcdn(long j, int i, String str, String str2, String str3);
138 |
139 | public native int startTask(long j, boolean z);
140 |
141 | public native int statExternalInfo(long j, int i, String str, String str2);
142 |
143 | public native int stopDcdn(long j, int i);
144 |
145 | public native int stopTask(long j);
146 |
147 | public native int stopTaskWithReason(long j, int i);
148 |
149 | public native int switchOriginToAllResDownload(long j);
150 |
151 | public native int unInit();
152 |
153 | public XLLoader() {
154 | System.loadLibrary("xl_stat");
155 | System.loadLibrary("xluagc");
156 | System.loadLibrary("xl_thunder_sdk");
157 | }
158 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ghost/thunder/download/DownLoadUtil.java:
--------------------------------------------------------------------------------
1 | package com.ghost.thunder.download;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.text.TextUtils;
7 |
8 | import com.ghost.thunder.utils.LogPrinter;
9 | import com.ghost.thunder.utils.StorageUtils;
10 | import com.ghost.thunder.utils.UrlType;
11 | import com.xunlei.downloadlib.XLTaskHelper;
12 | import com.xunlei.downloadlib.parameter.TorrentInfo;
13 | import com.xunlei.downloadlib.parameter.XLTaskInfo;
14 |
15 | import java.io.File;
16 |
17 | /**
18 | * Created by yuntao.wei on 2018/8/9.
19 | * github:https://github.com/YuntaoWei
20 | * blog:http://blog.csdn.net/qq_17541215
21 | */
22 |
23 | public class DownLoadUtil {
24 |
25 | private static final String TAG = "DownLoadUtil";
26 |
27 | private static final int TASK_UPDATE_PROGRESS = 0x001;
28 |
29 | private static DownLoadUtil mInstance;
30 |
31 | private DownLoadProgressListener progressListener;
32 |
33 | private long taskID;
34 |
35 | private Context globalContext;
36 |
37 | private String savePath;
38 |
39 | private String preFile;
40 |
41 | private boolean dstFileIsTorrentFileTask;
42 |
43 | private Handler progressHandler = new Handler() {
44 |
45 | @Override
46 | public void handleMessage(Message msg) {
47 | switch (msg.what) {
48 |
49 | case TASK_UPDATE_PROGRESS: {
50 | if (progressListener != null) {
51 | XLTaskInfo taskInfo = XLTaskHelper.instance(globalContext).getTaskInfo(taskID);
52 | if (taskInfo.mFileSize == taskInfo.mDownloadSize) {
53 | if (TextUtils.isEmpty(taskInfo.mFileName)) {
54 | progressListener.onDonwloadEnd(preFile);
55 | } else {
56 | progressListener.onDonwloadEnd(savePath + "/" + taskInfo.mFileName);
57 | }
58 | return;
59 | }
60 |
61 | progressListener.onProgressChangeRealSize(taskInfo.mFileSize,
62 | taskInfo.mDownloadSize, taskInfo.mDownloadSpeed);
63 |
64 | progressListener.onProgressChange(StorageUtils.convertFileSize(taskInfo.mFileSize)
65 | , StorageUtils.convertFileSize(taskInfo.mDownloadSize)
66 | , StorageUtils.convertFileSize(taskInfo.mDownloadSpeed));
67 | progressHandler.sendEmptyMessageDelayed(TASK_UPDATE_PROGRESS, 1000);
68 | }
69 | break;
70 | }
71 |
72 |
73 | }
74 | }
75 | };
76 |
77 | private DownLoadUtil(Context ctx) {
78 | globalContext = ctx.getApplicationContext();
79 | init();
80 | }
81 |
82 | public static DownLoadUtil getInstance(Context ctx) {
83 |
84 | if (mInstance == null) {
85 | synchronized (DownLoadUtil.class) {
86 |
87 | if (mInstance == null)
88 | mInstance = new DownLoadUtil(ctx);
89 |
90 | }
91 | }
92 |
93 | return mInstance;
94 | }
95 |
96 | private void init() {
97 | LogPrinter.i(TAG, "init");
98 | XLTaskHelper.init(globalContext);
99 | }
100 |
101 | public void startDownLoad(String url) throws Exception {
102 | savePath = StorageUtils.getDefaultSavePath(globalContext);
103 | String fileName = null;
104 | if (UrlType.isTorrentUrl(url)) {
105 | TorrentInfo info = getTorrentInfo(url);
106 | savePath += "/" + info.mMultiFileBaseFolder;
107 | File f = new File(savePath);
108 | f.mkdirs();
109 | fileName = null;
110 | } else {
111 | fileName = getFileName(url);
112 | }
113 |
114 | preFile = savePath + (fileName == null ? "" : "/" + fileName);
115 | LogPrinter.i(TAG, "start download url : " + url + ", save path : " + savePath);
116 |
117 | if (UrlType.isThunderUrl(url) || UrlType.isHttpOrHttpsUrl(url) || UrlType.isFTPUrl(url)) {
118 | taskID = XLTaskHelper.instance(globalContext)
119 | .addThunderTask(url, savePath, fileName);
120 | } else if (UrlType.isMagnetUrl(url)) {
121 | taskID = XLTaskHelper.instance(globalContext)
122 | .addMagentTask(url, savePath, fileName);
123 | } else if (StorageUtils.isTorrentFile(url)) {
124 | taskID = XLTaskHelper.instance(globalContext)
125 | .addTorrentTask(url, savePath, null);
126 | }
127 |
128 | LogPrinter.i(TAG, "download url taskID : " + taskID);
129 | updateProgress();
130 | }
131 |
132 | public void startDownLoad(String url, DownLoadProgressListener progressListener) throws Exception {
133 | this.progressListener = progressListener;
134 | startDownLoad(url);
135 | }
136 |
137 | public void updateProgress() {
138 |
139 | if (progressListener != null) {
140 | progressHandler.sendEmptyMessageDelayed(TASK_UPDATE_PROGRESS, 1000);
141 | }
142 |
143 | }
144 |
145 | public void stopTask() {
146 | XLTaskInfo taskInfo = XLTaskHelper.instance(globalContext).getTaskInfo(taskID);
147 | int status = taskInfo.mTaskStatus;
148 | LogPrinter.i(TAG, "stopTask -- > taskStatus : " + status);
149 | XLTaskHelper.instance(globalContext).stopTask(taskID);
150 | }
151 |
152 | public void getTaskInfo(String url) {
153 | XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);
154 |
155 | if (UrlType.isTorrentUrl(url)) {
156 | TorrentInfo torrentInfo = xlTaskHelper.getTorrentInfo(url);
157 | LogPrinter.i(TAG, torrentInfo.toString());
158 | } else {
159 | String fileName = xlTaskHelper.getFileName(url);
160 | if (fileName.endsWith(".torrent"))
161 | dstFileIsTorrentFileTask = true;
162 | LogPrinter.i(TAG, fileName);
163 | }
164 | }
165 |
166 | private TorrentInfo getTorrentInfo(String url) {
167 | XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);
168 | TorrentInfo torrentInfo = xlTaskHelper.getTorrentInfo(url);
169 | return torrentInfo;
170 | }
171 |
172 | private String getFileName(String url) {
173 | XLTaskHelper xlTaskHelper = XLTaskHelper.instance(globalContext);
174 | return xlTaskHelper.getFileName(url);
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/ErrorCodeToMsg.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class ErrorCodeToMsg {
4 | public static final String ErrCodeToMsg = "{ \"9000\": \"XL_NO_ERRNO \" , \"9101\": \"XL_ALREADY_INIT \" , \"9102\": \"XL_SDK_NOT_INIT \" , \"9103\": \"XL_TASK_ALREADY_EXIST \" , \"9104\": \"XL_TASK_NOT_EXIST \" , \"9105\": \"XL_TASK_ALREADY_STOPPED \" , \"9106\": \"XL_TASK_ALREADY_RUNNING \" , \"9107\": \"XL_TASK_NOT_START \" , \"9108\": \"XL_TASK_STILL_RUNNING \" , \"9109\": \"XL_FILE_EXISTED \" , \"9110\": \"XL_DISK_FULL \" , \"9111\": \"XL_TOO_MUCH_TASK \" , \"9112\": \"XL_PARAM_ERROR \" , \"9113\": \"XL_SCHEMA_NOT_SUPPORT \" , \"9114\": \"XL_DYNAMIC_PARAM_FAIL \" , \"9115\": \"XL_CONTINUE_NO_NAME \" , \"9116\": \"XL_APPNAME_APPKEY_ERROR \" , \"9117\": \"XL_CREATE_THREAD_ERROR \" , \"9118\": \"XL_TASK_FINISH \" , \"9119\": \"XL_TASK_NOT_RUNNING \" , \"9120\": \"XL_TASK_NOT_IDLE \" , \"9121\": \"XL_TASK_TYPE_NOT_SUPPORT \" , \"9122\": \"XL_ADD_RESOURCE_ERROR \" , \"9123\": \"XL_TASK_LOADING_CFG \" , \"9301\": \"XL_NO_ENOUGH_BUFFER \" , \"9302\": \"XL_TORRENT_PARSE_ERROR \" , \"9303\": \"XL_INDEX_NOT_READY \" , \"9304\": \"XL_TORRENT_IMCOMPLETE \" , \"9900\": \"DOWNLOAD_MANAGER_ERROR \" , \"9901\": \"APPKEY_CHECKER_ERROR \" , \"111024\": \"COMMON_ERRCODE_BASE \" , \"111025\": \"TARGET_THREAD_STOPING \" , \"111026\": \"OUT_OF_MEMORY \" , \"111031\": \"TASK_USE_TOO_MUCH_MEM \" , \"111032\": \"OUT_OF_FIXED_MEMORY \" , \"111033\": \"QUEUE_NO_ROOM \" , \"111035\": \"MAP_UNINIT \" , \"111036\": \"MAP_DUPLICATE_KEY \" , \"111037\": \"MAP_KEY_NOT_FOUND \" , \"111038\": \"INVALID_ITERATOR \" , \"111039\": \"BUFFER_OVERFLOW \" , \"111041\": \"INVALID_ARGUMENT \" , \"111048\": \"INVALID_SOCKET_DESCRIPTOR \" , \"111050\": \"ERROR_INVALID_INADDR \" , \"111181\": \"REDIRECT_TOO_MUCH \" , \"111057\": \"NOT_IMPLEMENT \" , \"111074\": \"INVALID_TIMER_INDEX \" , \"111078\": \"DNS_INVALID_ADDR \" , \"111083\": \"BAD_DIR_PATH \" , \"111084\": \"FILE_CANNOT_TRUNCATE \" , \"111085\": \"INSUFFICIENT_DISK_SPACE \" , \"111086\": \"FILE_TOO_BIG \" , \"111118\": \"DISPATCHER_ERRCODE_BASE \" , \"111119\": \"DATA_MGR_ERRCODE_BASE \" , \"111120\": \"ALLOC_INVALID_SIZE \" , \"111121\": \"DATA_BUFFER_IS_FULL \" , \"111122\": \"BLOCK_NO_INVALID \" , \"111123\": \"CHECK_DATA_BUFFER_NOT_ENOUG \" , \"111124\": \"BCID_CHECK_FAIL \" , \"111125\": \"BCID_ONCE_CHECT_TOO_MUCH \" , \"111126\": \"READ_FILE_ERR \" , \"111127\": \"WRITE_FILE_ERR \" , \"111128\": \"OPEN_FILE_ERR \" , \"111129\": \"FILE_PATH_TOO_LONG \" , \"111130\": \"SD_INVALID_FILE_SIZE \" , \"111131\": \"FILE_CFG_MAGIC_ERROR \" , \"111132\": \"FILE_CFG_READ_ERROR \" , \"111133\": \"FILE_CFG_WRITE_ERROR \" , \"111134\": \"FILE_CFG_READ_HEADER_ERROR \" , \"111135\": \"FILE_CFG_RESOLVE_ERROR \" , \"111136\": \"TASK_FAILURE_NO_DATA_PIPE \" , \"111137\": \"NO_FILE_NAME \" , \"111138\": \"CANNOT_GET_FILE_NAME \" , \"111139\": \"CREATE_FILE_FAIL \" , \"111140\": \"OPEN_OLD_FILE_FAIL \" , \"111141\": \"FILE_SIZE_NOT_BELIEVE \" , \"111142\": \"FILE_SIZE_TOO_SMALL \" , \"111143\": \"FILE_NOT_EXIST \" , \"111144\": \"FILE_INVALID_PARA \" , \"111145\": \"FILE_CREATING \" , \"111146\": \"FIL_INFO_INVALID_DATA \" , \"111147\": \"FIL_INFO_RECVED_DATA \" , \"111159\": \"CONF_MGR_ERRCODE_BASE \" , \"111160\": \"SETTINGS_ERR_UNKNOWN \" , \"111161\": \"SETTINGS_ERR_INVALID_FILE_NAME \" , \"111162\": \"SETTINGS_ERR_CFG_FILE_NOT_EXIST \" , \"111163\": \"SETTINGS_ERR_INVALID_LINE \" , \"111164\": \"SETTINGS_ERR_INVALID_ITEM_NAME \" , \"111165\": \"SETTINGS_ERR_INVALID_ITEM_VALUE \" , \"111166\": \"SETTINGS_ERR_LIST_EMPTY \" , \"111167\": \"SETTINGS_ERR_ITEM_NOT_FOUND \" , \"111168\": \"NET_REACTOR_ERRCODE_BASE \" , \"111169\": \"NET_CONNECT_SSL_ERR \" , \"111170\": \"NET_BROKEN_PIPE \" , \"111171\": \"NET_CONNECTION_REFUSED \" , \"111172\": \"NET_SSL_GET_FD_ERROR \" , \"111173\": \"NET_OP_CANCEL \" , \"111174\": \"NET_UNKNOWN_ERROR \" , \"111175\": \"NET_NORMAL_CLOSE \" , \"111176\": \"TASK_FAIL_LONG_TIME_NO_RECV_DATA \" , \"111177\": \"TASK_FILE_SIZE_TOO_LARGE \" , \"111178\": \"TASK_RETRY_ALWAY_FAIL \" , \"111300\": \"ASYN_FILE_E_BASE \" , \"111301\": \"ASYN_FILE_E_OP_NONE \" , \"111302\": \"ASYN_FILE_E_OP_BUSY \" , \"111303\": \"ASYN_FILE_E_FILE_NOT_OPEN \" , \"111304\": \"ASYN_FILE_E_FILE_REOPEN \" , \"111305\": \"ASYN_FILE_E_EMPTY_FILE \" , \"111306\": \"ASYN_FILE_E_FILE_SIZE_LESS \" , \"111307\": \"ASYN_FILE_E_TOO_MUCH_DATA \" , \"111308\": \"ASYN_FILE_E_FILE_CLOSING \" , \"112400\": \"ERR_PTL_PROTOCOL_NOT_SUPPORT \" , \"112500\": \"ERR_PTL_PEER_OFFLINE \" , \"112600\": \"ERR_PTL_GET_PEERSN_FAILED \" , \"11300\": \"P2P_PIPE_ERRCODE_BASE\t\t\t \" , \"11301\": \"ERR_P2P_VERSION_NOT_SUPPORT\t\t \" , \"11302\": \"ERR_P2P_WAITING_CLOSE\t\t\t \" , \"11303\": \"ERR_P2P_HANDSHAKE_RESP_FAIL\t\t \" , \"11304\": \"ERR_P2P_REQUEST_RESP_FAIL\t\t \" , \"11305\": \"ERR_P2P_UPLOAD_OVER_MAX\t\t\t \" , \"11306\": \"ERR_P2P_REMOTE_UNKNOWN_MY_CMD\t \" , \"11307\": \"ERR_P2P_NOT_SUPPORT_UDT\t\t\t \" , \"11308\": \"ERR_P2P_BROKER_CONNECT\t\t\t \" , \"11309\": \"ERR_P2P_INVALID_COMMAND\t\t\t \" , \"11310\": \"ERR_P2P_INVALID_PARAM\t\t\t \" , \"11311\": \"ERR_P2P_CONNECT_FAILED\t\t\t \" , \"11312\": \"ERR_P2P_CONNECT_UPLOAD_SLOW\t \" , \"11313\": \"ERR_P2P_ALLOC_MEM_ERR \" , \"11314\": \"ERR_P2P_SEND_HANDSHAKE \" , \"114001\": \"TASK_FAILURE_QUERY_EMULE_HUB_FAILED\" , \"114101\": \"TASK_FAILURE_EMULE_NO_RECORD \" , \"114002\": \"TASK_FAILURE_SUBTASK_FAILED \" , \"114003\": \"TASK_FAILURE_CANNOT_START_SUBTASK \" , \"114004\": \"TASK_FAILURE_QUERY_BT_HUB_FAILED \" , \"114005\": \"TASK_FAILURE_PARSE_TORRENT_FAILED \" , \"114006\": \"TASK_FAILURE_GET_TORRENT_FAILED \" , \"114007\": \"TASK_FAILURE_SAVE_TORRENT_FAILED \" , \"115000\": \"RES_QUERY_E_BASE \" , \"115100\": \"HTTP_HUB_CLIENT_E_BASE \" , \"116000\": \"IP6_ERRCODE_BASE \" , \"116001\": \"ERR_INVALID_ADDRESS_FAMILY \" , \"116002\": \"IP6_INVALID_IN6ADDR \" , \"116003\": \"IP6_NOT_SUPPORT_SSL \" , \"117000\": \"PAUSE_TASK_WRITE_CFG_ERR \" , \"117001\": \"PAUSE_TASK_WRITE_DATA_TIMEOUT \" }";
5 | }
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/XLTaskHelper.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.os.Environment;
6 | import android.os.Handler;
7 | import android.text.TextUtils;
8 |
9 | import com.xunlei.downloadlib.parameter.BtIndexSet;
10 | import com.xunlei.downloadlib.parameter.BtSubTaskDetail;
11 | import com.xunlei.downloadlib.parameter.BtTaskParam;
12 | import com.xunlei.downloadlib.parameter.EmuleTaskParam;
13 | import com.xunlei.downloadlib.parameter.GetFileName;
14 | import com.xunlei.downloadlib.parameter.GetTaskId;
15 | import com.xunlei.downloadlib.parameter.InitParam;
16 | import com.xunlei.downloadlib.parameter.MagnetTaskParam;
17 | import com.xunlei.downloadlib.parameter.P2spTaskParam;
18 | import com.xunlei.downloadlib.parameter.TorrentFileInfo;
19 | import com.xunlei.downloadlib.parameter.TorrentInfo;
20 | import com.xunlei.downloadlib.parameter.XLTaskInfo;
21 | import com.xunlei.downloadlib.parameter.XLTaskLocalUrl;
22 |
23 | import java.util.concurrent.ConcurrentHashMap;
24 | import java.util.concurrent.atomic.AtomicInteger;
25 |
26 | /**
27 | * Created by oceanzhang on 2017/7/27.
28 | */
29 |
30 | public class XLTaskHelper {
31 | private static final String TAG = "XLTaskHelper";
32 |
33 | public static void init(Context context) {
34 | XLDownloadManager instance = XLDownloadManager.getInstance();
35 | InitParam initParam = new InitParam();
36 | initParam.mAppKey = "bpIzNjAxNTsxNTA0MDk0ODg4LjQyODAwMA&&OxNw==^a2cec7^10e7f1756b15519e20ffb6cf0fbf671f";
37 | initParam.mAppVersion = "5.45.2.5080";
38 | initParam.mStatSavePath = context.getFilesDir().getPath();
39 | initParam.mStatCfgSavePath = context.getFilesDir().getPath();
40 | initParam.mPermissionLevel = 2;
41 | instance.init(context, initParam);
42 | instance.setOSVersion(Build.VERSION.INCREMENTAL);
43 | instance.setSpeedLimit(-1, -1);
44 | XLDownloadManager.getInstance().setUserId("");
45 | }
46 |
47 |
48 | private String innerSDCardPath;
49 | private Context context;
50 | private AtomicInteger seq = new AtomicInteger(0);
51 |
52 | private XLTaskHelper(final Context context) {
53 | this.context = context;
54 | innerSDCardPath = Environment.getExternalStorageDirectory().getPath();
55 | }
56 |
57 |
58 | private static volatile XLTaskHelper instance = null;
59 |
60 | public static XLTaskHelper instance(Context context) {
61 | if (instance == null) {
62 | synchronized (XLTaskHelper.class) {
63 | if (instance == null) {
64 | instance = new XLTaskHelper(context.getApplicationContext());
65 | }
66 | }
67 |
68 | }
69 | return instance;
70 | }
71 |
72 | /**
73 | * 获取任务详情, 包含当前状态,下载进度,下载速度,文件大小
74 | * mDownloadSize:已下载大小 mDownloadSpeed:下载速度 mFileSize:文件总大小 mTaskStatus:当前状态,0连接中1下载中 2下载完成 3失败 mAdditionalResDCDNSpeed DCDN加速 速度
75 | * @param taskId
76 | * @return
77 | */
78 | public synchronized XLTaskInfo getTaskInfo(long taskId) {
79 | XLTaskInfo taskInfo = new XLTaskInfo();
80 | XLDownloadManager.getInstance().getTaskInfo(taskId,1,taskInfo);
81 | return taskInfo;
82 | }
83 |
84 | /**
85 | * 添加迅雷链接任务 支持thunder:// ftp:// ed2k:// http:// https:// 协议
86 | * @param url
87 | * @param savePath 下载文件保存路径
88 | * @param fileName 下载文件名 可以通过 getFileName(url) 获取到,为空默认为getFileName(url)的值
89 | * @return
90 | */
91 | public synchronized long addThunderTask(String url,String savePath,String fileName) throws Exception {
92 | if (url.startsWith("thunder://")) url = XLDownloadManager.getInstance().parserThunderUrl(url);
93 | final GetTaskId getTaskId = new GetTaskId();
94 | GetFileName getFileName = new GetFileName();
95 | XLDownloadManager.getInstance().getFileNameFromUrl(url, getFileName);
96 | if (url.startsWith("ftp://") || url.startsWith("http")) {
97 | P2spTaskParam taskParam = new P2spTaskParam();
98 | taskParam.setCreateMode(1);
99 | taskParam.setFileName(getFileName.getFileName());
100 | taskParam.setFilePath(savePath);
101 | taskParam.setUrl(url);
102 | taskParam.setSeqId(seq.incrementAndGet());
103 | taskParam.setCookie("");
104 | taskParam.setRefUrl("");
105 | taskParam.setUser("");
106 | taskParam.setPass("");
107 | XLDownloadManager.getInstance().createP2spTask(taskParam, getTaskId);
108 | } else if (url.startsWith("ed2k://")) {
109 | EmuleTaskParam taskParam = new EmuleTaskParam();
110 | taskParam.setFilePath(savePath);
111 | taskParam.setFileName(getFileName.getFileName());
112 | taskParam.setUrl(url);
113 | taskParam.setSeqId(seq.incrementAndGet());
114 | taskParam.setCreateMode(1);
115 | XLDownloadManager.getInstance().createEmuleTask(taskParam, getTaskId);
116 | } else {
117 | throw new Exception("url illegal.");
118 | }
119 |
120 | XLDownloadManager.getInstance().setDownloadTaskOrigin(getTaskId.getTaskId(), "out_app/out_app_paste");
121 | XLDownloadManager.getInstance().setOriginUserAgent(getTaskId.getTaskId(), "AndroidDownloadManager/4.4.4 (Linux; U; Android 4.4.4; Build/KTU84Q)");
122 | XLDownloadManager.getInstance().startTask(getTaskId.getTaskId(), false);
123 | XLDownloadManager.getInstance().setTaskLxState(getTaskId.getTaskId(), 0, 1);
124 | XLDownloadManager.getInstance().startDcdn(getTaskId.getTaskId(), 0, "", "", "");
125 |
126 | return getTaskId.getTaskId();
127 | }
128 | /**
129 | * 添加磁力链任务
130 | * @param url 磁力链接 magnet:? 开头
131 | * @param savePath
132 | * @param fileName
133 | * @return
134 | * @throws Exception
135 | */
136 | public synchronized long addMagentTask(final String url,final String savePath,String fileName) throws Exception {
137 | if (url.startsWith("magnet:?")) {
138 | if(TextUtils.isEmpty(fileName)) {
139 | final GetFileName getFileName = new GetFileName();
140 | XLDownloadManager.getInstance().getFileNameFromUrl(url, getFileName);
141 | fileName = getFileName.getFileName();
142 | }
143 | MagnetTaskParam magnetTaskParam = new MagnetTaskParam();
144 | magnetTaskParam.setFileName(fileName);
145 | magnetTaskParam.setFilePath(savePath);
146 | magnetTaskParam.setUrl(url);
147 | final GetTaskId getTaskId = new GetTaskId();
148 | XLDownloadManager.getInstance().createBtMagnetTask(magnetTaskParam, getTaskId);
149 |
150 | XLDownloadManager.getInstance().setTaskLxState(getTaskId.getTaskId(), 0, 1);
151 | XLDownloadManager.getInstance().startDcdn(getTaskId.getTaskId(), 0, "", "", "");
152 | XLDownloadManager.getInstance().startTask(getTaskId.getTaskId(), false);
153 | return getTaskId.getTaskId();
154 | } else {
155 | throw new Exception("url illegal.");
156 | }
157 | }
158 | /**
159 | * 获取种子详情
160 | * @param torrentPath
161 | * @return
162 | */
163 | public synchronized TorrentInfo getTorrentInfo(String torrentPath) {
164 | TorrentInfo torrentInfo = new TorrentInfo();
165 | XLDownloadManager.getInstance().getTorrentInfo(torrentPath,torrentInfo);
166 | return torrentInfo;
167 | }
168 |
169 | /**
170 | * 添加种子下载任务,如果是磁力链需要先通过addMagentTask将种子下载下来
171 | * @param torrentPath 种子地址
172 | * @param savePath 保存路径
173 | * @param indexs 需要下载的文件索引
174 | * @return
175 | * @throws Exception
176 | */
177 | public synchronized long addTorrentTask(String torrentPath,String savePath,int []indexs) throws Exception {
178 | TorrentInfo torrentInfo = new TorrentInfo();
179 | XLDownloadManager.getInstance().getTorrentInfo(torrentPath,torrentInfo);
180 | TorrentFileInfo[] fileInfos = torrentInfo.mSubFileInfo;
181 | BtTaskParam taskParam = new BtTaskParam();
182 | taskParam.setCreateMode(1);
183 | taskParam.setFilePath(savePath);
184 | taskParam.setMaxConcurrent(3);
185 | taskParam.setSeqId(seq.incrementAndGet());
186 | taskParam.setTorrentPath(torrentPath);
187 | GetTaskId getTaskId = new GetTaskId();
188 | XLDownloadManager.getInstance().createBtTask(taskParam,getTaskId);
189 | if(fileInfos.length > 1 && indexs != null && indexs.length > 0) {
190 | BtIndexSet btIndexSet = new BtIndexSet(indexs.length);
191 | int i = 0;
192 | for(int index : indexs) {
193 | btIndexSet.mIndexSet[i++] = index;
194 | }
195 | XLDownloadManager.getInstance().selectBtSubTask(getTaskId.getTaskId(),btIndexSet);
196 | }
197 | XLDownloadManager.getInstance().setTaskLxState(getTaskId.getTaskId(), 0, 1);
198 | // XLDownloadManager.getInstance().startDcdn(getTaskId.getTaskId(), currentFileInfo.mRealIndex, "", "", "");
199 | XLDownloadManager.getInstance().startTask(getTaskId.getTaskId(), false);
200 | // XLDownloadManager.getInstance().setBtPriorSubTask(getTaskId.getTaskId(),currentFileInfo.mRealIndex);
201 | // XLTaskLocalUrl localUrl = new XLTaskLocalUrl();
202 | // XLDownloadManager.getInstance().getLocalUrl(savePath+"/" +(TextUtils.isEmpty(currentFileInfo.mSubPath) ? "" : currentFileInfo.mSubPath+"/")+ currentFileInfo.mFileName,localUrl);
203 | // currentFileInfo.playUrl = localUrl.mStrUrl;
204 | // currentFileInfo.hash = torrentInfo.mInfoHash;
205 | // return currentFileInfo;
206 | return getTaskId.getTaskId();
207 | }
208 |
209 | /**
210 | * 获取某个文件的本地proxy url,如果是音视频文件可以实现变下边播
211 | * @param filePath
212 | * @return
213 | */
214 | public synchronized String getLoclUrl(String filePath) {
215 | XLTaskLocalUrl localUrl = new XLTaskLocalUrl();
216 | XLDownloadManager.getInstance().getLocalUrl(filePath,localUrl);
217 | return localUrl.mStrUrl;
218 | }
219 |
220 | /**
221 | * 停止任务 文件保留
222 | * @param taskId
223 | */
224 | public synchronized void stopTask(long taskId) {
225 | XLDownloadManager.getInstance().stopTask(taskId);
226 | XLDownloadManager.getInstance().releaseTask(taskId);
227 | }
228 |
229 | /**
230 | * 删除一个任务,会把文件也删掉
231 | * @param taskId
232 | * @param savePath
233 | */
234 | public synchronized void deleteTask(long taskId,final String savePath) {
235 | stopTask(taskId);
236 | new Handler(Daemon.looper()).post(new Runnable() {
237 | @Override
238 | public void run() {
239 | try {
240 | new LinuxFileCommand(Runtime.getRuntime()).deleteDirectory(savePath);
241 | } catch (Exception e) {
242 | e.printStackTrace();
243 | }
244 | }
245 | });
246 | }
247 |
248 |
249 | /**
250 | * 通过链接获取文件名
251 | * @param url
252 | * @return
253 | */
254 | public synchronized String getFileName(String url) {
255 | if (url.startsWith("thunder://")) url = XLDownloadManager.getInstance().parserThunderUrl(url);
256 | GetFileName getFileName = new GetFileName();
257 | XLDownloadManager.getInstance().getFileNameFromUrl(url, getFileName);
258 | return getFileName.getFileName();
259 | }
260 |
261 | /**
262 | * 获取种子文件子任务的详情
263 | * @param taskId
264 | * @param fileIndex
265 | * @return
266 | */
267 | public synchronized BtSubTaskDetail getBtSubTaskInfo(long taskId, int fileIndex) {
268 | BtSubTaskDetail subTaskDetail = new BtSubTaskDetail();
269 | XLDownloadManager.getInstance().getBtSubTaskInfo(taskId,fileIndex,subTaskDetail);
270 | return subTaskDetail;
271 | }
272 |
273 | /**
274 | * 开启dcdn加速
275 | * @param taskId
276 | * @param btFileIndex
277 | */
278 | public synchronized void startDcdn(long taskId,int btFileIndex) {
279 | XLDownloadManager.getInstance().startDcdn(taskId, btFileIndex, "", "", "");
280 | }
281 |
282 |
283 | /**
284 | * 停止dcdn加速
285 | * @param taskId
286 | * @param btFileIndex
287 | */
288 | public synchronized void stopDcdn(long taskId,int btFileIndex) {
289 | XLDownloadManager.getInstance().stopDcdn(taskId,btFileIndex);
290 | }
291 |
292 |
293 | }
294 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/parameter/XLConstant.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.parameter;
2 |
3 | public class XLConstant {
4 |
5 | public static class QuickInfoState {
6 | public static final int QI_FAILED = 3;
7 | public static final int QI_FINISH = 2;
8 | public static final int QI_STOP = 0;
9 | public static final int QI_TRY = 1;
10 | }
11 |
12 | public enum XLCreateTaskMode {
13 | NEW_TASK,
14 | CONTINUE_TASK
15 | }
16 |
17 | public enum XLDownloadHeaderState {
18 | GDHS_UNKOWN,
19 | GDHS_REQUESTING,
20 | GDHS_SUCCESS,
21 | GDHS_ERROR
22 | }
23 |
24 | public static class XLErrorCode {
25 | public static final int ADD_RESOURCE_ERROR = 9122;
26 | public static final int ALREADY_INIT = 9101;
27 | public static final int APPKEY_CHECKER_ERROR = 9901;
28 | public static final int APPNAME_APPKEY_ERROR = 9116;
29 | public static final int ASYN_FILE_E_BASE = 111300;
30 | public static final int ASYN_FILE_E_EMPTY_FILE = 111305;
31 | public static final int ASYN_FILE_E_FILE_CLOSING = 111308;
32 | public static final int ASYN_FILE_E_FILE_NOT_OPEN = 111303;
33 | public static final int ASYN_FILE_E_FILE_REOPEN = 111304;
34 | public static final int ASYN_FILE_E_FILE_SIZE_LESS = 111306;
35 | public static final int ASYN_FILE_E_OP_BUSY = 111302;
36 | public static final int ASYN_FILE_E_OP_NONE = 111301;
37 | public static final int ASYN_FILE_E_TOO_MUCH_DATA = 111307;
38 | public static final int BAD_DIR_PATH = 111083;
39 | public static final int BT_SUB_TASK_NOT_SELECT = 9306;
40 | public static final int BUFFER_OVERFLOW = 111039;
41 | public static final int COMMON_ERRCODE_BASE = 111024;
42 | public static final int CONF_MGR_ERRCODE_BASE = 111159;
43 | public static final int CONTINUE_NO_NAME = 9115;
44 | public static final int CORRECT_CDN_ERROR = 111180;
45 | public static final int CORRECT_TIMES_TOO_MUCH = 111179;
46 | public static final int CREATE_FILE_FAIL = 111139;
47 | public static final int CREATE_THREAD_ERROR = 9117;
48 | public static final int DATA_MGR_ERRCODE_BASE = 111119;
49 | public static final int DISK_FULL = 9110;
50 | public static final int DISPATCHER_ERRCODE_BASE = 111118;
51 | public static final int DNS_INVALID_ADDR = 111078;
52 | public static final int DNS_NO_SERVER = 111077;
53 | public static final int DOWNLOAD_MANAGER_ERROR = 9900;
54 | public static final int DYNAMIC_PARAM_FAIL = 9114;
55 | public static final int ERROR_INVALID_INADDR = 111050;
56 | public static final int ERR_DPLAY_ALL_SEND_COMPLETE = 118000;
57 | public static final int ERR_DPLAY_BROKEN_SOCKET_RECV = 118307;
58 | public static final int ERR_DPLAY_BROKEN_SOCKET_SEND = 118306;
59 | public static final int ERR_DPLAY_CLIENT_ACTIVE_DISCONNECT = 118001;
60 | public static final int ERR_DPLAY_DO_DOWNLOAD_FAIL = 118305;
61 | public static final int ERR_DPLAY_DO_READFILE_FAIL = 118311;
62 | public static final int ERR_DPLAY_EV_SEND_TIMTOUT = 118310;
63 | public static final int ERR_DPLAY_HANDLE_DOWNLOAD_FAILED = 118302;
64 | public static final int ERR_DPLAY_NOT_FOUND = 118005;
65 | public static final int ERR_DPLAY_PLAY_FILE_NOT_EXIST = 118304;
66 | public static final int ERR_DPLAY_RECV_STATE_INVALID = 118308;
67 | public static final int ERR_DPLAY_SEND_FAILED = 118300;
68 | public static final int ERR_DPLAY_SEND_RANGE_INVALID = 118301;
69 | public static final int ERR_DPLAY_SEND_STATE_INVALID = 118309;
70 | public static final int ERR_DPLAY_TASK_FINISH_CANNT_DOWNLOAD = 118004;
71 | public static final int ERR_DPLAY_TASK_FINISH_CONTINUE = 118003;
72 | public static final int ERR_DPLAY_TASK_FINISH_DESTROY = 118002;
73 | public static final int ERR_DPLAY_UNKNOW_HTTP_METHOD = 118303;
74 | public static final int ERR_INVALID_ADDRESS_FAMILY = 116001;
75 | public static final int ERR_P2P_ALLOC_MEM_ERR = 11313;
76 | public static final int ERR_P2P_BROKER_CONNECT = 11308;
77 | public static final int ERR_P2P_CONNECT_FAILED = 11311;
78 | public static final int ERR_P2P_CONNECT_UPLOAD_SLOW = 11312;
79 | public static final int ERR_P2P_HANDSHAKE_RESP_FAIL = 11303;
80 | public static final int ERR_P2P_INVALID_COMMAND = 11309;
81 | public static final int ERR_P2P_INVALID_PARAM = 11310;
82 | public static final int ERR_P2P_NOT_SUPPORT_UDT = 11307;
83 | public static final int ERR_P2P_REMOTE_UNKNOWN_MY_CMD = 11306;
84 | public static final int ERR_P2P_REQUEST_RESP_FAIL = 11304;
85 | public static final int ERR_P2P_SEND_HANDSHAKE = 11314;
86 | public static final int ERR_P2P_UPLOAD_OVER_MAX = 11305;
87 | public static final int ERR_P2P_VERSION_NOT_SUPPORT = 11301;
88 | public static final int ERR_P2P_WAITING_CLOSE = 11302;
89 | public static final int ERR_PTL_GET_PEERSN_FAILED = 112600;
90 | public static final int ERR_PTL_PEER_OFFLINE = 112500;
91 | public static final int ERR_PTL_PROTOCOL_NOT_SUPPORT = 112400;
92 | public static final int FILE_CANNOT_TRUNCATE = 111084;
93 | public static final int FILE_CFG_ERASE_ERROR = 111130;
94 | public static final int FILE_CFG_MAGIC_ERROR = 111131;
95 | public static final int FILE_CFG_READ_ERROR = 111132;
96 | public static final int FILE_CFG_READ_HEADER_ERROR = 111134;
97 | public static final int FILE_CFG_RESOLVE_ERROR = 111135;
98 | public static final int FILE_CFG_TRY_FIX = 111129;
99 | public static final int FILE_CFG_WRITE_ERROR = 111133;
100 | public static final int FILE_CREATING = 111145;
101 | public static final int FILE_EXISTED = 9109;
102 | public static final int FILE_INVALID_PARA = 111144;
103 | public static final int FILE_NAME_TOO_LONG = 9125;
104 | public static final int FILE_NOT_EXIST = 111143;
105 | public static final int FILE_PATH_TOO_LONG = 111120;
106 | public static final int FILE_SIZE_NOT_BELIEVE = 111141;
107 | public static final int FILE_SIZE_TOO_SMALL = 111142;
108 | public static final int FILE_TOO_BIG = 111086;
109 | public static final int FIL_INFO_INVALID_DATA = 111146;
110 | public static final int FIL_INFO_RECVED_DATA = 111147;
111 | public static final int FULL_PATH_NAME_OCCUPIED = 9128;
112 | public static final int FULL_PATH_NAME_TOO_LONG = 9127;
113 | public static final int FUNCTION_NOT_SUPPORT = 9123;
114 | public static final int HTTP_HUB_CLIENT_E_BASE = 115100;
115 | public static final int HTTP_SERVER_NOT_START = 9400;
116 | public static final int INDEX_NOT_READY = 9303;
117 | public static final int INSUFFICIENT_DISK_SPACE = 111085;
118 | public static final int INVALID_ARGUMENT = 111041;
119 | public static final int INVALID_ITERATOR = 111038;
120 | public static final int INVALID_SOCKET_DESCRIPTOR = 111048;
121 | public static final int INVALID_TIMER_INDEX = 111074;
122 | public static final int IP6_ERRCODE_BASE = 116000;
123 | public static final int IP6_INVALID_IN6ADDR = 116002;
124 | public static final int IP6_NOT_SUPPORT_SSL = 116003;
125 | public static final int MAP_DUPLICATE_KEY = 111036;
126 | public static final int MAP_KEY_NOT_FOUND = 111037;
127 | public static final int MAP_UNINIT = 111035;
128 | public static final int NET_BROKEN_PIPE = 111170;
129 | public static final int NET_CONNECTION_REFUSED = 111171;
130 | public static final int NET_CONNECT_SSL_ERR = 111169;
131 | public static final int NET_NORMAL_CLOSE = 111175;
132 | public static final int NET_OP_CANCEL = 111173;
133 | public static final int NET_REACTOR_ERRCODE_BASE = 111168;
134 | public static final int NET_SSL_GET_FD_ERROR = 111172;
135 | public static final int NET_UNKNOWN_ERROR = 111174;
136 | public static final int NOT_FULL_PATH_NAME = 9404;
137 | public static final int NOT_IMPLEMENT = 111057;
138 | public static final int NO_ENOUGH_BUFFER = 9301;
139 | public static final int NO_ERROR = 9000;
140 | public static final int ONE_PATH_LEVEL_NAME_TOO_LONG = 9126;
141 | public static final int OPEN_FILE_ERR = 111128;
142 | public static final int OPEN_OLD_FILE_FAIL = 111140;
143 | public static final int OUT_OF_FIXED_MEMORY = 111032;
144 | public static final int OUT_OF_MEMORY = 111026;
145 | public static final int P2P_PIPE_ERRCODE_BASE = 11300;
146 | public static final int PARAM_ERROR = 9112;
147 | public static final int PAUSE_TASK_WRITE_CFG_ERR = 117000;
148 | public static final int PAUSE_TASK_WRITE_DATA_TIMEOUT = 117001;
149 | public static final int PRIOR_TASK_FINISH = 9308;
150 | public static final int PRIOR_TASK_NO_INDEX = 9307;
151 | public static final int QUEUE_NO_ROOM = 111033;
152 | public static final int READ_FILE_ERR = 111126;
153 | public static final int REDIRECT_TOO_MUCH = 111181;
154 | public static final int RES_QUERY_E_BASE = 115000;
155 | public static final int SCHEMA_NOT_SUPPORT = 9113;
156 | public static final int SDK_NOT_INIT = 9102;
157 | public static final int SETTINGS_ERR_CFG_FILE_NOT_EXIST = 111162;
158 | public static final int SETTINGS_ERR_INVALID_FILE_NAME = 111161;
159 | public static final int SETTINGS_ERR_INVALID_ITEM_NAME = 111164;
160 | public static final int SETTINGS_ERR_INVALID_ITEM_VALUE = 111165;
161 | public static final int SETTINGS_ERR_INVALID_LINE = 111163;
162 | public static final int SETTINGS_ERR_ITEM_NOT_FOUND = 111167;
163 | public static final int SETTINGS_ERR_LIST_EMPTY = 111166;
164 | public static final int SETTINGS_ERR_UNKNOWN = 111160;
165 | public static final int TARGET_THREAD_STOPING = 111025;
166 | public static final int TASK_ALREADY_EXIST = 9103;
167 | public static final int TASK_ALREADY_RUNNING = 9106;
168 | public static final int TASK_ALREADY_STOPPED = 9105;
169 | public static final int TASK_CONTROL_STRATEGY = 9501;
170 | public static final int TASK_FAILURE_ALL_SUBTASK_FAILED = 114009;
171 | public static final int TASK_FAILURE_BTHUB_NO_RECORD = 114008;
172 | public static final int TASK_FAILURE_CANNOT_START_SUBTASK = 114003;
173 | public static final int TASK_FAILURE_EMULE_NO_RECORD = 114101;
174 | public static final int TASK_FAILURE_GET_TORRENT_FAILED = 114006;
175 | public static final int TASK_FAILURE_NO_DATA_PIPE = 111136;
176 | public static final int TASK_FAILURE_PARSE_TORRENT_FAILED = 114005;
177 | public static final int TASK_FAILURE_PART_SUBTASK_FAILED = 114011;
178 | public static final int TASK_FAILURE_QUERY_BT_HUB_FAILED = 114004;
179 | public static final int TASK_FAILURE_QUERY_EMULE_HUB_FAILED = 114001;
180 | public static final int TASK_FAILURE_SAVE_TORRENT_FAILED = 114007;
181 | public static final int TASK_FAILURE_SUBTASK_FAILED = 114002;
182 | public static final int TASK_FAILURE_THEONLY_SUBTASK_FAILED = 114010;
183 | public static final int TASK_FAIL_LONG_TIME_NO_RECV_DATA = 111176;
184 | public static final int TASK_FILE_NAME_EMPTY = 9401;
185 | public static final int TASK_FILE_NOT_VEDIO = 9402;
186 | public static final int TASK_FILE_SIZE_TOO_LARGE = 111177;
187 | public static final int TASK_FINISH = 9118;
188 | public static final int TASK_NOT_EXIST = 9104;
189 | public static final int TASK_NOT_IDLE = 9120;
190 | public static final int TASK_NOT_RUNNING = 9119;
191 | public static final int TASK_NOT_START = 9107;
192 | public static final int TASK_NO_FILE_NAME = 9129;
193 | public static final int TASK_NO_INDEX_NO_ORIGIN = 111148;
194 | public static final int TASK_ORIGIN_NONEXISTENCE = 111149;
195 | public static final int TASK_RETRY_ALWAY_FAIL = 111178;
196 | public static final int TASK_STILL_RUNNING = 9108;
197 | public static final int TASK_TYPE_NOT_SUPPORT = 9121;
198 | public static final int TASK_UNKNOWN_ERROR = 9403;
199 | public static final int TASK_USE_TOO_MUCH_MEM = 111031;
200 | public static final int THUNDER_URL_PARSE_ERROR = 9305;
201 | public static final int TOO_MUCH_TASK = 9111;
202 | public static final int TORRENT_IMCOMPLETE = 9304;
203 | public static final int TORRENT_PARSE_ERROR = 9302;
204 | public static final int URL_IS_TOO_LONG = 111047;
205 | public static final int URL_PARSER_ERROR = 111046;
206 | public static final int VIDEO_CACHE_FINISH = 9410;
207 | public static final int WRITE_FILE_ERR = 111127;
208 | }
209 |
210 | public enum XLManagerStatus {
211 | MANAGER_UNINIT,
212 | MANAGER_INIT_FAIL,
213 | MANAGER_RUNNING
214 | }
215 |
216 | public enum XLNetWorkCarrier {
217 | NWC_Unknow,
218 | NWC_CMCC,
219 | NWC_CU,
220 | NWC_CT
221 | }
222 |
223 | public static class XLOriginResState {
224 | public static final int ORIGIN_RES_CHECKING = 1;
225 | public static final int ORIGIN_RES_DEATH_LINK = 3;
226 | public static final int ORIGIN_RES_UNUSED = 0;
227 | public static final int ORIGIN_RES_VALID_LINK = 2;
228 | }
229 |
230 | public enum XLQueryIndexStatus {
231 | QIS_UNQUERY,
232 | QIS_QUERYING,
233 | QIS_QUERY_HAVE_INFO,
234 | QIS_QUERY_HAVENT_INFO
235 | }
236 |
237 | public enum XLResStrategy {
238 | RUS_PRIOR_USE
239 | }
240 |
241 | public static class XLTaskStatus {
242 | public static final int TASK_FAILED = 3;
243 | public static final int TASK_IDLE = 0;
244 | public static final int TASK_RUNNING = 1;
245 | public static final int TASK_STOPPED = 4;
246 | public static final int TASK_SUCCESS = 2;
247 | }
248 |
249 | public static class XLTaskType {
250 | public static final int P2SP_TASK_TYP = 1;
251 | }
252 | }
253 |
--------------------------------------------------------------------------------
/thunder/src/main/java/com/xunlei/downloadlib/android/XLUtil.java:
--------------------------------------------------------------------------------
1 | package com.xunlei.downloadlib.android;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.net.ConnectivityManager;
6 | import android.net.NetworkInfo;
7 | import android.net.wifi.WifiInfo;
8 | import android.net.wifi.WifiManager;
9 | import android.os.Build;
10 | import android.os.Build.VERSION;
11 | import android.telephony.TelephonyManager;
12 | import android.text.TextUtils;
13 | import android.util.Base64;
14 | import java.io.FileNotFoundException;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 | import java.io.UnsupportedEncodingException;
19 | import java.net.NetworkInterface;
20 | import java.security.MessageDigest;
21 | import java.security.NoSuchAlgorithmException;
22 | import java.util.Collections;
23 | import java.util.HashMap;
24 | import java.util.Iterator;
25 | import java.util.Map;
26 | import java.util.Map.Entry;
27 | import java.util.concurrent.locks.ReadWriteLock;
28 | import java.util.concurrent.locks.ReentrantReadWriteLock;
29 | import org.json.JSONException;
30 | import org.json.JSONObject;
31 |
32 | public class XLUtil {
33 | private static final int IMEI_LEN = 15;
34 | private static final String TAG = "XLUtil";
35 | private static final ConfigFile sConfigFile = new ConfigFile();
36 |
37 | private static class ConfigFile {
38 | private static final String IDENTIFY_FILE_NAME = "Identify.txt";
39 | private Map configMap;
40 | private ReadWriteLock lock;
41 |
42 | private ConfigFile() {
43 | this.configMap = new HashMap();
44 | this.lock = new ReentrantReadWriteLock();
45 | }
46 |
47 | String get(Context context, String str, String str2) {
48 | this.lock.readLock().lock();
49 | String str3 = (String) this.configMap.get(str);
50 | if (str3 == null) {
51 | loadFile(context);
52 | str3 = (String) this.configMap.get(str);
53 | }
54 | this.lock.readLock().unlock();
55 | return str3 != null ? str3 : str2;
56 | }
57 |
58 | void set(Context context, String str, String str2) {
59 | this.lock.writeLock().lock();
60 | this.configMap.put(str, str2);
61 | saveFile(context);
62 | this.lock.writeLock().unlock();
63 | XLLog.i(XLUtil.TAG, "ConfigFile set key=" + str + " value=" + str2);
64 | }
65 |
66 | private void loadFile(Context context) {
67 | XLLog.i(XLUtil.TAG, "loadAndParseFile start");
68 | if (context == null || IDENTIFY_FILE_NAME == null) {
69 | XLLog.e(XLUtil.TAG, "loadAndParseFile end, parameter invalid, fileName:Identify.txt");
70 | return;
71 | }
72 | String readFromFile = readFromFile(context, IDENTIFY_FILE_NAME);
73 | if (readFromFile == null) {
74 | XLLog.i(XLUtil.TAG, "loadAndParseFile end, fileContext is empty");
75 | return;
76 | }
77 | this.configMap.clear();
78 | String[] split = readFromFile.split("\n");
79 | for (String split2 : split) {
80 | String[] split3 = split2.split("=");
81 | if (split3.length == 2) {
82 | this.configMap.put(split3[0], split3[1]);
83 | XLLog.i(XLUtil.TAG, "ConfigFile loadFile key=" + split3[0] + " value=" + split3[1]);
84 | }
85 | }
86 | XLLog.i(XLUtil.TAG, "loadAndParseFile end");
87 | }
88 |
89 | private void saveFile(Context context) {
90 | StringBuilder stringBuilder = new StringBuilder();
91 | for (Entry entry : this.configMap.entrySet()) {
92 | stringBuilder.append(((String) entry.getKey()) + "=" + ((String) entry.getValue()) + "\n");
93 | }
94 | writeToFile(context, stringBuilder.toString(), IDENTIFY_FILE_NAME);
95 | }
96 |
97 | private void writeToFile(Context context, String str, String str2) {
98 | if (context == null || str == null || str2 == null) {
99 | XLLog.e(XLUtil.TAG, "writeToFile, Parameter invalid, fileName:" + str2);
100 | return;
101 | }
102 | try {
103 | OutputStream openFileOutput = context.openFileOutput(str2, 0);
104 | try {
105 | openFileOutput.write(str.getBytes("utf-8"));
106 | openFileOutput.close();
107 | } catch (UnsupportedEncodingException e) {
108 | e.printStackTrace();
109 | } catch (IOException e2) {
110 | e2.printStackTrace();
111 | }
112 | } catch (FileNotFoundException e3) {
113 | e3.printStackTrace();
114 | }
115 | }
116 |
117 | private String readFromFile(Context context, String str) {
118 | String str2 = null;
119 | if (context == null || str == null) {
120 | XLLog.e(XLUtil.TAG, "readFromFile, parameter invalid, fileName:" + str);
121 | } else {
122 | try {
123 | InputStream openFileInput = context.openFileInput(str);
124 | byte[] bArr = new byte[256];
125 | try {
126 | int read = openFileInput.read(bArr);
127 | if (read > 0) {
128 | str2 = new String(bArr, 0, read, "utf-8");
129 | }
130 | openFileInput.close();
131 | } catch (IOException e) {
132 | e.printStackTrace();
133 | }
134 | } catch (FileNotFoundException e2) {
135 | XLLog.i(XLUtil.TAG, str + " File Not Found");
136 | }
137 | }
138 | return str2;
139 | }
140 | }
141 |
142 | public enum GUID_TYPE {
143 | DEFAULT,
144 | JUST_IMEI,
145 | JUST_MAC,
146 | ALL
147 | }
148 |
149 | public static class GuidInfo {
150 | public String mGuid = null;
151 | public GUID_TYPE mType = GUID_TYPE.DEFAULT;
152 | }
153 |
154 | public enum NetWorkCarrier {
155 | UNKNOWN,
156 | CMCC,
157 | CU,
158 | CT
159 | }
160 |
161 | public static long getCurrentUnixTime() {
162 | return System.currentTimeMillis() / 1000;
163 | }
164 |
165 | public static String getPeerid(Context context) {
166 | if (context == null) {
167 | return null;
168 | }
169 | String str = sConfigFile.get(context, "peerid", null);
170 | if (!TextUtils.isEmpty(str)) {
171 | return str;
172 | }
173 | String mac = getMAC(context);
174 | if (TextUtils.isEmpty(mac)) {
175 | mac = getIMEI(context);
176 | if (!TextUtils.isEmpty(mac)) {
177 | str = mac + "V";
178 | }
179 | } else {
180 | str = mac + "004V";
181 | }
182 | if (TextUtils.isEmpty(str)) {
183 | return null;
184 | }
185 | sConfigFile.set(context, "peerid", str);
186 | return str;
187 | }
188 |
189 | public static String getMAC(Context context) {
190 | String str = null;
191 | if (context != null) {
192 | str = sConfigFile.get(context, "MAC", null);
193 | if (TextUtils.isEmpty(str)) {
194 | str = getWifiMacAddress();
195 | if (!TextUtils.isEmpty(str)) {
196 | sConfigFile.set(context, "MAC", str);
197 | }
198 | }
199 | }
200 | return str;
201 | }
202 |
203 | @SuppressLint({"NewApi"})
204 | public static String getWifiMacAddress() {
205 | try {
206 | String str = "wlan0";
207 | for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
208 | if (networkInterface.getName().equalsIgnoreCase(str)) {
209 | byte[] hardwareAddress = networkInterface.getHardwareAddress();
210 | if (hardwareAddress == null) {
211 | return null;
212 | }
213 | StringBuilder stringBuilder = new StringBuilder();
214 | int length = hardwareAddress.length;
215 | for (int i = 0; i < length; i++) {
216 | stringBuilder.append(String.format("%02X", new Object[]{Byte.valueOf(hardwareAddress[i])}));
217 | }
218 | return stringBuilder.toString();
219 | }
220 | }
221 | } catch (Exception e) {
222 | e.printStackTrace();
223 | }
224 | return null;
225 | }
226 |
227 | public static String getIMEI(Context context) {
228 | Exception e;
229 | if (context == null) {
230 | return null;
231 | }
232 | String str = sConfigFile.get(context, "IMEI", null);
233 | if (!TextUtils.isEmpty(str)) {
234 | return str;
235 | }
236 | String deviceId;
237 | TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
238 | if (telephonyManager != null) {
239 | try {
240 | deviceId = telephonyManager.getDeviceId();
241 | if (deviceId != null) {
242 | try {
243 | if (deviceId.length() < 15) {
244 | str = deviceId;
245 | int length = 15 - deviceId.length();
246 | while (true) {
247 | int i = length - 1;
248 | if (length <= 0) {
249 | break;
250 | }
251 | str = str + "M";
252 | length = i;
253 | }
254 | deviceId = str;
255 | }
256 | sConfigFile.set(context, "IMEI", deviceId);
257 | } catch (Exception e2) {
258 | e = e2;
259 | e.printStackTrace();
260 | return deviceId;
261 | }
262 | }
263 | } catch (Exception e3) {
264 | Exception exception = e3;
265 | deviceId = str;
266 | e = exception;
267 | }
268 | } else {
269 | deviceId = str;
270 | }
271 | return deviceId;
272 | }
273 |
274 | public static GuidInfo generateGuid(Context context) {
275 | GuidInfo guidInfo = new GuidInfo();
276 | GUID_TYPE guid_type = GUID_TYPE.DEFAULT;
277 | String imei = getIMEI(context);
278 | if (TextUtils.isEmpty(imei)) {
279 | imei = "000000000000000";
280 | } else {
281 | guid_type = GUID_TYPE.JUST_IMEI;
282 | }
283 | String mac = getMAC(context);
284 | if (TextUtils.isEmpty(mac)) {
285 | mac = "000000000000";
286 | } else if (guid_type == GUID_TYPE.JUST_IMEI) {
287 | guid_type = GUID_TYPE.ALL;
288 | } else {
289 | guid_type = GUID_TYPE.JUST_MAC;
290 | }
291 | guidInfo.mGuid = imei + "_" + mac;
292 | guidInfo.mType = guid_type;
293 | return guidInfo;
294 | }
295 |
296 | public static String getOSVersion(Context context) {
297 | StringBuilder stringBuilder = new StringBuilder();
298 | stringBuilder.append("SDKV = " + VERSION.RELEASE);
299 | stringBuilder.append("_MANUFACTURER = " + Build.MANUFACTURER);
300 | stringBuilder.append("_MODEL = " + Build.MODEL);
301 | stringBuilder.append("_PRODUCT = " + Build.PRODUCT);
302 | stringBuilder.append("_FINGERPRINT = " + Build.FINGERPRINT);
303 | stringBuilder.append("_CPU_ABI = " + Build.CPU_ABI);
304 | stringBuilder.append("_ID = " + Build.ID);
305 | return stringBuilder.toString();
306 | }
307 |
308 | public static String getAPNName(Context context) {
309 | if (context == null) {
310 | return null;
311 | }
312 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
313 | if (connectivityManager == null) {
314 | return null;
315 | }
316 | NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
317 | if (networkInfo == null) {
318 | return null;
319 | }
320 | return networkInfo.getExtraInfo();
321 | }
322 |
323 | public static String getSSID(Context context) {
324 | if (context == null) {
325 | XLLog.e(TAG, "getSSID, context invalid");
326 | return null;
327 | }
328 | WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
329 | if (wifiManager != null) {
330 | WifiInfo connectionInfo = wifiManager.getConnectionInfo();
331 | if (connectionInfo != null) {
332 | return connectionInfo.getSSID();
333 | }
334 | }
335 | return null;
336 | }
337 |
338 | public static String getBSSID(Context context) {
339 | if (context == null) {
340 | XLLog.e(TAG, "getBSSID, context invalid");
341 | return null;
342 | }
343 | WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
344 | if (wifiManager != null) {
345 | try {
346 | WifiInfo connectionInfo = wifiManager.getConnectionInfo();
347 | if (connectionInfo != null) {
348 | return connectionInfo.getBSSID();
349 | }
350 | } catch (Exception e) {
351 | }
352 | }
353 | return null;
354 | }
355 |
356 | public static int getNetworkTypeComplete(Context context) {
357 | if (context == null) {
358 | XLLog.e(TAG, "getNetworkTypeComplete, context invalid");
359 | return 0;
360 | }
361 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
362 | if (connectivityManager == null) {
363 | return 0;
364 | }
365 | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
366 | if (activeNetworkInfo == null) {
367 | return 0;
368 | }
369 | int type = activeNetworkInfo.getType();
370 | if (type == 1) {
371 | return 9;
372 | }
373 | if (type != 0) {
374 | return 5;
375 | }
376 | int i;
377 | switch (activeNetworkInfo.getSubtype()) {
378 | case 1:
379 | case 2:
380 | case 4:
381 | case 7:
382 | case 11:
383 | return 2;
384 | case 3:
385 | case 5:
386 | case 6:
387 | case 8:
388 | case 9:
389 | case 10:
390 | case 12:
391 | case 14:
392 | case 15:
393 | return 3;
394 | case 13:
395 | i = 4;
396 | break;
397 | default:
398 | i = 0;
399 | break;
400 | }
401 | return i;
402 | }
403 |
404 | public static int getNetworkTypeSimple(Context context) {
405 | if (context == null) {
406 | XLLog.e(TAG, "getNetworkTypeSimple, context invalid");
407 | return 0;
408 | }
409 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
410 | if (connectivityManager == null) {
411 | return 1;
412 | }
413 | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
414 | if (activeNetworkInfo == null) {
415 | return 1;
416 | }
417 | int type = activeNetworkInfo.getType();
418 | if (type == 1) {
419 | return 2;
420 | }
421 | if (type != 0) {
422 | return 1;
423 | }
424 | int i;
425 | switch (activeNetworkInfo.getSubtype()) {
426 | case 1:
427 | case 2:
428 | case 3:
429 | case 4:
430 | case 5:
431 | case 6:
432 | case 7:
433 | case 8:
434 | case 9:
435 | case 10:
436 | case 11:
437 | case 12:
438 | case 13:
439 | case 14:
440 | case 15:
441 | i = 3;
442 | break;
443 | default:
444 | i = 1;
445 | break;
446 | }
447 | return i;
448 | }
449 |
450 | public static String getMd5(String str) {
451 | if (str == null) {
452 | XLLog.e(TAG, "getMd5, key invalid");
453 | return null;
454 | }
455 | try {
456 | char[] cArr = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
457 | MessageDigest instance = MessageDigest.getInstance("MD5");
458 | byte[] bytes = str.getBytes();
459 | instance.update(bytes, 0, bytes.length);
460 | byte[] digest = instance.digest();
461 | StringBuilder stringBuilder = new StringBuilder(32);
462 | for (byte b : digest) {
463 | stringBuilder.append(cArr[(b >> 4) & 15]).append(cArr[(b >> 0) & 15]);
464 | }
465 | return stringBuilder.toString();
466 | } catch (NoSuchAlgorithmException e) {
467 | e.printStackTrace();
468 | return str;
469 | }
470 | }
471 |
472 | public static String generateAppKey(String str, short s, byte b) {
473 | if (str == null) {
474 | XLLog.e(TAG, "generateAppKey, appName invalid");
475 | return null;
476 | }
477 | int length = str.length();
478 | byte[] bArr = new byte[(((length + 1) + 2) + 1)];
479 | byte[] bytes = str.getBytes();
480 | for (int i = 0; i < bytes.length; i++) {
481 | bArr[i] = bytes[i];
482 | }
483 | bArr[length] = (byte) 0;
484 | bArr[length + 1] = (byte) (s & 255);
485 | bArr[length + 2] = (byte) ((s >> 8) & 255);
486 | bArr[length + 3] = b;
487 | return new String(Base64.encode(bArr, 0)).trim();
488 | }
489 |
490 | public static Map parseJSONString(String str) {
491 | if (str == null) {
492 | XLLog.e(TAG, "parseJSONString, JSONString invalid");
493 | return null;
494 | }
495 | Map hashMap = new HashMap();
496 | try {
497 | JSONObject jSONObject = new JSONObject(str);
498 | Iterator keys = jSONObject.keys();
499 | while (keys.hasNext()) {
500 | String str2 = (String) keys.next();
501 | hashMap.put(str2, jSONObject.getString(str2));
502 | }
503 | } catch (JSONException e) {
504 | e.printStackTrace();
505 | }
506 | return hashMap;
507 | }
508 |
509 | public static NetWorkCarrier getNetWorkCarrier(Context context) {
510 | if (context != null) {
511 | TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
512 | if (telephonyManager != null) {
513 | try {
514 | String subscriberId = telephonyManager.getSubscriberId();
515 | if (subscriberId.startsWith("46000") || subscriberId.startsWith("46002")) {
516 | return NetWorkCarrier.CMCC;
517 | }
518 | if (subscriberId.startsWith("46001")) {
519 | return NetWorkCarrier.CU;
520 | }
521 | if (subscriberId.startsWith("46003")) {
522 | return NetWorkCarrier.CT;
523 | }
524 | } catch (Exception e) {
525 | e.printStackTrace();
526 | }
527 | }
528 | }
529 | return NetWorkCarrier.UNKNOWN;
530 | }
531 | }
532 |
--------------------------------------------------------------------------------