Commit 1c3df0fa by pye52

修复一个因为shell立即执行导致任务未完成而不断循环的问题

parent df2f1314
......@@ -6,17 +6,23 @@ import androidx.annotation.NonNull;
import androidx.work.WorkerParameters;
import com.bgycc.smartcanteen.entity.CommandShell;
import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.utils.DangerousUtils;
import com.blankj.utilcode.util.EncryptUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ShellUtils;
import java.util.concurrent.TimeUnit;
import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class ShellCommandWorker extends CommandWorker {
private static final String KEY = "sc_shell";
private static final String TRANSFORMATION = "DES/CBC/PKCS5Padding";
private static final String IV = "12345678";
// shell指令需要在其他线程延迟执行(先让任务被标记为成功,否则可能会引发异常)
private static final long EXEC_DELAY = 500;
private CommandShell commandShell;
public ShellCommandWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
......@@ -33,13 +39,16 @@ public class ShellCommandWorker extends CommandWorker {
}
CommandShell.CommandShellData data = commandShell.getData();
byte[] decryptAES = EncryptUtils.decryptHexStringAES(data.getShell(), KEY.getBytes(), TRANSFORMATION, IV.getBytes());
String shell = new String(decryptAES);
final String shell = new String(decryptAES);
inProgress("开始执行shell: " + shell);
LogUtils.d(TAG, "执行shell: " + shell);
ShellUtils.CommandResult result = ShellUtils.execCmd(shell, DangerousUtils.isDeviceRooted());
LogUtils.d(TAG, "shell执行结果: " + result.result +
"\nsuccess: " + result.successMsg +
"\nerror: " + result.errorMsg);
SCTaskExecutor.getInstance()
.schedule(() -> {
ShellUtils.CommandResult result = ShellUtils.execCmd(shell, DangerousUtils.isDeviceRooted());
LogUtils.d(TAG, "shell执行结果: " + result.result +
"\nsuccess: " + result.successMsg +
"\nerror: " + result.errorMsg);
}, EXEC_DELAY, TimeUnit.MILLISECONDS);
return success();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment