From e227b85bb81eff0cedf990c19c0c0654606ac99b Mon Sep 17 00:00:00 2001 From: Daniel Buscaglia Date: Fri, 19 Feb 2016 15:27:25 -0800 Subject: [PATCH 1/3] Fixing nullpointer in bugsnag. --- .../src/org/haxe/extension/iap/util/IabHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java b/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java index 417ce52..7af2551 100755 --- a/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java +++ b/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java @@ -403,7 +403,15 @@ public void launchPurchaseFlow(Activity act, String sku, String itemType, int re try { logDebug("Constructing buy intent for " + sku + ", item type: " + itemType); + // This is where it has a null pointer exception in our code base (source repo is slightly ahead) + if (mService == null || mContext == null) { + result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "mService or mContext is null. Initialization was not correct"); + listener.onIabPurchaseFinished(result, null); + return; + } + Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData); + // int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { logError("Unable to buy item, Error response: " + getResponseDesc(response)); From 66dc8ae9ffe0af78779ab7884670ad0b8627f340 Mon Sep 17 00:00:00 2001 From: Daniel Buscaglia Date: Thu, 17 Mar 2016 15:14:21 -0700 Subject: [PATCH 2/3] Logging support for debugging in amplitude. --- .../org/haxe/extension/iap/InAppPurchase.java | 6 ++++-- extension/iap/IAPEvent.hx | 3 +++ extension/iap/Inventory.hx | 11 ++++++++++- extension/iap/android/IAP.hx | 18 +++++++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java index d815b9b..b3ce704 100644 --- a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java +++ b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java @@ -41,6 +41,7 @@ public void run() { } catch (Exception exception) { // see: https://github.com/openfl/extension-iap/issues/28 Log.e("IAP", "Failed to launch purchase flow.", exception); + InAppPurchase.callback.call("loggerCallback", new Object[] { "AndroidFailedToLaunchPurchaseFlow" }); mPurchaseFinishedListener.onIabPurchaseFinished( new IabResult(IabHelper.BILLING_RESPONSE_RESULT_ERROR, null), null); @@ -81,12 +82,15 @@ public static void consume (final String purchaseJson, final String itemType, fi } public static void queryInventory (final boolean querySkuDetails, String[] moreSkusArr) { + Log.d("DanB", "querying inventory"); final List moreSkus = Arrays.asList(moreSkusArr); Extension.mainActivity.runOnUiThread(new Runnable() { public void run() { try { InAppPurchase.inAppPurchaseHelper.queryInventoryAsync(querySkuDetails, moreSkus, mGotInventoryListener); + InAppPurchase.callback.call("loggerCallback", new Object[] { "AndroidQueryInventorySuccessful" }); } catch(Exception e) { + InAppPurchase.callback.call("onQueryInventoryException", new Object[] { e.getMessage() }); Log.d("IAP", e.getMessage()); } } @@ -134,9 +138,7 @@ public void onIabSetupFinished (final IabResult result) { Extension.callbackHandler.post (new Runnable () { @Override public void run () { - InAppPurchase.callback.call ("onStarted", new Object[] { "Failure" }); - } }); diff --git a/extension/iap/IAPEvent.hx b/extension/iap/IAPEvent.hx index 7a7ce49..069bc10 100644 --- a/extension/iap/IAPEvent.hx +++ b/extension/iap/IAPEvent.hx @@ -24,6 +24,9 @@ class IAPEvent extends Event { public static inline var DOWNLOAD_COMPLETE = "downloadComplete"; public static inline var DOWNLOAD_START = "downloadStart"; public static inline var DOWNLOAD_PROGRESS = "downloadProgress"; + + public static inline var IAP_LOGGING_EVENT = "loggingEvent"; + public static inline var IAP_QUERY_INVENTORY_EXCEPTION = "queryInventoryException"; public var productID:String; public var productsData:Array; diff --git a/extension/iap/Inventory.hx b/extension/iap/Inventory.hx index 2922ed8..c0435bd 100644 --- a/extension/iap/Inventory.hx +++ b/extension/iap/Inventory.hx @@ -1,5 +1,8 @@ package extension.iap; +import extension.iap.IAP; +import extension.iap.IAPEvent; + /** * Represents a block of information about in-app items. * An Inventory is returned by such methods as {@link IAP#queryInventory}. @@ -71,7 +74,13 @@ class Inventory */ public function erasePurchase(productId:String) :Void { - if (purchaseMap.exists(productId)) purchaseMap.remove(productId); + if (purchaseMap.exists(productId)) { + purchaseMap.remove(productId); + } else { + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_LOGGING_EVENT, productId); + evt.message = "AndroidPaymentsProductIdNotFoundInPurchaseMap"; + IAP.dispatcher.dispatchEvent (evt); + } } } diff --git a/extension/iap/android/IAP.hx b/extension/iap/android/IAP.hx index 7a13b7a..dd21ce2 100644 --- a/extension/iap/android/IAP.hx +++ b/extension/iap/android/IAP.hx @@ -73,7 +73,6 @@ import openfl.utils.JNI; */ public static function initialize (publicKey:String = ""):Void { - if (funcInit == null) { funcInit = JNI.createStaticMethod ("org/haxe/extension/iap/InAppPurchase", "initialize", "(Ljava/lang/String;Lorg/haxe/lime/HaxeObject;)V"); } @@ -257,6 +256,23 @@ private class IAPHandler { IAP.dispatcher.dispatchEvent (evt); } + public function loggerCallback(response:String):Void { + var productID:String = ""; + productID = lastPurchaseRequest; //temporal fix + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_LOGGING_EVENT, productID); + evt.message = response; + IAP.dispatcher.dispatchEvent (evt); + } + + public function onQueryInventoryException(response:String):Void { + var productID:String = ""; + productID = lastPurchaseRequest; //temporal fix + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_QUERY_INVENTORY_EXCEPTION, productID); + evt.message = response; + IAP.dispatcher.dispatchEvent (evt); + + } + /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// From 53cd92cf0cd9c476a6be213c57013dc58a9ab832 Mon Sep 17 00:00:00 2001 From: Daniel Buscaglia Date: Thu, 17 Mar 2016 15:16:15 -0700 Subject: [PATCH 3/3] Removing log spam. --- .../android/src/org/haxe/extension/iap/InAppPurchase.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java index b3ce704..e848f52 100644 --- a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java +++ b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java @@ -82,7 +82,6 @@ public static void consume (final String purchaseJson, final String itemType, fi } public static void queryInventory (final boolean querySkuDetails, String[] moreSkusArr) { - Log.d("DanB", "querying inventory"); final List moreSkus = Arrays.asList(moreSkusArr); Extension.mainActivity.runOnUiThread(new Runnable() { public void run() {