diff --git a/FtpComponent/src/main/resources/META-INF/MANIFEST.MF b/FtpComponent/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/FtpComponent/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/HttpComponent/src/main/resources/META-INF/MANIFEST.MF b/HttpComponent/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/HttpComponent/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/M3U8Component/src/main/resources/META-INF/MANIFEST.MF b/M3U8Component/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/M3U8Component/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/AriaServiceLoader.java b/PublicComponent/src/main/java/com/arialyy/aria/util/AriaServiceLoader.java index ad6c480a..a7e486a1 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/AriaServiceLoader.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/AriaServiceLoader.java @@ -32,7 +32,7 @@ import java.util.ServiceLoader; * 参考{@link ServiceLoader} */ public class AriaServiceLoader { - + private static final String TAG = "AriaServiceLoader"; private static final String PREFIX = "META-INF/services/"; // The class or interface representing the service being loaded @@ -177,6 +177,10 @@ public class AriaServiceLoader { } private S loadService(String serviceName) { + if (pending == null){ + ALog.e(TAG, "pending为空"); + return null; + } for (String s : pending) { if (s.equals(serviceName)) { Class c = null; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java index 962f12af..76fd0392 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java @@ -24,9 +24,11 @@ import com.arialyy.aria.core.listener.IEventListener; import com.arialyy.aria.core.task.AbsTask; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper; -import com.arialyy.aria.exception.AriaComponentException; import java.lang.ref.SoftReference; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.List; /** @@ -43,12 +45,9 @@ public class ComponentUtil { private String TAG = CommonUtil.getClassName(getClass()); private static volatile ComponentUtil INSTANCE = null; - private AriaServiceLoader utilLoader; - private AriaServiceLoader listenerLoader; private ComponentUtil() { - utilLoader = AriaServiceLoader.load(IUtil.class); - listenerLoader = AriaServiceLoader.load(IEventListener.class); + } public static ComponentUtil getInstance() { @@ -105,7 +104,8 @@ public class ComponentUtil { * * @return 返回任务工具 */ - public synchronized IUtil buildUtil(AbsTaskWrapper wrapper, IEventListener listener) { + public synchronized T buildUtil(AbsTaskWrapper wrapper, + IEventListener listener) { int requestType = wrapper.getRequestType(); String className = null; switch (requestType) { @@ -140,11 +140,30 @@ public class ComponentUtil { className = "com.arialyy.aria.sftp.upload.SFtpULoaderUtil"; break; } - IUtil util = utilLoader.getService(className); - if (util == null) { - throw new AriaComponentException("加载工具异常,请求类型:" + wrapper.getRequestType()); + if (className == null) { + ALog.e(TAG, "不识别的类名:" + className); + return null; } - return util.setParams(wrapper, listener); + T util = null; + try { + Class clazz = (Class) getClass().getClassLoader().loadClass(className); + Constructor con = clazz.getConstructor(); + util = con.newInstance(); + Method method = + CommonUtil.getMethod(clazz, "setParams", AbsTaskWrapper.class, IEventListener.class); + method.invoke(util, wrapper, listener); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return util; } /** @@ -153,7 +172,7 @@ public class ComponentUtil { * @param wrapperType 任务类型{@link ITaskWrapper} * @return 返回事件监听,如果创建失败返回null */ - public synchronized IEventListener buildListener(int wrapperType, AbsTask task, + public synchronized T buildListener(int wrapperType, AbsTask task, Handler outHandler) { String className = null, errorStr = "请添加FTP插件"; switch (wrapperType) { @@ -180,12 +199,26 @@ public class ComponentUtil { if (className == null) { return null; } - - IEventListener listener = listenerLoader.getService(className); - if (listener == null) { - throw new AriaComponentException(errorStr); + T listener = null; + try { + Class clazz = (Class) getClass().getClassLoader().loadClass(className); + Constructor con = clazz.getConstructor(); + listener = con.newInstance(); + Method method = + CommonUtil.getMethod(clazz, "setParams", AbsTask.class, Handler.class); + method.invoke(listener, task, outHandler); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(errorStr); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); } - return listener.setParams(task, outHandler); + return listener; } /** diff --git a/PublicComponent/src/main/resources/META-INF/MANIFEST.MF b/PublicComponent/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/PublicComponent/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/SFtpComponent/src/main/resources/META-INF/MANIFEST.MF b/SFtpComponent/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/SFtpComponent/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/app/build.gradle b/app/build.gradle index 9748e9bb..a2e970f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,9 @@ android { buildTypes { release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + zipAlignEnabled true + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } } @@ -43,6 +44,7 @@ android { packagingOptions { exclude 'META-INF/services/javax.annotation.processing.Processor' + merge 'META-INF/services/com.arialyy.aria.core.inf.IUtil' } lintOptions { @@ -61,6 +63,7 @@ dependencies { androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.material:material:1.0.0' @@ -70,16 +73,23 @@ dependencies { implementation 'com.github.bumptech.glide:glide:3.7.0' implementation 'com.pddstudio:highlightjs-android:1.5.0' implementation 'org.greenrobot:eventbus:3.1.1' + implementation project(':AppFrame') // aria kapt project(':AriaCompiler') implementation project(':Aria') - implementation project(':AppFrame') implementation project(':M3U8Component') implementation project(':FtpComponent') implementation project(path: ':AriaAnnotations') implementation project(path: ':SFtpComponent') + +// implementation 'com.arialyy.aria:core:3.8.12' +// kapt 'com.arialyy.aria:compiler:3.8.12' +// implementation 'com.arialyy.aria:ftpComponent:3.8.12' // 如果需要使用ftp,请增加该组件 +// implementation 'com.arialyy.aria:sftpComponent:3.8.12' // 如果需要使用ftp,请增加该组件 +// implementation 'com.arialyy.aria:m3u8Component:3.8.12' // 如果需要使用m3u8下载功能,请增加该组件 + debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' } repositories { diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..142c0793 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,135 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +################################### 混淆配置 start ########################################### +#指定代码的压缩级别 +-optimizationpasses 1 +#包明不混合大小写 +-dontusemixedcaseclassnames +#不去忽略非公共的库类 +-dontskipnonpubliclibraryclasses +#优化 不优化输入的类文件 +-dontoptimize +#预校验 +-dontpreverify +#混淆时是否记录日志 +-verbose +# 混淆时所采用的算法 +#-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* +-optimizations !code/simplification/cast,!field/*,!class/merging/* +#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* +#忽略警告 +#-ignorewarning +################################### 混淆配置 end ############################################ + + +################## 记录生成的日志数据,gradle build时在本项目根目录输出 ################# +####### 输出文件夹 build/outputs/mapping +#apk 包内所有 class 的内部结构 +-dump build/outputs/mapping/class_files.txt +#未混淆的类和成员 +-printseeds build/outputs/mapping/kpa_seeds.txt +#列出从 apk 中删除的代码 +-printusage build/outputs/mapping/kpa_unused.txt +#混淆前后的映射 +-printmapping build/outputs/mapping/kpa_mapping.txt +################## 记录生成的日志数据,gradle build时 在本项目根目录输出-end ################# + +################## 常用属性配置-start ################## +# 保护注解 +-keepattributes *Annotation* +# 保护support v4 包 +-dontwarn android.support.v4.app.** +-keep class android.support.v4.app.**{ *; } +# 保护andorid x +-keep class com.google.android.material.** {*;} +-keep class androidx.** {*;} +-keep public class * extends androidx.** +-keep interface androidx.** {*;} +-dontwarn com.google.android.material.** +-dontnote com.google.android.material.** +-dontwarn androidx.** +# 保护一些奇葩的问题 +-dontwarn org.xmlpull.v1.XmlPullParser +-dontwarn org.xmlpull.v1.XmlSerializer +-keep class org.xmlpull.v1.* {*;} + +# 保护JS接口 +-keepclassmembers class * { + @android.webkit.JavascriptInterface ; +} +##保持 native 方法不被混淆 +-keepclasseswithmembernames class * { + native ; +} +##保持 Parcelable 不被混淆 +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} +##保持 Serializable 不被混淆 +-keepnames class * implements java.io.Serializable +# +#保持 Serializable 不被混淆并且enum 类也不被混淆 +-keepclassmembers class * implements java.io.Serializable { + static final long serialVersionUID; + private static final java.io.ObjectStreamField[] serialPersistentFields; + private void writeObject(java.io.ObjectOutputStream); + private void readObject(java.io.ObjectInputStream); + java.lang.Object writeReplace(); + java.lang.Object readResolve(); +} +#避免混淆泛型 如果混淆报错建议关掉 +#–keepattributes Signature +# webview + js +-keepattributes *JavascriptInterface* + +################## 常用属性配置-end ################## + +################## kotlin-start ################## +-keep class kotlin.** { *; } +-keep class kotlin.Metadata { *; } +-dontwarn kotlin.** +-keepclassmembers class **$WhenMappings { + ; +} +-keepclassmembers class kotlin.Metadata { + public ; +} +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + static void checkParameterIsNotNull(java.lang.Object, java.lang.String); +} +################## kotlin-end ################## + +-dontwarn com.arialyy.aria.** +-keep class com.arialyy.aria.**{*;} +-keep class **$$DownloadListenerProxy{ *; } +-keep class **$$UploadListenerProxy{ *; } +-keep class **$$DownloadGroupListenerProxy{ *; } +-keep class **$$DGSubListenerProxy{ *; } +-keepclasseswithmembernames class * { + @Download.* ; + @Upload.* ; + @DownloadGroup.* ; +} +-keep class com.arialyy.aria.ftp.download.FtpDLoaderUtil{*;} +-adaptresourcefilenames **.IUtil +-adaptresourcefilecontents **.IUtil \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index f78770c5..09f18bce 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -35,12 +35,14 @@ import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.HttpOption; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskListener; +import com.arialyy.aria.core.download.target.HttpNormalTarget; import com.arialyy.aria.core.listener.ISchedulers; import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface; import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; +import com.arialyy.aria.util.FileUtil; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; @@ -120,6 +122,25 @@ public class SingleTaskActivity extends BaseActivity { @Override public void cancel(View v, AbsEntity entity) { Aria.download(this).load(mTaskId).cancel(false); + // //1. 删除本地文件目录 + // File localDirFile = new File(mFilePath); + // if (localDirFile.exists()) { + // FileUtil.deleteDir(localDirFile.getParentFile()); + // } + // + // //2. 删除记录 + // HttpNormalTarget target = Aria.download(SingleTaskActivity.this).load(mTaskId); + // if (target != null) { + // // target.cancel(); + // target.removeRecord(); + // } + // + // List notCompleteTask = Aria.download(SingleTaskActivity.this).getAllNotCompleteTask(); + // if (notCompleteTask == null){ + // Log.d(TAG, "未完成的任务数:0"); + // return; + // } + // Log.d(TAG, "未完成的任务数:" + notCompleteTask.size()); } }); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java index af3b15f2..55096d12 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java @@ -314,7 +314,7 @@ public class M3U8VodDLoadActivity extends BaseActivity { option.generateIndexFile(); //option.setKeyUrlConverter(new KeyUrlConverter()); //option.setVodTsUrlConvert(new VodTsUrlConverter()); - //option.setBandWidthUrlConverter(new BandWidthUrlConverter()); + option.setBandWidthUrlConverter(new BandWidthUrlConverter()); //option.setUseDefConvert(true); return option; } diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java index afd73706..f8c89876 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java @@ -34,8 +34,8 @@ public class M3U8VodModule extends BaseViewModule { // m3u8测试集合:http://www.voidcn.com/article/p-snaliarm-ct.html //private final String defUrl = "https://www.gaoya123.cn/2019/1557993797897.m3u8"; // 多码率地址: - //private final String defUrl = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"; - private final String defUrl = "http://pp3zvsk2n.bkt.clouddn.com/20200806/sd/15967206011811803/38475fadd55e4ecea3.m3u8"; + private final String defUrl = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"; + //private final String defUrl = "http://pp3zvsk2n.bkt.clouddn.com/20200806/sd/15967206011811803/38475fadd55e4ecea3.m3u8"; //private final String defUrl = "http://youku.cdn7-okzy.com/20200123/16815_fbe419ed/index.m3u8"; //private final String defUrl = "https://cn7.kankia.com/hls/20200108/e1eaec074274c64fe46a3bdb5d2ba487/1578488360/index.m3u8";