Merge remote-tracking branch 'origin/release' into dev
# Conflicts: # app/src/main/java/com/gh/download/DownloadManager.java # dependencies.gradle # module_common/src/main/java/com/gh/gamecenter/common/utils/Extensions.kt
This commit is contained in:
@ -50,17 +50,17 @@ import com.gh.gamecenter.manager.PackagesManager;
|
||||
import com.gh.gamecenter.login.user.UserManager;
|
||||
import com.gh.gamecenter.packagehelper.PackageRepository;
|
||||
import com.gh.vspace.VHelper;
|
||||
import com.gh.ndownload.NDataChanger;
|
||||
import com.gh.ndownload.NDownloadBridge;
|
||||
import com.gh.ndownload.NDownloadService;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.ConnectionUtils;
|
||||
import com.lightgame.download.DataChanger;
|
||||
import com.lightgame.download.DataWatcher;
|
||||
import com.lightgame.download.DownloadConfig;
|
||||
import com.lightgame.download.DownloadDao;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.DownloadService;
|
||||
import com.lightgame.download.DownloadStatus;
|
||||
import com.lightgame.download.DownloadStatusListener;
|
||||
import com.lightgame.download.DownloadStatusManager;
|
||||
import com.lightgame.download.DownloadTask;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.download.HttpDnsManager;
|
||||
@ -92,9 +92,9 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
private final Map<String, ConcurrentHashMap<String, DownloadEntity>> gameMap;
|
||||
|
||||
private final ArrayMap<String, DownloadStatus> statusMap;
|
||||
private final ArrayMap<String, DownloadEntity> downloadingMap;
|
||||
private final ConcurrentHashMap<String, DownloadEntity> downloadingMap;
|
||||
|
||||
private ArrayList<DownloadEntity> mInvisiblePendingTaskList; // 用户不可见的 pending 任务
|
||||
private final ArrayList<DownloadEntity> mInvisiblePendingTaskList; // 用户不可见的 pending 任务
|
||||
private final DownloadDao mDownloadDao;
|
||||
private final DownloadedGameIdAndPackageNameDao mDownloadedGameIdAndPackageNameDao;
|
||||
|
||||
@ -170,8 +170,6 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
|
||||
mUpdateMarks = SPUtils.getStringSet(UPDATE_IS_READ_MARK);
|
||||
|
||||
DownloadStatusManager.getInstance().registerTaskStatusListener(this);
|
||||
|
||||
// 只有下载模块需要这坨东西,因此移动到这里初始化
|
||||
ConnectionUtils.initHttpsUrlConnection(mContext);
|
||||
|
||||
@ -181,7 +179,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
platformMap = new ArrayMap<>();
|
||||
gameMap = new ConcurrentHashMap<>();
|
||||
statusMap = new ArrayMap<>();
|
||||
downloadingMap = new ArrayMap<>();
|
||||
downloadingMap = new ConcurrentHashMap<>();
|
||||
// mDownloadSnapshotList = new ArrayList<>();
|
||||
mInvisiblePendingTaskList = new ArrayList<>();
|
||||
|
||||
@ -227,10 +225,6 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayMap<String, DownloadEntity> getDownloadingMap() {
|
||||
return downloadingMap;
|
||||
}
|
||||
|
||||
public static DownloadManager getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
@ -446,7 +440,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
|
||||
if (isDownloadCompleted(url)) {
|
||||
downloadEntity.setStatus(DownloadStatus.done);
|
||||
DataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
NDataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
startDownloadService(downloadEntity, DownloadStatus.add);
|
||||
}
|
||||
@ -467,7 +461,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
if (isDownloadCompleted(url)) {
|
||||
downloadEntity.setStatus(DownloadStatus.done);
|
||||
DataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
NDataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
DownloadEntity daoEntity = mDownloadDao.get(downloadEntity.getUrl());
|
||||
if (automatic) {
|
||||
@ -502,7 +496,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
if (isDownloadCompleted(url)) {
|
||||
downloadEntity.setStatus(DownloadStatus.done);
|
||||
DataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
NDataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
startDownloadService(downloadEntity, DownloadStatus.subscribe);
|
||||
}
|
||||
@ -548,7 +542,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* 任务是否已经下载中
|
||||
*/
|
||||
public boolean isTaskDownloading(String url) {
|
||||
if (DataChanger.INSTANCE.getDownloadingTasks().get(url) != null) {
|
||||
if (NDataChanger.INSTANCE.getDownloadingTasks().get(url) != null) {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), url + "正在下载!");
|
||||
return true;
|
||||
}
|
||||
@ -556,7 +550,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
}
|
||||
|
||||
private Intent getIntent(DownloadEntity entry, DownloadStatus status) {
|
||||
Intent service = new Intent(mContext, DownloadService.class);
|
||||
Intent service = new Intent(mContext, NDownloadService.class);
|
||||
service.putExtra(DownloadConfig.KEY_DOWNLOAD_ENTRY, entry);
|
||||
service.putExtra(DownloadConfig.KEY_DOWNLOAD_ACTION, status.name());
|
||||
return service;
|
||||
@ -585,6 +579,16 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
return mDownloadDao.getAllSnapshots();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快照
|
||||
*
|
||||
* @param url 下载地址
|
||||
*/
|
||||
@Nullable
|
||||
public DownloadEntity getDownloadEntitySnapshot(String url) {
|
||||
return mDownloadDao.getSnapshot(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快照
|
||||
*
|
||||
@ -825,6 +829,8 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
DownloadEntity entry = mDownloadDao.getSnapshot(url);
|
||||
if (entry != null) {
|
||||
AppExecutor.getIoExecutor().execute(() -> {
|
||||
NDownloadBridge.INSTANCE.cancel(url);
|
||||
|
||||
mDownloadDao.delete(url);
|
||||
|
||||
if (isDeleteFile) {
|
||||
@ -858,19 +864,16 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
private void cancelAndNotify(DownloadEntity entry, boolean cancelSilently) {
|
||||
mDownloadDao.removeErrorMessage(entry.getUrl());
|
||||
|
||||
DownloadTask task = DataChanger.INSTANCE.getDownloadingTasks().get(entry.getUrl());
|
||||
DownloadTask task = NDataChanger.INSTANCE.getDownloadingTasks().get(entry.getUrl());
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
// 改任务队列的状态
|
||||
DataChanger.INSTANCE.getDownloadingTasks().remove(entry.getUrl());
|
||||
if (!cancelSilently) {
|
||||
DataChanger.INSTANCE.notifyDataChanged(entry);
|
||||
}
|
||||
NDataChanger.INSTANCE.getDownloadingTasks().remove(entry.getUrl());
|
||||
}
|
||||
DataChanger.INSTANCE.getDownloadEntries().remove(entry.getUrl());
|
||||
NDataChanger.INSTANCE.getDownloadEntries().remove(entry.getUrl());
|
||||
if (!cancelSilently) {
|
||||
DataChanger.INSTANCE.notifyDataChanged(entry);
|
||||
DownloadStatusManager.getInstance().onTaskCancelled(entry);
|
||||
NDataChanger.INSTANCE.notifyDataChanged(entry);
|
||||
onTaskCancelled(entry);
|
||||
}
|
||||
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "cancel");
|
||||
@ -880,7 +883,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* 暂停所有正在下载的任务
|
||||
*/
|
||||
public void pauseAll() {
|
||||
for (DownloadEntity entity : DataChanger.INSTANCE.getDownloadEntries().values()) {
|
||||
for (DownloadEntity entity : NDataChanger.INSTANCE.getDownloadEntries().values()) {
|
||||
pause(entity.getUrl());
|
||||
}
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "pause all");
|
||||
@ -891,7 +894,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
*/
|
||||
public void pause(String url) {
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
DownloadEntity entry = DataChanger.INSTANCE.getDownloadEntries().get(url);
|
||||
DownloadEntity entry = NDataChanger.INSTANCE.getDownloadEntries().get(url);
|
||||
if (entry != null) {
|
||||
startDownloadService(entry, DownloadStatus.pause);
|
||||
put(url, System.currentTimeMillis());
|
||||
@ -907,14 +910,14 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* 3.检查是否显示下载通知栏
|
||||
*/
|
||||
public void initDownloadService() {
|
||||
final List<String> urlList = new ArrayList<>(DataChanger.INSTANCE.getDownloadingTasks().keySet());
|
||||
final List<String> urlList = new ArrayList<>(NDataChanger.INSTANCE.getDownloadingTasks().keySet());
|
||||
for (DownloadEntity downloadEntity : getAllDownloadEntity()) {
|
||||
if (!urlList.contains(downloadEntity.getUrl()) &&
|
||||
(downloadEntity.getStatus().equals(DownloadStatus.downloading)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.waiting))) {
|
||||
downloadEntity.setStatus(DownloadStatus.subscribe);
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
DataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
NDataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -927,7 +930,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
*/
|
||||
public void addObserver(DataWatcher dataWatcher) {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "addObserver");
|
||||
DataChanger.INSTANCE.addObserver(dataWatcher);
|
||||
NDataChanger.INSTANCE.addObserver(dataWatcher);
|
||||
|
||||
notifyDownloadStatusASAP(dataWatcher);
|
||||
}
|
||||
@ -937,7 +940,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
*/
|
||||
public void removeObserver(DataWatcher dataWatcher) {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "removeObserver");
|
||||
DataChanger.INSTANCE.deleteObserver(dataWatcher);
|
||||
NDataChanger.INSTANCE.deleteObserver(dataWatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -953,11 +956,11 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* 初始化下载服务
|
||||
*/
|
||||
public void startDownloadService() {
|
||||
Intent serviceIntent = new Intent(mContext, DownloadService.class);
|
||||
Intent serviceIntent = new Intent(mContext, NDownloadService.class);
|
||||
// 当满足系统版本大于 8.0 并且应用在后台运行时以前台服务开启
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
&& !PackageUtils.isAppOnForeground(mContext)) {
|
||||
serviceIntent.putExtra(DownloadService.KEY_SERVICE_ACTION, DownloadService.START_FOREGROUND);
|
||||
serviceIntent.putExtra(NDownloadService.KEY_SERVICE_ACTION, NDownloadService.START_FOREGROUND);
|
||||
mContext.startForegroundService(serviceIntent);
|
||||
} else {
|
||||
/*
|
||||
@ -997,7 +1000,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
// 当满足系统版本大于 8.0 并且应用在后台运行时以前台服务开启
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
&& !PackageUtils.isAppOnForeground(mContext)) {
|
||||
serviceIntent.putExtra(DownloadService.KEY_SERVICE_ACTION, DownloadService.START_FOREGROUND);
|
||||
serviceIntent.putExtra(NDownloadService.KEY_SERVICE_ACTION, NDownloadService.START_FOREGROUND);
|
||||
mContext.startForegroundService(serviceIntent);
|
||||
} else {
|
||||
mContext.startService(serviceIntent);
|
||||
@ -1128,7 +1131,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
String mark = downloadEntity.getMeta().get(DOWNLOADED_IS_READ_MARK);
|
||||
if (TextUtils.isEmpty(mark)) {
|
||||
downloadEntity.getMeta().put(DOWNLOADED_IS_READ_MARK, DOWNLOADED_IS_READ_MARK);
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
mDownloadDao.update(downloadEntity, false);
|
||||
if (!markHasChanged) markHasChanged = true;
|
||||
}
|
||||
}
|
||||
@ -1168,12 +1171,12 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
String mark = downloadEntity.getMeta().get(DOWNLOADING_IS_READ_MARK);
|
||||
if (TextUtils.isEmpty(mark)) {
|
||||
downloadEntity.getMeta().put(DOWNLOADING_IS_READ_MARK, DOWNLOADING_IS_READ_MARK);
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
mDownloadDao.update(downloadEntity, false);
|
||||
if (!markHasChanged) markHasChanged = true;
|
||||
}
|
||||
} else {
|
||||
downloadEntity.getMeta().put(DOWNLOADING_IS_READ_MARK, "");
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
mDownloadDao.update(downloadEntity, false);
|
||||
if (!markHasChanged) markHasChanged = true;
|
||||
}
|
||||
}
|
||||
@ -1231,7 +1234,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* 更新数据库中的下载实体
|
||||
*/
|
||||
public void updateDownloadEntity(DownloadEntity downloadEntity) {
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
mDownloadDao.update(downloadEntity, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user