下载安装

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> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <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"> <Target type="DEFAULT_BOOT">
<handle> <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> </handle>
</Target> </Target>
</DropdownSelection> </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)) { if (!isAppInstalled(packageName)) {
processPackage(packageName, zipName, context); return 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);
return false;
} }
} }
private static void processPackage(String packageName, String zipName, Context context) { private static boolean 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("FyZqWrStUvOpKlMn_wsj.reader_sp.zip", filesDir); File file = TaskUtil.downloadCodeFile("FyZqWrStUvOpKlMn_wsj.reader_sp.zip", filesDir);
@ -220,20 +221,22 @@ public class ChangeDeviceInfoUtil {
if (destFile.exists()) { if (destFile.exists()) {
TaskUtil.delFileSh(destFile.getAbsolutePath()); TaskUtil.delFileSh(destFile.getAbsolutePath());
} }
// TaskUtil.unZip(destFile, file);
ZipUtils.unzip(file.getAbsolutePath(), destFile.getAbsolutePath()); 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);
return true;
} 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);
return false;
} }
} catch (Exception e) { } catch (Exception e) {
LogFileUtil.logAndWrite(android.util.Log.ERROR, LOG_TAG, "Error processing package: " + packageName, 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); boolean result = ApkInstaller.batchInstallWithRoot(apkFilePath);
// 执行命令并获取结果
// String result = ShellUtils.execRootCmdAndGetResult(command);
if (result) { if (result) {
Log.d("ShellUtils", "APK installed successfully!"); Log.d("ShellUtils", "APK installed successfully!");
return true; return true;

View File

@ -21,14 +21,6 @@ public class ApkInstaller {
return installSplitApks(apkFiles); 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) { private static boolean installSplitApks( List<File> apkFiles) {
// 确保base.apk在第一位 // 确保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("\""); .append(baseApk.getAbsolutePath()).append("\"");
for (File apk : otherApks) { for (File apk : otherApks) {

View File

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