Example usage for android.os Bundle getStringArrayList

List of usage examples for android.os Bundle getStringArrayList

Introduction

In this page you can find the example usage for android.os Bundle getStringArrayList.

Prototype

@Override
@Nullable
public ArrayList<String> getStringArrayList(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * Restores purchases from Google Play./*from ww  w. j a v  a2  s  .  co  m*/
 *
 * @throws JSONException
 * @throws RemoteException
 */
private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType);
    SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName());
    boolean verificationFailed = false;
    String continueToken = null;

    do {
        SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(), itemType,
                continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response));
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields.");
            return IabResult.IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                Context.MODE_PRIVATE);
        String publicKey = prefs.getString(GooglePlayIabService.PUBLICKEY_KEY, "");
        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            if (Security.verifyPurchase(publicKey, purchaseData, signature)) {
                SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku);
                IabPurchase purchase = new IabPurchase(itemType, purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!");
                    SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item.");
                SoomlaUtils.LogDebug(TAG, "   IabPurchase data: " + purchaseData);
                SoomlaUtils.LogDebug(TAG, "   Signature: " + signature);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK;
}

From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java

/**
 * Restores purchases from Google Play./*from   ww w.jav a 2 s.  c  o  m*/
 *
 * @throws JSONException
 * @throws RemoteException
 */
private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType);
    SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName());
    boolean verificationFailed = false;
    String continueToken = null;

    do {
        SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(), itemType,
                continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response));
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields.");
            return IabResult.IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                Context.MODE_PRIVATE);
        String publicKey = prefs.getString(TapClashIabService.PUBLICKEY_KEY, "");
        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            if (Security.verifyPurchase(publicKey, purchaseData, signature)) {
                SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku);
                IabPurchase purchase = new IabPurchase(itemType, purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!");
                    SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item.");
                SoomlaUtils.LogDebug(TAG, "   IabPurchase data: " + purchaseData);
                SoomlaUtils.LogDebug(TAG, "   Signature: " + signature);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK;
}

From source file:com.mk.a2dp.billingUtil.IabHelper.java

int queryPurchases(Inventory inv) throws JSONException, RemoteException {
    // Query purchases
    logDebug("Querying owned items...");
    logDebug("Package name: " + mContext.getPackageName());
    // boolean hasMore = true;
    boolean verificationFailed = false;
    String continueToken = null;//from w ww .j  a  v a  2s.  c  o  m

    do {
        logDebug("Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), ITEM_TYPE_INAPP, continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        logDebug("Owned items response: " + String.valueOf(response));
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logDebug("getPurchases() failed: " + getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            logError("Bundle returned from getPurchases() doesn't contain required fields.");
            return IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
                logDebug("Sku is owned: " + sku);
                Purchase purchase = new Purchase(purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    logWarn("BUG: empty/null token!");
                    logDebug("Purchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                logWarn("Purchase signature verification **FAILED**. Not adding item.");
                logDebug("   Purchase data: " + purchaseData);
                logDebug("   Signature: " + signature);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        logDebug("Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
}

From source file:se.springworks.android.utils.iab.IabHelper.java

int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    logDebug("Querying owned items, item type: " + itemType);
    logDebug("Package name: " + mContext.getPackageName());
    boolean verificationFailed = false;
    String continueToken = null;/*from   w ww. j a  va2s .c om*/

    do {
        logDebug("Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        logDebug("Owned items response: " + String.valueOf(response));
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logDebug("getPurchases() failed: " + getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            logError("Bundle returned from getPurchases() doesn't contain required fields.");
            return IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            logDebug("verifyPurchase() base64 = " + mSignatureBase64 + " data = " + purchaseData
                    + " signature = " + signature);
            if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
                logDebug("Sku is owned: " + sku);
                Purchase purchase = new Purchase(itemType, purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    logWarn("BUG: empty/null token!");
                    logDebug("Purchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                logWarn("Purchase signature verification **FAILED**. Not adding item.");
                logDebug("   Purchase data: " + purchaseData);
                logDebug("   Signature: " + signature);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        logDebug("Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
}

From source file:org.onepf.oms.appstore.skubitUtils.SkubitIabHelper.java

/**
 * @param inv      - Inventory with application SKUs
 * @param moreSkus - storeSKUs (processed in {@link OpenIabHelper#queryInventory(boolean, List, List)}
 *//*from ww w.ja v a2s  .co  m*/
int querySkuDetails(String itemType, @NotNull Inventory inv, @Nullable List<String> moreSkus)
        throws RemoteException, JSONException {
    Logger.d("querySkuDetails() Querying SKU details.");
    final SkuManager skuManager = SkuManager.getInstance();
    final String appstoreName = mAppstore.getAppstoreName();

    Set<String> storeSkus = new TreeSet<String>();
    for (String sku : inv.getAllOwnedSkus(itemType)) {
        storeSkus.add(skuManager.getStoreSku(appstoreName, sku));
    }
    if (moreSkus != null) {
        for (String sku : moreSkus) {
            storeSkus.add(skuManager.getStoreSku(appstoreName, sku));
        }
    }
    if (storeSkus.isEmpty()) {
        Logger.d("querySkuDetails(): nothing to do because there are no SKUs.");
        return RESULT_OK;
    }

    // Split the sku list in blocks of no more than QUERY_SKU_DETAILS_BATCH_SIZE elements.
    ArrayList<ArrayList<String>> batches = new ArrayList<ArrayList<String>>();
    ArrayList<String> tmpBatch = new ArrayList<String>(QUERY_SKU_DETAILS_BATCH_SIZE);
    int iSku = 0;
    for (String sku : storeSkus) {
        tmpBatch.add(sku);
        iSku++;
        if (tmpBatch.size() == QUERY_SKU_DETAILS_BATCH_SIZE || iSku == storeSkus.size()) {
            batches.add(tmpBatch);
            tmpBatch = new ArrayList<String>(QUERY_SKU_DETAILS_BATCH_SIZE);
        }
    }

    Logger.d("querySkuDetails() batches: ", batches.size(), ", ", batches);

    for (ArrayList<String> batch : batches) {
        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, batch);
        if (mService == null) {
            Logger.e("In-app billing error: unable to get sku details: service is not connected.");
            return IABHELPER_BAD_RESPONSE;
        }
        Bundle skuDetails = mService.getSkuDetails(1, mContext.getPackageName(), itemType, querySkus);

        if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
            int response = getResponseCodeFromBundle(skuDetails);
            if (response != RESULT_OK) {
                Logger.d("getSkuDetails() failed: ", getResponseDesc(response));
                return response;
            } else {
                Logger.e(
                        "In-app billing error: getSkuDetails() returned a bundle with neither an error nor a detail list.");
                return IABHELPER_BAD_RESPONSE;
            }
        }

        ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

        for (String thisResponse : responseList) {
            SkuDetails d = new SkuDetails(itemType, thisResponse);
            d.setSku(SkuManager.getInstance().getSku(appstoreName, d.getSku()));
            Logger.d("querySkuDetails() Got sku details: ", d);
            inv.addSkuDetails(d);
        }
    }

    return RESULT_OK;
}

From source file:com.soomla.store.billing.nokia.NokiaIabHelper.java

/**
 * Restores purchases from Nokia Store/*from w  w  w. j ava2  s. co  m*/
 *
 * @throws JSONException
 * @throws RemoteException
 */
private int queryPurchases(IabInventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    SoomlaUtils.LogDebug(TAG, "Querying owned items, item type: " + itemType);
    SoomlaUtils.LogDebug(TAG, "Package name: " + SoomlaApp.getAppContext().getPackageName());
    boolean verificationFailed = false;
    String continueToken = null;

    //TODO: Tofix
    ArrayList<String> products = new ArrayList<String>(StoreInfo.getAllProductIds());
    Bundle queryBundle = new Bundle();
    queryBundle.putStringArrayList("ITEM_ID_LIST", products);

    do {
        SoomlaUtils.LogDebug(TAG, "Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, SoomlaApp.getAppContext().getPackageName(),
                ITEM_TYPE_INAPP, queryBundle, continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        SoomlaUtils.LogDebug(TAG, "Owned items response: " + String.valueOf(response));
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogDebug(TAG, "getPurchases() failed: " + IabResult.getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
        //|| !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)
        ) {
            SoomlaUtils.LogError(TAG, "Bundle returned from getPurchases() doesn't contain required fields.");
            return IabResult.IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);

        SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                Context.MODE_PRIVATE);
        String publicKey = prefs.getString(NokiaStoreIabService.PUBLICKEY_KEY, "");
        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String sku = ownedSkus.get(i);
            if (Security.verifyPurchase(publicKey, purchaseData)) {
                SoomlaUtils.LogDebug(TAG, "Sku is owned: " + sku);
                IabPurchase purchase = new IabPurchase(itemType, purchaseData, "");

                if (TextUtils.isEmpty(purchase.getToken())) {
                    SoomlaUtils.LogWarning(TAG, "BUG: empty/null token!");
                    SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                SoomlaUtils.LogWarning(TAG, "IabPurchase signature verification **FAILED**. Not adding item.");
                SoomlaUtils.LogDebug(TAG, "   IabPurchase data: " + purchaseData);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        SoomlaUtils.LogDebug(TAG, "Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IabResult.IABHELPER_VERIFICATION_FAILED : IabResult.BILLING_RESPONSE_RESULT_OK;
}

From source file:com.ffmpeger.card.iabutils.IabHelper.java

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
        throws RemoteException, JSONException {
    logDebug("Querying SKU details.");
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(itemType));
    if (moreSkus != null) {
        for (String sku : moreSkus) {
            if (!skuList.contains(sku)) {
                skuList.add(sku);/*from  w  ww.java2  s .  c  o m*/
            }
        }
    }

    if (skuList.size() == 0) {
        logDebug("queryPrices: nothing to do because there are no SKUs.");
        return BILLING_RESPONSE_RESULT_OK;
    }

    // Split the sku list in blocks of no more than 20 elements.
    ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>();
    ArrayList<String> tempList;
    int n = skuList.size() / 20;
    int mod = skuList.size() % 20;
    for (int i = 0; i < n; i++) {
        tempList = new ArrayList<String>();
        for (String s : skuList.subList(i * 20, i * 20 + 20)) {
            tempList.add(s);
        }
        packs.add(tempList);
    }
    if (mod != 0) {
        tempList = new ArrayList<String>();
        for (String s : skuList.subList(n * 20, n * 20 + mod)) {
            tempList.add(s);
        }
        packs.add(tempList);

        for (ArrayList<String> skuPartList : packs) {
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList);
            Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

            if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
                int response = getResponseCodeFromBundle(skuDetails);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                    return response;
                } else {
                    logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                    return IABHELPER_BAD_RESPONSE;
                }
            }

            ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

            for (String thisResponse : responseList) {
                SkuDetails d = new SkuDetails(itemType, thisResponse);
                logDebug("Got sku details: " + d);
                inv.addSkuDetails(d);
            }
        }

    }

    return BILLING_RESPONSE_RESULT_OK;
}

From source file:com.kyleshaver.minuteofangle.util.IabHelper.java

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
            throws RemoteException, JSONException {
        logDebug("Querying SKU details.");
        ArrayList<String> skuList = new ArrayList<String>();
        skuList.addAll(inv.getAllOwnedSkus(itemType));
        if (moreSkus != null) {
            for (String sku : moreSkus) {
                if (!skuList.contains(sku)) {
                    skuList.add(sku);/*ww  w  .  j a v  a  2 s  .c  o m*/
                }
            }
        }

        if (skuList.size() == 0) {
            logDebug("queryPrices: nothing to do because there are no SKUs.");
            return BILLING_RESPONSE_RESULT_OK;
        }

        // Split the sku list in blocks of no more than 20 elements.
        ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>();
        ArrayList<String> tempList;
        int n = skuList.size() / 20;
        int mod = skuList.size() % 20;
        for (int i = 0; i < n; i++) {
            tempList = new ArrayList<String>();
            for (String s : skuList.subList(i * 20, i * 20 + 20)) {
                tempList.add(s);
            }
            packs.add(tempList);
        }
        if (mod != 0) {
            tempList = new ArrayList<String>();
            for (String s : skuList.subList(n * 20, n * 20 + mod)) {
                tempList.add(s);
            }
            packs.add(tempList);
        }

        for (ArrayList<String> skuPartList : packs) {
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList);
            Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

            if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
                int response = getResponseCodeFromBundle(skuDetails);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                    return response;
                } else {
                    logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                    return IABHELPER_BAD_RESPONSE;
                }
            }

            ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

            for (String thisResponse : responseList) {
                SkuDetails d = new SkuDetails(itemType, thisResponse);
                logDebug("Got sku details: " + d);
                inv.addSkuDetails(d);
            }
        }

        return BILLING_RESPONSE_RESULT_OK;
    }

From source file:org.onepf.oms.appstore.googleUtils.IabHelper.java

/**
 * @param inv - Inventory with application SKUs 
 * @param moreSkus - storeSKUs (processed in {@link OpenIabHelper#queryInventory(boolean, List, List)} 
 *//*  w  ww.  j av  a  2 s .  c o m*/
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
        throws RemoteException, JSONException {
    logDebug("querySkuDetails() Querying SKU details.");
    Set<String> storeSkus = new TreeSet<String>();
    final List<String> allOwnedSkus = inv.getAllOwnedSkus(itemType);
    for (String sku : allOwnedSkus) {
        storeSkus.add(OpenIabHelper.getStoreSku(appstore.getAppstoreName(), sku));
    }
    if (moreSkus != null) {
        for (String sku : moreSkus) {
            storeSkus.add(OpenIabHelper.getStoreSku(appstore.getAppstoreName(), sku));
        }
    }
    if (storeSkus.size() == 0) {
        logDebug("querySkuDetails(): nothing to do because there are no SKUs.");
        return BILLING_RESPONSE_RESULT_OK;
    }

    // Split the sku list in blocks of no more than QUERY_SKU_DETAILS_BATCH_SIZE elements.
    ArrayList<ArrayList<String>> batches = new ArrayList<ArrayList<String>>();
    ArrayList<String> tmpBatch = new ArrayList<String>(QUERY_SKU_DETAILS_BATCH_SIZE);
    int iSku = 0;
    for (String sku : storeSkus) {
        tmpBatch.add(sku);
        iSku++;
        if (tmpBatch.size() == QUERY_SKU_DETAILS_BATCH_SIZE || iSku == storeSkus.size()) {
            batches.add(tmpBatch);
            tmpBatch = new ArrayList<String>(QUERY_SKU_DETAILS_BATCH_SIZE);
        }
    }

    logDebug("querySkuDetails() batches: " + batches.size() + ", " + batches);

    for (ArrayList<String> batch : batches) {
        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, batch);
        if (mService == null) {
            logError("unable to get sku details: service is not connected.");
            return IABHELPER_BAD_RESPONSE;
        }
        Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

        if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
            int response = getResponseCodeFromBundle(skuDetails);
            if (response != BILLING_RESPONSE_RESULT_OK) {
                logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                return response;
            } else {
                logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                return IABHELPER_BAD_RESPONSE;
            }
        }

        ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

        for (String thisResponse : responseList) {
            SkuDetails d = new SkuDetails(itemType, thisResponse);
            d.setSku(OpenIabHelper.getSku(appstore.getAppstoreName(), d.getSku()));
            logDebug("querySkuDetails() Got sku details: " + d);
            inv.addSkuDetails(d);
        }
    }

    return BILLING_RESPONSE_RESULT_OK;
}

From source file:com.freshplanet.inapppurchase.IabHelper.java

int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    logDebug("Querying owned items, item type: " + itemType);
    logDebug("Package name: " + mContext.getPackageName());
    boolean verificationFailed = false;
    String continueToken = null;/*w  w w.  ja  v  a2 s .  c o  m*/

    do {
        logDebug("Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        logDebug("Owned items response: " + String.valueOf(response));
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logDebug("getPurchases() failed: " + getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            logError("Bundle returned from getPurchases() doesn't contain required fields.");
            return IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            logDebug("Sku is owned: " + sku);
            Purchase purchase = new Purchase(itemType, purchaseData, signature);

            if (TextUtils.isEmpty(purchase.getToken())) {
                logWarn("BUG: empty/null token!");
                logDebug("Purchase data: " + purchaseData);
            }

            // Record ownership and token
            inv.addPurchase(purchase);
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        logDebug("Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
}