// Path: library/src/main/java/jp/alessandro/android/iab/handler/ErrorHandler.java
// public interface ErrorHandler {
// 
//     void onError(BillingException e);
// }
// 
// Path: library/src/main/java/jp/alessandro/android/iab/handler/StartActivityHandler.java
// public interface StartActivityHandler extends ErrorHandler {
// 
//     void onSuccess();
// }


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.SparseArray;
import com.android.vending.billing.IInAppBillingService;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import jp.alessandro.android.iab.handler.ConsumeItemHandler;
import jp.alessandro.android.iab.handler.ErrorHandler;
import jp.alessandro.android.iab.handler.InventoryHandler;
import jp.alessandro.android.iab.handler.ItemDetailsHandler;
import jp.alessandro.android.iab.handler.PurchaseHandler;
import jp.alessandro.android.iab.handler.PurchasesHandler;
import jp.alessandro.android.iab.handler.StartActivityHandler;
import jp.alessandro.android.iab.logger.Logger;
import jp.alessandro.android.iab.response.PurchaseResponse;
     * Check if nAppIInAppBillingService is supported on the device.
     *
     * @param context
     * @return true if it is supported
     */
    public synchronized static boolean isServiceAvailable(Context context) {
        PackageManager packageManager = context.getPackageManager();
        Intent serviceIntent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
        serviceIntent.setPackage(Constants.VENDING_PACKAGE);
        List<ResolveInfo> list = packageManager.queryIntentServices(serviceIntent, 0);

        return list != null && !list.isEmpty();
    }

    /**
     * Purchase a subscription
     * This will be executed from UI Thread
     *
     * @param activity         activity calling this method
     * @param requestCode
     * @param itemId           new subscription item id
     * @param purchaseType     IN_APP or SUBSCRIPTION
     * @param developerPayload optional argument to be sent back with the purchase information. It helps to identify the user
     * @param handler          callback called asynchronously
     */
    public void startPurchase(Activity activity,
                              int requestCode,
                              String itemId,
                              PurchaseType purchaseType,
                              String developerPayload,
// Path: library/src/main/java/jp/alessandro/android/iab/handler/ErrorHandler.java
// public interface ErrorHandler {
// 
//     void onError(BillingException e);
// }
// 
// Path: library/src/main/java/jp/alessandro/android/iab/handler/StartActivityHandler.java
// public interface StartActivityHandler extends ErrorHandler {
// 
//     void onSuccess();
// }


// Path: library/src/main/java/jp/alessandro/android/iab/BillingProcessor.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.SparseArray;
import com.android.vending.billing.IInAppBillingService;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import jp.alessandro.android.iab.handler.ConsumeItemHandler;
import jp.alessandro.android.iab.handler.ErrorHandler;
import jp.alessandro.android.iab.handler.InventoryHandler;
import jp.alessandro.android.iab.handler.ItemDetailsHandler;
import jp.alessandro.android.iab.handler.PurchaseHandler;
import jp.alessandro.android.iab.handler.PurchasesHandler;
import jp.alessandro.android.iab.handler.StartActivityHandler;
import jp.alessandro.android.iab.logger.Logger;
import jp.alessandro.android.iab.response.PurchaseResponse;

     * Check if nAppIInAppBillingService is supported on the device.
     *
     * @param context
     * @return true if it is supported
     */
    public synchronized static boolean isServiceAvailable(Context context) {
        PackageManager packageManager = context.getPackageManager();
        Intent serviceIntent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
        serviceIntent.setPackage(Constants.VENDING_PACKAGE);
        List<ResolveInfo> list = packageManager.queryIntentServices(serviceIntent, 0);

        return list != null && !list.isEmpty();
    }

    /**
     * Purchase a subscription
     * This will be executed from UI Thread
     *
     * @param activity         activity calling this method
     * @param requestCode
     * @param itemId           new subscription item id
     * @param purchaseType     IN_APP or SUBSCRIPTION
     * @param developerPayload optional argument to be sent back with the purchase information. It helps to identify the user
     * @param handler          callback called asynchronously
     */
    public void startPurchase(Activity activity,
                              int requestCode,
                              String itemId,
                              PurchaseType purchaseType,
                              String developerPayload,
                              StartActivityHandler handler) {