Skip to content

Commit

Permalink
perf(core-websdk/googleplay): handle AppNotFound Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
xz-dev committed Jul 7, 2022
1 parent 8b39dd7 commit 105f61a
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.xzos.upgradeall.core.websdk.api.client_proxy.hubs
import com.aurora.gplayapi.DeviceManager
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.providers.DeviceInfoProvider
import com.aurora.gplayapi.exceptions.ApiException
import com.aurora.gplayapi.helpers.AppDetailsHelper
import com.aurora.gplayapi.helpers.AuthHelper
import com.aurora.gplayapi.helpers.PurchaseHelper
Expand All @@ -11,6 +12,9 @@ import net.xzos.upgradeall.core.utils.constant.VERSION_CODE
import net.xzos.upgradeall.core.utils.data_cache.DataCacheManager
import net.xzos.upgradeall.core.utils.data_cache.utils.JsonObjectEncoder
import net.xzos.upgradeall.core.utils.getLocale
import net.xzos.upgradeall.core.utils.log.Log
import net.xzos.upgradeall.core.utils.log.ObjectTag
import net.xzos.upgradeall.core.utils.log.ObjectTag.Companion.core
import net.xzos.upgradeall.core.websdk.api.client_proxy.APK_CONTENT_TYPE
import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData
import net.xzos.upgradeall.core.websdk.api.web.proxy.OkhttpProxy
Expand All @@ -35,18 +39,26 @@ class GooglePlay(
private fun getAuthData(authJson: JSONObject, deviceName: String = "px_3a"): AuthData? {
val email = authJson.getString("email")
val auth = authJson.getString("auth")
Log.i(logObjectTag, TAG, "getAuthData: email: $email")
val properties = DeviceManager.loadProperties("$deviceName.properties") ?: return null
val locale = getLocale()
Log.i(logObjectTag, TAG, "getAuthData: locale: $locale")
val deviceInfoProvider = DeviceInfoProvider(properties, locale.toString())
return AuthHelper.buildInsecure(email, auth, locale, deviceInfoProvider)
}

override fun getRelease(data: ApiRequestData): List<ReleaseGson>? {
val appPackage = data.appId[ANDROID_APP_TYPE] ?: return emptyList()
Log.i(logObjectTag, TAG, "getRelease: package: $appPackage")
val authJson = getAuthJson() ?: return null
val authData = getAuthData(authJson) ?: return null
val detailHelper = AppDetailsHelper(authData)
val app = detailHelper.getAppByPackageName(appPackage)
val app = try {
detailHelper.getAppByPackageName(appPackage)
} catch (e: ApiException.AppNotFound) {
return emptyList()
}
Log.i(logObjectTag, TAG, "getRelease: appInfo: ${app.appInfo.appInfoMap}")
return listOf(
ReleaseGson(
versionNumber = app.versionName,
Expand Down Expand Up @@ -81,4 +93,9 @@ class GooglePlay(
DownloadItem(it.name, it.url, null, null)
}
}

companion object {
private const val TAG = "GooglePlay"
private val logObjectTag = ObjectTag(core, TAG)
}
}

0 comments on commit 105f61a

Please sign in to comment.