poiuytrez / AndroidInAppBilling

Android App Billing plugin for Cordova
174 stars 144 forks source link

getProductDetails() crashes the app in certain circuimstances #45

Open muszek opened 10 years ago

muszek commented 10 years ago

When the plugin is initialized, there's no internet connection and getProductDetails() is called, the app crashes. Steps to reproduce:

  1. call inappbilling.init() (needs to be successful)
  2. disconnect from the internet.
  3. call getProductDetails().

I've tried it a few times, with and without the internet connection at #3. Every time it crashed the app when connection was not present and was successful when the device was connected.

A log from ddms (I hope I got all the relevant parts):

04-22 17:02:11.728: D/CordovaLog(5729): file:///android_asset/www/plugins/com.smartmobilesoftware.inappbilling/www/inappbilling.js: Line 6 : InAppBilling[js]: getProductDetails called!
04-22 17:02:11.728: I/chromium(5729): [INFO:CONSOLE(6)] "InAppBilling[js]: getProductDetails called!", source: file:///android_asset/www/plugins/com.smartmobilesoftware.inappbilling/www/inappbilling.js (6)
04-22 17:02:11.728: D/CordovaLog(5729): file:///android_asset/www/plugins/com.smartmobilesoftware.inappbilling/www/inappbilling.js: Line 6 : InAppBilling[js]: load ["test_9"]
04-22 17:02:11.728: I/chromium(5729): [INFO:CONSOLE(6)] "InAppBilling[js]: load ["test_9"]", source: file:///android_asset/www/plugins/com.smartmobilesoftware.inappbilling/www/inappbilling.js (6)
04-22 17:02:11.728: D/CORDOVA_BILLING(5729): Num SKUs Found: 1
04-22 17:02:11.728: D/CORDOVA_BILLING(5729): Product SKU Added: test_9
04-22 17:02:11.728: D/CORDOVA_BILLING(5729): Beginning Sku(s) Query!
04-22 17:02:11.728: D/IabHelper(5729): Starting async operation: refresh inventory
04-22 17:02:11.738: D/IabHelper(5729): Querying owned items, item type: inapp
04-22 17:02:11.738: D/IabHelper(5729): Package name: info.percentagecalculator.billingTest
04-22 17:02:11.738: D/IabHelper(5729): Calling getPurchases with continuation token: null
04-22 17:02:11.738: D/Finsky(2714): [1680] InAppBillingUtils.getPreferredAccount: info.percentagecalculator.billingTest: Account from first account - [UmQOtrmjdJbOnWsGnn6iIZtCqv4]
04-22 17:02:11.748: D/Finsky(2714): [1680] InAppBillingUtils.getPreferredAccount: info.percentagecalculator.billingTest: Account from first account - [UmQOtrmjdJbOnWsGnn6iIZtCqv4]
04-22 17:02:11.748: D/IabHelper(5729): Owned items response: 0
04-22 17:02:11.748: D/IabHelper(5729): Sku is owned: test_1
04-22 17:02:11.758: D/IabHelper(5729): Sku is owned: test_2
04-22 17:02:11.758: D/IabHelper(5729): Continuation token: null
04-22 17:02:11.758: D/IabHelper(5729): Querying SKU details.
04-22 17:02:11.758: D/IabHelper(5729): moreSkus: Building SKUs List
04-22 17:02:11.758: D/IabHelper(5729): moreSkus: test_9
04-22 17:02:11.758: D/Finsky(2714): [1681] InAppBillingUtils.getPreferredAccount: info.percentagecalculator.billingTest: Account from first account - [UmQOtrmjdJbOnWsGnn6iIZtCqv4]
04-22 17:02:11.758: D/Finsky(2714): [1681] InAppBillingUtils.getPreferredAccount: info.percentagecalculator.billingTest: Account from first account - [UmQOtrmjdJbOnWsGnn6iIZtCqv4]
04-22 17:02:11.808: W/GLSUser(12641): GoogleAccountDataService.getToken()
04-22 17:02:11.868: D/IabHelper(5729): getSkuDetails() failed: 6:Error
04-22 17:02:11.868: D/IabHelper(5729): Ending async operation: refresh inventory
04-22 17:02:11.868: D/CORDOVA_BILLING(5729): Inside mGotDetailsListener
04-22 17:02:11.868: D/CORDOVA_BILLING(5729): Query details was successful.
04-22 17:02:11.868: W/dalvikvm(5729): threadid=15: thread exiting with uncaught exception (group=0x41a67ba8)
04-22 17:02:11.878: D/dalvikvm(12641): GC_CONCURRENT freed 442K, 8% free 8723K/9408K, paused 4ms+2ms, total 45ms
04-22 17:02:11.878: E/AndroidRuntime(5729): FATAL EXCEPTION: JavaBridge
04-22 17:02:11.878: E/AndroidRuntime(5729): Process: info.percentagecalculator.billingTest, PID: 5729
04-22 17:02:11.878: E/AndroidRuntime(5729): java.lang.NullPointerException
04-22 17:02:11.878: E/AndroidRuntime(5729):     at com.smartmobilesoftware.inappbilling.InAppBillingPlugin$3.onQueryInventoryFinished(InAppBillingPlugin.java:313)
04-22 17:02:11.878: E/AndroidRuntime(5729):     at com.smartmobilesoftware.util.IabHelper$2$1.run(IabHelper.java:630)
04-22 17:02:11.878: E/AndroidRuntime(5729):     at android.os.Handler.handleCallback(Handler.java:733)
04-22 17:02:11.878: E/AndroidRuntime(5729):     at android.os.Handler.dispatchMessage(Handler.java:95)
04-22 17:02:11.878: E/AndroidRuntime(5729):     at android.os.Looper.loop(Looper.java:136)
04-22 17:02:11.878: E/AndroidRuntime(5729):     at android.os.HandlerThread.run(HandlerThread.java:61)
04-22 17:02:11.878: W/ActivityManager(501):   Force finishing activity info.percentagecalculator.billingTest/.PercentageCalculator
04-22 17:02:11.898: D/CordovaActivity(5729): Paused the application!
04-22 17:02:11.898: D/CordovaWebView(5729): Handle the pause
04-22 17:02:11.948: E/memtrack(6215): Couldn't load memtrack module (No such file or directory)
04-22 17:02:11.948: E/android.os.Debug(6215): failed to load memtrack module: -2
04-22 17:02:12.038: D/AndroidRuntime(6215): Calling main entry com.android.commands.pm.Pm
04-22 17:02:12.098: D/AndroidRuntime(6215): Shutting down VM
04-22 17:02:12.098: D/jdwp(6215): Got wake-up signal, bailing out of select
04-22 17:02:12.098: D/dalvikvm(6215): Debugger has detached; object registry had 1 entries
04-22 17:02:12.388: I/ActivityManager(501): Killing 20610:com.facebook.katana:dash/u0a124 (adj 15): empty #17
04-22 17:02:12.398: W/SurfaceFlinger(122): couldn't log to binary event log: overflow.
04-22 17:02:12.408: D/CordovaActivity(5729): CordovaActivity.onDestroy()
04-22 17:02:12.408: D/CordovaWebView(5729): >>> loadUrlNow()
04-22 17:02:12.408: D/CORDOVA_BILLING(5729): Destroying helper.
04-22 17:02:12.408: D/IabHelper(5729): Disposing.
04-22 17:02:12.408: D/IabHelper(5729): Unbinding from service.
mlegenhausen commented 10 years ago

You can fix the problem in the following way:

In InAppBillingPlugin.java look for:

if (!hasErrorsAndUpdateInventory(result, inventory)) {

}

and change it to:

if (hasErrorsAndUpdateInventory(result, inventory)) return;
muszek commented 10 years ago

@poiuytrez a fix for ya? (I don't speak Java, I don't think I should make the commit).

mlegenhausen commented 10 years ago

If you want a working version you can check out my fork. Which also allows the installation via

cordova plugin add https://github.com/werk85/AndroidInAppBilling
muszek commented 10 years ago

Can you please make a pull request?

On Thu, Jun 19, 2014 at 11:34 AM, Malte Legenhausen < notifications@github.com> wrote:

If you want a working version you can check out my fork. Which also allows the installation via cordova plugin add https://github.com/werk85/AndroidInAppBilling

— Reply to this email directly or view it on GitHub https://github.com/poiuytrez/AndroidInAppBilling/issues/45#issuecomment-46540842 .

Kind regards, Mateusz Mucha muszek@gmail.com

poiuytrez commented 10 years ago

@mlegenhausen Do not hesitate to make a pull request, I will accept it.