fix: 修复初次启动时会多次获取已安装列表的问题
This commit is contained in:
@ -22,7 +22,6 @@ import com.android.apksig.ApkVerifier;
|
||||
import com.android.apksig.internal.apk.ApkSigningBlockUtilsLite;
|
||||
import com.g00fy2.versioncompare.Version;
|
||||
import com.gh.common.xapk.XapkInstaller;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.common.constant.Constants;
|
||||
import com.gh.gamecenter.common.utils.ExtensionsKt;
|
||||
@ -35,7 +34,6 @@ import com.gh.gamecenter.manager.PackagesManager;
|
||||
import com.gh.vspace.VHelper;
|
||||
import com.gh.vspace.db.VGameEntity;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import net.dongliu.apk.parser.ApkFile;
|
||||
@ -64,8 +62,13 @@ import java.util.zip.ZipFile;
|
||||
|
||||
public class PackageUtils {
|
||||
|
||||
private static long mLastInstalledPackageListTime = 0L;
|
||||
private static List<PackageInfo> mInstalledPackageList = null;
|
||||
|
||||
public static final String publicKey = "OpenSSLRSAPublicKey{modulus=a8c4bb5748fec8d5c35db1a7a182d41ba4721a91131a417330af79ef4ddb43f9fa0ff4907b0a613bfe152de0ed8fc1b2e6f94a908aa98a5f7adc1ce814ba7ec919d75d9910bdfd8649b4789da6a90ffb61f0d23ac4f828a78fcd0d6f6120c1c43c1f87f7498a89eb40ca8e32dfc2f9d5c10d612b95192870223674e241e53305abf320d7eed76ded398778576e4db7b17b3bc6a792f13de5e43a6a5fae4276c73e6990ce97f68dff0ec16fc9594f175c8d49cd0d7877340d9de60942ca0efc737e50b6c295dfe0713e4532b4e810e1ea11b702b4a27753e41559cbceb247e7f044ec4e3ab2e8bccd8b9fd71286e63307550bcde86deee95adb8133076269135b,publicExponent=10001}";
|
||||
|
||||
private static final String TAG = "PackageUtils";
|
||||
|
||||
/*
|
||||
* 判断是否可以更新,只判断gh_version的大小
|
||||
*/
|
||||
@ -872,12 +875,36 @@ public class PackageUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 弃用已安装列表缓存
|
||||
*/
|
||||
public static void dumpInstalledListCache() {
|
||||
mLastInstalledPackageListTime = 0;
|
||||
}
|
||||
|
||||
public static List<PackageInfo> getInstalledPackages(Context context, int flags) {
|
||||
Utils.log(TAG, "即将获取已安装应用列表");
|
||||
|
||||
// 简单 debounce 掉过于频繁的调用获取已安装列表调用
|
||||
if (System.currentTimeMillis() - mLastInstalledPackageListTime < 1000
|
||||
&& mInstalledPackageList != null
|
||||
&& mInstalledPackageList.size() > 0) {
|
||||
Utils.log(TAG, "使用了缓存的已安装应用列表");
|
||||
return new ArrayList<>(mInstalledPackageList);
|
||||
}
|
||||
|
||||
Utils.log(TAG, "调用系统 API 获取全新的已安装应用列表");
|
||||
|
||||
mLastInstalledPackageListTime = System.currentTimeMillis();
|
||||
mInstalledPackageList = getInstalledPackagesInternal(context, flags);
|
||||
return mInstalledPackageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在5.1系统手机使用PackageManager获取已安装应用容易发生Package manager has died异常
|
||||
* https://stackoverflow.com/questions/13235793/transactiontoolargeeception-when-trying-to-get-a-list-of-applications-installed/30062632#30062632
|
||||
* https://stackoverflow.com/questions/13235793/transactiontoolargeeception-when-trying-tÏo-get-a-list-of-applications-installed/30062632#30062632
|
||||
*/
|
||||
public static List<PackageInfo> getInstalledPackages(Context context, int flags) {
|
||||
private static List<PackageInfo> getInstalledPackagesInternal(Context context, int flags) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
try {
|
||||
return pm.getInstalledPackages(flags);
|
||||
|
||||
Reference in New Issue
Block a user