修复 5.0以下的手机无法获取到代理文件的问题

pull/330/head
laoyuyu 6 years ago
parent cb6f08aa0d
commit c0993ab538
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  2. 59
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java

@ -50,9 +50,6 @@ public class ProxyHelper {
List<String> classes = CommonUtil.getClassName(AriaManager.APP, List<String> classes = CommonUtil.getClassName(AriaManager.APP,
"com.arialyy.aria.ProxyClassCounter"); "com.arialyy.aria.ProxyClassCounter");
for (String className : classes) { for (String className : classes) {
if (!className.startsWith("com.arialyy.aria.ProxyClassCounter")) {
continue;
}
count(className); count(className);
} }
} }

@ -40,7 +40,6 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import dalvik.system.DexFile; import dalvik.system.DexFile;
import dalvik.system.PathClassLoader;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -80,42 +79,50 @@ public class CommonUtil {
*/ */
public static List<String> getClassName(Context context, String className) { public static List<String> getClassName(Context context, String className) {
List<String> classNameList = new ArrayList<>(); List<String> classNameList = new ArrayList<>();
try { String pPath = context.getPackageCodePath();
String pPath = context.getPackageCodePath(); File dir = new File(pPath).getParentFile();
File dir = new File(pPath).getParentFile(); String[] paths = dir.list();
//PathClassLoader classLoader = (PathClassLoader) context.getClassLoader(); if (paths == null) {
classNameList.addAll(getPkgClassName(pPath, className));
} else {
String dPath = dir.getPath(); String dPath = dir.getPath();
for (String path : dir.list()) { for (String path : dir.list()) {
String fPath = dPath + "/" + path; String fPath = dPath + "/" + path;
Log.d(TAG, fPath);
if (!fPath.endsWith(".apk")) { if (!fPath.endsWith(".apk")) {
continue; continue;
} }
DexFile df = new DexFile(fPath);//通过DexFile查找当前的APK中可执行文件 classNameList.addAll(getPkgClassName(fPath, className));
Enumeration<String> enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式 }
while (enumeration.hasMoreElements()) { }
String _className = enumeration.nextElement(); return classNameList;
if (!_className.contains(className)) { }
continue;
} /**
//Class clazz = classLoader.loadClass(_className); // 处理4.4手机无法获取到类的问题 * 获取指定包名下的所有类
//String cn = clazz.getName(); *
//if (clazz.getName().contains(className)) {//在当前所有可执行的类里面查找包含有该包名的所有类 * @param path dex路径
// classNameList.add(_className); * @param filterClass 需要过滤的类
//} */
if (_className.contains(className)){ public static List<String> getPkgClassName(String path, String filterClass) {
classNameList.add(_className); List<String> list = new ArrayList<>();
} try {
DexFile df = new DexFile(path);//通过DexFile查找当前的APK中可执行文件
Enumeration<String> enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式
while (enumeration.hasMoreElements()) {
String _className = enumeration.nextElement();
if (!_className.contains(filterClass)) {
continue;
}
if (_className.contains(filterClass)) {
list.add(_className);
} }
df.close();
} }
df.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
//catch (ClassNotFoundException e) { return list;
// e.printStackTrace();
//}
return classNameList;
} }
/** /**

Loading…
Cancel
Save