Commit 072f0164 by pye52

整合new_master多机型安装方案

parent 4c0691ea
......@@ -3,6 +3,7 @@ package com.bgycc.smartcanteen.action
import com.bgycc.smartcanteen.BuildConfig
import com.bgycc.smartcanteen.event.SettingStateEvent
import com.bgycc.smartcanteen.helper.TimerHelper
import com.bgycc.smartcanteen.util.InstallManager
import com.blankj.utilcode.util.*
import okhttp3.Call
import okhttp3.OkHttpClient
......@@ -88,7 +89,7 @@ class UpdateAction private constructor() : Action(ActionEnum.CONFIG_UPDATE.name)
EventBus.getDefault().post(SettingStateEvent(99, "不允许安装低版本"))
} else {
EventBus.getDefault().post(SettingStateEvent(99, "安装更新包"))
AppUtils.installApp(FILE_UPDATE_APK)
InstallManager.install(FILE_UPDATE_APK)
}
finish()
return
......
......@@ -8,9 +8,9 @@ import com.bgycc.smartcanteen.event.LogEvent;
import com.bgycc.smartcanteen.event.QRCodeInvalidEvent;
import com.bgycc.smartcanteen.helper.TimerHelper;
import com.bgycc.smartcanteen.qrcode.IQRCodeScan;
import com.bgycc.smartcanteen.qrcode.QRCodeScanFactory;
import com.bgycc.smartcanteen.server.websocket.MainWebSocket;
import com.bgycc.smartcanteen.util.ByteUtil;
import com.bgycc.smartcanteen.util.DeviceProxy;
import com.blankj.utilcode.util.LogUtils;
import org.greenrobot.eventbus.EventBus;
......@@ -53,7 +53,7 @@ public class QRCodeTask {
if (mScanAsyncTask == null) {
try {
serial = QRCodeScanFactory.create();
serial = DeviceProxy.createQRCodeScan();
} catch (Exception e) {
LogUtils.file("串口初始化失败");
}
......
package com.bgycc.smartcanteen.util;
import com.bgycc.smartcanteen.qrcode.IQRCodeScan;
import com.bgycc.smartcanteen.qrcode.QRCodeScanFactory;
import java.io.File;
/**
* 多设备相关方案的代理类 <br/>
* 设计该代理类目的是为了增加设备时,务必在下面所有方法的实际执行里进行适配
*/
public class DeviceProxy {
public static final String DEVICE_MODEL_TPS = "TPS";
public static final String DEVICE_MODEL_QUAD = "QUAD";
public static IQRCodeScan createQRCodeScan() throws Exception {
return QRCodeScanFactory.create();
}
public static boolean updateApp(File updateApk) {
return InstallManager.install(updateApk);
}
}
package com.bgycc.smartcanteen.util;
import android.os.Build;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.LogUtils;
import java.io.File;
public class InstallManager {
public static boolean install(File updateApk) {
String model = Build.MODEL;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
// 6.0以下安装包需要修改权限才能安装
try {
Process p = Runtime.getRuntime().exec("chmod 755 " + updateApk);
p.waitFor();
LogUtils.d("InstallManager", "开始安装");
} catch (Exception e) {
LogUtils.e("InstallManager", "安装文件权限修改失败");
return false;
}
}
if (model.contains(DeviceProxy.DEVICE_MODEL_TPS)) {
return DangerousUtils.installAppSilent(updateApk);
} else if (model.contains(DeviceProxy.DEVICE_MODEL_QUAD)) {
AppUtils.installApp(updateApk);
return true;
} else {
throw new RuntimeException("不明设备型号: " + model);
}
}
}
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