Commit 47898798 by pye52

1、现在删除日志文件时,不会只限定为logutils生成的文件了,而是目录文件夹下的所有日志文件

2、优化安装任务的逻辑,将安装放到其他线程进行处理,让指令先执行完毕
3、主界面增加任务进度日志输出
4、优化wifi配置指令,会把当前链接的wifi取消保存,再链接新的wifi
parent 6d907c58
......@@ -290,6 +290,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
settingLayout.animate().setDuration(50).alpha(0f);
return;
}
LogUtils.d(TAG, "\n任务: " + (runningCommand != null ? runningCommand.toString() : "null") +
"\n进度: " + workInfo.toString());
WorkInfo.State state = workInfo.getState();
if (state.isFinished()) {
Data data = workInfo.getOutputData();
......
......@@ -8,6 +8,7 @@ import androidx.work.WorkerParameters;
import com.bgycc.smartcanteen.BuildConfig;
import com.bgycc.smartcanteen.api.SCRetrofit;
import com.bgycc.smartcanteen.entity.CommandUpdate;
import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.utils.DeviceProxy;
import com.bgycc.smartcanteen.utils.TrustAllCerts;
import com.blankj.utilcode.util.AppUtils;
......@@ -19,6 +20,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.Request;
......@@ -59,17 +61,6 @@ public class UpdateCommandWorker extends CommandWorker {
return failed("更新包地址异常");
}
File updateApk = new File(UPDATE_APK_PATH, UPDATE_APK);
if (updateApk.exists()) {
// 若文件存在,则检查安装文件版本是否与当前应用版本一致
// 若一致则说明已安装完毕,直接返回即可
AppUtils.AppInfo info = AppUtils.getApkInfo(updateApk);
if (info != null
&& info.getPackageName().equals(BuildConfig.APPLICATION_ID)
&& info.getVersionCode() == BuildConfig.VERSION_CODE) {
LogUtils.d(TAG, "版本" + info.getVersionCode() + "已安装完毕");
return success("已是最新版本");
}
}
updateApk.deleteOnExit();
String url = commandUpdate.getData().getUrl();
......@@ -146,12 +137,16 @@ public class UpdateCommandWorker extends CommandWorker {
LogUtils.d(TAG, "不允许安装低版本");
inProgress("不允许安装低版本");
} else {
// 安装任务需要抛到其他线程进行操作,当前任务直接返回
SCTaskExecutor.getInstance()
.schedule(() -> {
LogUtils.d(TAG, "开始安装更新包: " + updateApk.getAbsolutePath());
if (DeviceProxy.updateApp(updateApk)) {
inProgress("开始安装");
} else {
inProgress("安装文件权限修改失败");
}
}, INSTALL_DELAY, TimeUnit.MILLISECONDS);
}
return success("开始安装更新包");
}
......
......@@ -14,7 +14,7 @@ import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class WifiConfigCommandWorker extends CommandWorker {
private static final long DEFAULT_DELAY = 3000;
private static final long POLLING_DELAY = 100;
private static final long POLLING_DELAY = 200;
private CommandWifiConfig wifiConfig;
public WifiConfigCommandWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
......@@ -44,6 +44,13 @@ public class WifiConfigCommandWorker extends CommandWorker {
}
}
// 断开当前在链接的wifi
WifiInfo currentWifiInfo = NetworkUtils.getWifiInfo();
if (currentWifiInfo != null) {
NetworkUtils.disconnect(currentWifiInfo.getNetworkId());
LogUtils.d(TAG, "断开当前wifi: " + currentWifiInfo.toString());
}
String ssid = data.getSsid();
String identity = data.getIdentity();
String pwd = data.getPwd();
......@@ -54,7 +61,7 @@ public class WifiConfigCommandWorker extends CommandWorker {
try {
NetworkUtils.connect(ssid, identity, pwd, type);
// 轮询检查wifi是否链接成功
for (int i = 0; i < 30; i++) {
for (int i = 0; i < 50; i++) {
Thread.sleep(POLLING_DELAY);
WifiInfo info = NetworkUtils.getWifiInfo();
if (info == null || info.getIpAddress() == 0) {
......
......@@ -30,7 +30,7 @@ public class LogFileMonitor extends Worker {
+ ", 总大小: " + totalSize);
while (availableSize < (totalSize * 0.1f)) {
// 当可用小于10%时,删除旧日志文件
List<File> logFiles = LogUtils.getLogFiles();
List<File> logFiles = FileUtils.listFilesInDir(logDirPath);
int size = logFiles.size();
switch (size) {
case 0:
......
......@@ -253,6 +253,10 @@ public class NetworkUtils {
return true;
}
public static boolean disconnect(int netId) {
return wifiManager.removeNetwork(netId);
}
private static WifiConfiguration createWifiConfiguration(String ssid, String identity, String pwd, String type) {
if(ssid == null || ssid.isEmpty())
return null;
......
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