1.apk 安装过程中重启apk未安装未删除安装包修改为继续安装并删除安装包
2.apk 安装过程中重启apk已安装未删除安装包修改为删除安装包 3.DownLoadManager撤回下载任务但文件丢失会产生-tmp 0 size大小文件bug,下载异常日志打印
This commit is contained in:
@@ -44,6 +44,7 @@ import com.android.nebulasdk.bean.FavNaviBean;
|
||||
import com.android.util.GsonUtil;
|
||||
import com.android.util.IntentUtil;
|
||||
import com.android.util.LogUtils;
|
||||
import com.android.util.NetUtil;
|
||||
import com.android.util.PakageInstallUtil;
|
||||
import com.ik.mboxlauncher.R;
|
||||
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
||||
@@ -322,7 +323,12 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean isNetworkAvailable() {
|
||||
int netState = NetUtil.getNetWorkState(this);
|
||||
return netState == NetUtil.NETWORK_MOBILE
|
||||
|| netState == NetUtil.NETWORK_WIFI
|
||||
|| netState == NetUtil.NETWORK_ETHERNET;
|
||||
}
|
||||
@Override
|
||||
protected int getFramlayoutId() {
|
||||
return R.layout.main;
|
||||
@@ -949,7 +955,10 @@ public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
if(isSplashEnd) {
|
||||
ADSWindowManager.getInstance().startVideo();
|
||||
}
|
||||
if(isNetworkAvailable()){
|
||||
ADManager.getInstance().clearApkFileByPowerDown();
|
||||
ADManager.getInstance().clearTaskInteruptQueueAndRestart();
|
||||
}
|
||||
setImageViewData();
|
||||
loadShortAppList();
|
||||
}
|
||||
|
||||
@@ -143,7 +143,9 @@ public class DownLoadManeger {
|
||||
TaskQueue.getInstance().add(new DownLoadTaskThread(downLoadTaskBean, observer));
|
||||
}
|
||||
}
|
||||
|
||||
if(!file.exists()&&downLoadTaskBean.getCurrentProgress()==0){
|
||||
LogUtils.loge("power down but downloadstaskbean table remain task");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,13 +158,6 @@ public class DownLoadManeger {
|
||||
if(file.exists()&&file.length()>0&&file.length()<=downLoadTaskBean.getTotal()){
|
||||
downLoadTaskBean.setCurrentProgress(file.length());
|
||||
DaoManager.getInstance().update(DownLoadTaskBean.class,downLoadTaskBean);
|
||||
}else if(!file.exists()){
|
||||
try {
|
||||
boolean createFileSuccess=file.createNewFile();
|
||||
LogUtils.loge("下载任务但文件丢失创建文件="+createFileSuccess);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}else if(downLoadTaskBean.getCurrentProgress()!=0&&!TextUtils.isEmpty(downLoadTaskBean.getUrl())&&!TextUtils.isEmpty(downLoadTaskBean.getFileName())&&!TextUtils.isEmpty(downLoadTaskBean.getPath())){
|
||||
File file = new File(downLoadTaskBean.getPath()+downLoadTaskBean.getFileName()+"-tmp");
|
||||
|
||||
@@ -64,9 +64,9 @@ public class DownLoadTaskThread implements Runnable {
|
||||
if(currentTotal==bean.getTotal()){
|
||||
File targFile = new File(bean.getPath(), bean.getFileName());
|
||||
file.renameTo(targFile);//重命名
|
||||
Thread.sleep(5000);
|
||||
file.delete();//删除临时文件
|
||||
Thread.sleep(3000);
|
||||
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
||||
file.delete();//删除临时文件
|
||||
return;
|
||||
}
|
||||
//设置下载位置
|
||||
@@ -115,10 +115,10 @@ public class DownLoadTaskThread implements Runnable {
|
||||
LogUtils.loge("download Exception===>sleeping before");
|
||||
File targFile = new File(bean.getPath(), bean.getFileName());
|
||||
file.renameTo(targFile);//重命名
|
||||
Thread.sleep(5000);
|
||||
file.delete();//删除临时文件
|
||||
Thread.sleep(3000);
|
||||
LogUtils.loge("download Exception===>sleeping after");
|
||||
observer.onFinish(bean, bean.getTaskId(), currentTotal);
|
||||
file.delete();//删除临时文件
|
||||
}else {
|
||||
LogUtils.loge("下载失败");
|
||||
if (observer != null) {
|
||||
|
||||
@@ -454,7 +454,44 @@ public class ADManager implements DownLoadManeger.DownloadListener {
|
||||
DownLoadManeger.getInstance().updateDownloadTaskBeanTable();
|
||||
}
|
||||
|
||||
public void clearApkFileByPowerDown(){
|
||||
List<DownLoadTaskBean> list = DaoManager.getInstance().queryList(DownLoadTaskBean.class);
|
||||
if(list==null||list.size()==0){
|
||||
String apkDir = FileUtil.getBakPath(mContext, 1);
|
||||
File apkFile = new File(apkDir);
|
||||
if(apkFile.exists()){
|
||||
File[] files = apkFile.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
boolean isApk = files[i].getAbsolutePath().endsWith("apk");
|
||||
if(isApk){
|
||||
String apkFileName = files[i].getName();
|
||||
int apkFileContainIndex=-1;
|
||||
List<AdsInfoBean> adsInfoBeanList = DaoManager.getInstance().queryList(AdsInfoBean.class);
|
||||
for (int j = 0; j < adsInfoBeanList.size(); j++) {
|
||||
if(!TextUtils.isEmpty(adsInfoBeanList.get(j).getAppUrl())&&adsInfoBeanList.get(j).getAppUrl().contains(apkFileName)){
|
||||
apkFileContainIndex=j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(apkFileContainIndex==-1){
|
||||
files[i].delete();
|
||||
LogUtils.loge("apk data rm need delete app");
|
||||
}else {
|
||||
AdsInfoBean adsInfoBean = adsInfoBeanList.get(apkFileContainIndex);
|
||||
if(!(PakageInstallUtil.checkAppInstall(mContext,adsInfoBean.getInfo()))||PakageInstallUtil.checkAppUpdate(mContext,adsInfoBean.getInfo(),(int) adsInfoBean.getAppVersion())){ //需要跟新app
|
||||
LogUtils.loge("need reinstall app");
|
||||
addDownloadTask(adsInfoBean,adsInfoBean.getAppUrl(),1,adsInfoBean.getAppSize());
|
||||
}else {
|
||||
LogUtils.loge("need delete app");
|
||||
files[i].delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user