/** * Sometimes Google Play is not that fast in updating information on device. Let's wait it a * little bit as if we don't wait we might cache expired information (though, it will be * updated soon as RequestType#GET_PURCHASES cache entry expires quite often) */ static void waitGooglePlay() { try { Thread.sleep(100L); } catch (InterruptedException e) { error(e); } }
static void error(@Nonnull Exception e) { error(e.getMessage(), e); }
@Override @Nullable public Entry get(@Nonnull Key key) { try { return mCache.get(key); } catch (Exception e) { Billing.error(e); return null; } }
@Override public void init() { try { mCache.init(); } catch (Exception e) { Billing.error(e); } }
@Override public void remove(@Nonnull Key key) { try { mCache.remove(key); } catch (Exception e) { Billing.error(e); } }
@Override public void removeAll(int type) { try { mCache.removeAll(type); } catch (Exception e) { Billing.error(e); } }
private void handleError(@Nonnull Exception e) { Billing.error("Exception in Purchase/ChangePurchase request: ", e); onError(ResponseCodes.EXCEPTION, e); }
@Override public void put(@Nonnull Key key, @Nonnull Entry entry) { try { mCache.put(key, entry); } catch (Exception e) { Billing.error(e); } }
@Override public void clear() { try { mCache.clear(); } catch (Exception e) { Billing.error(e); } } }
@Override public void execute(Runnable command) { final Executor executor; synchronized (mLock) { executor = mRequests != null ? mRequests.getDeliveryExecutor() : null; } if (executor != null) { executor.execute(command); } else { Billing.error("Trying to deliver result on a stopped checkout."); } } }
public void onError(@Nonnull Exception e) { Check.isFalse(e instanceof BillingException, "Use onError(int) instead"); Billing.error("Exception in " + this + " request: ", e); onError(EXCEPTION, e); }
@Override public void verify(@Nonnull List<Purchase> purchases, @Nonnull RequestListener<List<Purchase>> listener) { final List<Purchase> verifiedPurchases = new ArrayList<Purchase>(purchases.size()); for (Purchase purchase : purchases) { // test purchases don't contain signatures let's auto-verify them if (TEST_SKUS.contains(purchase.sku)) { Billing.debug("Auto-verifying a test purchase: " + purchase); verifiedPurchases.add(purchase); continue; } if (Security.verifyPurchase(mPublicKey, purchase.data, purchase.signature)) { verifiedPurchases.add(purchase); continue; } if (isEmpty(purchase.signature)) { Billing.error("Cannot verify purchase: " + purchase + ". Signature is empty"); } else { Billing.error("Cannot verify purchase: " + purchase + ". Wrong signature"); } } listener.onSuccess(verifiedPurchases); } }
private void handleError(int response) { Billing.error("Error response: " + response + " in Purchase/ChangePurchase request"); onError(response, new BillingException(response)); }
@Nonnull Inventory.Products load(@Nonnull Inventory.Request request) { SQLiteDatabase db = null; try { final String databasePath = RobotmediaDatabase.getDatabasePath(mContext); db = openDatabase(databasePath, null, OPEN_READONLY); return loadProducts(request, db); } catch (RuntimeException e) { Billing.error(e); } finally { if (db != null) { db.close(); } } return toInventoryProducts(ProductTypes.ALL); }
protected void onError(int response) { String message = ResponseCodes.toString(response); Billing.error("Error response: " + message + " in " + this + " request"); onError(response, new BillingException(response)); }