QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 ApkExplorer.java 源代码,内容仅作参考
package com.dike.lib.apkmarker;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import com.dike.lib.apkmarker.Apk;
import com.tencent.mtt.compliance.MethodDelegate;
import com.xiaomi.mipush.sdk.Constants;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ApkExplorer {
private static final String PATH_ANDROID_DATA = "androiddata:";
private static final String PATH_DOWNLOAD = "download:";
private static final String PATH_ROOT = "root:";
private static final String TAG = "ApkExplorer";
private static final Map<String, String> mSpecialPathSearchMap = new HashMap();
private static final Handler mHandler = new a(Looper.getMainLooper());
private static final String[] mPresetSearchPathArr = {"root:/QQBrowser/安装包/", "androiddata:/com.tencent.mtt/files/.pre_dw", "root:/tencent/TMAssistantSDK/Download/", "root:/tencent/tassistant/apk/", "root:/ColorOS/Market/app/", "root:/MiMarket/fiIes/apk/", "root:/360Download/", "root:/"};
private static final List<String> mCustomSearchPathList = new LinkedList();
public interface InstallListener {
public static final int RESULT_FAILED = -1;
public static final int RESULT_SUCCESS = 1;
void onResult(int i, String str);
}
public enum VersionCodeCompareMode {
Equal,
LessThan,
NotLessThan,
GreaterThan,
NotGreaterThan
}
static class a extends Handler {
a(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message message) {
InstallListener installListener;
if (message != null && Object[].class.isInstance(message.obj)) {
Object[] objArr = (Object[]) message.obj;
if (3 != objArr.length || (installListener = (InstallListener) objArr[0]) == null) {
return;
}
installListener.onResult(((Integer) objArr[1]).intValue(), (String) objArr[2]);
}
}
}
static class b extends Thread {
final String f3288a;
final Apk f3289b;
final InstallListener f3290c;
final Context f3291d;
final String e;
b(String str, Apk apk, InstallListener installListener, Context context, String str2) {
this.f3288a = str;
this.f3289b = apk;
this.f3290c = installListener;
this.f3291d = context;
this.e = str2;
}
@Override
public void run() {
Uri fromFile;
String str = TextUtils.isEmpty(this.f3288a) ? " " : this.f3288a;
Apk apk = this.f3289b;
if (apk != null) {
Apk.IEditor iEditor = null;
try {
try {
iEditor = apk.edit("rw");
iEditor.putString(Apk.IEditor.KEY_CHANNEL, str);
iEditor.commit();
if (iEditor != null) {
iEditor.release();
}
} catch (Exception e) {
ApkExplorer.notifyInstallListener(this.f3290c, -1, e.getMessage());
if (iEditor != null) {
iEditor.release();
return;
}
return;
}
} catch (Throwable th) {
if (iEditor != null) {
iEditor.release();
}
throw th;
}
}
Apk apk2 = this.f3289b;
if (apk2 == null) {
ApkExplorer.notifyInstallListener(this.f3290c, -1, "apk not found");
return;
}
File file = new File(apk2.getEditPath());
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.setFlags(268435456);
if (Build.VERSION.SDK_INT >= 24) {
fromFile = h.a(this.f3291d, this.e, file);
intent.addFlags(1);
} else {
fromFile = Uri.fromFile(file);
}
intent.setDataAndType(fromFile, "application/vnd.android.package-archive");
this.f3291d.startActivity(intent);
ApkExplorer.notifyInstallListener(this.f3290c, 1, "success, changed channel to " + str);
}
}
public static class c {
static final int[] f3292a = new int[VersionCodeCompareMode.values().length];
static {
try {
f3292a[VersionCodeCompareMode.Equal.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
f3292a[VersionCodeCompareMode.LessThan.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
f3292a[VersionCodeCompareMode.NotLessThan.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
f3292a[VersionCodeCompareMode.GreaterThan.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
f3292a[VersionCodeCompareMode.NotGreaterThan.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
}
}
static {
mSpecialPathSearchMap.put("com.dike.application", "root:/test.apk");
}
public static void addCustomerSearchPath(String str) {
mCustomSearchPathList.add(str);
}
public static Apk findApk(Context context, String str, int i, VersionCodeCompareMode versionCodeCompareMode, boolean z) {
Apk apk;
String[] split;
int size;
int i2;
Apk findInEditorDir = findInEditorDir(str, i, versionCodeCompareMode);
if (findInEditorDir == null) {
String[] strArr = mPresetSearchPathArr;
if (strArr.length > 0) {
apk = findInEditorDir;
for (String str2 : strArr) {
apk = getApk(context, new File(fixPath(str2)), str, i, versionCodeCompareMode, z);
if (apk != null) {
break;
}
}
if (apk == null && (size = mCustomSearchPathList.size()) > 0) {
for (i2 = 0; i2 < size; i2++) {
apk = getApk(context, new File(fixPath(mCustomSearchPathList.get(i2))), str, i, versionCodeCompareMode, z);
if (apk != null) {
break;
}
}
}
if (apk == null) {
String str3 = mSpecialPathSearchMap.get(str);
if (!TextUtils.isEmpty(str3) && (split = str3.split("\\|")) != null && split.length > 0) {
for (String str4 : split) {
apk = getApk(context, new File(fixPath(str4)), str, i, versionCodeCompareMode, z);
if (apk != null) {
break;
}
}
}
}
if (apk == null) {
List<String> findApkFilePathFromSystemDatabase = findApkFilePathFromSystemDatabase(context);
if (findApkFilePathFromSystemDatabase.size() > 0) {
Iterator<String> it = findApkFilePathFromSystemDatabase.iterator();
while (it.hasNext() && (apk = getApk(context, new File(it.next()), str, i, versionCodeCompareMode, z)) == null) {
}
}
}
return apk;
}
}
apk = findInEditorDir;
if (apk == null) {
while (i2 < size) {
}
}
if (apk == null) {
}
if (apk == null) {
}
return apk;
}
private static List<String> findApkFilePathFromSystemDatabase(Context context) {
ContentResolver contentResolver = context.getContentResolver();
String[] strArr = {"%.apk", "%.apk.1"};
ArrayList arrayList = new ArrayList();
Cursor cursor = null;
try {
try {
cursor = MethodDelegate.query(contentResolver, MediaStore.Files.getContentUri("external"), new String[]{"_id", "_data", "_size"}, "_data LIKE ? OR _data LIKE ?", strArr, "_size DESC ");
if (cursor != null) {
int columnIndex = cursor.getColumnIndex("_data");
while (cursor.moveToNext()) {
arrayList.add(cursor.getString(columnIndex));
}
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
private static Apk findInEditorDir(String str, int i, VersionCodeCompareMode versionCodeCompareMode) {
File[] listFiles;
File file;
File a2 = com.dike.lib.apkmarker.a.a();
if (a2.exists() && (listFiles = a2.listFiles()) != null && listFiles.length > 0) {
String a3 = com.dike.lib.apkmarker.a.a(str, i);
if (VersionCodeCompareMode.Equal == versionCodeCompareMode) {
file = new File(a2, a3);
} else {
HashMap hashMap = new HashMap();
for (File file2 : listFiles) {
String[] split = m.a(file2).split("_");
if (split != null && split.length == 2) {
List list = (List) hashMap.get(split[0]);
if (list == null) {
list = new LinkedList();
hashMap.put(split[0], list);
}
int a4 = m.a(split[1], -1);
if (-1 != a4) {
list.add(Integer.valueOf(a4));
}
}
}
List list2 = (List) hashMap.get(str);
if (list2 != null && -1 != (i = findMatchedVersion(list2, i, versionCodeCompareMode))) {
file = new File(a2, com.dike.lib.apkmarker.a.a(str, i));
String absolutePath = file.getAbsolutePath();
return Apk.create(str, absolutePath, absolutePath, i);
}
}
}
return null;
}
private static int findMatchedVersion(List<Integer> list, int i, VersionCodeCompareMode versionCodeCompareMode) {
Integer next;
if (VersionCodeCompareMode.Equal == versionCodeCompareMode) {
if (-1 == list.indexOf(Integer.valueOf(i))) {
return -1;
}
return i;
}
if (VersionCodeCompareMode.LessThan == versionCodeCompareMode) {
Iterator<Integer> it = list.iterator();
while (it.hasNext()) {
next = it.next();
if (next.intValue() < i) {
}
}
return -1;
}
if (VersionCodeCompareMode.GreaterThan == versionCodeCompareMode) {
Iterator<Integer> it2 = list.iterator();
while (it2.hasNext()) {
next = it2.next();
if (next.intValue() > i) {
}
}
return -1;
}
if (VersionCodeCompareMode.NotGreaterThan == versionCodeCompareMode) {
Iterator<Integer> it3 = list.iterator();
while (it3.hasNext()) {
next = it3.next();
if (next.intValue() <= i) {
}
}
return -1;
}
if (VersionCodeCompareMode.NotLessThan != versionCodeCompareMode) {
return -1;
}
Iterator<Integer> it4 = list.iterator();
while (it4.hasNext()) {
next = it4.next();
if (next.intValue() >= i) {
}
}
return -1;
return next.intValue();
}
private static String fixPath(String str) {
StringBuilder sb;
File downloadCacheDirectory;
String str2;
if (TextUtils.isEmpty(str)) {
return "";
}
int indexOf = str.indexOf(Constants.COLON_SEPARATOR);
if (-1 == indexOf) {
return str;
}
int i = indexOf + 1;
String substring = str.substring(0, i);
String substring2 = str.substring(i);
if (PATH_ROOT.equalsIgnoreCase(substring)) {
sb = new StringBuilder();
downloadCacheDirectory = Environment.getExternalStorageDirectory();
} else {
if (PATH_ANDROID_DATA.equalsIgnoreCase(substring)) {
sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory().getAbsolutePath());
str2 = "/Android/data";
sb.append(str2);
sb.append(substring2);
return sb.toString();
}
if (!PATH_DOWNLOAD.equalsIgnoreCase(substring)) {
throw new IllegalStateException("The prefix[" + substring + "] not support");
}
sb = new StringBuilder();
downloadCacheDirectory = Environment.getDownloadCacheDirectory();
}
str2 = downloadCacheDirectory.getAbsolutePath();
sb.append(str2);
sb.append(substring2);
return sb.toString();
}
private static Apk getApk(Context context, File file, String str, int i, VersionCodeCompareMode versionCodeCompareMode, boolean z) {
Apk apk = null;
if (!file.exists()) {
return null;
}
if (file.isFile()) {
if (!z || file.getAbsolutePath().toLowerCase().endsWith(".apk")) {
return getMatchedApk(context, file.getAbsolutePath(), str, i, versionCodeCompareMode);
}
return null;
}
File[] listFiles = file.listFiles();
if (listFiles == null || listFiles.length <= 0) {
return null;
}
for (File file2 : listFiles) {
if (!file2.isDirectory() && (apk = getApk(context, file2, str, i, versionCodeCompareMode, z)) != null) {
return apk;
}
}
return apk;
}
private static Apk getMatchedApk(Context context, String str, String str2, int i, VersionCodeCompareMode versionCodeCompareMode) {
int i2;
PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(str, 1);
if (packageArchiveInfo != null) {
String str3 = packageArchiveInfo.applicationInfo.packageName;
int longVersionCode = Build.VERSION.SDK_INT >= 28 ? (int) packageArchiveInfo.getLongVersionCode() : packageArchiveInfo.versionCode;
if (str2.equalsIgnoreCase(str3) && ((i2 = c.f3292a[versionCodeCompareMode.ordinal()]) == 1 ? longVersionCode == i : !(i2 == 2 ? longVersionCode >= i : i2 == 3 ? longVersionCode < i : i2 == 4 ? longVersionCode <= i : i2 != 5 || longVersionCode > i))) {
return Apk.create(str2, str, longVersionCode);
}
}
return null;
}
public static void install(Context context, Apk apk, String str, String str2, InstallListener installListener) {
try {
new b(str, apk, installListener, context, str2).start();
} catch (Exception e) {
notifyInstallListener(installListener, -1, e.getMessage());
}
}
public static void notifyInstallListener(InstallListener installListener, int i, String str) {
if (Looper.myLooper() == Looper.getMainLooper()) {
if (installListener != null) {
installListener.onResult(i, str);
}
} else {
Message obtain = Message.obtain();
obtain.obj = new Object[]{installListener, Integer.valueOf(i), str};
mHandler.sendMessage(obtain);
}
}
}