-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-websdk/googleplay): add Google Play support
- Loading branch information
Showing
10 changed files
with
125 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
core-utils/src/main/java/net/xzos/upgradeall/core/utils/LocaleUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.xzos.upgradeall.core.utils | ||
|
||
import java.util.* | ||
|
||
/** | ||
* 提供 Android properties 格式的 Locale | ||
* 例如:* toString(): zh_CN | ||
*/ | ||
fun getLocale(): Locale { | ||
val locale = Locale.getDefault() | ||
return Locale(locale.language, locale.country) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.xzos.upgradeall.core.websdk.api.client_proxy | ||
|
||
const val APK_CONTENT_TYPE = "application/vnd.android.package-archive" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/hubs/GooglePlay.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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.helpers.AppDetailsHelper | ||
import com.aurora.gplayapi.helpers.AuthHelper | ||
import com.aurora.gplayapi.helpers.PurchaseHelper | ||
import net.xzos.upgradeall.core.utils.constant.ANDROID_APP_TYPE | ||
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.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 | ||
import net.xzos.upgradeall.core.websdk.base_model.ApiRequestData | ||
import net.xzos.upgradeall.core.websdk.json.AssetGson | ||
import net.xzos.upgradeall.core.websdk.json.DownloadItem | ||
import net.xzos.upgradeall.core.websdk.json.ReleaseGson | ||
import org.json.JSONObject | ||
|
||
class GooglePlay( | ||
dataCache: DataCacheManager, okhttpProxy: OkhttpProxy | ||
) : BaseHub(dataCache, okhttpProxy) { | ||
override val uuid: String = "65c2f60c-7d08-48b8-b4ba-ac6ee924f6fa" | ||
|
||
private fun getAuthJson(url: String = "https://auroraoss.com/api/auth"): JSONObject? { | ||
return dataCache.get("AuroraOSS_auth", JsonObjectEncoder) { | ||
okhttpProxy.okhttpExecute(HttpRequestData(url))?.body?.string() | ||
?.let { JSONObject(it) } | ||
} | ||
} | ||
|
||
private fun getAuthData(authJson: JSONObject, deviceName: String = "px_3a"): AuthData? { | ||
val email = authJson.getString("email") | ||
val auth = authJson.getString("auth") | ||
val properties = DeviceManager.loadProperties("$deviceName.properties") ?: return null | ||
val locale = getLocale() | ||
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() | ||
val authJson = getAuthJson() ?: return null | ||
val authData = getAuthData(authJson) ?: return null | ||
val detailHelper = AppDetailsHelper(authData) | ||
val app = detailHelper.getAppByPackageName(appPackage) | ||
return listOf( | ||
ReleaseGson( | ||
versionNumber = app.versionName, | ||
extra = mapOf(VERSION_CODE to app.versionCode), | ||
changelog = app.changes, | ||
assetGsonList = app.fileList.map { | ||
AssetGson( | ||
fileName = it.name, | ||
fileType = APK_CONTENT_TYPE, | ||
downloadUrl = it.url, | ||
) | ||
} | ||
) | ||
) | ||
} | ||
|
||
override fun getDownload( | ||
data: ApiRequestData, | ||
assetIndex: List<Int>, | ||
assetGson: AssetGson? | ||
): List<DownloadItem>? { | ||
val appPackage = data.appId[ANDROID_APP_TYPE] ?: return emptyList() | ||
val authJson = getAuthJson() ?: return null | ||
val authData = getAuthData(authJson) ?: return null | ||
val detailHelper = AppDetailsHelper(authData) | ||
val app = detailHelper.getAppByPackageName(appPackage) | ||
return PurchaseHelper(authData).purchase( | ||
app.packageName, | ||
app.versionCode, | ||
app.offerType | ||
).map { | ||
DownloadItem(it.name, it.url, null, null) | ||
} | ||
} | ||
} |