Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.
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
56 changes: 39 additions & 17 deletions src/android/IabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,28 @@ public void onServiceConnected(ComponentName name, IBinder service) {

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
try {
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
return;
}
}
else {
// no service available to handle that Intent
catch (NullPointerException e) {
// unexpected failure while accessing the service,
// report the error.
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
new IabResult(BILLING_RESPONSE_RESULT_ERROR,
"Billing service failed to initialize."));
}
return;
}
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}

Expand Down Expand Up @@ -560,10 +571,14 @@ public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSk
}

if (querySkuDetails) {
r = querySkuDetails(ITEM_TYPE_INAPP, inv, moreItemSkus);
if (r != BILLING_RESPONSE_RESULT_OK) {
throw new IabException(r, "Error refreshing inventory (querying prices of items).");
}
try {
r = querySkuDetails(ITEM_TYPE_INAPP, inv, moreItemSkus);
if (r != BILLING_RESPONSE_RESULT_OK) {
throw new IabException(r, "Error refreshing inventory (querying prices of items).");
}
} catch (NullPointerException e) {
throw new IabException(IABHELPER_UNKNOWN_ERROR, "NullPointerException while refreshing inventory.", e);
}
}

// if subscriptions are supported, then also query for subscriptions
Expand All @@ -573,11 +588,15 @@ public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSk
throw new IabException(r, "Error refreshing inventory (querying owned subscriptions).");
}

if (querySkuDetails) {
r = querySkuDetails(ITEM_TYPE_SUBS, inv, moreItemSkus);
if (r != BILLING_RESPONSE_RESULT_OK) {
throw new IabException(r, "Error refreshing inventory (querying prices of subscriptions).");
}
if (querySkuDetails) {
try {
r = querySkuDetails(ITEM_TYPE_SUBS, inv, moreItemSkus);
if (r != BILLING_RESPONSE_RESULT_OK) {
throw new IabException(r, "Error refreshing inventory (querying prices of subscriptions).");
}
} catch (NullPointerException e) {
throw new IabException(IABHELPER_UNKNOWN_ERROR, "NullPointerException while refreshing inventory.", e);
}
}
}

Expand All @@ -589,6 +608,9 @@ public Inventory queryInventory(boolean querySkuDetails, List<String> moreItemSk
catch (JSONException e) {
throw new IabException(IABHELPER_BAD_RESPONSE, "Error parsing JSON response while refreshing inventory.", e);
}
catch (NullPointerException e) {
throw new IabException(IABHELPER_UNKNOWN_ERROR, "NullPointer while refreshing inventory.", e);
}
}

/**
Expand Down Expand Up @@ -843,7 +865,7 @@ void flagEndAsync() {
}


int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException, NullPointerException {
// Query purchases
logDebug("Querying owned items, item type: " + itemType);
logDebug("Package name: " + mContext.getPackageName());
Expand Down