[Android] Fix iab IllegalStateException

Nicolas Pomepuy git at videolan.org
Wed Aug 5 14:29:59 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Aug  5 09:53:09 2020 +0200| [4225726ea5f3d04023dca49051251a79aefcf5ae] | committer: Nicolas Pomepuy

Fix iab IllegalStateException

> https://code.videolan.org/videolan/vlc-android/commit/4225726ea5f3d04023dca49051251a79aefcf5ae
---

 .../src/main/java/org/videolan/vlc/donations/VLCBilling.kt    | 11 +++++------
 .../main/java/org/videolan/vlc/donations/util/IabHelper.java  |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/application/donations/src/main/java/org/videolan/vlc/donations/VLCBilling.kt b/application/donations/src/main/java/org/videolan/vlc/donations/VLCBilling.kt
index 7068df06e..92886ba59 100644
--- a/application/donations/src/main/java/org/videolan/vlc/donations/VLCBilling.kt
+++ b/application/donations/src/main/java/org/videolan/vlc/donations/VLCBilling.kt
@@ -29,6 +29,7 @@ import android.content.IntentFilter
 import android.util.Log
 import org.videolan.tools.SingletonHolder
 import org.videolan.vlc.donations.util.*
+import java.util.concurrent.atomic.AtomicBoolean
 
 private const val DONATION_TIER_1 = "donation_tier_1"
 private const val DONATION_TIER_2 = "donation_tier_2"
@@ -82,15 +83,15 @@ class VLCBilling private constructor(private val context: Application) : IabBroa
             val broadcastFilter = IntentFilter(IabBroadcastReceiver.ACTION)
             context.registerReceiver(mBroadcastReceiver, broadcastFilter)
 
-            iabHelper.queryInventoryAsync(true, skuList, this)
+            if (!iabHelper.mAsyncInProgress) iabHelper.queryInventoryAsync(true, skuList, this)
         }
     }
 
     fun reloadSkus() {
-        iabHelper.queryInventoryAsync(true, skuList, this)
+        if (!iabHelper.mAsyncInProgress) iabHelper.queryInventoryAsync(true, skuList, this)
     }
 
-    override fun receivedBroadcast() { }
+    override fun receivedBroadcast() {}
 
     override fun onQueryInventoryFinished(result: IabResult?, inventory: Inventory?) {
 
@@ -111,7 +112,7 @@ class VLCBilling private constructor(private val context: Application) : IabBroa
             val details = inventory?.getSkuDetails(skuDetail)
             details?.let { if (skuDetail.contains("subscription")) subsDetails.add(it) else skuDetails.add(it) }
             if (skuDetail.contains("donation") && inventory?.hasPurchase(skuDetail) == true) {
-                iabHelper.consumeAsync(inventory.getPurchase(skuDetail)){ _, _ ->
+                iabHelper.consumeAsync(inventory.getPurchase(skuDetail)) { _, _ ->
                     if (debug) Log.d("VLCBilling", "Consumed")
                 }
             }
@@ -121,10 +122,8 @@ class VLCBilling private constructor(private val context: Application) : IabBroa
 
 
         status = BillingStatus.SKU_RETRIEVED
-
     }
 
-
     companion object : SingletonHolder<VLCBilling, Application>(::VLCBilling)
 }
 
diff --git a/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.java b/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.java
index bdc39e755..ebe2b105c 100644
--- a/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.java
+++ b/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.java
@@ -86,7 +86,7 @@ public class IabHelper {
 
     // Is an asynchronous operation in progress?
     // (only one at a time can be in progress)
-    boolean mAsyncInProgress = false;
+    public boolean mAsyncInProgress = false;
 
     // (for logging/debugging)
     // if mAsyncInProgress == true, what asynchronous operation is in progress?



More information about the Android mailing list