static void equals(@Nullable Object expected, @Nullable Object actual) { equals(expected, actual, "Should be equal"); }
private void checkIsNotStopped() { Check.isFalse(mState == State.STOPPED, "Checkout is stopped"); }
@Override public void onError(int response, @Nonnull Exception e) { Check.isMainThread(); if (response == EXCEPTION) { handleError(e); } else { handleError(response); } } }
/** * Same as {@link #loadSkus(String, List)} with one element in the list. */ @Nonnull public Request loadSkus(@Nonnull String product, @Nonnull String sku) { ProductTypes.checkSupported(product); Check.isNotEmpty(sku); final List<String> list = mSkus.get(product); Check.isTrue(!list.contains(sku), "Adding same SKU is not allowed"); list.add(sku); return this; }
private boolean existsUnsupported() { Check.isTrue(Thread.holdsLock(mLock), "Must be synchronized"); for (Product product : mProducts) { if (!product.supported) { return true; } } return false; } }
@Override public int isPurchaseWithExtraParamsSupported(@Nonnull String product, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return isBillingSupported(product, Billing.V6, listener); }
/** * Starts this {@link Checkout} and sends an initial request that checks whether billing is * supported for each product available in the Billing API. * * @param listener initial request listener */ public void start(@Nullable final Listener listener) { Check.isMainThread(); synchronized (mLock) { Check.isFalse(mState == State.STARTED, "Already started"); Check.isNull(mRequests, "Already started"); mState = State.STARTED; mBilling.onCheckoutStarted(); mRequests = mBilling.getRequests(mTag); } whenReady(listener == null ? new EmptyListener() {} : listener); }
Check.isMainThread(); Check.isNotNull(mRequests); final Billing.Requests requests = mRequests;
void onActivityResult(int requestCode, int resultCode, Intent intent) { try { Check.equals(mRequestCode, requestCode); if (intent == null) { // sometimes intent is null (it's not obvious when it happens but it happens from time to time) handleError(NULL_INTENT); return; } final int responseCode = intent.getIntExtra(EXTRA_RESPONSE, OK); if (resultCode != RESULT_OK || responseCode != OK) { handleError(responseCode); return; } final String data = intent.getStringExtra(EXTRA_PURCHASE_DATA); final String signature = intent.getStringExtra(EXTRA_PURCHASE_SIGNATURE); Check.isNotNull(data); Check.isNotNull(signature); final Purchase purchase = Purchase.fromJson(data, signature); mVerifier.verify(singletonList(purchase), new VerificationListener()); } catch (RuntimeException | JSONException e) { handleError(e); } }
/** * Makes {@link RequestListener} methods to be called on the main application thread. * Default choice if neither this nor {@link #onBackgroundThread()} was called. * * @return this builder */ @Nonnull public RequestsBuilder onMainThread() { Check.isNull(mOnMainThread); mOnMainThread = true; return this; }
static void isNotNull(@Nullable Object o) { isNotNull(o, "Object should not be null"); }
private void onError(int response, @Nonnull Exception e) { Check.notEquals(OK, response); final RequestListener<R> l = getListener(); if (l != null) { if (checkListenerCalled()) return; l.onError(response, e); } }
static void checkSupported(@Nonnull String product) { Check.isTrue(ALL.contains(product), "Unsupported product: " + product); } }
@Override public int isGetPurchaseHistorySupported(@Nonnull String product, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return isBillingSupported(product, Billing.V6, listener); }
/** * Makes {@link RequestListener} methods to be called on a background thread. * * @return this builder */ @Nonnull public RequestsBuilder onBackgroundThread() { Check.isNull(mOnMainThread); mOnMainThread = false; return this; }
@Override void start(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException, RequestException { final Bundle bundle = service.getBuyIntentToReplaceSkus(mApiVersion, packageName, mOldSkus, mNewSku, mProduct, mPayload == null ? "" : mPayload); if (handleError(bundle)) { return; } final PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT"); Check.isNotNull(pendingIntent); onSuccess(pendingIntent); }
BillingSupportedRequest(@Nonnull String product, int apiVersion, @Nullable Bundle extraParams) { super(BILLING_SUPPORTED, apiVersion); Check.isTrue(extraParams == null || apiVersion >= Billing.V7, "#isBillingSupportedExtraParams only works in Billing API v7 or higher"); mProduct = product; mExtraParams = extraParams; }
@Override public int purchase(@Nonnull String product, @Nonnull String sku, @Nullable String payload, @Nonnull PurchaseFlow purchaseFlow) { Check.isNotEmpty(product); Check.isNotEmpty(sku); return runWhenConnected(new PurchaseRequest(product, sku, payload), wrapListener(purchaseFlow), mTag); }
@Override public boolean isLoading() { Check.isMainThread(); synchronized (mLock) { return !mTasks.isEmpty(); } }