处理 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

@ -11,6 +11,7 @@ import android.text.TextUtils;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.eventbus.EBPackage;
import com.halo.assistant.HaloApp;
import com.lightgame.download.DownloadEntity;
import org.greenrobot.eventbus.EventBus;
@ -33,12 +34,13 @@ public class InstallUtils {
private static Map<String, Long> installMap;
private static Map<String, Long> uninstallMap;
private static volatile InstallUtils mInstance;
private PackageManager packageManager;
private Handler handler;
private boolean isRunning;
private InstallUtils(Context context) {
private InstallUtils() {
Context context = HaloApp.getInstance().getApplicationContext();
isRunning = false;
packageManager = context.getPackageManager();
@ -63,7 +65,7 @@ public class InstallUtils {
} else if (list.contains(packageName)) {
keys.add(packageName);
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getDownloadEntityByPackageName(packageName);
DownloadEntity downloadEntity = DownloadManager.getInstance().getDownloadEntityByPackageName(packageName);
String installVersion = PackageUtils.getVersionNameByPackageName(packageName);
if (!TextUtils.isEmpty(installVersion) && downloadEntity != null &&
installVersion.equals(downloadEntity.getVersionName())) {
@ -103,15 +105,8 @@ public class InstallUtils {
};
}
public static InstallUtils getInstance(Context context) {
if (mInstance == null) {
synchronized (InstallUtils.class) {
if (mInstance == null) {
mInstance = new InstallUtils(context.getApplicationContext());
}
}
}
return mInstance;
public static InstallUtils getInstance() {
return SingletonHolder.INSTANCE;
}
public void addInstall(String packageName) {
@ -153,4 +148,7 @@ public class InstallUtils {
}
}
private static class SingletonHolder {
private static final InstallUtils INSTANCE = new InstallUtils();
}
}