修復同包名遊戲安裝完成時可能誤刪錯誤遊戲的問題

This commit is contained in:
juntao
2021-02-04 18:17:25 +08:00
parent 63403c7c29
commit 8dfde8ddd0
4 changed files with 28 additions and 2 deletions

View File

@ -68,6 +68,8 @@ public class Constants {
public static final String SP_IMEI = "imei";
public static final String SP_ANDROID_ID = "android_id";
public static final String LAST_INSTALL_GAME = "last_install_game";
//引导设置 “通知管理” 引导弹窗
public static final String SP_SHOWED_NOTIFICATION_LOGIN = "show_notification_login_hint";

View File

@ -71,6 +71,8 @@ object PackageInstaller {
fun install(context: Context, pkgPath: String) {
try {
if (PackageUtils.isCanLaunchSetup(context, pkgPath)) {
HaloApp.put(Constants.LAST_INSTALL_GAME, pkgPath)
val installIntent = getInstallIntent(context, pkgPath)
context.startActivity(installIntent)
} else {

View File

@ -3,6 +3,7 @@ package com.gh.download
import android.annotation.SuppressLint
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.*
@ -40,21 +41,36 @@ object PackageObserver {
var mDownloadEntity: DownloadEntity? = null
val sp = PreferenceManager.getDefaultSharedPreferences(application)
var approximateGameId = "" // 模糊的 gameId
var foundMatchedGame = false // 是否找到準確的遊戲 (有可能出現同包名同版本的情況)
for (downloadEntity in DownloadManager.getInstance(application).allDownloadEntity) {
if (packageName == downloadEntity.packageName) {
mDownloadEntity = downloadEntity
gameId = mDownloadEntity.gameId
if (TextUtils.isEmpty(busFour.versionName)) {
// 没有版本号的事件直接选用第一个找到的 downloadEntity
foundMatchedGame = true
break
} else {
// 直接選擇安裝位置一樣的
if (downloadEntity.path == HaloApp.get(Constants.LAST_INSTALL_GAME, false)) {
foundMatchedGame = true
break
}
// 有版本号的事件直接尽量找到版本一致的 downloadEntity
if (versionName == downloadEntity.versionName) {
break
approximateGameId = gameId
}
}
}
}
if (!foundMatchedGame && approximateGameId.isNotEmpty()) {
gameId = approximateGameId
}
if ("安装" == busFour.type) {
mPackageViewModel.addInstalledGame(packageName)

View File

@ -523,7 +523,13 @@ public class MainActivity extends BaseActivity {
@Override
public Boolean invoke(Integer code) {
if (code == 404001) {
toast("抱歉,暂未找到相关内容");
if (showAd) {
AppExecutor.getUiExecutor().executeWithDelay(() -> {
toast("抱歉,暂未找到相关内容");
}, 1000);
} else {
toast("抱歉,暂未找到相关内容");
}
LogUtils.uploadPackageSkip("external_jump", "进入游戏库", "", "");
EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_MAIN, MainWrapperFragment.INDEX_GAME));
return true;