/*******************************************************************************
 * Copyright 2013 One Platform Foundation
 *
 *       Licensed under the Apache License, Version 2.0 (the "License");
 *       you may not use this file except in compliance with the License.
 *       You may obtain a copy of the License at
 *
 *           http://www.apache.org/licenses/LICENSE-2.0
 *
 *       Unless required by applicable law or agreed to in writing, software
 *       distributed under the License is distributed on an "AS IS" BASIS,
 *       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *       See the License for the specific language governing permissions and
 *       limitations under the License.
 ******************************************************************************/

package org.onepf.life2.oms.appstore;

import android.content.Context;
import org.onepf.life2.oms.Appstore;
import org.onepf.life2.oms.AppstoreInAppBillingService;
import org.onepf.life2.oms.AppstoreName;
import org.onepf.life2.oms.AppstoreService;

/**
 * Author: Ruslan Sayfutdinov
 * Date: 16.04.13
 */
public class AmazonAppstore implements Appstore {
    private final Context mContext;
    private final AmazonAppstoreBillingService mBillingService;

    public AmazonAppstore(Context context) {
        mContext = context;
        mBillingService = new AmazonAppstoreBillingService(mContext);
    }

    @Override
    public boolean isAppAvailable(String packageName) {
        return false;
    }

    @Override
    public boolean isInstaller() {
        return mBillingService.getIsInstaller();
    }

    @Override
    public boolean isServiceSupported(AppstoreService appstoreService) {
        if (appstoreService == AppstoreService.APPSTORE_SERVICE_IN_APP_BILLING) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public AppstoreInAppBillingService getInAppBillingService() {
        return mBillingService;
    }

    @Override
    public AppstoreName getAppstoreName() {
        return AppstoreName.AMAZON;
    }
}

@@ -1162,24 +1162,138 @@
  Appstore %7B%0A
+    private static volatile boolean IS_SANDBOX_MODE;%0A    private static volatile boolean IS_SANDBOX_MODE_CHECKED;%0A
     private 
@@ -1328,22 +1328,16 @@
 private 
-final 
 AmazonAp
@@ -1452,78 +1452,8 @@
 xt;%0A
-        mBillingService = new AmazonAppstoreBillingService(mContext);%0A
     
@@ -1603,32 +1603,670 @@
 ler() %7B%0A        
+if (IS_SANDBOX_MODE_CHECKED) %7B%0A            return !IS_SANDBOX_MODE;%0A        %7D%0A        synchronized (AmazonAppstore.class) %7B%0A            if (IS_SANDBOX_MODE_CHECKED) %7B%0A                return !IS_SANDBOX_MODE;%0A            %7D%0A            try %7B%0A                ClassLoader localClassLoader = AmazonAppstore.class.getClassLoader();%0A                localClassLoader.loadClass(%22com.amazon.android.Kiwi%22);%0A                IS_SANDBOX_MODE = false;%0A            %7D catch (Throwable localThrowable) %7B%0A                IS_SANDBOX_MODE = true;%0A            %7D%0A            IS_SANDBOX_MODE_CHECKED = true;%0A        %7D%0A        return !IS_SANDBOX_MODE;%0A        //
 return mBillingS
@@ -2557,32 +2557,32 @@
 %0A%0A    @Override%0A
-
     public Appst
@@ -2627,24 +2627,147 @@
 Service() %7B%0A
+        if (mBillingService == null) %7B%0A            mBillingService = new AmazonAppstoreBillingService(mContext);%0A        %7D%0A
         retu

Optimize object creating in Amazon part. Add native check from Amazon IAP library.