下载安装

This commit is contained in:
Administrator 2025-06-26 16:51:31 +08:00
parent e619d85361
commit 203fccea87
5 changed files with 25 additions and 36 deletions

View File

@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-06-26T03:06:21.212850800Z">
<DropdownSelection timestamp="2025-06-26T06:59:46.673021800Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="Default" identifier="serial=8.217.74.194:1137;connection=09fcafd5" />
<DeviceId pluginId="Default" identifier="serial=8.217.74.194:1137;connection=a396d877" />
</handle>
</Target>
</DropdownSelection>

View File

@ -201,16 +201,17 @@ public class ChangeDeviceInfoUtil {
}
}
public static void processPackageInfoWithDeviceInfo(String packageName,String zipName, Context context, String androidId, String taskId) {
public static boolean processPackageInfoWithDeviceInfo(String packageName,String zipName, Context context, String androidId, String taskId) {
if (!isAppInstalled(packageName)) {
processPackage(packageName, zipName, context);
return processPackage(packageName, zipName, context);
// TaskUtil.postDeviceInfo(androidId, taskId, packageName);
} else {
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "Package not installed: " + packageName, null);
return false;
}
}
private static void processPackage(String packageName, String zipName, Context context) {
private static boolean processPackage(String packageName, String zipName, Context context) {
try {
File filesDir = new File(context.getExternalFilesDir(null).getAbsolutePath());
File file = TaskUtil.downloadCodeFile("FyZqWrStUvOpKlMn_wsj.reader_sp.zip", filesDir);
@ -220,20 +221,22 @@ public class ChangeDeviceInfoUtil {
if (destFile.exists()) {
TaskUtil.delFileSh(destFile.getAbsolutePath());
}
// TaskUtil.unZip(destFile, file);
ZipUtils.unzip(file.getAbsolutePath(), destFile.getAbsolutePath());
if (destFile.exists()) {
installApk(destFile.getAbsolutePath());
}
// TaskUtil.delFileSh(destFile.getAbsolutePath());
// TaskUtil.delFileSh(file.getAbsolutePath());
TaskUtil.delFileSh(destFile.getAbsolutePath());
TaskUtil.delFileSh(file.getAbsolutePath());
LogFileUtil.logAndWrite(Log.DEBUG, LOG_TAG, "Processed package: " + packageName, null);
return true;
} else {
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG, "File download failed for package: " + packageName, null);
return false;
}
} catch (Exception e) {
LogFileUtil.logAndWrite(android.util.Log.ERROR, LOG_TAG, "Error processing package: " + packageName, e);
return false;
}
}
@ -252,8 +255,6 @@ public class ChangeDeviceInfoUtil {
}
boolean result = ApkInstaller.batchInstallWithRoot(apkFilePath);
// 执行命令并获取结果
// String result = ShellUtils.execRootCmdAndGetResult(command);
if (result) {
Log.d("ShellUtils", "APK installed successfully!");
return true;

View File

@ -21,14 +21,6 @@ public class ApkInstaller {
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在第一位
@ -49,7 +41,7 @@ public class ApkInstaller {
}
// 构建安装命令
StringBuilder cmd = new StringBuilder("pm install-multiple \"")
StringBuilder cmd = new StringBuilder("pm install \"")
.append(baseApk.getAbsolutePath()).append("\"");
for (File apk : otherApks) {

View File

@ -84,14 +84,4 @@ public class ZipUtils {
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();
}
}

View File

@ -20,6 +20,7 @@ import com.example.studyapp.device.ChangeDeviceInfoUtil;
import com.example.studyapp.proxy.ClashUtil;
import com.example.studyapp.task.TaskUtil;
import com.example.studyapp.utils.LogFileUtil;
import com.example.studyapp.utils.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -37,8 +38,10 @@ import kotlin.coroutines.Continuation;
public class LoadDeviceWorker extends CoroutineWorker {
private String androidId = "FyZqWrStUvOpKlMn";
private Context context;
public LoadDeviceWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
this.context = context;
}
@Override
@ -49,8 +52,10 @@ public class LoadDeviceWorker extends CoroutineWorker {
String zipName = ChangeDeviceInfoUtil.zipName;
Log.d("TAG", "doWork: "+result+" "+packageName+" "+zipName);
if (result && !TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(zipName)){
ChangeDeviceInfoUtil.processPackageInfoWithDeviceInfo(packageName,zipName, getApplicationContext(), androidId, taskId);
// executeSingleLogic(getApplicationContext());
boolean isSuccess = ChangeDeviceInfoUtil.processPackageInfoWithDeviceInfo(packageName,zipName, getApplicationContext(), androidId, taskId);
if (isSuccess){
executeSingleLogic(context);
}
}else {
Log.d("TAG", "doWork: get Device info false");
}
@ -65,6 +70,7 @@ public class LoadDeviceWorker extends CoroutineWorker {
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Changing device info",null);
ChangeDeviceInfoUtil.changeDeviceInfo(context.getPackageName(), context);
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script",null);
Utils.writePackageName(ChangeDeviceInfoUtil.packageName);
AutoJsUtil.runAutojsScript(context);
}
@ -75,11 +81,11 @@ public class LoadDeviceWorker extends CoroutineWorker {
return;
}
if (!(context instanceof Activity)) {
Toast.makeText(context, "Context must be an Activity", Toast.LENGTH_SHORT).show();
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Context is not an Activity.",null);
return;
}
// if (!(context instanceof Activity)) {
// Toast.makeText(context, "Context must be an Activity", Toast.LENGTH_SHORT).show();
// LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Context is not an Activity.",null);
// return;
// }
try {
ClashUtil.startProxy(context); // 在主线程中调用