Skip to content

Commit 7e60b7d

Browse files
committed
feat(core-websdk/googleplay): add Google Play support
1 parent 780a08a commit 7e60b7d

10 files changed

Lines changed: 125 additions & 19 deletions

File tree

app/build.gradle

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ android {
1919
applicationId "net.xzos.upgradeall"
2020
minSdkVersion 21
2121
targetSdkVersion 33
22-
versionCode 99
23-
versionName "0.13-alpha.2"
22+
versionCode 100
23+
versionName "0.13-alpha.3"
2424
if (project.hasProperty('appVerName')) {
2525
versionName = "${versionName}_${appVerName}"
2626
}
@@ -76,14 +76,6 @@ android {
7676
dataBinding true
7777
viewBinding true
7878
}
79-
packagingOptions {
80-
jniLibs {
81-
excludes += ['META-INF/**', 'kotlin/**', 'org/**']
82-
}
83-
resources {
84-
excludes += ['META-INF/**', 'kotlin/**', 'org/**', '**.properties', '**.bin']
85-
}
86-
}
8779

8880
dependenciesInfo.includeInApk false
8981
lint {
@@ -169,4 +161,11 @@ dependencies {
169161
implementation 'com.google.firebase:firebase-analytics:21.0.0'
170162
implementation 'com.google.firebase:firebase-crashlytics:18.2.11'
171163
}
164+
//Protobuf
165+
implementation "com.google.protobuf:protobuf-java:3.21.2"
166+
}
167+
// fix different protobuf versions of gplayapi and firebase
168+
configurations {
169+
all*.exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
170+
all*.exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
172171
}

app/proguard-rules.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,8 @@
162162
-keep class * extends androidx.room.RoomDatabase
163163
-keep @androidx.room.Entity class *
164164
-dontwarn androidx.room.paging.**
165-
##---------------End: proguard configuration for ROOM ----------
165+
##---------------End: proguard configuration for ROOM ----------
166+
167+
##---------------Begin: proguard configuration for Firebase ----------
168+
-keep class com.google.firebase.** { *; }
169+
##---------------End: proguard configuration for Firebase ----------
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.xzos.upgradeall.core.utils
2+
3+
import java.util.*
4+
5+
/**
6+
* 提供 Android properties 格式的 Locale
7+
* 例如:* toString(): zh_CN
8+
*/
9+
fun getLocale(): Locale {
10+
val locale = Locale.getDefault()
11+
return Locale(locale.language, locale.country)
12+
}

core-websdk/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ dependencies {
5353
implementation 'org.dom4j:dom4j:2.1.3'
5454
// markdown support
5555
implementation 'org.jetbrains:markdown:0.3.1'
56+
// google play support
57+
implementation('com.gitlab.AuroraOSS:gplayapi:0e224071')
5658
}

core-websdk/proguard-rules.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
##---------------Begin: proguard configuration for GPlay API ----------
24+
-keep public class com.aurora.gplayapi.** { *; }
25+
##---------------End: proguard configuration for GPlay API ----------

core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/ClientProxyApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class ClientProxyApi(dataCache: DataCacheManager) : BaseApi {
2323
LsposedRepo(dataCache, okhttpProxy),
2424
FDroid(dataCache, okhttpProxy),
2525
Gitlab(dataCache, okhttpProxy),
26+
GooglePlay(dataCache, okhttpProxy),
2627
).associateBy({ it.uuid }, { it })
2728

2829
override fun getCloudConfig(url: String): CloudConfigList? {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package net.xzos.upgradeall.core.websdk.api.client_proxy
2+
3+
const val APK_CONTENT_TYPE = "application/vnd.android.package-archive"

core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/hubs/CoolApk.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import net.xzos.upgradeall.core.utils.log.Log
1010
import net.xzos.upgradeall.core.utils.log.ObjectTag
1111
import net.xzos.upgradeall.core.utils.log.ObjectTag.Companion.core
1212
import net.xzos.upgradeall.core.utils.md5
13+
import net.xzos.upgradeall.core.websdk.api.client_proxy.APK_CONTENT_TYPE
1314
import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData
1415
import net.xzos.upgradeall.core.websdk.api.web.proxy.OkhttpProxy
1516
import net.xzos.upgradeall.core.websdk.base_model.ApiRequestData
@@ -97,9 +98,7 @@ internal class CoolApk(
9798
assetGson: AssetGson?
9899
): List<DownloadItem>? {
99100
val request = assetGson?.downloadUrl?.let { httpRedirects(it) }
100-
if (request?.headers?.get("Content-Type")?.split(";")
101-
?.get(0) != "application/vnd.android.package-archive"
102-
) {
101+
if (request?.headers?.get("Content-Type")?.split(";")?.get(0) != APK_CONTENT_TYPE) {
103102
Log.i(logObjectTag, TAG, "getDownload: 返回非安装包数据")
104103
val newAssets = getRelease(data)?.get(assetIndex[0])?.assetGsonList?.get(assetIndex[1])
105104
?: return null

core-websdk/src/main/java/net/xzos/upgradeall/core/websdk/api/client_proxy/hubs/FDroid.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import net.xzos.upgradeall.core.utils.constant.ANDROID_APP_TYPE
44
import net.xzos.upgradeall.core.utils.constant.VERSION_CODE
55
import net.xzos.upgradeall.core.utils.data_cache.DataCacheManager
66
import net.xzos.upgradeall.core.utils.data_cache.utils.StringEncoder
7+
import net.xzos.upgradeall.core.websdk.api.client_proxy.APK_CONTENT_TYPE
78
import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData
89
import net.xzos.upgradeall.core.websdk.api.web.proxy.OkhttpProxy
910
import net.xzos.upgradeall.core.websdk.base_model.ApiRequestData
@@ -34,10 +35,7 @@ class FDroid(
3435
changelog = changelog.apply { changelog = null },
3536
assetGsonList = listOf(
3637
it.valueOf("apkname").let { name ->
37-
AssetGson(
38-
name, "application/vnd.android.package-archive",
39-
"$url/$name"
40-
)
38+
AssetGson(name, APK_CONTENT_TYPE, "$url/$name")
4139
}
4240
)
4341
)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package net.xzos.upgradeall.core.websdk.api.client_proxy.hubs
2+
3+
import com.aurora.gplayapi.DeviceManager
4+
import com.aurora.gplayapi.data.models.AuthData
5+
import com.aurora.gplayapi.data.providers.DeviceInfoProvider
6+
import com.aurora.gplayapi.helpers.AppDetailsHelper
7+
import com.aurora.gplayapi.helpers.AuthHelper
8+
import com.aurora.gplayapi.helpers.PurchaseHelper
9+
import net.xzos.upgradeall.core.utils.constant.ANDROID_APP_TYPE
10+
import net.xzos.upgradeall.core.utils.constant.VERSION_CODE
11+
import net.xzos.upgradeall.core.utils.data_cache.DataCacheManager
12+
import net.xzos.upgradeall.core.utils.data_cache.utils.JsonObjectEncoder
13+
import net.xzos.upgradeall.core.utils.getLocale
14+
import net.xzos.upgradeall.core.websdk.api.client_proxy.APK_CONTENT_TYPE
15+
import net.xzos.upgradeall.core.websdk.api.web.http.HttpRequestData
16+
import net.xzos.upgradeall.core.websdk.api.web.proxy.OkhttpProxy
17+
import net.xzos.upgradeall.core.websdk.base_model.ApiRequestData
18+
import net.xzos.upgradeall.core.websdk.json.AssetGson
19+
import net.xzos.upgradeall.core.websdk.json.DownloadItem
20+
import net.xzos.upgradeall.core.websdk.json.ReleaseGson
21+
import org.json.JSONObject
22+
23+
class GooglePlay(
24+
dataCache: DataCacheManager, okhttpProxy: OkhttpProxy
25+
) : BaseHub(dataCache, okhttpProxy) {
26+
override val uuid: String = "65c2f60c-7d08-48b8-b4ba-ac6ee924f6fa"
27+
28+
private fun getAuthJson(url: String = "https://auroraoss.com/api/auth"): JSONObject? {
29+
return dataCache.get("AuroraOSS_auth", JsonObjectEncoder) {
30+
okhttpProxy.okhttpExecute(HttpRequestData(url))?.body?.string()
31+
?.let { JSONObject(it) }
32+
}
33+
}
34+
35+
private fun getAuthData(authJson: JSONObject, deviceName: String = "px_3a"): AuthData? {
36+
val email = authJson.getString("email")
37+
val auth = authJson.getString("auth")
38+
val properties = DeviceManager.loadProperties("$deviceName.properties") ?: return null
39+
val locale = getLocale()
40+
val deviceInfoProvider = DeviceInfoProvider(properties, locale.toString())
41+
return AuthHelper.buildInsecure(email, auth, locale, deviceInfoProvider)
42+
}
43+
44+
override fun getRelease(data: ApiRequestData): List<ReleaseGson>? {
45+
val appPackage = data.appId[ANDROID_APP_TYPE] ?: return emptyList()
46+
val authJson = getAuthJson() ?: return null
47+
val authData = getAuthData(authJson) ?: return null
48+
val detailHelper = AppDetailsHelper(authData)
49+
val app = detailHelper.getAppByPackageName(appPackage)
50+
return listOf(
51+
ReleaseGson(
52+
versionNumber = app.versionName,
53+
extra = mapOf(VERSION_CODE to app.versionCode),
54+
changelog = app.changes,
55+
assetGsonList = app.fileList.map {
56+
AssetGson(
57+
fileName = it.name,
58+
fileType = APK_CONTENT_TYPE,
59+
downloadUrl = it.url,
60+
)
61+
}
62+
)
63+
)
64+
}
65+
66+
override fun getDownload(
67+
data: ApiRequestData,
68+
assetIndex: List<Int>,
69+
assetGson: AssetGson?
70+
): List<DownloadItem>? {
71+
val appPackage = data.appId[ANDROID_APP_TYPE] ?: return emptyList()
72+
val authJson = getAuthJson() ?: return null
73+
val authData = getAuthData(authJson) ?: return null
74+
val detailHelper = AppDetailsHelper(authData)
75+
val app = detailHelper.getAppByPackageName(appPackage)
76+
return PurchaseHelper(authData).purchase(
77+
app.packageName,
78+
app.versionCode,
79+
app.offerType
80+
).map {
81+
DownloadItem(it.name, it.url, null, null)
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)