Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Fix known errors from Stackoverflow and users experiences #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions library/src/org/onepf/oms/appstore/googleUtils/IabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSk
throw new IabException(IABHELPER_REMOTE_EXCEPTION, "Remote exception while refreshing inventory.", e);
} catch (JSONException e) {
throw new IabException(IABHELPER_BAD_RESPONSE, "Error parsing JSON response while refreshing inventory.", e);
} catch (Exception e) {
throw new IabException(IABHELPER_UNKNOWN_ERROR, "Exception while refreshing inventory.", e);
}
}

Expand Down Expand Up @@ -639,17 +641,31 @@ public void run() {
inv = queryInventory(querySkuDetails, moreSkus);
} catch (IabException ex) {
result = ex.getResult();
} catch (NullPointerException e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which variable is null here?

// Ignore errors if disposed during async operations
if (mSetupDone) {
flagEndAsync();
throw e;
}
} catch (IllegalStateException e) {
// Ignore errors if disposed during async operations
if (mSetupDone) {
flagEndAsync();
throw e;
}
}

flagEndAsync();

final IabResult result_f = result;
final Inventory inv_f = inv;
handler.post(new Runnable() {
public void run() {
listener.onQueryInventoryFinished(result_f, inv_f);
}
});
if (mSetupDone && listener != null) {
handler.post(new Runnable() {
public void run() {
listener.onQueryInventoryFinished(result_f, inv_f);
}
});
}
}
})).start();
}
Expand Down Expand Up @@ -828,6 +844,11 @@ void checkSetupDone(String operation) {

// Workaround to bug where sometimes response codes come as Long instead of Integer
int getResponseCodeFromBundle(Bundle b) {

if (b == null) {
return BILLING_RESPONSE_RESULT_ERROR;
}

Object o = b.get(RESPONSE_CODE);
if (o == null) {
logDebug("Bundle with null response code, assuming OK (known issue)");
Expand All @@ -843,7 +864,7 @@ int getResponseCodeFromBundle(Bundle b) {

// Workaround to bug where sometimes response codes come as Long instead of Integer
int getResponseCodeFromIntent(Intent i) {
Object o = i.getExtras().get(RESPONSE_CODE);
Object o = (i.getExtras() != null) ? i.getExtras().get(RESPONSE_CODE) : null;
if (o == null) {
logError("Intent with no response code, assuming OK (known issue)");
return BILLING_RESPONSE_RESULT_OK;
Expand Down Expand Up @@ -880,7 +901,7 @@ int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteE

do {
logDebug("Calling getPurchases with continuation token: " + continueToken);
if(mService==null){
if (mService == null){
logDebug("getPurchases() failed: service is not connected.");
return BILLING_RESPONSE_RESULT_ERROR;
}
Expand Down Expand Up @@ -1023,14 +1044,14 @@ public void run() {
}

flagEndAsync();
if (singleListener != null) {
if (mSetupDone && singleListener != null) {
handler.post(new Runnable() {
public void run() {
singleListener.onConsumeFinished(purchases.get(0), results.get(0));
}
});
}
if (multiListener != null) {
if (mSetupDone && multiListener != null) {
handler.post(new Runnable() {
public void run() {
multiListener.onConsumeMultiFinished(purchases, results);
Expand Down