diff --git a/app/src/main/java/com/gh/gamecenter/packagehelper/PackageRepository.kt b/app/src/main/java/com/gh/gamecenter/packagehelper/PackageRepository.kt index 807b21e103..67127c2783 100644 --- a/app/src/main/java/com/gh/gamecenter/packagehelper/PackageRepository.kt +++ b/app/src/main/java/com/gh/gamecenter/packagehelper/PackageRepository.kt @@ -9,15 +9,17 @@ import com.gh.common.filter.RegionSettingHelper import com.gh.common.util.GameUtils import com.gh.common.util.PackageHelper import com.gh.common.util.PackageUtils -import com.gh.gamecenter.R import com.gh.gamecenter.common.constant.Constants +import com.gh.gamecenter.common.entity.InstalledPackagesAction import com.gh.gamecenter.common.exposure.meta.MetaUtil import com.gh.gamecenter.common.loghub.LoghubUtils import com.gh.gamecenter.common.retrofit.BiResponse +import com.gh.gamecenter.common.retrofit.EmptyResponse import com.gh.gamecenter.common.retrofit.ObservableUtil import com.gh.gamecenter.common.retrofit.Response import com.gh.gamecenter.common.utils.secondOrNull import com.gh.gamecenter.common.utils.toArrayList +import com.gh.gamecenter.common.utils.toRequestBody import com.gh.gamecenter.common.utils.tryCatchInRelease import com.gh.gamecenter.core.runOnIoThread import com.gh.gamecenter.core.utils.SPUtils @@ -41,10 +43,12 @@ import io.reactivex.SingleObserver import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers +import okhttp3.ResponseBody import org.greenrobot.eventbus.EventBus import org.json.JSONException import org.json.JSONObject import java.util.* +import kotlin.collections.HashSet /** * 该类存储的是已安装的所有游戏(助手后台已收录的)和所有更新(包括插件化)数据 @@ -624,7 +628,20 @@ object PackageRepository { pkgSet.add(iterator.next()) } + postInstalledPackageList(pkgSet) + PackagesManager.initInstallPkgSet(pkgSet) } + private fun postInstalledPackageList(pkgSet: HashSet) { + val requestBody = InstalledPackagesAction( + action = "launch", + packages = pkgSet.toList() + ).toRequestBody() + + RetrofitManager.getInstance().newApi.postInstalledPackages(HaloApp.getInstance().gid, requestBody) + .subscribeOn(Schedulers.io()) + .subscribe(EmptyResponse()) + } + } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 3302510d07..04dd31a6ac 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -3521,4 +3521,11 @@ public interface ApiService { @Headers({"Content-Type: application/json", "Accept: application/json"}) @POST("suggestions") Single uploadAcceleratorErrorLog(@Body RequestBody toRequestBody); + + /** + * 上传设备已安装的游戏 + */ + @POST("/devices/{device_id}/installed_games") + Single postInstalledPackages(@Path("device_id") String deviceId, @Body RequestBody body); + } \ No newline at end of file diff --git a/module_common/src/main/java/com/gh/gamecenter/common/entity/InstalledPackagesAction.kt b/module_common/src/main/java/com/gh/gamecenter/common/entity/InstalledPackagesAction.kt new file mode 100644 index 0000000000..8bd3f742c1 --- /dev/null +++ b/module_common/src/main/java/com/gh/gamecenter/common/entity/InstalledPackagesAction.kt @@ -0,0 +1,10 @@ +package com.gh.gamecenter.common.entity + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +class InstalledPackagesAction( + val action: String, + val packages: List, +): Parcelable \ No newline at end of file