@Override public void onError(int response, @Nonnull Exception e) { Check.isMainThread(); if (response == EXCEPTION) { handleError(e); } else { handleError(response); } } }
@Override public boolean isLoading() { Check.isMainThread(); synchronized (mLock) { return !mTasks.isEmpty(); } }
public Billing(@Nonnull Context context, @Nonnull Configuration configuration) { this(context, new Handler(), configuration); Check.isMainThread(); }
@Override public void onSuccess(@Nonnull List<Purchase> verifiedPurchases) { Check.isMainThread(); if (verifiedPurchases.isEmpty()) { handleError(WRONG_SIGNATURE); return; } if (mListener == null) { return; } mListener.onSuccess(verifiedPurchases.get(0)); }
private void disconnectOnMainThread() { Check.isMainThread(); mConnector.disconnect(); }
public void onCheckoutStarted() { Check.isMainThread(); synchronized (mLock) { mCheckoutCount++; if (mCheckoutCount > 0 && mConfiguration.isAutoConnect()) { connect(); } } }
private void connectOnMainThread() { Check.isMainThread(); final boolean connecting = mConnector.connect(); if (!connecting) { setState(State.FAILED); } }
/** * Method clears all listeners and cancels all pending requests. After this method is called no * more work can be done with this class unless {@link Checkout#start()} method is called * again. */ public void stop() { Check.isMainThread(); synchronized (mLock) { if (mState != State.INITIAL) { mState = State.STOPPED; } if (mRequests != null) { mRequests.cancelAll(); mRequests = null; } if (mState == State.STOPPED) { mBilling.onCheckoutStopped(); } } }
void onCheckoutStopped() { Check.isMainThread(); synchronized (mLock) { mCheckoutCount--; if (mCheckoutCount < 0) { mCheckoutCount = 0; warning("Billing#onCheckoutStopped is called more than Billing#onCheckoutStarted"); } if (mCheckoutCount == 0 && mConfiguration.isAutoConnect()) { disconnect(); } } }
/** * 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); }
/** * Creates an {@link Inventory} object related to this {@link Checkout} instance. The created * {@link Inventory} will use a fall-back {@link Inventory} if it is returned from * {@link Billing.Configuration#getFallbackInventory(Checkout, Executor)} method. * * @return inventory */ @Nonnull public Inventory makeInventory() { Check.isMainThread(); synchronized (mLock) { checkIsNotStopped(); } final Inventory inventory; final Inventory fallbackInventory = mBilling.getConfiguration().getFallbackInventory(this, mOnLoadExecutor); if (fallbackInventory == null) { inventory = new CheckoutInventory(this); } else { inventory = new FallingBackInventory(this, fallbackInventory); } return inventory; }
/** * Cancels all pending requests with {@link ResponseCodes#SERVICE_NOT_CONNECTED} error code. */ void onConnectionFailed() { Check.isMainThread(); RequestRunnable requestRunnable = pop(); while (requestRunnable != null) { final Request request = requestRunnable.getRequest(); if (request != null) { request.onError(ResponseCodes.SERVICE_NOT_CONNECTED); requestRunnable.cancel(); } requestRunnable = pop(); } } }