Skip to content

Commit

Permalink
Only query Google Play after app launch and potential purchases
Browse files Browse the repository at this point in the history
Summary:
Previously, we triggered our in-app purchase auto-logging:
1. When the app was first launched
2.  In the onActivityResume callback.

This means every time an application activity was resumed, we queried Google play for in-app purchase info and product info.

This is very inefficient, as it leads to many network requests, even when there is seemingly no in-app purchase related events on the application layer.

While debugging, I discovered that [this activity, titled ProxyBillingActivity](https://github.com/DimaDake/billing/blob/master/library/src/main/java/com/android/billingclient/api/ProxyBillingActivity.java), is the name of the Google Play Activity that surfaces when a user has the ability to make an in-app purchase. This is the case for Google Play Billing Libraries 2 through 7. Therefore, to log in-app purchases, we can send requests to Google Play only after this activity is closed (and still during app launch to catch any edge cases).

This will reduce unnecessary network requests by ``> 99% ``!

Reviewed By: jjiang10

Differential Revision: D62056860

fbshipit-source-id: 647a175b9897f96e695cd5c78d4cf919f7b7a13e
  • Loading branch information
maxalbrightmeta authored and facebook-github-bot committed Sep 27, 2024
1 parent 7ad0224 commit 3b9140c
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ private constructor(
} catch (e: Exception) {
/* swallow */
}
if (loggingRunnable != null && loggingRunnable is Runnable) {
loggingRunnable.run()
}
}
if (loggingRunnable != null && loggingRunnable is Runnable) {
loggingRunnable.run()
}
}

Expand Down Expand Up @@ -505,7 +505,7 @@ private constructor(
private val TAG = InAppPurchaseBillingClientWrapperV5V7::class.java.canonicalName
val isServiceConnected = AtomicBoolean(false)
private var instance: InAppPurchaseBillingClientWrapperV5V7? = null

// Use ConcurrentHashMap because purchase values may be updated in different threads
val purchaseDetailsMap: MutableMap<String, JSONObject> = ConcurrentHashMap()
val productDetailsMap: MutableMap<String, JSONObject> = ConcurrentHashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ object InAppPurchaseManager {

@JvmStatic
fun startTracking() {

if (!enabled.get()) {
return
}
Expand Down
Loading

0 comments on commit 3b9140c

Please sign in to comment.