临时简单处理光遇游戏包点击更新时会卡住的问题
This commit is contained in:
@ -6,6 +6,8 @@ import com.gh.base.BaseActivity
|
||||
import com.gh.common.constant.Constants
|
||||
import com.gh.common.exposure.ExposureUtils
|
||||
import com.gh.common.exposure.meta.MetaUtil
|
||||
import com.gh.common.runOnIoThread
|
||||
import com.gh.common.runOnUiThread
|
||||
import com.gh.common.simulator.SimulatorDownloadManager
|
||||
import com.gh.common.simulator.SimulatorGameManager
|
||||
import com.gh.common.util.EnergyTaskHelper.postEnergyTask
|
||||
@ -166,17 +168,21 @@ object DownloadObserver {
|
||||
Utils.toast(mApplication, R.string.install_failure_hint)
|
||||
downloadManager.cancel(downloadEntity.url)
|
||||
} else {
|
||||
if (PackageUtils.isCanLaunchSetup(mApplication, downloadEntity.path)) {
|
||||
downloadEntity.meta[Constants.MARK_ALREADY_TRIGGERED_INSTALLATION] = "YES"
|
||||
tryWithDefaultCatch {
|
||||
PackageInstaller.install(mApplication, downloadEntity, false)
|
||||
}
|
||||
} else {
|
||||
// 弹出卸载提示框
|
||||
if (downloadEntity.isPlugin) {
|
||||
EventBus.getDefault().post(EBShowDialog(BaseActivity.PLUGGABLE, downloadEntity.path))
|
||||
runOnIoThread {
|
||||
if (PackageUtils.isInstallable(mApplication, downloadEntity.path)) {
|
||||
downloadEntity.meta[Constants.MARK_ALREADY_TRIGGERED_INSTALLATION] = "YES"
|
||||
tryWithDefaultCatch {
|
||||
runOnUiThread {
|
||||
PackageInstaller.install(mApplication, downloadEntity, false)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EventBus.getDefault().post(EBShowDialog(BaseActivity.SIGNATURE_CONFLICT, downloadEntity.path))
|
||||
// 弹出卸载提示框
|
||||
if (downloadEntity.isPlugin) {
|
||||
EventBus.getDefault().post(EBShowDialog(BaseActivity.PLUGGABLE, downloadEntity.path))
|
||||
} else {
|
||||
EventBus.getDefault().post(EBShowDialog(BaseActivity.SIGNATURE_CONFLICT, downloadEntity.path))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.FileProvider
|
||||
import com.gh.common.constant.Constants
|
||||
import com.gh.common.dialog.InstallPermissionDialogFragment
|
||||
import com.gh.common.runOnIoThread
|
||||
import com.gh.common.runOnUiThread
|
||||
import com.gh.common.xapk.XapkInstaller
|
||||
import com.gh.download.server.BrowserInstallHelper
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
@ -77,20 +79,26 @@ object PackageInstaller {
|
||||
return
|
||||
}
|
||||
|
||||
if (PackageUtils.isCanLaunchSetup(context, pkgPath)) {
|
||||
HaloApp.put(Constants.LAST_INSTALL_GAME, pkgPath)
|
||||
runOnIoThread {
|
||||
if (PackageUtils.isInstallable(context, pkgPath)) {
|
||||
runOnUiThread {
|
||||
HaloApp.put(Constants.LAST_INSTALL_GAME, pkgPath)
|
||||
|
||||
val installIntent = getInstallIntent(context, pkgPath)
|
||||
context.startActivity(installIntent)
|
||||
} else {
|
||||
if (isPluggin) {
|
||||
DialogHelper.showPluginDialog(context) {
|
||||
uninstall(context, pkgPath)
|
||||
val installIntent = getInstallIntent(context, pkgPath)
|
||||
context.startActivity(installIntent)
|
||||
}
|
||||
} else {
|
||||
// 非插件化的同包名不同签名冲突
|
||||
DialogHelper.showSignatureConflictDialog(context) {
|
||||
uninstall(context, pkgPath)
|
||||
runOnUiThread {
|
||||
if (isPluggin) {
|
||||
DialogHelper.showPluginDialog(context) {
|
||||
uninstall(context, pkgPath)
|
||||
}
|
||||
} else {
|
||||
// 非插件化的同包名不同签名冲突
|
||||
DialogHelper.showSignatureConflictDialog(context) {
|
||||
uninstall(context, pkgPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.base.fragment.BaseFragment_ViewPager;
|
||||
import com.gh.common.AppExecutor;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadNotificationHelper;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
@ -44,42 +45,49 @@ public class InstallReceiver extends BroadcastReceiver {
|
||||
}
|
||||
updateNotification(downloadEntity);
|
||||
|
||||
if (PackageUtils.isCanLaunchSetup(context, path)) {
|
||||
if (downloadEntity != null) {
|
||||
PackageInstaller.install(context, downloadEntity);
|
||||
DownloadEntity finalDownloadEntity = downloadEntity;
|
||||
AppExecutor.getIoExecutor().execute(() -> {
|
||||
if (PackageUtils.isInstallable(context, path)) {
|
||||
AppExecutor.getUiExecutor().execute(() -> {
|
||||
if (finalDownloadEntity != null) {
|
||||
PackageInstaller.install(context, finalDownloadEntity);
|
||||
} else {
|
||||
PackageInstaller.install(context, false, path);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PackageInstaller.install(context, false, path);
|
||||
}
|
||||
} else {
|
||||
if (RunningUtils.isRunning(context)) {
|
||||
if (RunningUtils.isEqualsTop(context, DownloadManagerActivity.class.getName())) {
|
||||
// 这里是指从后台返回到前台 前两个的是关键
|
||||
Intent intent2 = new Intent();
|
||||
intent2.setAction(Intent.ACTION_MAIN);
|
||||
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent2.setComponent(new ComponentName(context, DownloadManagerActivity.class));
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
context.startActivity(intent2);
|
||||
AppExecutor.getUiExecutor().execute(() -> {
|
||||
if (RunningUtils.isRunning(context)) {
|
||||
if (RunningUtils.isEqualsTop(context, DownloadManagerActivity.class.getName())) {
|
||||
// 这里是指从后台返回到前台 前两个的是关键
|
||||
Intent intent2 = new Intent();
|
||||
intent2.setAction(Intent.ACTION_MAIN);
|
||||
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent2.setComponent(new ComponentName(context, DownloadManagerActivity.class));
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
context.startActivity(intent2);
|
||||
|
||||
EventBus.getDefault().post(new EBMiPush("plugin_install", path));
|
||||
} else {
|
||||
Intent intent2 = new Intent(context, DownloadManagerActivity.class);
|
||||
intent2.putExtra(BaseFragment_ViewPager.ARGS_INDEX, 0);
|
||||
intent2.putExtra(EntranceUtils.KEY_PATH, path);
|
||||
intent2.putExtra(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent2);
|
||||
}
|
||||
} else {
|
||||
// 应用未在运行
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_TO, DownloadManagerActivity.TAG);
|
||||
bundle.putInt(BaseFragment_ViewPager.ARGS_INDEX, 0);
|
||||
bundle.putString(EntranceUtils.KEY_PATH, path);
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
|
||||
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
|
||||
EventBus.getDefault().post(new EBMiPush("plugin_install", path));
|
||||
} else {
|
||||
Intent intent2 = new Intent(context, DownloadManagerActivity.class);
|
||||
intent2.putExtra(BaseFragment_ViewPager.ARGS_INDEX, 0);
|
||||
intent2.putExtra(EntranceUtils.KEY_PATH, path);
|
||||
intent2.putExtra(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent2);
|
||||
}
|
||||
} else {
|
||||
// 应用未在运行
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_TO, DownloadManagerActivity.TAG);
|
||||
bundle.putInt(BaseFragment_ViewPager.ARGS_INDEX, 0);
|
||||
bundle.putString(EntranceUtils.KEY_PATH, path);
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
|
||||
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user