Skip to content

Commit 3dd9687

Browse files
Merge pull request livecode#6896 from livecodepanos/bugfix-21880
[21880] Prevent crash when restoring IAP but Google Billing Service is disconnected
2 parents a49c0c6 + 961fa04 commit 3dd9687

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

docs/notes/bugfix-21880.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Prevent crash when restoring in-app-purchases but the Billing Service is disconnected

engine/src/java/com/runrev/android/billing/google/IabHelper.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public class IabHelper {
129129
public static final int IABHELPER_UNKNOWN_ERROR = -1008;
130130
public static final int IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE = -1009;
131131
public static final int IABHELPER_INVALID_CONSUMPTION = -1010;
132+
public static final int IABHELPER_SERVICE_IS_NULL = -1011;
132133

133134
// Keys for the responses from InAppBillingService
134135
public static final String RESPONSE_CODE = "RESPONSE_CODE";
@@ -788,7 +789,6 @@ else if (code < 0 || code >= iab_msgs.length)
788789
return iab_msgs[code];
789790
}
790791

791-
792792
// Checks that setup was done; if not, throws an exception.
793793
void checkSetupDone(String operation) {
794794
if (!mSetupDone) {
@@ -851,6 +851,9 @@ int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteE
851851
boolean verificationFailed = false;
852852
String continueToken = null;
853853

854+
if (mService == null)
855+
return serviceIsDisconnected("queryPurchases");
856+
854857
do {
855858
logDebug("Calling getPurchases with continuation token: " + continueToken);
856859
Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(),
@@ -910,6 +913,8 @@ int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteE
910913
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
911914
throws RemoteException, JSONException {
912915
logDebug("Querying SKU details.");
916+
if (mService == null)
917+
return serviceIsDisconnected("querySkuDetails");
913918
ArrayList<String> skuList = new ArrayList<String>();
914919
skuList.addAll(inv.getAllOwnedSkus(itemType));
915920
if (moreSkus != null) {
@@ -1028,4 +1033,9 @@ void logError(String msg) {
10281033
void logWarn(String msg) {
10291034
Log.w(mDebugTag, "In-app billing warning: " + msg);
10301035
}
1031-
}
1036+
1037+
private int serviceIsDisconnected(String operation) {
1038+
logError("IabHelper.mService is null. Service not connected: " + operation);
1039+
return IABHELPER_SERVICE_IS_NULL;
1040+
}
1041+
}

0 commit comments

Comments
 (0)