全志Launcher代码首次提交
This commit is contained in:
489
mylibrary/src/main/java/com/android/nebulasdk/TaskManager.java
Normal file
489
mylibrary/src/main/java/com/android/nebulasdk/TaskManager.java
Normal file
@@ -0,0 +1,489 @@
|
||||
package com.android.nebulasdk;
|
||||
|
||||
import android.app.TaskInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
import com.android.database.DaoManager;
|
||||
import com.android.database.lib.AppConfigBean;
|
||||
import com.android.database.lib.DownLoadTaskBean;
|
||||
import com.android.database.lib.TaskInfoBean;
|
||||
import com.android.download.AppExecutors;
|
||||
import com.android.download.DownLoadManeger;
|
||||
import com.android.util.DateUtil;
|
||||
import com.android.util.DeviceUtil;
|
||||
import com.android.util.FileUtil;
|
||||
import com.android.util.GsonUtil;
|
||||
import com.android.util.LogUtils;
|
||||
import com.android.util.PakageInstallUtil;
|
||||
import com.android.util.SharedPreferencesUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 任务管理
|
||||
*/
|
||||
//public class TaskManager implements DownLoadManeger.DownloadListener {
|
||||
//
|
||||
// private List<TaskInfo> taskInfoList = new ArrayList<>();
|
||||
// private Context mContext;
|
||||
// private static TaskManager mInstance = null;
|
||||
// private TaskInfo mCurrentTaskInfo = null;
|
||||
// /**launcher 资源更新通知*/
|
||||
// public static final String NOTIFY_LAUNCHER_UPDATE="com.ik.launcher.res.notify";
|
||||
// /**Advert 资源更新通知*/
|
||||
// public static final String NOTIFY_ADVERT_UPDATE="com.ik.Advert.res.notify";
|
||||
//// List<RecordDownlaodInfo> recordDownlaodInfoList = new ArrayList<>();
|
||||
// /**app禁用标识**/
|
||||
// private static final int APP_DIAABLE = 1;
|
||||
// /**app未禁用标识**/
|
||||
// private static final int APP_UNDIAABLE = 0;
|
||||
//
|
||||
// private TaskManager(Context context){
|
||||
// this.mContext = context;
|
||||
// DownLoadManeger.init(mContext);
|
||||
// DownLoadManeger.getInstance().registerDownloadListener(this);
|
||||
// }
|
||||
//
|
||||
// public static void init(Context context){
|
||||
// if(mInstance==null){
|
||||
// mInstance = new TaskManager(context);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// public static TaskManager getInstance(){
|
||||
// return mInstance;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void addTaskInfos(List<TaskInfo> taskInfoList){
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// for (TaskInfo taskInfoItem:taskInfoList){
|
||||
//
|
||||
// int activiteCount = SharedPreferencesUtil.getSharePrefrencesInteger(mContext,SharedPreferencesUtil.CONFIG_ACTIVATE_COUNT);
|
||||
// if(taskInfoItem.getCountActivate()!=0&&taskInfoItem.getCountActivate()>activiteCount){
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// ResInfo resInfo = taskInfoItem.getTaskData();
|
||||
// if(resInfo==null){
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// //1.当前app是否已安装
|
||||
// if(PakageInstallUtil.checkAppInstall(mContext,taskInfoItem.getTaskData().getPackageName(),taskInfoItem.getTaskData().getVersionCode())){
|
||||
// LogUtils.loge("The app already exists");
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// List<TaskInfoBean> taskInfoBeanList =DaoManager.getInstance().queryByKeyList(TaskInfoBean.class,"taskId",taskInfoItem.getTaskId()+"");
|
||||
//
|
||||
// List<AppConfigBean> appConfigBeanList =DaoManager.getInstance().queryByKeyList(AppConfigBean.class,"taskId",taskInfoItem.getTaskId()+"");
|
||||
//
|
||||
// TaskInfoBean taskInfoBean =null;
|
||||
// AppConfigBean appConfigBean = null;
|
||||
//
|
||||
// if(taskInfoBeanList.size()>0){
|
||||
// taskInfoBean =taskInfoBeanList.get(0);
|
||||
// appConfigBean = appConfigBeanList.get(0);
|
||||
//
|
||||
// LogUtils.loge("currentVersionCode|newVersionCode:"+taskInfoBean.getTaskVersionCode()+"|"+taskInfoItem.getTaskVersionCode());
|
||||
// if(taskInfoBean.getTaskVersionCode()<taskInfoItem.getTaskVersionCode()){
|
||||
// //需要更新当前版本
|
||||
// taskInfoBean.setFile_url(resInfo.getFileUrl());
|
||||
// taskInfoBean.setTaskVersionCode(taskInfoItem.getTaskVersionCode());
|
||||
// taskInfoBean.setFileName(resInfo.getFileName());
|
||||
// taskInfoBean.setTaskId(taskInfoItem.getTaskId());
|
||||
// taskInfoBean.setFilesize(resInfo.getFileSize());
|
||||
// //需要更新当前app的配置信息
|
||||
// appConfigBean.setTaskId(taskInfoItem.getTaskId());
|
||||
// appConfigBean.setDisable(taskInfoItem.getDisable());
|
||||
// appConfigBean.setAutoStart(taskInfoItem.isIs_auto_start()?1:0);
|
||||
// appConfigBean.setPackageName(resInfo.getPackageName());
|
||||
// appConfigBean.setVersionCode(resInfo.getVersionCode());
|
||||
// appConfigBean.setVersionName(resInfo.getVersionName());
|
||||
// appConfigBean.setSystemPermissions(resInfo.isSystemApp());
|
||||
// appConfigBean.setInstallFilePath(resInfo.getInstallPath());
|
||||
//
|
||||
// DaoManager.getInstance().update(AppConfigBean.class,appConfigBean);
|
||||
// DaoManager.getInstance().update(TaskInfoBean.class,taskInfoBean);
|
||||
// if(taskInfoItem.getDisable()==APP_UNDIAABLE) {
|
||||
// taskInfoBean.setStatus(0); //表示要下载
|
||||
// downloadTask(taskInfoBean, resInfo);
|
||||
// }
|
||||
//
|
||||
// }else {
|
||||
// //需要更新当前资源
|
||||
// LogUtils.loge("taskId: "+taskInfoBean.getTaskId()+" This is already the latest task");
|
||||
// continue;
|
||||
// }
|
||||
// }else {
|
||||
// taskInfoBean = new TaskInfoBean();
|
||||
// appConfigBean = new AppConfigBean();
|
||||
// taskInfoBean.setTaskId(taskInfoItem.getTaskId());
|
||||
// taskInfoBean.setTaskType(taskInfoItem.getTaskType());
|
||||
// taskInfoBean.setTaskVersionCode(taskInfoItem.getTaskVersionCode());
|
||||
// taskInfoBean.setFile_url(resInfo.getFileUrl());
|
||||
// taskInfoBean.setMimeType(resInfo.getMimeType());
|
||||
// taskInfoBean.setStatus(0); //表示要下载
|
||||
// taskInfoBean.setFileName(resInfo.getFileName());
|
||||
// taskInfoBean.setFilesize(resInfo.getFileSize());
|
||||
//
|
||||
// //创建app的配置信息
|
||||
// appConfigBean.setTaskId(taskInfoItem.getTaskId());
|
||||
// appConfigBean.setDisable(taskInfoItem.getDisable());
|
||||
// appConfigBean.setAutoStart(resInfo.isAutoStart()?1:0);
|
||||
// appConfigBean.setPackageName(resInfo.getPackageName());
|
||||
// appConfigBean.setVersionCode(resInfo.getVersionCode());
|
||||
// appConfigBean.setVersionName(resInfo.getVersionName());
|
||||
// appConfigBean.setSystemPermissions(resInfo.isSystemApp());
|
||||
// appConfigBean.setInstallFilePath(resInfo.getInstallPath());
|
||||
// DaoManager.getInstance().insert(AppConfigBean.class,appConfigBean);
|
||||
// DaoManager.getInstance().insert(TaskInfoBean.class,taskInfoBean);
|
||||
// if(taskInfoItem.getDisable()==APP_UNDIAABLE) { //新任务不是禁用任务才可以下载
|
||||
// downloadTask(taskInfoBean,resInfo);
|
||||
// LogUtils.loge("Task Start Download ");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//// EventManager.getInstance().submit(); //改为开机提交下载记录
|
||||
//// new Handler().postDelayed(new Runnable() {
|
||||
//// @Override
|
||||
//// public void run() {
|
||||
//// downLoadManeger.startAll(); //开始下载任务
|
||||
////
|
||||
//// }
|
||||
//// },3000);
|
||||
//
|
||||
//
|
||||
//// starDownloadTask();
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void onDestroy() {//放在activity对应生命周期里,全部暂停
|
||||
// DownLoadManeger.getInstance().clear();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 开机/网络变化重新开启下载任务
|
||||
// */
|
||||
// public void starLocalDownloadTask(){
|
||||
// DownLoadManeger.getInstance().restDownloadTask();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 开启任务下载
|
||||
// * */
|
||||
//// private void downloadTask(ResInfo resInfo,int taskType){
|
||||
////
|
||||
//// if(taskType==1){
|
||||
//// if(!checkAppUpdate(resInfo.getPackage_name(),resInfo.getVersion_code())){
|
||||
//// LogUtils.loge(resInfo.getPackage_name()+"-已是最新版本");
|
||||
//// return;
|
||||
//// }
|
||||
//// }
|
||||
//// addDownloadTask(resInfo.getFile_url(),resInfo.getFileName(),resInfo.getMimeType(),taskType);
|
||||
////
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 开启任务下载
|
||||
// * */
|
||||
// private void downloadTask(TaskInfoBean taskInfoBean,ResInfo resInfo){
|
||||
//
|
||||
// try {
|
||||
// if(taskInfoBean.getTaskType()==1){
|
||||
// if(!checkAppUpdate(resInfo.getPackageName(),resInfo.getVersionCode())){
|
||||
// LogUtils.loge(resInfo.getPackageName()+"-已是最新版本");
|
||||
// return;
|
||||
// }else {
|
||||
// //记录app下载事件
|
||||
//// Map<String,Object> dataMap = new HashMap<>();
|
||||
//// dataMap.put("package_name",resInfo.getPackageName());
|
||||
//// dataMap.put("verison_code",resInfo.getVersionCode()+"");
|
||||
//// dataMap.put("verison_name",resInfo.getVersionName());
|
||||
//// dataMap.put("mac", DeviceUtil.getEthernetMac());
|
||||
//// EventManager.getInstance().recordEvent(EventManager.EVENT_DOWNLOAD_APP_CODE,dataMap);
|
||||
// }
|
||||
// }
|
||||
// addDownloadTask(resInfo.getFileUrl(),resInfo.getFileName(),resInfo.getMimeType(),taskInfoBean.getTaskType(),resInfo.getFileSize());
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 开启任务下载
|
||||
// * */
|
||||
//// private void downloadTask(TaskInfoBean taskInfoBean){
|
||||
//// addDownloadTask(taskInfoBean.getFile_url(),taskInfoBean.getFileName(),taskInfoBean.getMimeType(),taskInfoBean.getTaskType());
|
||||
////
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// private void addDownloadTask(String url, String fileName, String minType,int taskType,long fileSize) {
|
||||
// String filePath = FileUtil.getBakPath(mContext,taskType);
|
||||
// LogUtils.loge("filePath===>"+filePath);
|
||||
// DownLoadManeger.getInstance().addDownloadTask(new DownLoadManeger.DownloadBuilder().url(url).fileName(fileName).filePath(filePath).taskType(taskType).fileTotal(fileSize));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// private boolean checkAppUpdate(String packageName,int appVersionCode){
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// String tmpPackage = null;
|
||||
// if(packageName.contains("/")){
|
||||
// String[] pramArray = packageName.split("/");
|
||||
// tmpPackage = pramArray[0];
|
||||
// }else {
|
||||
// tmpPackage = packageName;
|
||||
// }
|
||||
//
|
||||
// PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(tmpPackage,0);
|
||||
// if(packageInfo==null){
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// if(packageInfo.versionCode<appVersionCode){
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } catch (PackageManager.NameNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void startDisableApp(){
|
||||
// new Thread(){
|
||||
// @Override
|
||||
// public void run() {
|
||||
// super.run();
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// //禁用app
|
||||
// List<AppConfigBean> taskInfoBeanList =DaoManager.getInstance().queryByValueList(AppConfigBean.class,new String[]{"disable"},new String[]{APP_DIAABLE+""});
|
||||
//
|
||||
//
|
||||
// for (AppConfigBean appConfigBean:taskInfoBeanList){ //禁用app
|
||||
// String tmpPackageName = null;
|
||||
// if(appConfigBean.getPackageName().contains("/")){
|
||||
// String[] pramArray = appConfigBean.getPackageName().split("/");
|
||||
// tmpPackageName = pramArray[0];
|
||||
// }else {
|
||||
// tmpPackageName =appConfigBean.getPackageName();
|
||||
// }
|
||||
// PakageInstallUtil.executeAppUnInstall(mContext,tmpPackageName);
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// //开机启动的必须是sservice app
|
||||
// List<AppConfigBean> taskInfoBeanList =DaoManager.getInstance().queryByValueList(AppConfigBean.class,new String[]{"autoStart"},new String[]{"1"});
|
||||
// for (AppConfigBean appConfigBean:taskInfoBeanList){ //启动server app
|
||||
// try {
|
||||
// if(appConfigBean.getDisable()==APP_DIAABLE){ //该任务已禁用
|
||||
// continue;
|
||||
// }
|
||||
// String packageName = appConfigBean.getPackageName();
|
||||
// if (packageName != null && packageName.contains("/")) { // 根据包名判断只启动服务app,其他情况不启动app
|
||||
// String[] packageNameArray = packageName.split("/");
|
||||
// Intent intent = new Intent();
|
||||
// intent.setComponent(new ComponentName(packageNameArray[0], packageNameArray[1]));
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// mContext.startForegroundService(intent);
|
||||
// } else {
|
||||
// mContext.startService(intent);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onStart(DownLoadTaskBean bean, long taskId) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(DownLoadTaskBean bean, long taskId, String erroMsg) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onProgress(DownLoadTaskBean bean, long taskId, long progress) {
|
||||
// LogUtils.loge("onProgress:"+taskId+"||"+bean.getFileName()+"||"+progress);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish(DownLoadTaskBean bean, long taskId) {
|
||||
//
|
||||
// AppExecutors.getAppExecutors().diskIO().execute(() -> {
|
||||
// String appInstallPath = bean.getPath()+ File.separator+bean.getFileName();
|
||||
// LogUtils.loge("filePath==>" + bean.getTaskType()+"||"+appInstallPath);
|
||||
// TaskInfoBean taskInfoBean =null;
|
||||
// AppConfigBean appConfigBean = null;
|
||||
// List<TaskInfoBean> taskInfoBeanList = DaoManager.getInstance().queryByKeyList(TaskInfoBean.class,"file_url",bean.getUrl());
|
||||
// if(taskInfoBeanList.size()>0){
|
||||
// taskInfoBean = taskInfoBeanList.get(0);
|
||||
// taskInfoBean.setStatus(2);//表示下载完成
|
||||
// DaoManager.getInstance().update(TaskInfoBean.class,taskInfoBean);
|
||||
// List<AppConfigBean> appConfigBeanList = DaoManager.getInstance().queryByKeyList(AppConfigBean.class,"taskId",taskInfoBean.getTaskId()+"");
|
||||
// appConfigBean = appConfigBeanList.get(0);
|
||||
//
|
||||
// }else {
|
||||
// LogUtils.loge("任务下载完成,未找到对应的任务。");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// switch (bean.getTaskType()){
|
||||
// case 1:
|
||||
// if(appConfigBean.isSystemPermissions()){
|
||||
// //执行app系统拷贝安装,该方案不可行,但是可以拷贝推送文件到指定的非系统目录下,暂时保留该方案
|
||||
// try {
|
||||
// File sourceFileFile = new File(appInstallPath);
|
||||
// File targetFile = new File(appConfigBean.getInstallFilePath()+bean.getFileName());
|
||||
// FileUtil.copyFilesFromTo(targetFile,sourceFileFile,0);
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//// PakageInstallUtil.executeStstemAppInstall(mContext,appInstallPath);
|
||||
//
|
||||
// }else {
|
||||
// // 执行app普通安装
|
||||
// boolean flag = PakageInstallUtil.silentInstall(mContext,appInstallPath);
|
||||
// if(flag) {
|
||||
//// FileUtil.deleteFile(appInstallPath); //安装成功后删除文件
|
||||
// LogUtils.loge("executeAppInstall==>" + flag + "||" + appInstallPath);
|
||||
//
|
||||
// Map<String,Object> parm=new HashMap<>();
|
||||
// parm.put("mac",DeviceUtil.getEthernetMac());
|
||||
// parm.put("taskId",taskInfoBean.getTaskId()+"");
|
||||
// parm.put("pushTaskTime", DateUtil.format(new Date(),DateUtil.FORMAT_FULL));
|
||||
// List<Map<String,Object>> parmArry = new ArrayList<>();
|
||||
// parmArry.add(parm);
|
||||
// LogUtils.loge("executeAppInstall===>"+GsonUtil.GsonString(parmArry));
|
||||
// EventManager.getInstance().recordEvent(EventManager.EVENT_PUSH_TASK_CODE,parmArry);
|
||||
//
|
||||
//
|
||||
//// List<AppConfigBean> appConfigBeanList = DaoManager.getInstance().queryByKeyList(AppConfigBean.class,"taskId",taskInfoBean.getTaskId()+"");
|
||||
//// for (AppConfigBean appConfigBean:appConfigBeanList){
|
||||
//// try {
|
||||
//// if (appConfigBean.getAutoStart() == 1 && appConfigBean.getDisable() == 1) {
|
||||
//// String packageName = appConfigBean.getPackageName();
|
||||
//// if (packageName != null && packageName.contains("/")) { // 根据包名判断只启动服务app,必须是service app
|
||||
//// String[] packageNameArray = packageName.split("/");
|
||||
//// Intent intent = new Intent();
|
||||
//// intent.setComponent(new ComponentName(packageNameArray[0], packageNameArray[1]));
|
||||
//// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
//// mContext.startForegroundService(intent);
|
||||
//// } else {
|
||||
//// mContext.startService(intent);
|
||||
//// }
|
||||
//// LogUtils.loge("executeAppInstall==>" + packageName);
|
||||
//// }
|
||||
////
|
||||
//// }
|
||||
//// }catch (Exception e){
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
//
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// case 0:
|
||||
// //TODO 广告已zip包的方式存在,下载完后进行解压,并把路径通知出去
|
||||
//// Intent intent=new Intent(NOTIFY_ADVERT_UPDATE);
|
||||
//// intent.addFlags(0x01000000);
|
||||
//// mContext.sendBroadcast(intent);
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user