Skip to content

Commit 92623c3

Browse files
DaVinci9196mar-v-in
authored andcommitted
Vending: Handle absent derived APK IDs in acquire requests
1 parent 59bbefd commit 92623c3

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

  • play-services-core-proto/src/main/proto
  • vending-app/src/main/java/org/microg/vending/billing/core

‎play-services-core-proto/src/main/proto/Purchase.proto‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,19 @@ message ClientInfo {
263263
string oldSkuPurchaseId = 17;
264264
}
265265
optional int32 versionCode1 = 18;
266-
optional UnKnownMessage21 unKnownMessage21 = 21;
266+
oneof DerivedApkInfo {
267+
DerivedApkId derivedApkId = 21;
268+
DerivedApkIdAbsent derivedApkIdAbsent = 22;
269+
}
267270
optional string skuPackageSignatureSha256 = 23;
268271
optional AccountNameMessage secondaryAccount = 24;
269272
}
270273

271-
message UnKnownMessage21 {
272-
optional int32 unknown1 = 1;
274+
message DerivedApkId {
275+
optional int32 derivedId = 1;
276+
}
277+
278+
message DerivedApkIdAbsent {
273279
}
274280

275281
message UnkMessage1 {
@@ -1457,4 +1463,4 @@ enum SessionRestoreOption {
14571463
SESSION_RESTORE_OPTION_REQUIRE = 2;
14581464
SESSION_RESTORE_OPTION_TRY = 3;
14591465
SESSION_RESTORE_OPTION_STORE = 4;
1460-
}
1466+
}

‎vending-app/src/main/java/org/microg/vending/billing/core/IAPCore.kt‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ class IAPCore(
146146

147147
val skuPackageName = params.buyFlowParams.skuParams["skuPackageName"] ?: clientInfo.pkgName
148148
val extendedPackageInfo = ExtendedPackageInfo(context, skuPackageName as String)
149+
val derivedApkId = runCatching {
150+
context.packageManager
151+
.getApplicationInfo(skuPackageName, PackageManager.GET_META_DATA)
152+
.metaData
153+
?.getInt("com.android.vending.derived.apk.id", 0)
154+
?.takeIf { it != 0 }
155+
}.getOrNull()
149156
val docId = if (params.buyFlowParams.skuSerializedDockIdList?.isNotEmpty() == true) {
150157
val sDocIdBytes = Base64.decode(params.buyFlowParams.skuSerializedDockIdList[0], Base64.URL_SAFE + Base64.NO_WRAP)
151158
DocId.ADAPTER.decode(sDocIdBytes)
@@ -193,16 +200,13 @@ class IAPCore(
193200
this.oldSkuPurchaseToken = null
194201
this.oldSkuPurchaseId = params.buyFlowParams.oldSkuPurchaseId
195202
}
196-
unKnownMessage21 = UnKnownMessage21.Builder().apply {
197-
val pkg = skuPackageName as? String ?: return@apply
198-
this.unknown1 = runCatching {
199-
context.packageManager
200-
.getApplicationInfo(pkg, PackageManager.GET_META_DATA)
201-
.metaData
202-
?.getInt("com.android.vending.derived.apk.id", 0)
203-
?.takeIf { it != 0 }
204-
}.getOrNull()
205-
}.build()
203+
if (derivedApkId != null) {
204+
this.derivedApkId = DerivedApkId.Builder().apply {
205+
this.derivedId = derivedApkId
206+
}.build()
207+
} else {
208+
this.derivedApkIdAbsent = DerivedApkIdAbsent.Builder().build()
209+
}
206210
this.skuPackageSignatureSha256 = extendedPackageInfo.firstCertificateSha256?.toBase64(11)
207211
this.secondaryAccount = AccountNameMessage.Builder().apply {
208212
this.accountName = params.buyFlowParams.accountName
@@ -395,4 +399,4 @@ class IAPCore(
395399
throw RuntimeException("Network request failed. message=${e.message}")
396400
}
397401
}
398-
}
402+
}

0 commit comments

Comments
 (0)