@@ -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