尝试修复安装完成触发的 ANR
This commit is contained in:
@ -185,6 +185,11 @@ public class PackageUtils {
|
||||
|
||||
public static boolean compareSignatureBetweenInstalledAppWithApk(Context context, String packageName, String apkFilePath) {
|
||||
try {
|
||||
// 统计签名比较使用的频率 (大文件会触发 ANR)
|
||||
SentryHelper.INSTANCE.onEvent(
|
||||
"SIGNATURE_COMPARE",
|
||||
"packageName", packageName);
|
||||
|
||||
Signature sig = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures[0];
|
||||
|
||||
// Fuck HUAWEI, 华为系统调用 getPackageArchiveInfo 获取魔羯 apk 的签名时会耗时超过5秒造成 ANR,没有找到解决方法
|
||||
|
||||
@ -7,6 +7,7 @@ import android.preference.PreferenceManager
|
||||
import android.text.TextUtils
|
||||
import com.gh.common.constant.Constants
|
||||
import com.gh.common.loghub.LoghubUtils
|
||||
import com.gh.common.runOnIoThread
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.entity.GameDigestEntity
|
||||
import com.gh.gamecenter.eventbus.EBPackage
|
||||
@ -106,7 +107,8 @@ object PackageObserver {
|
||||
}
|
||||
})
|
||||
}
|
||||
postNewlyInstalledApp(gameId, packageName)
|
||||
|
||||
runOnIoThread { postNewlyInstalledApp(gameId, packageName) }
|
||||
}
|
||||
|
||||
if ("卸载" == busFour.type) {
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.gh.common.AppExecutor;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.ExtensionsKt;
|
||||
import com.gh.common.util.InstallUtils;
|
||||
@ -38,7 +39,14 @@ public class InstallAndUninstallReceiver extends BroadcastReceiver {
|
||||
String versionName = PackageUtils.getVersionByPackage(packageName);
|
||||
EBPackage installEb = new EBPackage("安装", packageName, versionName);
|
||||
EventBus.getDefault().post(installEb);
|
||||
PackageObserver.onPackageChanged(installEb);
|
||||
if (PackageUtils.isAppOnForeground(context)) {
|
||||
PackageObserver.onPackageChanged(installEb);
|
||||
} else {
|
||||
// 处于后台运行的时候尝试延迟 1 秒再触发 onPackageChanged (猜测是引起 ANR 的原因)
|
||||
AppExecutor.getUiExecutor().executeWithDelay(() -> {
|
||||
PackageObserver.onPackageChanged(installEb);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// 接收卸载广播
|
||||
|
||||
Reference in New Issue
Block a user