Null checks

This commit is contained in:
Björn Ritzl 2020-07-23 19:30:20 +02:00
parent a88fab1543
commit 3c5f8c1424

View File

@ -184,11 +184,14 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
*/ */
private List<Purchase> queryPurchases(final String type) { private List<Purchase> queryPurchases(final String type) {
PurchasesResult result = billingClient.queryPurchases(type); PurchasesResult result = billingClient.queryPurchases(type);
List<Purchase> purchases = result.getPurchasesList();
if (purchases == null) {
purchases = new ArrayList<Purchase>();
}
if (result.getBillingResult().getResponseCode() != BillingResponseCode.OK) { if (result.getBillingResult().getResponseCode() != BillingResponseCode.OK) {
Log.e(TAG, "Unable to query pending purchases: " + result.getBillingResult().getDebugMessage()); Log.e(TAG, "Unable to query pending purchases: " + result.getBillingResult().getDebugMessage());
return new ArrayList<Purchase>();
} }
return result.getPurchasesList(); return purchases;
} }
/** /**
@ -332,12 +335,14 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
@Override @Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetails) { public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetails) {
if (skuDetails != null) {
// cache skus (cache will be used to speed up buying) // cache skus (cache will be used to speed up buying)
for (SkuDetails sd : skuDetails) { for (SkuDetails sd : skuDetails) {
IapGooglePlay.this.products.put(sd.getSku(), sd); IapGooglePlay.this.products.put(sd.getSku(), sd);
} }
// add to list of all sku details // add to list of all sku details
allSkuDetails.addAll(skuDetails); allSkuDetails.addAll(skuDetails);
}
// we're finished when we have queried for both in-app and subs // we're finished when we have queried for both in-app and subs
queries--; queries--;
if (queries == 0) { if (queries == 0) {