临时简单处理光遇游戏包点击更新时会卡住的问题

This commit is contained in:
juntao
2021-08-16 15:30:15 +08:00
parent 5c02d37852
commit 86edc8b919
4 changed files with 89 additions and 58 deletions

View File

@ -16,8 +16,10 @@ import android.os.PowerManager;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.g00fy2.versioncompare.Version;
import com.gh.common.AppExecutor;
import com.gh.common.xapk.XapkInstaller;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.entity.ApkEntity;
@ -226,9 +228,13 @@ public class PackageUtils {
return null;
}
// TODO 找一个更好的办法来比较签名并且不触发 ANR
// TODO 找一个更高效的方式来比较 V2 签名
public static boolean compareSignatureBetweenInstalledAppWithApk(Context context, String packageName, String apkFilePath) {
try {
AppExecutor.getUiExecutor().execute(() -> {
ToastUtils.toast("安装包校验中约需要3~5秒请稍候");
});
// 据 Sentry 统计,刚上架一个周末的包里对这个方法有 700+ 次调用,然后其中一部分会造成 ANR
Signature sig = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures[0];
@ -281,11 +287,14 @@ public class PackageUtils {
}
/**
* 根据 path 获取 apk 信息确定处理方式
* 根据 path 获取 apk 是否可安装 (全新安装或覆盖安装)
*
* 由于部分不存在 V1 签名的大安装包在调用系统 API 获取签名信息时会非常慢,所以请在工作线程里调用此方法
*
* @return true 为直接唤起系统 PackageInstaller, false 为需要插件化
* @return true 为直接唤起系统 PackageInstaller, false 为需要插件化
*/
public static boolean isCanLaunchSetup(Context context, String path) {
@WorkerThread
public static boolean isInstallable(Context context, String path) {
String packageName = getPackageNameByPath(context, path);
if (TextUtils.isEmpty(packageName)) {