处理 SonarQube 问题:

双重检查锁方式实现的单例,改为使用静态内部类方式
This commit is contained in:
lyr
2021-12-21 16:51:44 +08:00
parent 27f14ac914
commit 9feb4e774a
330 changed files with 828 additions and 885 deletions

View File

@ -144,7 +144,7 @@ public class UpdateManager {
}
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
DownloadManager.getInstance(mApplicationContext).cancel(downloadEntity.getUrl(), false, true);
DownloadManager.getInstance().cancel(downloadEntity.getUrl(), false, true);
if (downloadDialog != null) {
try {
downloadDialog.dismiss();
@ -214,7 +214,7 @@ public class UpdateManager {
loadingDialog = DialogUtils.showWaitDialog(mContext, "检查更新中...");
}
String channel = HaloApp.getInstance().getChannel();
RetrofitManager.getInstance(mApplicationContext).getApi().getUpdate(PackageUtils.getGhVersionName(), PackageUtils.getGhVersionCode(), channel)
RetrofitManager.getInstance().getApi().getUpdate(PackageUtils.getGhVersionName(), PackageUtils.getGhVersionCode(), channel)
.map(appEntity -> {
boolean isShowUpdateDialog = false;
@ -438,7 +438,7 @@ public class UpdateManager {
appProgressFilling = view.findViewById(R.id.progress_filling);
view.findViewById(R.id.app_tv_cancel).setOnClickListener(v -> {
DownloadManager.getInstance(context).cancel(appEntity.getUrl());
DownloadManager.getInstance().cancel(appEntity.getUrl());
if (appEntity.isForce()) {
exitApp();
} else {
@ -447,7 +447,7 @@ public class UpdateManager {
});
downloadDialog.setOnDismissListener(dialog -> {
DownloadManager.getInstance(context).removeObserver(dataWatcher);
DownloadManager.getInstance().removeObserver(dataWatcher);
isShowDownload = false;
});
@ -466,20 +466,20 @@ public class UpdateManager {
}
private void createUpdate(String md5, boolean isSilentUpdate) {
DownloadManager.getInstance(mApplicationContext).addObserver(dataWatcher);
DownloadManager.getInstance().addObserver(dataWatcher);
boolean shouldCancelPreviousDownload = true; // 是否应该取消旧更新任务
// 在部分设备上取消正在进行中的旧下载任务再创建新下载任务有机率造成新下载任务依然带有 "静默更新" 标签导致无法唤起安装
// 所以这里对当前静默更新任务正在进行中的时候就不用删旧任务,直接改 meta 标签
if (!isSilentUpdate
&& DownloadManager.getInstance(mApplicationContext).isTaskDownloading(appEntity.getUrl())) {
&& DownloadManager.getInstance().isTaskDownloading(appEntity.getUrl())) {
try {
DownloadEntity entity = DataChanger.INSTANCE.getDownloadEntries().get(appEntity.getUrl());
if (entity != null) {
ExtensionsKt.addMetaExtra(entity, Constants.EXTRA_DOWNLOAD_TYPE, "不再是静默更新");
DownloadManager.getInstance(mApplicationContext).updateDownloadEntity(entity);
DownloadManager.getInstance(mApplicationContext).resume(entity, false);
DownloadManager.getInstance().updateDownloadEntity(entity);
DownloadManager.getInstance().resume(entity, false);
shouldCancelPreviousDownload = false;
}
@ -517,11 +517,11 @@ public class UpdateManager {
}
downloadEntity.setPackageName(mApplicationContext.getPackageName());
DownloadManager.getInstance(mApplicationContext).cancel(appEntity.getUrl(), true, true);
DownloadManager.getInstance(mApplicationContext).pauseAll();
DownloadManager.getInstance().cancel(appEntity.getUrl(), true, true);
DownloadManager.getInstance().pauseAll();
AppExecutor.getUiExecutor().executeWithDelay(() -> {
DownloadManager.getInstance(mApplicationContext).add(downloadEntity);
DownloadManager.getInstance().add(downloadEntity);
}, 200);
}
}