Skip to content

Commit

Permalink
Support additional strange behaviors
Browse files Browse the repository at this point in the history
Support unexpected scenarios spotted in the wild on a best-effort basis:

* Enterprise policies with apps missing policy fields
* App not downloading due to not being purchased
  • Loading branch information
fynngodau committed Oct 19, 2024
1 parent a6dc3b3 commit b2cec33
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions vending-app/src/main/java/org/microg/vending/ui/VendingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.microg.vending.enterprise.NotCompatible
import org.microg.vending.enterprise.NotInstalled
import org.microg.vending.enterprise.Pending
import org.microg.vending.enterprise.UpdateAvailable
import org.microg.vending.enterprise.proto.AppInstallPolicy
import org.microg.vending.proto.AppMeta
import org.microg.vending.proto.GetItemsRequest
import org.microg.vending.proto.RequestApp
Expand Down Expand Up @@ -97,22 +98,31 @@ class VendingActivity : ComponentActivity() {

val client = HttpClient()

// Purchase app (only needs to be done once, in theory – behaviour seems flaky)
// Ignore failures
runCatching {
if (app.policy != AppInstallPolicy.MANDATORY) {
val parameters = mapOf(
"ot" to "1",
"doc" to app.packageName,
"vc" to app.versionCode.toString()
)
client.post(
url = URL_PURCHASE,
headers = buildRequestHeaders(
auth!!.authToken,
auth!!.gsfId.toLong(16)
),
params = parameters,
adapter = GoogleApiResponse.ADAPTER
)
}
}.onFailure { Log.i(TAG, "couldn't purchase ${app.packageName}: ${it.message}") }
.onSuccess { Log.d(TAG, "purchased ${app.packageName} successfully") }

// Get download links for requested package
val downloadUrls = runCatching {

// Purchase app (only needs to be done once, in theory)
val parameters = mapOf(
"ot" to "1",
"doc" to app.packageName,
"vc" to app.versionCode.toString()
)
client.post(
url = URL_PURCHASE,
headers = buildRequestHeaders(auth!!.authToken, auth!!.gsfId.toLong(16)),
params = parameters,
adapter = GoogleApiResponse.ADAPTER
)

client.requestDownloadUrls(
app.packageName,
app.versionCode!!.toLong(),
Expand Down Expand Up @@ -213,7 +223,7 @@ class VendingActivity : ComponentActivity() {
url = URL_ENTERPRISE_CLIENT_POLICY,
headers = headers.plus("content-type" to "application/x-protobuf"),
adapter = GoogleApiResponse.ADAPTER
).payload?.enterpriseClientPolicyResponse?.policy?.apps?.filter { it.packageName != null && it.policy != null }
).payload?.enterpriseClientPolicyResponse?.policy?.apps?.filter { it.packageName != null }

if (apps == null) {
Log.e(TAG, "unexpected network response: missing expected fields")
Expand Down Expand Up @@ -265,7 +275,7 @@ class VendingActivity : ComponentActivity() {
item.detail!!.name!!.displayName!!,
item.detail.icon?.icon?.paint?.url,
item.offer?.delivery?.key,
apps.find { it.packageName!! == item.meta.packageName }!!.policy!!,
apps.find { it.packageName!! == item.meta.packageName }!!.policy ?: AppInstallPolicy.OPTIONAL,
) to state
}.onEach {
Log.v(TAG, "${it.key.packageName} (state: ${it.value}) delivery token: ${it.key.deliveryToken ?: "none acquired"}")
Expand Down

0 comments on commit b2cec33

Please sign in to comment.