This commit is contained in:
parent
6fa7c334ea
commit
e619d85361
|
@ -4,10 +4,10 @@
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2025-06-23T04:03:54.535123700Z">
|
<DropdownSelection timestamp="2025-06-26T03:06:21.212850800Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=LMV500N03f5c1fc" />
|
<DeviceId pluginId="Default" identifier="serial=8.217.74.194:1137;connection=09fcafd5" />
|
||||||
</handle>
|
</handle>
|
||||||
</Target>
|
</Target>
|
||||||
</DropdownSelection>
|
</DropdownSelection>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
|
|
|
@ -38,6 +38,7 @@ import com.example.studyapp.task.TaskUtil;
|
||||||
import com.example.studyapp.utils.LogFileUtil;
|
import com.example.studyapp.utils.LogFileUtil;
|
||||||
import com.example.studyapp.utils.ShellUtils;
|
import com.example.studyapp.utils.ShellUtils;
|
||||||
import com.example.studyapp.utils.Utils;
|
import com.example.studyapp.utils.Utils;
|
||||||
|
import com.example.studyapp.utils.ZipUtils;
|
||||||
import com.example.studyapp.worker.CheckAccessibilityWorker;
|
import com.example.studyapp.worker.CheckAccessibilityWorker;
|
||||||
import com.example.studyapp.worker.LoadDeviceWorker;
|
import com.example.studyapp.worker.LoadDeviceWorker;
|
||||||
|
|
||||||
|
@ -159,7 +160,21 @@ public class MainActivity extends AppCompatActivity {
|
||||||
if (runScriptButton != null) {
|
if (runScriptButton != null) {
|
||||||
// runScriptButton.setOnClickListener(v -> AutoJsUtil.runAutojsScript(this));
|
// runScriptButton.setOnClickListener(v -> AutoJsUtil.runAutojsScript(this));
|
||||||
runScriptButton.setOnClickListener(v -> {
|
runScriptButton.setOnClickListener(v -> {
|
||||||
Utils.writePackageName("com.test.app");
|
initializeExecutorService();
|
||||||
|
executorService.submit(() -> {
|
||||||
|
File files1Dir = new File(getExternalFilesDir(null).getAbsolutePath(),"FyZqWrStUvOpKlMn_wsj.reader_sp.zip");
|
||||||
|
File destFile = new File(Environment.getExternalStorageDirectory(), "apkpath");
|
||||||
|
Log.d("TAG", "onCreate: "+destFile.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
// ZipUtils.unzip(files1Dir.getAbsolutePath(), destFile.getAbsolutePath());
|
||||||
|
if (destFile.exists()) {
|
||||||
|
ChangeDeviceInfoUtil.installApk(destFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
LogFileUtil.logAndWrite(Log.WARN, "MainActivity", "Run Script Button not found",null);
|
LogFileUtil.logAndWrite(Log.WARN, "MainActivity", "Run Script Button not found",null);
|
||||||
|
|
|
@ -12,13 +12,16 @@ import com.example.studyapp.task.AfInfo;
|
||||||
import com.example.studyapp.task.BigoInfo;
|
import com.example.studyapp.task.BigoInfo;
|
||||||
import com.example.studyapp.task.DeviceInfo;
|
import com.example.studyapp.task.DeviceInfo;
|
||||||
import com.example.studyapp.task.TaskUtil;
|
import com.example.studyapp.task.TaskUtil;
|
||||||
|
import com.example.studyapp.utils.ApkInstaller;
|
||||||
import com.example.studyapp.utils.HttpUtil;
|
import com.example.studyapp.utils.HttpUtil;
|
||||||
import com.example.studyapp.utils.LogFileUtil;
|
import com.example.studyapp.utils.LogFileUtil;
|
||||||
import com.example.studyapp.utils.ShellUtils;
|
import com.example.studyapp.utils.ShellUtils;
|
||||||
|
import com.example.studyapp.utils.ZipUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -201,7 +204,7 @@ public class ChangeDeviceInfoUtil {
|
||||||
public static void processPackageInfoWithDeviceInfo(String packageName,String zipName, Context context, String androidId, String taskId) {
|
public static void processPackageInfoWithDeviceInfo(String packageName,String zipName, Context context, String androidId, String taskId) {
|
||||||
if (!isAppInstalled(packageName)) {
|
if (!isAppInstalled(packageName)) {
|
||||||
processPackage(packageName, zipName, context);
|
processPackage(packageName, zipName, context);
|
||||||
TaskUtil.postDeviceInfo(androidId, taskId, packageName);
|
// TaskUtil.postDeviceInfo(androidId, taskId, packageName);
|
||||||
} else {
|
} else {
|
||||||
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "Package not installed: " + packageName, null);
|
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "Package not installed: " + packageName, null);
|
||||||
}
|
}
|
||||||
|
@ -210,21 +213,21 @@ public class ChangeDeviceInfoUtil {
|
||||||
private static void processPackage(String packageName, String zipName, Context context) {
|
private static void processPackage(String packageName, String zipName, Context context) {
|
||||||
try {
|
try {
|
||||||
File filesDir = new File(context.getExternalFilesDir(null).getAbsolutePath());
|
File filesDir = new File(context.getExternalFilesDir(null).getAbsolutePath());
|
||||||
File file = TaskUtil.downloadCodeFile(zipName, filesDir);
|
File file = TaskUtil.downloadCodeFile("FyZqWrStUvOpKlMn_wsj.reader_sp.zip", filesDir);
|
||||||
|
|
||||||
if (file != null && file.exists()) {
|
if (file != null && file.exists()) {
|
||||||
File destFile = new File(context.getCacheDir(), packageName+"_download"+".apk");
|
File destFile = new File(context.getCacheDir(), packageName);
|
||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
TaskUtil.delFileSh(destFile.getAbsolutePath());
|
TaskUtil.delFileSh(destFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
TaskUtil.unZip(destFile, file);
|
// TaskUtil.unZip(destFile, file);
|
||||||
|
ZipUtils.unzip(file.getAbsolutePath(), destFile.getAbsolutePath());
|
||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
installApk(destFile.getAbsolutePath());
|
installApk(destFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskUtil.delFileSh(destFile.getAbsolutePath());
|
// TaskUtil.delFileSh(destFile.getAbsolutePath());
|
||||||
TaskUtil.delFileSh(file.getAbsolutePath());
|
// TaskUtil.delFileSh(file.getAbsolutePath());
|
||||||
LogFileUtil.logAndWrite(Log.DEBUG, LOG_TAG, "Processed package: " + packageName, null);
|
LogFileUtil.logAndWrite(Log.DEBUG, LOG_TAG, "Processed package: " + packageName, null);
|
||||||
} else {
|
} else {
|
||||||
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "File download failed for package: " + packageName, null);
|
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "File download failed for package: " + packageName, null);
|
||||||
|
@ -248,12 +251,10 @@ public class ChangeDeviceInfoUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造安装命令
|
boolean result = ApkInstaller.batchInstallWithRoot(apkFilePath);
|
||||||
String command = "pm install-multiple " + apkFilePath;
|
|
||||||
|
|
||||||
// 执行命令并获取结果
|
// 执行命令并获取结果
|
||||||
String result = ShellUtils.execRootCmdAndGetResult(command);
|
// String result = ShellUtils.execRootCmdAndGetResult(command);
|
||||||
if (result != null && result.contains("Success")) {
|
if (result) {
|
||||||
Log.d("ShellUtils", "APK installed successfully!");
|
Log.d("ShellUtils", "APK installed successfully!");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.example.studyapp.utils;
|
||||||
|
|
||||||
|
import static com.example.studyapp.utils.ZipUtils.getAllApkFiles;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ApkInstaller {
|
||||||
|
public static boolean batchInstallWithRoot(String dirPath) {
|
||||||
|
|
||||||
|
// 获取APK文件
|
||||||
|
List<File> apkFiles = getAllApkFiles(dirPath);
|
||||||
|
|
||||||
|
return installSplitApks(apkFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSplitApk(List<File> apkFiles) {
|
||||||
|
for (File apk : apkFiles) {
|
||||||
|
if (apk.getName().contains("base.apk")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean installSplitApks( List<File> apkFiles) {
|
||||||
|
// 确保base.apk在第一位
|
||||||
|
File baseApk = null;
|
||||||
|
List<File> otherApks = new ArrayList<>();
|
||||||
|
|
||||||
|
for (File apk : apkFiles) {
|
||||||
|
if (apk.getName().contains("base.apk")) {
|
||||||
|
baseApk = apk;
|
||||||
|
} else {
|
||||||
|
otherApks.add(apk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseApk == null) {
|
||||||
|
Log.d("TAG", "installSplitApks: 没有 base apk");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建安装命令
|
||||||
|
StringBuilder cmd = new StringBuilder("pm install-multiple \"")
|
||||||
|
.append(baseApk.getAbsolutePath()).append("\"");
|
||||||
|
|
||||||
|
for (File apk : otherApks) {
|
||||||
|
cmd.append(" \"").append(apk.getAbsolutePath()).append("\"");
|
||||||
|
}
|
||||||
|
Log.d("TAG", "installSplitApks: "+cmd);
|
||||||
|
// 执行命令
|
||||||
|
String result = ShellUtils.execRootCmdAndGetResult(cmd.toString());
|
||||||
|
if (result != null && result.contains("Success")) {
|
||||||
|
Log.d("TAG", "installSplitApks: install success");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Log.d("TAG", "installSplitApks: install failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.example.studyapp.utils;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
public class ZipUtils {
|
||||||
|
/**
|
||||||
|
* 解压ZIP文件到指定目录
|
||||||
|
* @param zipFile ZIP文件路径
|
||||||
|
* @param destDir 目标目录路径
|
||||||
|
* @throws IOException 如果解压失败
|
||||||
|
*/
|
||||||
|
public static void unzip(String zipFile, String destDir) throws IOException {
|
||||||
|
File dir = new File(destDir);
|
||||||
|
// 创建目标目录(如果不存在)
|
||||||
|
if (!dir.exists()) {
|
||||||
|
if (!dir.mkdirs()) {
|
||||||
|
throw new IOException("Failed to create directory: " + destDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)))) {
|
||||||
|
ZipEntry ze;
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int count;
|
||||||
|
|
||||||
|
while ((ze = zis.getNextEntry()) != null) {
|
||||||
|
String fileName = ze.getName();
|
||||||
|
File file = new File(destDir, fileName);
|
||||||
|
|
||||||
|
// 创建必要的父目录
|
||||||
|
File parent = file.getParentFile();
|
||||||
|
if (parent != null && !parent.exists()) {
|
||||||
|
if (!parent.mkdirs()) {
|
||||||
|
throw new IOException("Failed to create parent directory: " + parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ze.isDirectory()) {
|
||||||
|
if (!file.mkdirs()) {
|
||||||
|
throw new IOException("Failed to create directory: " + file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
||||||
|
|
||||||
|
while ((count = zis.read(buffer)) != -1) {
|
||||||
|
bos.write(buffer, 0, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<File> getAllApkFiles(String dirPath) {
|
||||||
|
List<File> apkFiles = new ArrayList<>();
|
||||||
|
File dir = new File(dirPath);
|
||||||
|
|
||||||
|
if (!dir.exists() || !dir.isDirectory()) {
|
||||||
|
Log.e("APK", "目录不存在或不是目录: " + dirPath);
|
||||||
|
return apkFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
if (files == null) return apkFiles;
|
||||||
|
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isFile() && file.getName().toLowerCase().endsWith(".apk")) {
|
||||||
|
apkFiles.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return apkFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String buildInstallCommand(List<File> apkFiles) {
|
||||||
|
StringBuilder cmd = new StringBuilder("pm install-multiple");
|
||||||
|
|
||||||
|
for (File apk : apkFiles) {
|
||||||
|
cmd.append(" \"").append(apk.getAbsolutePath()).append("\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,7 +50,7 @@ public class LoadDeviceWorker extends CoroutineWorker {
|
||||||
Log.d("TAG", "doWork: "+result+" "+packageName+" "+zipName);
|
Log.d("TAG", "doWork: "+result+" "+packageName+" "+zipName);
|
||||||
if (result && !TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(zipName)){
|
if (result && !TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(zipName)){
|
||||||
ChangeDeviceInfoUtil.processPackageInfoWithDeviceInfo(packageName,zipName, getApplicationContext(), androidId, taskId);
|
ChangeDeviceInfoUtil.processPackageInfoWithDeviceInfo(packageName,zipName, getApplicationContext(), androidId, taskId);
|
||||||
executeSingleLogic(getApplicationContext());
|
// executeSingleLogic(getApplicationContext());
|
||||||
}else {
|
}else {
|
||||||
Log.d("TAG", "doWork: get Device info false");
|
Log.d("TAG", "doWork: get Device info false");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue