Skip to content

Commit

Permalink
Replace volley with ktor + okhttp
Browse files Browse the repository at this point in the history
Allows downloading large applications
  • Loading branch information
fynngodau committed Sep 25, 2024
1 parent 2e1dfec commit ec18cdb
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 154 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ buildscript {

ext.slf4jVersion = '1.7.36'
ext.volleyVersion = '1.2.1'
ext.okHttpVersion = '4.12.0'
ext.ktorVersion = '2.3.12'
ext.wireVersion = '4.9.9'

ext.androidBuildGradleVersion = '8.2.2'
Expand Down
6 changes: 5 additions & 1 deletion vending-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ android {
removeUnusedResources false
obfuscate false
optimizeCode false
proguardFile 'proguard-rules.pro'
}
}
release {
Expand All @@ -34,6 +35,7 @@ android {
removeUnusedResources true
obfuscate false
optimizeCode true
proguardFile 'proguard-rules.pro'
}
}
}
Expand Down Expand Up @@ -96,7 +98,9 @@ dependencies {
implementation "com.squareup.wire:wire-runtime:$wireVersion"
implementation "com.squareup.wire:wire-grpc-client:$wireVersion"

implementation "com.android.volley:volley:$volleyVersion"
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "io.ktor:ktor-client-core:$ktorVersion"
implementation "io.ktor:ktor-client-okhttp:$ktorVersion"

implementation "androidx.webkit:webkit:$webkitVersion"

Expand Down
6 changes: 6 additions & 0 deletions vending-app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# OKHttp rules
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn org.slf4j.impl.StaticLoggerBinder
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.util.Log
import com.android.vending.AUTH_TOKEN_SCOPE
import com.android.vending.buildRequestHeaders
import com.android.vending.getAuthToken
import com.android.volley.VolleyError
import org.microg.vending.billing.core.HttpClient
import org.microg.vending.billing.proto.GoogleApiResponse
import java.io.IOException
Expand Down Expand Up @@ -126,11 +125,8 @@ suspend fun HttpClient.checkLicense(
packageName, auth, packageInfo.versionCode, decodedAndroidId
)
} ?: ErrorResponse(NOT_LICENSED)
} catch (e: VolleyError) {
Log.e(TAG, "License request failed with $e")
ErrorResponse(ERROR_CONTACTING_SERVER)
} catch (e: IOException) {
Log.e(TAG, "Encountered a network error during operation ($e)")
Log.e(TAG, "Encountered a network error during operation", e)
ErrorResponse(ERROR_CONTACTING_SERVER)
} catch (e: OperationCanceledException) {
ErrorResponse(ERROR_CONTACTING_SERVER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import android.os.RemoteException
import android.util.Log
import com.android.vending.VendingPreferences.isLicensingEnabled
import com.android.vending.VendingPreferences.isLicensingPurchaseFreeAppsEnabled
import com.android.volley.RequestQueue
import com.android.volley.toolbox.Volley
import kotlinx.coroutines.runBlocking
import org.microg.gms.auth.AuthConstants
import org.microg.gms.profile.ProfileManager.ensureInitialized
import org.microg.vending.billing.acquireFreeAppLicense
import org.microg.vending.billing.core.HttpClient

class LicensingService : Service() {
private lateinit var queue: RequestQueue
private lateinit var accountManager: AccountManager
private lateinit var androidId: String
private lateinit var httpClient: HttpClient
Expand Down Expand Up @@ -199,9 +196,8 @@ class LicensingService : Service() {
androidId = java.lang.Long.toHexString(cursor.getLong(0))
}
}
queue = Volley.newRequestQueue(this)
accountManager = AccountManager.get(this)
httpClient = HttpClient(this)
httpClient = HttpClient()

return mLicenseService
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.microg.vending.billing
import android.accounts.Account
import android.content.Context
import android.util.Log
import com.android.volley.VolleyError
import io.ktor.utils.io.errors.IOException
import org.microg.vending.billing.core.GooglePlayApi.Companion.URL_DETAILS
import org.microg.vending.billing.core.GooglePlayApi.Companion.URL_PURCHASE
import org.microg.vending.billing.core.HeaderProvider
Expand All @@ -29,8 +29,8 @@ suspend fun HttpClient.acquireFreeAppLicense(context: Context, account: Account,
params = mapOf("doc" to packageName),
adapter = GoogleApiResponse.ADAPTER
).payload?.detailsResponse
} catch (e: VolleyError) {
Log.e(TAG, "Unable to auto-purchase $packageName because of a network error or unexpected response when gathering app data")
} catch (e: IOException) {
Log.e(TAG, "Unable to auto-purchase $packageName because of a network error or unexpected response when gathering app data", e)
return false
}

Expand Down Expand Up @@ -67,8 +67,8 @@ suspend fun HttpClient.acquireFreeAppLicense(context: Context, account: Account,
params = parameters,
adapter = GoogleApiResponse.ADAPTER
).payload?.buyResponse
} catch (e: VolleyError) {
Log.e(TAG, "Unable to auto-purchase $packageName because of a network error or unexpected response during purchase")
} catch (e: IOException) {
Log.e(TAG, "Unable to auto-purchase $packageName because of a network error or unexpected response during purchase", e)
return false
}

Expand Down
Loading

0 comments on commit ec18cdb

Please sign in to comment.