Skip to content

Commit

Permalink
Add new GK to gate in app subscription autologging
Browse files Browse the repository at this point in the history
Summary: In this diff, we use a GK to gate the logging of subscriptions.

Reviewed By: jjiang10

Differential Revision: D64275263

fbshipit-source-id: 7bffbb16bc2cbd67dca83da3df9aa3c7e540fcdd
  • Loading branch information
maxalbrightmeta authored and facebook-github-bot committed Oct 23, 2024
1 parent d8e0824 commit 1cf9c1d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.facebook.appevents.iap.InAppPurchaseUtils.IAPProductType.INAPP
import android.content.Context
import androidx.annotation.RestrictTo
import com.facebook.appevents.iap.InAppPurchaseUtils.IAPProductType.SUBS
import com.facebook.internal.FeatureManager
import com.facebook.internal.FeatureManager.isEnabled
import com.facebook.internal.instrument.crashshield.AutoHandleExceptions
import java.util.concurrent.atomic.AtomicBoolean

Expand Down Expand Up @@ -43,8 +45,14 @@ object InAppPurchaseAutoLogger {
failedToCreateWrapper.set(true)
return
}
billingClientWrapper.queryPurchaseHistory(INAPP) {
billingClientWrapper.queryPurchaseHistory(SUBS) {
if (isEnabled(FeatureManager.Feature.AndroidIAPSubscriptionAutoLogging)) {
billingClientWrapper.queryPurchaseHistory(INAPP) {
billingClientWrapper.queryPurchaseHistory(SUBS) {
logPurchase(billingClientVersion, context.packageName)
}
}
} else {
billingClientWrapper.queryPurchaseHistory(INAPP) {
logPurchase(billingClientVersion, context.packageName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ object FeatureManager {
Feature.IapLoggingLib5To7,
Feature.AndroidManualImplicitPurchaseDedupe,
Feature.AndroidManualImplicitSubsDedupe,
Feature.AndroidIAPSubscriptionAutoLogging,
Feature.BannedParamFiltering,
Feature.ProtectedMode,
Feature.StdParamEnforcement,
Expand Down Expand Up @@ -194,6 +195,7 @@ object FeatureManager {
IapLoggingLib5To7(0x0010702),
AndroidManualImplicitPurchaseDedupe(0x0010703),
AndroidManualImplicitSubsDedupe(0x0010704),
AndroidIAPSubscriptionAutoLogging(0x0010705),
Instrument(0x00020000),
CrashReport(0x00020100),
CrashShield(0x00020101),
Expand Down Expand Up @@ -247,6 +249,7 @@ object FeatureManager {
IapLoggingLib5To7 -> "IAPLoggingLib5To7"
AndroidManualImplicitPurchaseDedupe -> "AndroidManualImplicitPurchaseDedupe"
AndroidManualImplicitSubsDedupe -> "AndroidManualImplicitSubsDedupe"
AndroidIAPSubscriptionAutoLogging -> "AndroidIAPSubscriptionAutoLogging"
Monitoring -> "Monitoring"
Megatron -> "Megatron"
Elora -> "Elora"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.facebook.appevents.iap

import android.content.Context
import com.facebook.FacebookPowerMockTestCase
import com.facebook.internal.FeatureManager
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
Expand All @@ -25,7 +26,8 @@ import org.powermock.reflect.Whitebox
InAppPurchaseBillingClientWrapperV2V4::class,
InAppPurchaseBillingClientWrapperV5V7::class,
InAppPurchaseUtils::class,
InAppPurchaseLoggerManager::class
InAppPurchaseLoggerManager::class,
FeatureManager::class
)
class InAppPurchaseAutoLoggerTest : FacebookPowerMockTestCase() {
private lateinit var mockBillingClientWrapperV2_V4: InAppPurchaseBillingClientWrapperV2V4
Expand All @@ -45,6 +47,7 @@ class InAppPurchaseAutoLoggerTest : FacebookPowerMockTestCase() {
PowerMockito.mockStatic(InAppPurchaseBillingClientWrapperV5V7::class.java)
PowerMockito.mockStatic(InAppPurchaseLoggerManager::class.java)
PowerMockito.mockStatic(InAppPurchaseUtils::class.java)
PowerMockito.mockStatic(FeatureManager::class.java)
PowerMockito.doAnswer { Class.forName(className) }
.`when`(InAppPurchaseUtils::class.java, "getClass", any())
}
Expand Down Expand Up @@ -109,7 +112,10 @@ class InAppPurchaseAutoLoggerTest : FacebookPowerMockTestCase() {
}

@Test
fun testStartIapLoggingV2_V4() {
fun testStartIapLoggingWithQuerySubsEnabledV2_V4() {
whenever(FeatureManager.isEnabled(FeatureManager.Feature.AndroidIAPSubscriptionAutoLogging)).thenReturn(
true
)
Whitebox.setInternalState(
InAppPurchaseBillingClientWrapperV2V4::class.java,
"instance",
Expand Down Expand Up @@ -168,7 +174,59 @@ class InAppPurchaseAutoLoggerTest : FacebookPowerMockTestCase() {
}

@Test
fun testStartIapLoggingV5_V7() {
fun testStartIapLoggingWithQuerySubsDisabledV2_V4() {
whenever(FeatureManager.isEnabled(FeatureManager.Feature.AndroidIAPSubscriptionAutoLogging)).thenReturn(
false
)
Whitebox.setInternalState(
InAppPurchaseBillingClientWrapperV2V4::class.java,
"instance",
mockBillingClientWrapperV2_V4
)
var logPurchaseCallTimes = 0
var queryPurchaseCount = 0
var querySubCount = 0
var loggingRunnable: Runnable? = null
var querySubsRunnable: Runnable? = null
whenever(
InAppPurchaseLoggerManager.filterPurchaseLogging(
any(),
any(),
any(),
any(),
any()
)
).thenAnswer {
logPurchaseCallTimes++
Unit
}
whenever(
mockBillingClientWrapperV2_V4.queryPurchaseHistory(
eq(InAppPurchaseUtils.IAPProductType.INAPP),
any()
)
).thenAnswer {
queryPurchaseCount++
loggingRunnable = it.getArgument(1) as Runnable
Unit
}

InAppPurchaseAutoLogger.startIapLogging(
mockContext,
InAppPurchaseUtils.BillingClientVersion.V2_V4
)
assertThat(loggingRunnable).isNotNull
loggingRunnable?.run()
assertThat(logPurchaseCallTimes).isEqualTo(2)
assertThat(queryPurchaseCount).isEqualTo(1)
assertThat(InAppPurchaseAutoLogger.failedToCreateWrapper.get()).isFalse()
}

@Test
fun testStartIapLoggingWithQuerySubsEnabledV5_V7() {
whenever(FeatureManager.isEnabled(FeatureManager.Feature.AndroidIAPSubscriptionAutoLogging)).thenReturn(
true
)
Whitebox.setInternalState(
InAppPurchaseBillingClientWrapperV5V7::class.java,
"instance",
Expand Down Expand Up @@ -225,4 +283,53 @@ class InAppPurchaseAutoLoggerTest : FacebookPowerMockTestCase() {
assertThat(querySubCount).isEqualTo(1)
assertThat(InAppPurchaseAutoLogger.failedToCreateWrapper.get()).isFalse()
}

@Test
fun testStartIapLoggingWithQuerySubsDisabledV5_V7() {
whenever(FeatureManager.isEnabled(FeatureManager.Feature.AndroidIAPSubscriptionAutoLogging)).thenReturn(
false
)
Whitebox.setInternalState(
InAppPurchaseBillingClientWrapperV5V7::class.java,
"instance",
mockBillingClientWrapperV5Plus
)
var logPurchaseCallTimes = 0
var queryPurchaseCount = 0
var querySubCount = 0
var loggingRunnable: Runnable? = null
var querySubsRunnable: Runnable? = null
whenever(
InAppPurchaseLoggerManager.filterPurchaseLogging(
any(),
any(),
any(),
any(),
any()
)
).thenAnswer {
logPurchaseCallTimes++
Unit
}
whenever(
mockBillingClientWrapperV5Plus.queryPurchaseHistory(
eq(InAppPurchaseUtils.IAPProductType.INAPP),
any()
)
).thenAnswer {
queryPurchaseCount++
loggingRunnable = it.getArgument(1) as Runnable
Unit
}

InAppPurchaseAutoLogger.startIapLogging(
mockContext,
InAppPurchaseUtils.BillingClientVersion.V5_V7
)
assertThat(loggingRunnable).isNotNull
loggingRunnable?.run()
assertThat(logPurchaseCallTimes).isEqualTo(2)
assertThat(queryPurchaseCount).isEqualTo(1)
assertThat(InAppPurchaseAutoLogger.failedToCreateWrapper.get()).isFalse()
}
}

0 comments on commit 1cf9c1d

Please sign in to comment.