处理 SonarQube 问题:
双重检查锁方式实现的单例,改为使用静态内部类方式
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user