VegeFruits v7.1版本的 MD5 值为:2ff167dfba698c783e879938fe00b9ce

以下内容为反编译后的 IronSourceWebView.java 源代码,内容仅作参考


package com.ironsource.sdk.controller;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.MutableContextWrapper;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.ironsource.environment.ApplicationContext;
import com.ironsource.environment.ConnectivityService;
import com.ironsource.environment.DeviceStatus;
import com.ironsource.environment.LocationService;
import com.ironsource.environment.UrlHandler;
import com.ironsource.sdk.agent.IronSourceAdsPublisherAgent;
import com.ironsource.sdk.data.AdUnitsReady;
import com.ironsource.sdk.data.AdUnitsState;
import com.ironsource.sdk.data.DemandSource;
import com.ironsource.sdk.data.SSABCParameters;
import com.ironsource.sdk.data.SSAEnums;
import com.ironsource.sdk.data.SSAFile;
import com.ironsource.sdk.data.SSAObj;
import com.ironsource.sdk.listeners.DSRewardedVideoListener;
import com.ironsource.sdk.listeners.OnGenericFunctionListener;
import com.ironsource.sdk.listeners.OnInterstitialListener;
import com.ironsource.sdk.listeners.OnOfferWallListener;
import com.ironsource.sdk.listeners.OnWebViewChangeListener;
import com.ironsource.sdk.precache.DownloadManager;
import com.ironsource.sdk.utils.Constants;
import com.ironsource.sdk.utils.DeviceProperties;
import com.ironsource.sdk.utils.IronSourceAsyncHttpRequestTask;
import com.ironsource.sdk.utils.IronSourceSharedPrefHelper;
import com.ironsource.sdk.utils.IronSourceStorageUtils;
import com.ironsource.sdk.utils.Logger;
import com.ironsource.sdk.utils.SDKUtils;
import com.tapjoy.TJAdUnitConstants;
import com.vk.sdk.api.model.VKApiCommunityFull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class IronSourceWebView extends WebView implements DownloadManager.OnPreCacheCompletion, DownloadListener {
    private final String GENERIC_MESSAGE;
    private String PUB_TAG;
    private String TAG;
    private DownloadManager downloadManager;
    private Boolean isKitkatAndAbove;
    private boolean isRemoveCloseEventHandler;
    private String mCacheDirectory;
    private OnWebViewChangeListener mChangeListener;
    private CountDownTimer mCloseEventTimer;
    private BroadcastReceiver mConnectionReceiver;
    private String mControllerKeyPressed;
    private FrameLayout mControllerLayout;
    private SSAEnums.ControllerState mControllerState;
    Context mCurrentActivityContext;
    private View mCustomView;
    private WebChromeClient.CustomViewCallback mCustomViewCallback;
    private FrameLayout mCustomViewContainer;
    private boolean mGlobalControllerTimeFinish;
    private CountDownTimer mGlobalControllerTimer;
    private int mHiddenForceCloseHeight;
    private String mHiddenForceCloseLocation;
    private int mHiddenForceCloseWidth;
    private String mISAppKey;
    private Map<String, String> mISExtraParameters;
    private String mISUserId;
    private boolean mISmiss;
    private boolean mIsActivityThemeTranslucent;
    private boolean mIsImmersive;
    private Boolean mIsInterstitialAvailable;
    private CountDownTimer mLoadControllerTimer;
    private String mOWAppKey;
    private String mOWCreditsAppKey;
    private boolean mOWCreditsMiss;
    private String mOWCreditsUserId;
    private Map<String, String> mOWExtraParameters;
    private String mOWUserId;
    private boolean mOWmiss;
    private OnGenericFunctionListener mOnGenericFunctionListener;
    private OnInterstitialListener mOnInitInterstitialListener;
    private OnOfferWallListener mOnOfferWallListener;
    private DSRewardedVideoListener mOnRewardedVideoListener;
    private String mOrientationState;
    private String mRVAppKey;
    private String mRVUserId;
    private String mRequestParameters;
    private AdUnitsState mSavedState;
    private Object mSavedStateLocker;
    private State mState;
    Handler mUiHandler;
    private Uri mUri;
    private VideoEventsListener mVideoEventsListener;
    private ChromeClient mWebChromeClient;
    public static int mDebugMode = 0;
    public static String IS_STORE = "is_store";
    public static String IS_STORE_CLOSE = "is_store_close";
    public static String WEBVIEW_TYPE = "webview_type";
    public static String EXTERNAL_URL = "external_url";
    public static String SECONDARY_WEB_VIEW = "secondary_web_view";
    public static int DISPLAY_WEB_VIEW_INTENT = 0;
    public static int OPEN_URL_INTENT = 1;
    public static String APP_IDS = "appIds";
    public static String REQUEST_ID = "requestId";
    public static String IS_INSTALLED = "isInstalled";
    public static String RESULT = "result";
    private static String JSON_KEY_SUCCESS = "success";
    private static String JSON_KEY_FAIL = "fail";

    public enum State {
        Display,
        Gone
    }

    public IronSourceWebView(Context context) {
        super(context.getApplicationContext());
        this.TAG = IronSourceWebView.class.getSimpleName();
        this.PUB_TAG = "IronSource";
        this.GENERIC_MESSAGE = "We're sorry, some error occurred. we will investigate it";
        this.mIsInterstitialAvailable = null;
        this.mControllerKeyPressed = "interrupt";
        this.mHiddenForceCloseWidth = 50;
        this.mHiddenForceCloseHeight = 50;
        this.mHiddenForceCloseLocation = Constants.ForceClosePosition.TOP_RIGHT;
        this.mControllerState = SSAEnums.ControllerState.None;
        this.isKitkatAndAbove = null;
        this.mSavedStateLocker = new Object();
        this.mIsImmersive = false;
        this.mIsActivityThemeTranslucent = false;
        this.mConnectionReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context2, Intent intent) {
                if (IronSourceWebView.this.mControllerState == SSAEnums.ControllerState.Ready) {
                    String networkType = Constants.ParametersKeys.ORIENTATION_NONE;
                    if (ConnectivityService.isConnectedWifi(context2)) {
                        networkType = "wifi";
                    } else if (ConnectivityService.isConnectedMobile(context2)) {
                        networkType = ConnectivityService.NETWORK_TYPE_3G;
                    }
                    IronSourceWebView.this.deviceStatusChanged(networkType);
                }
            }
        };
        Logger.i(this.TAG, "C'tor");
        this.mCacheDirectory = initializeCacheDirectory(context.getApplicationContext());
        this.mCurrentActivityContext = context;
        initLayout(this.mCurrentActivityContext);
        this.mSavedState = new AdUnitsState();
        this.downloadManager = getDownloadManager();
        this.downloadManager.setOnPreCacheCompletion(this);
        this.mWebChromeClient = new ChromeClient();
        setWebViewClient(new ViewClient());
        setWebChromeClient(this.mWebChromeClient);
        setWebViewSettings();
        addJavascriptInterface(createJSInterface(context), Constants.JAVASCRIPT_INTERFACE_NAME);
        setDownloadListener(this);
        setOnTouchListener(new SupersonicWebViewTouchListener());
        this.mUiHandler = createMainThreadHandler();
    }

    JSInterface createJSInterface(Context context) {
        return new JSInterface(context);
    }

    Handler createMainThreadHandler() {
        return new Handler(Looper.getMainLooper());
    }

    DownloadManager getDownloadManager() {
        return DownloadManager.getInstance(this.mCacheDirectory);
    }

    String initializeCacheDirectory(Context context) {
        return IronSourceStorageUtils.initializeCacheDirectory(context.getApplicationContext());
    }

    private class SupersonicWebViewTouchListener implements View.OnTouchListener {
        private SupersonicWebViewTouchListener() {
        }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == 1) {
                float xTouch = event.getX();
                float yTouch = event.getY();
                Logger.i(IronSourceWebView.this.TAG, "X:" + ((int) xTouch) + " Y:" + ((int) yTouch));
                int width = DeviceStatus.getDeviceWidth();
                int height = DeviceStatus.getDeviceHeight();
                Logger.i(IronSourceWebView.this.TAG, "Width:" + width + " Height:" + height);
                int boundsTouchAreaX = SDKUtils.dpToPx(IronSourceWebView.this.mHiddenForceCloseWidth);
                int boundsTouchAreaY = SDKUtils.dpToPx(IronSourceWebView.this.mHiddenForceCloseHeight);
                int actualTouchX = 0;
                int actualTouchY = 0;
                if (Constants.ForceClosePosition.TOP_RIGHT.equalsIgnoreCase(IronSourceWebView.this.mHiddenForceCloseLocation)) {
                    actualTouchX = width - ((int) xTouch);
                    actualTouchY = (int) yTouch;
                } else if (Constants.ForceClosePosition.TOP_LEFT.equalsIgnoreCase(IronSourceWebView.this.mHiddenForceCloseLocation)) {
                    actualTouchX = (int) xTouch;
                    actualTouchY = (int) yTouch;
                } else if (Constants.ForceClosePosition.BOTTOM_RIGHT.equalsIgnoreCase(IronSourceWebView.this.mHiddenForceCloseLocation)) {
                    actualTouchX = width - ((int) xTouch);
                    actualTouchY = height - ((int) yTouch);
                } else if (Constants.ForceClosePosition.BOTTOM_LEFT.equalsIgnoreCase(IronSourceWebView.this.mHiddenForceCloseLocation)) {
                    actualTouchX = (int) xTouch;
                    actualTouchY = height - ((int) yTouch);
                }
                if (actualTouchX <= boundsTouchAreaX && actualTouchY <= boundsTouchAreaY) {
                    IronSourceWebView.this.isRemoveCloseEventHandler = false;
                    if (IronSourceWebView.this.mCloseEventTimer != null) {
                        IronSourceWebView.this.mCloseEventTimer.cancel();
                    }
                    IronSourceWebView.this.mCloseEventTimer = new CountDownTimer(2000L, 500L) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            Logger.i(IronSourceWebView.this.TAG, "Close Event Timer Tick " + millisUntilFinished);
                        }

                        @Override
                        public void onFinish() {
                            Logger.i(IronSourceWebView.this.TAG, "Close Event Timer Finish");
                            if (IronSourceWebView.this.isRemoveCloseEventHandler) {
                                IronSourceWebView.this.isRemoveCloseEventHandler = false;
                            } else {
                                IronSourceWebView.this.engageEnd("forceClose");
                            }
                        }
                    }.start();
                    return false;
                }
                return false;
            }
            return false;
        }
    }

    private void initLayout(Context context) {
        FrameLayout.LayoutParams coverScreenParams = new FrameLayout.LayoutParams(-1, -1);
        this.mControllerLayout = new FrameLayout(context);
        this.mCustomViewContainer = new FrameLayout(context);
        FrameLayout.LayoutParams fp = new FrameLayout.LayoutParams(-1, -1);
        this.mCustomViewContainer.setLayoutParams(fp);
        this.mCustomViewContainer.setVisibility(8);
        FrameLayout mContentView = new FrameLayout(context);
        FrameLayout.LayoutParams lpChild2 = new FrameLayout.LayoutParams(-1, -1);
        mContentView.setLayoutParams(lpChild2);
        mContentView.addView(this);
        this.mControllerLayout.addView(this.mCustomViewContainer, coverScreenParams);
        this.mControllerLayout.addView(mContentView);
    }

    private void setWebViewSettings() {
        WebSettings s = getSettings();
        s.setLoadWithOverviewMode(true);
        s.setUseWideViewPort(true);
        setVerticalScrollBarEnabled(false);
        setHorizontalScrollBarEnabled(false);
        s.setBuiltInZoomControls(false);
        s.setJavaScriptEnabled(true);
        s.setSupportMultipleWindows(true);
        s.setJavaScriptCanOpenWindowsAutomatically(true);
        s.setGeolocationEnabled(true);
        s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");
        s.setDomStorageEnabled(true);
        try {
            setDisplayZoomControls(s);
            setMediaPlaybackJellyBean(s);
        } catch (Throwable e) {
            Logger.e(this.TAG, "setWebSettings - " + e.toString());
            new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=setWebViewSettings");
        }
    }

    private void setDisplayZoomControls(WebSettings s) {
        if (Build.VERSION.SDK_INT > 11) {
            s.setDisplayZoomControls(false);
        }
    }

    @Override
    public WebBackForwardList saveState(Bundle outState) {
        return super.saveState(outState);
    }

    @SuppressLint({"NewApi"})
    private void setMediaPlaybackJellyBean(WebSettings s) {
        if (Build.VERSION.SDK_INT >= 17) {
            s.setMediaPlaybackRequiresUserGesture(false);
        }
    }

    @SuppressLint({"NewApi"})
    private void setWebDebuggingEnabled() {
        if (Build.VERSION.SDK_INT >= 19) {
            setWebContentsDebuggingEnabled(true);
        }
    }

    public void downloadController() {
        IronSourceStorageUtils.deleteFile(this.mCacheDirectory, "", Constants.MOBILE_CONTROLLER_HTML);
        String controllerUrl = SDKUtils.getControllerUrl();
        SSAFile indexHtml = new SSAFile(controllerUrl, "");
        this.mGlobalControllerTimer = new CountDownTimer(200000L, 1000L) {
            @Override
            public void onTick(long millisUntilFinished) {
                Logger.i(IronSourceWebView.this.TAG, "Global Controller Timer Tick " + millisUntilFinished);
            }

            @Override
            public void onFinish() {
                Logger.i(IronSourceWebView.this.TAG, "Global Controller Timer Finish");
                IronSourceWebView.this.mGlobalControllerTimeFinish = true;
            }
        }.start();
        if (!this.downloadManager.isMobileControllerThreadLive()) {
            Logger.i(this.TAG, "Download Mobile Controller: " + controllerUrl);
            this.downloadManager.downloadMobileControllerFile(indexHtml);
        } else {
            Logger.i(this.TAG, "Download Mobile Controller: already alive");
        }
    }

    public void setDebugMode(int debugMode) {
        mDebugMode = debugMode;
    }

    public int getDebugMode() {
        return mDebugMode;
    }

    public boolean shouldNotifyDeveloper(String product) {
        boolean shouldNotify = false;
        if (TextUtils.isEmpty(product)) {
            Logger.d(this.TAG, "Trying to trigger a listener - no product was found");
            return false;
        }
        if (product.equalsIgnoreCase(SSAEnums.ProductType.Interstitial.toString())) {
            shouldNotify = this.mOnInitInterstitialListener != null;
        } else if (product.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
            shouldNotify = this.mOnRewardedVideoListener != null;
        } else if (product.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString()) || product.equalsIgnoreCase(SSAEnums.ProductType.OfferWallCredits.toString())) {
            shouldNotify = this.mOnOfferWallListener != null;
        }
        if (!shouldNotify) {
            Logger.d(this.TAG, "Trying to trigger a listener - no listener was found for product " + product);
        }
        return shouldNotify;
    }

    public void setOrientationState(String orientation) {
        this.mOrientationState = orientation;
    }

    public String getOrientationState() {
        return this.mOrientationState;
    }

    private class ViewClient extends WebViewClient {
        private ViewClient() {
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Logger.i("onPageStarted", url);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            Logger.i("onPageFinished", url);
            if (url.contains("adUnit") || url.contains("index.html")) {
                IronSourceWebView.this.pageFinished();
            }
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Logger.i("onReceivedError", failingUrl + " " + description);
            super.onReceivedError(view, errorCode, description, failingUrl);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Logger.i("shouldOverrideUrlLoading", url);
            try {
                if (IronSourceWebView.this.handleSearchKeysURLs(url)) {
                    IronSourceWebView.this.interceptedUrlToStore();
                    return true;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            Logger.i("shouldInterceptRequest", url);
            boolean mraidCall = false;
            try {
                URL mUrl = new URL(url);
                String file = mUrl.getFile();
                if (file.contains("mraid.js")) {
                    mraidCall = true;
                }
            } catch (MalformedURLException e) {
            }
            if (mraidCall) {
                String filePath = "file://" + IronSourceWebView.this.mCacheDirectory + File.separator + "mraid.js";
                File mraidFile = new File(filePath);
                try {
                    new FileInputStream(mraidFile);
                    return new WebResourceResponse("text/javascript", "UTF-8", getClass().getResourceAsStream(filePath));
                } catch (FileNotFoundException e2) {
                }
            }
            return super.shouldInterceptRequest(view, url);
        }
    }

    private class ChromeClient extends WebChromeClient {
        private ChromeClient() {
        }

        @Override
        public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
            WebView childView = new WebView(view.getContext());
            childView.setWebChromeClient(this);
            childView.setWebViewClient(new FrameBustWebViewClient());
            WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
            transport.setWebView(childView);
            resultMsg.sendToTarget();
            Logger.i("onCreateWindow", "onCreateWindow");
            return true;
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Logger.i("MyApplication", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId());
            return true;
        }

        @Override
        public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
            Logger.i("Test", "onShowCustomView");
            IronSourceWebView.this.setVisibility(8);
            if (IronSourceWebView.this.mCustomView != null) {
                Logger.i("Test", "mCustomView != null");
                callback.onCustomViewHidden();
                return;
            }
            Logger.i("Test", "mCustomView == null");
            IronSourceWebView.this.mCustomViewContainer.addView(view);
            IronSourceWebView.this.mCustomView = view;
            IronSourceWebView.this.mCustomViewCallback = callback;
            IronSourceWebView.this.mCustomViewContainer.setVisibility(0);
        }

        @Override
        public View getVideoLoadingProgressView() {
            FrameLayout frameLayout = new FrameLayout(IronSourceWebView.this.getCurrentActivityContext());
            frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
            return frameLayout;
        }

        @Override
        public void onHideCustomView() {
            Logger.i("Test", "onHideCustomView");
            if (IronSourceWebView.this.mCustomView != null) {
                IronSourceWebView.this.mCustomView.setVisibility(8);
                IronSourceWebView.this.mCustomViewContainer.removeView(IronSourceWebView.this.mCustomView);
                IronSourceWebView.this.mCustomView = null;
                IronSourceWebView.this.mCustomViewContainer.setVisibility(8);
                IronSourceWebView.this.mCustomViewCallback.onCustomViewHidden();
                IronSourceWebView.this.setVisibility(0);
            }
        }
    }

    private class FrameBustWebViewClient extends WebViewClient {
        private FrameBustWebViewClient() {
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Context ctx = IronSourceWebView.this.getCurrentActivityContext();
            Intent intent = new Intent(ctx, (Class<?>) OpenUrlActivity.class);
            intent.putExtra(IronSourceWebView.EXTERNAL_URL, url);
            intent.putExtra(IronSourceWebView.SECONDARY_WEB_VIEW, false);
            ctx.startActivity(intent);
            return true;
        }
    }

    public class JSInterface {
        volatile int udiaResults = 0;

        public JSInterface(Context context) {
        }

        @JavascriptInterface
        public void initController(String value) {
            Logger.i(IronSourceWebView.this.TAG, "initController(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (ssaObj.containsKey(Constants.ParametersKeys.STAGE)) {
                String stage = ssaObj.getString(Constants.ParametersKeys.STAGE);
                if (Constants.ParametersKeys.READY.equalsIgnoreCase(stage)) {
                    IronSourceWebView.this.mControllerState = SSAEnums.ControllerState.Ready;
                    IronSourceWebView.this.mGlobalControllerTimer.cancel();
                    IronSourceWebView.this.mLoadControllerTimer.cancel();
                    Collection<DemandSource> demandSources = IronSourceAdsPublisherAgent.getInstance((Activity) IronSourceWebView.this.getCurrentActivityContext()).getDemandSources();
                    for (DemandSource demandSource : demandSources) {
                        if (demandSource.getDemandSourceInitState() == 1) {
                            IronSourceWebView.this.initRewardedVideo(IronSourceWebView.this.mRVAppKey, IronSourceWebView.this.mRVUserId, demandSource.getDemandSourceName(), IronSourceWebView.this.mOnRewardedVideoListener);
                        }
                    }
                    if (IronSourceWebView.this.mISmiss) {
                        IronSourceWebView.this.initInterstitial(IronSourceWebView.this.mISAppKey, IronSourceWebView.this.mISUserId, IronSourceWebView.this.mISExtraParameters, IronSourceWebView.this.mOnInitInterstitialListener);
                    }
                    if (IronSourceWebView.this.mOWmiss) {
                        IronSourceWebView.this.initOfferWall(IronSourceWebView.this.mOWAppKey, IronSourceWebView.this.mOWUserId, IronSourceWebView.this.mOWExtraParameters, IronSourceWebView.this.mOnOfferWallListener);
                    }
                    if (IronSourceWebView.this.mOWCreditsMiss) {
                        IronSourceWebView.this.getOfferWallCredits(IronSourceWebView.this.mOWCreditsAppKey, IronSourceWebView.this.mOWCreditsUserId, IronSourceWebView.this.mOnOfferWallListener);
                    }
                    IronSourceWebView.this.restoreState(IronSourceWebView.this.mSavedState);
                    return;
                }
                if (Constants.ParametersKeys.LOADED.equalsIgnoreCase(stage)) {
                    IronSourceWebView.this.mControllerState = SSAEnums.ControllerState.Loaded;
                    return;
                }
                if (!Constants.ParametersKeys.FAILED.equalsIgnoreCase(stage)) {
                    Logger.i(IronSourceWebView.this.TAG, "No STAGE mentioned! Should not get here!");
                    return;
                }
                IronSourceWebView.this.mControllerState = SSAEnums.ControllerState.Failed;
                Collection<DemandSource> demandSources2 = IronSourceAdsPublisherAgent.getInstance((Activity) IronSourceWebView.this.getCurrentActivityContext()).getDemandSources();
                for (DemandSource demandSource2 : demandSources2) {
                    if (demandSource2.getDemandSourceInitState() == 1) {
                        IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.RewardedVideo, demandSource2.getDemandSourceName());
                    }
                }
                if (IronSourceWebView.this.mISmiss) {
                    IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.Interstitial, null);
                }
                if (IronSourceWebView.this.mOWmiss) {
                    IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.OfferWall, null);
                }
                if (IronSourceWebView.this.mOWCreditsMiss) {
                    IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.OfferWallCredits, null);
                }
            }
        }

        @JavascriptInterface
        public void alert(String message) {
        }

        @JavascriptInterface
        public void getDeviceStatus(String value) {
            Logger.i(IronSourceWebView.this.TAG, "getDeviceStatus(" + value + ")");
            String successFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            String failFunToCall = IronSourceWebView.this.extractFailFunctionToCall(value);
            Object[] objArr = new Object[2];
            Object[] resultArr = IronSourceWebView.this.getDeviceParams(IronSourceWebView.this.getContext());
            String params = (String) resultArr[0];
            boolean failed = ((Boolean) resultArr[1]).booleanValue();
            String funToCall = null;
            if (failed) {
                if (!TextUtils.isEmpty(failFunToCall)) {
                    funToCall = failFunToCall;
                }
            } else if (!TextUtils.isEmpty(successFunToCall)) {
                funToCall = successFunToCall;
            }
            if (!TextUtils.isEmpty(funToCall)) {
                String script = IronSourceWebView.this.generateJSToInject(funToCall, params, Constants.JSMethods.ON_GET_DEVICE_STATUS_SUCCESS, Constants.JSMethods.ON_GET_DEVICE_STATUS_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void setMixedContentAlwaysAllow(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setMixedContentAlwaysAllow(" + value + ")");
            IronSourceWebView.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (Build.VERSION.SDK_INT >= 21) {
                        IronSourceWebView.this.getSettings().setMixedContentMode(0);
                    }
                }
            });
        }

        @JavascriptInterface
        public void getApplicationInfo(String value) {
            Logger.i(IronSourceWebView.this.TAG, "getApplicationInfo(" + value + ")");
            String successFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            String failFunToCall = IronSourceWebView.this.extractFailFunctionToCall(value);
            SSAObj ssaObj = new SSAObj(value);
            String product = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            String demandSourceName = ssaObj.getString("demandSourceName");
            String funToCall = null;
            Object[] objArr = new Object[2];
            Object[] resultArr = IronSourceWebView.this.getApplicationParams(product, demandSourceName);
            String params = (String) resultArr[0];
            boolean failed = ((Boolean) resultArr[1]).booleanValue();
            if (failed) {
                if (!TextUtils.isEmpty(failFunToCall)) {
                    funToCall = failFunToCall;
                }
            } else if (!TextUtils.isEmpty(successFunToCall)) {
                funToCall = successFunToCall;
            }
            if (!TextUtils.isEmpty(funToCall)) {
                String script = IronSourceWebView.this.generateJSToInject(funToCall, params, Constants.JSMethods.ON_GET_APPLICATION_INFO_SUCCESS, Constants.JSMethods.ON_GET_APPLICATION_INFO_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void checkInstalledApps(String value) {
            Logger.i(IronSourceWebView.this.TAG, "checkInstalledApps(" + value + ")");
            String successFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            String failFunToCall = IronSourceWebView.this.extractFailFunctionToCall(value);
            String funToCall = null;
            SSAObj ssaObj = new SSAObj(value);
            String appIdsString = ssaObj.getString(IronSourceWebView.APP_IDS);
            String requestIdString = ssaObj.getString(IronSourceWebView.REQUEST_ID);
            Object[] resultArr = IronSourceWebView.this.getAppsStatus(appIdsString, requestIdString);
            String params = (String) resultArr[0];
            boolean failed = ((Boolean) resultArr[1]).booleanValue();
            if (failed) {
                if (!TextUtils.isEmpty(failFunToCall)) {
                    funToCall = failFunToCall;
                }
            } else if (!TextUtils.isEmpty(successFunToCall)) {
                funToCall = successFunToCall;
            }
            if (!TextUtils.isEmpty(funToCall)) {
                String script = IronSourceWebView.this.generateJSToInject(funToCall, params, Constants.JSMethods.ON_CHECK_INSTALLED_APPS_SUCCESS, Constants.JSMethods.ON_CHECK_INSTALLED_APPS_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void saveFile(String value) {
            String folder;
            Logger.i(IronSourceWebView.this.TAG, "saveFile(" + value + ")");
            SSAFile ssaFile = new SSAFile(value);
            if (DeviceStatus.getAvailableMemorySizeInMegaBytes(IronSourceWebView.this.mCacheDirectory) <= 0) {
                IronSourceWebView.this.responseBack(value, false, DownloadManager.NO_DISK_SPACE, null);
                return;
            }
            if (!SDKUtils.isExternalStorageAvailable()) {
                IronSourceWebView.this.responseBack(value, false, DownloadManager.STORAGE_UNAVAILABLE, null);
                return;
            }
            if (IronSourceStorageUtils.isFileCached(IronSourceWebView.this.mCacheDirectory, ssaFile)) {
                IronSourceWebView.this.responseBack(value, false, DownloadManager.FILE_ALREADY_EXIST, null);
                return;
            }
            if (!ConnectivityService.isConnected(IronSourceWebView.this.getContext())) {
                IronSourceWebView.this.responseBack(value, false, DownloadManager.NO_NETWORK_CONNECTION, null);
                return;
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            String lastUpdateTimeObj = ssaFile.getLastUpdateTime();
            if (lastUpdateTimeObj != null) {
                String lastUpdateTimeStr = String.valueOf(lastUpdateTimeObj);
                if (!TextUtils.isEmpty(lastUpdateTimeStr)) {
                    String path = ssaFile.getPath();
                    if (path.contains("/")) {
                        String[] splitArr = ssaFile.getPath().split("/");
                        folder = splitArr[splitArr.length - 1];
                    } else {
                        folder = path;
                    }
                    IronSourceSharedPrefHelper.getSupersonicPrefHelper().setCampaignLastUpdate(folder, lastUpdateTimeStr);
                }
            }
            IronSourceWebView.this.downloadManager.downloadFile(ssaFile);
        }

        @JavascriptInterface
        public void adUnitsReady(String value) {
            Logger.i(IronSourceWebView.this.TAG, "adUnitsReady(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String demandSourceName = ssaObj.getString("demandSourceName");
            final AdUnitsReady adUnitsReady = new AdUnitsReady(value);
            if (!adUnitsReady.isNumOfAdUnitsExist()) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.NUM_OF_AD_UNITS_DO_NOT_EXIST, null);
                return;
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            final String product = adUnitsReady.getProductType();
            if (IronSourceWebView.this.shouldNotifyDeveloper(product)) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        boolean fireSuccess;
                        int adUnits = Integer.parseInt(adUnitsReady.getNumOfAdUnits());
                        if (adUnits > 0) {
                            fireSuccess = true;
                        } else {
                            fireSuccess = false;
                        }
                        if (product.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
                            if (fireSuccess) {
                                Log.d(IronSourceWebView.this.TAG, "onRVInitSuccess()");
                                IronSourceWebView.this.mOnRewardedVideoListener.onRVInitSuccess(adUnitsReady, demandSourceName);
                            } else {
                                IronSourceWebView.this.mOnRewardedVideoListener.onRVNoMoreOffers(demandSourceName);
                            }
                        }
                    }
                });
            }
        }

        @JavascriptInterface
        public void deleteFolder(String value) {
            Logger.i(IronSourceWebView.this.TAG, "deleteFolder(" + value + ")");
            SSAFile file = new SSAFile(value);
            if (!IronSourceStorageUtils.isPathExist(IronSourceWebView.this.mCacheDirectory, file.getPath())) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.FOLDER_NOT_EXIST_MSG, "1");
            } else {
                boolean result = IronSourceStorageUtils.deleteFolder(IronSourceWebView.this.mCacheDirectory, file.getPath());
                IronSourceWebView.this.responseBack(value, result, null, null);
            }
        }

        @JavascriptInterface
        public void deleteFile(String value) {
            Logger.i(IronSourceWebView.this.TAG, "deleteFile(" + value + ")");
            SSAFile file = new SSAFile(value);
            if (!IronSourceStorageUtils.isPathExist(IronSourceWebView.this.mCacheDirectory, file.getPath())) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.FILE_NOT_EXIST_MSG, "1");
            } else {
                boolean result = IronSourceStorageUtils.deleteFile(IronSourceWebView.this.mCacheDirectory, file.getPath(), file.getFile());
                IronSourceWebView.this.responseBack(value, result, null, null);
            }
        }

        @JavascriptInterface
        public void displayWebView(String value) {
            Intent intent;
            Logger.i(IronSourceWebView.this.TAG, "displayWebView(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            SSAObj ssaObj = new SSAObj(value);
            boolean display = ((Boolean) ssaObj.get("display")).booleanValue();
            String productType = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            boolean isStandaloneView = ssaObj.getBoolean(Constants.ParametersKeys.IS_STANDALONE_VIEW);
            String demandSourceName = ssaObj.getString("demandSourceName");
            boolean isRewardedVideo = false;
            if (display) {
                IronSourceWebView.this.mIsImmersive = ssaObj.getBoolean(Constants.ParametersKeys.IMMERSIVE);
                IronSourceWebView.this.mIsActivityThemeTranslucent = ssaObj.getBoolean(Constants.ParametersKeys.ACTIVITY_THEME_TRANSLUCENT);
                if (IronSourceWebView.this.getState() == State.Display) {
                    Logger.i(IronSourceWebView.this.TAG, "State: " + IronSourceWebView.this.mState);
                    return;
                }
                IronSourceWebView.this.setState(State.Display);
                Logger.i(IronSourceWebView.this.TAG, "State: " + IronSourceWebView.this.mState);
                Context context = IronSourceWebView.this.getCurrentActivityContext();
                String orientation = IronSourceWebView.this.getOrientationState();
                int rotation = DeviceStatus.getApplicationRotation(context);
                if (!isStandaloneView) {
                    if (IronSourceWebView.this.mIsActivityThemeTranslucent) {
                        intent = new Intent(context, (Class<?>) InterstitialActivity.class);
                    } else {
                        intent = new Intent(context, (Class<?>) ControllerActivity.class);
                    }
                    if (SSAEnums.ProductType.RewardedVideo.toString().equalsIgnoreCase(productType)) {
                        if (Constants.ParametersKeys.ORIENTATION_APPLICATION.equals(orientation)) {
                            orientation = SDKUtils.translateRequestedOrientation(DeviceStatus.getActivityRequestedOrientation(IronSourceWebView.this.getCurrentActivityContext()));
                        }
                        isRewardedVideo = true;
                        intent.putExtra(Constants.ParametersKeys.PRODUCT_TYPE, SSAEnums.ProductType.RewardedVideo.toString());
                        IronSourceWebView.this.mSavedState.adOpened(SSAEnums.ProductType.RewardedVideo.ordinal());
                        IronSourceWebView.this.mSavedState.setDisplayedDemandSourceName(demandSourceName);
                    } else if (SSAEnums.ProductType.OfferWall.toString().equalsIgnoreCase(productType)) {
                        intent.putExtra(Constants.ParametersKeys.PRODUCT_TYPE, SSAEnums.ProductType.OfferWall.toString());
                        IronSourceWebView.this.mSavedState.adOpened(SSAEnums.ProductType.OfferWall.ordinal());
                    }
                    if (isRewardedVideo && IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.RewardedVideo.toString())) {
                        IronSourceWebView.this.mOnRewardedVideoListener.onRVAdOpened(demandSourceName);
                    }
                    intent.setFlags(536870912);
                    intent.putExtra(Constants.ParametersKeys.IMMERSIVE, IronSourceWebView.this.mIsImmersive);
                    intent.putExtra(Constants.ParametersKeys.ORIENTATION_SET_FLAG, orientation);
                    intent.putExtra(Constants.ParametersKeys.ROTATION_SET_FLAG, rotation);
                    context.startActivity(intent);
                    return;
                }
                ControllerView controllerView = new ControllerView(context);
                controllerView.addView(IronSourceWebView.this.mControllerLayout);
                controllerView.showInterstitial(IronSourceWebView.this);
                return;
            }
            IronSourceWebView.this.setState(State.Gone);
            IronSourceWebView.this.closeWebView();
        }

        @JavascriptInterface
        public void getOrientation(String value) {
            String funToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            String params = SDKUtils.getOrientation(IronSourceWebView.this.getCurrentActivityContext()).toString();
            if (!TextUtils.isEmpty(funToCall)) {
                String script = IronSourceWebView.this.generateJSToInject(funToCall, params, Constants.JSMethods.ON_GET_ORIENTATION_SUCCESS, Constants.JSMethods.ON_GET_ORIENTATION_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void setOrientation(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setOrientation(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String orientation = ssaObj.getString("orientation");
            IronSourceWebView.this.setOrientationState(orientation);
            int rotation = DeviceStatus.getApplicationRotation(IronSourceWebView.this.getCurrentActivityContext());
            if (IronSourceWebView.this.mChangeListener != null) {
                IronSourceWebView.this.mChangeListener.onOrientationChanged(orientation, rotation);
            }
        }

        @JavascriptInterface
        public void getCachedFilesMap(String value) {
            Logger.i(IronSourceWebView.this.TAG, "getCachedFilesMap(" + value + ")");
            String funToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            if (!TextUtils.isEmpty(funToCall)) {
                SSAObj ssaObj = new SSAObj(value);
                if (!ssaObj.containsKey("path")) {
                    IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.PATH_KEY_DOES_NOT_EXIST, null);
                    return;
                }
                String mapPath = (String) ssaObj.get("path");
                if (!IronSourceStorageUtils.isPathExist(IronSourceWebView.this.mCacheDirectory, mapPath)) {
                    IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.PATH_FILE_DOES_NOT_EXIST_ON_DISK, null);
                    return;
                }
                String fileSystmeMap = IronSourceStorageUtils.getCachedFilesMap(IronSourceWebView.this.mCacheDirectory, mapPath);
                String script = IronSourceWebView.this.generateJSToInject(funToCall, fileSystmeMap, Constants.JSMethods.ON_GET_CACHED_FILES_MAP_SUCCESS, Constants.JSMethods.ON_GET_CACHED_FILES_MAP_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void adCredited(final String value) {
            final String appKey;
            final String userId;
            Log.d(IronSourceWebView.this.PUB_TAG, "adCredited(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String creditsStr = ssaObj.getString(Constants.ParametersKeys.CREDITS);
            final int credits = creditsStr != null ? Integer.parseInt(creditsStr) : 0;
            String totalCreditsStr = ssaObj.getString(Constants.ParametersKeys.TOTAL);
            final int totalCredits = totalCreditsStr != null ? Integer.parseInt(totalCreditsStr) : 0;
            final String demandSourceName = ssaObj.getString("demandSourceName");
            final String product = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            boolean isExternalPoll = ssaObj.getBoolean("externalPoll");
            boolean totalCreditsFlag = false;
            String latestCompeltionsTime = null;
            boolean md5Signature = false;
            if (isExternalPoll) {
                appKey = IronSourceWebView.this.mOWCreditsAppKey;
                userId = IronSourceWebView.this.mOWCreditsUserId;
            } else {
                appKey = IronSourceWebView.this.mOWAppKey;
                userId = IronSourceWebView.this.mOWUserId;
            }
            if (product.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString())) {
                if (ssaObj.isNull("signature") || ssaObj.isNull("timestamp") || ssaObj.isNull("totalCreditsFlag")) {
                    IronSourceWebView.this.responseBack(value, false, "One of the keys are missing: signature/timestamp/totalCreditsFlag", null);
                    return;
                }
                String controllerMD5 = ssaObj.getString("signature");
                StringBuilder sig = new StringBuilder().append(totalCreditsStr).append(appKey).append(userId);
                String localMD5 = SDKUtils.getMD5(sig.toString());
                if (!controllerMD5.equalsIgnoreCase(localMD5)) {
                    IronSourceWebView.this.responseBack(value, false, "Controller signature is not equal to SDK signature", null);
                } else {
                    md5Signature = true;
                }
                totalCreditsFlag = ssaObj.getBoolean("totalCreditsFlag");
                latestCompeltionsTime = ssaObj.getString("timestamp");
            }
            if (IronSourceWebView.this.shouldNotifyDeveloper(product)) {
                final boolean mTotalCreditsFlag = totalCreditsFlag;
                final String mlatestCompeltionsTime = latestCompeltionsTime;
                final boolean mMd5Signature = md5Signature;
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (product.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
                            IronSourceWebView.this.mOnRewardedVideoListener.onRVAdCredited(credits, demandSourceName);
                            return;
                        }
                        if (product.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString()) && mMd5Signature && IronSourceWebView.this.mOnOfferWallListener.onOWAdCredited(credits, totalCredits, mTotalCreditsFlag) && !TextUtils.isEmpty(mlatestCompeltionsTime)) {
                            boolean result = IronSourceSharedPrefHelper.getSupersonicPrefHelper().setLatestCompeltionsTime(mlatestCompeltionsTime, appKey, userId);
                            if (result) {
                                IronSourceWebView.this.responseBack(value, true, null, null);
                            } else {
                                IronSourceWebView.this.responseBack(value, false, "Time Stamp could not be stored", null);
                            }
                        }
                    }
                });
            }
        }

        @JavascriptInterface
        public void removeCloseEventHandler(String value) {
            Logger.i(IronSourceWebView.this.TAG, "removeCloseEventHandler(" + value + ")");
            if (IronSourceWebView.this.mCloseEventTimer != null) {
                IronSourceWebView.this.mCloseEventTimer.cancel();
            }
            IronSourceWebView.this.isRemoveCloseEventHandler = true;
        }

        @JavascriptInterface
        public void onGetDeviceStatusSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetDeviceStatusSuccess(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_DEVICE_STATUS_SUCCESS, value);
        }

        @JavascriptInterface
        public void onGetDeviceStatusFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetDeviceStatusFail(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_DEVICE_STATUS_FAIL, value);
        }

        @JavascriptInterface
        public void onInitRewardedVideoSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onInitRewardedVideoSuccess(" + value + ")");
            SSABCParameters ssaBCParameters = new SSABCParameters(value);
            IronSourceSharedPrefHelper.getSupersonicPrefHelper().setSSABCParameters(ssaBCParameters);
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_REWARDED_VIDEO_SUCCESS, value);
        }

        @JavascriptInterface
        public void onInitRewardedVideoFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onInitRewardedVideoFail(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            final String demandSourceName = ssaObj.getString("demandSourceName");
            DemandSource demandSource = IronSourceAdsPublisherAgent.getInstance((Activity) IronSourceWebView.this.getCurrentActivityContext()).getDemandSourceByName(demandSourceName);
            if (demandSource != null) {
                demandSource.setDemandSourceInitState(3);
            }
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.RewardedVideo.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        Log.d(IronSourceWebView.this.TAG, "onRVInitFail(message:" + message + ")");
                        IronSourceWebView.this.mOnRewardedVideoListener.onRVInitFail(toSend, demandSourceName);
                    }
                });
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_REWARDED_VIDEO_FAIL, value);
        }

        @JavascriptInterface
        public void onGetApplicationInfoSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetApplicationInfoSuccess(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_APPLICATION_INFO_SUCCESS, value);
        }

        @JavascriptInterface
        public void onGetApplicationInfoFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetApplicationInfoFail(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_APPLICATION_INFO_FAIL, value);
        }

        @JavascriptInterface
        public void onShowRewardedVideoSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowRewardedVideoSuccess(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_REWARDED_VIDEO_SUCCESS, value);
        }

        @JavascriptInterface
        public void onShowRewardedVideoFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowRewardedVideoFail(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            final String demandSourceName = ssaObj.getString("demandSourceName");
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.RewardedVideo.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        Log.d(IronSourceWebView.this.TAG, "onRVShowFail(message:" + message + ")");
                        IronSourceWebView.this.mOnRewardedVideoListener.onRVShowFail(toSend, demandSourceName);
                    }
                });
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_REWARDED_VIDEO_FAIL, value);
        }

        @JavascriptInterface
        public void onGetCachedFilesMapSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetCachedFilesMapSuccess(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_CACHED_FILES_MAP_SUCCESS, value);
        }

        @JavascriptInterface
        public void onGetCachedFilesMapFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetCachedFilesMapFail(" + value + ")");
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_CACHED_FILES_MAP_FAIL, value);
        }

        @JavascriptInterface
        public void onShowOfferWallSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowOfferWallSuccess(" + value + ")");
            IronSourceWebView.this.mSavedState.adOpened(SSAEnums.ProductType.OfferWall.ordinal());
            final String placementId = SDKUtils.getValueFromJsonObject(value, "placementId");
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnOfferWallListener.onOWShowSuccess(placementId);
                    }
                });
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_OFFER_WALL_SUCCESS, value);
        }

        @JavascriptInterface
        public void onShowOfferWallFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowOfferWallFail(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        IronSourceWebView.this.mOnOfferWallListener.onOWShowFail(toSend);
                    }
                });
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_OFFER_WALL_FAIL, value);
        }

        @JavascriptInterface
        public void onInitInterstitialSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onInitInterstitialSuccess()");
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_INTERSTITIAL_SUCCESS, "true");
            IronSourceWebView.this.mSavedState.setInterstitialInitSuccess(true);
            if (IronSourceWebView.this.mSavedState.reportInitInterstitial()) {
                IronSourceWebView.this.mSavedState.setReportInitInterstitial(false);
                if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                    IronSourceWebView.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(IronSourceWebView.this.TAG, "onInterstitialInitSuccess()");
                            IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialInitSuccess();
                        }
                    });
                }
            }
        }

        @JavascriptInterface
        public void onInitInterstitialFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onInitInterstitialFail(" + value + ")");
            IronSourceWebView.this.mSavedState.setInterstitialInitSuccess(false);
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            if (IronSourceWebView.this.mSavedState.reportInitInterstitial()) {
                IronSourceWebView.this.mSavedState.setReportInitInterstitial(false);
                if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                    IronSourceWebView.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            String toSend = message;
                            if (toSend == null) {
                                toSend = "We're sorry, some error occurred. we will investigate it";
                            }
                            Log.d(IronSourceWebView.this.TAG, "onInterstitialInitFail(message:" + toSend + ")");
                            IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialInitFailed(toSend);
                        }
                    });
                }
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_INTERSTITIAL_FAIL, value);
        }

        private void setInterstitialAvailability(boolean isAvailable) {
            IronSourceWebView.this.mIsInterstitialAvailable = Boolean.valueOf(isAvailable);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INTERSTITIAL_AVAILABILITY, String.valueOf(IronSourceWebView.this.mIsInterstitialAvailable));
            }
        }

        @JavascriptInterface
        public void adClicked(String value) {
            Logger.i(IronSourceWebView.this.TAG, "adClicked(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String productType = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            if (productType.equalsIgnoreCase(SSAEnums.ProductType.Interstitial.toString()) && IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialClick();
                    }
                });
            } else if (productType.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString()) && IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.RewardedVideo.toString())) {
                final String demandSourceName = ssaObj.getString("demandSourceName");
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnRewardedVideoListener.onRVAdClicked(demandSourceName);
                    }
                });
            }
        }

        @JavascriptInterface
        public void onShowInterstitialSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowInterstitialSuccess(" + value + ")");
            IronSourceWebView.this.mSavedState.adOpened(SSAEnums.ProductType.Interstitial.ordinal());
            IronSourceWebView.this.responseBack(value, true, null, null);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialOpen();
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialShowSuccess();
                    }
                });
                IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_INTERSTITIAL_SUCCESS, value);
            }
            setInterstitialAvailability(false);
        }

        @JavascriptInterface
        public void onInitOfferWallSuccess(String value) {
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_OFFERWALL_SUCCESS, "true");
            IronSourceWebView.this.mSavedState.setOfferwallInitSuccess(true);
            if (IronSourceWebView.this.mSavedState.reportInitOfferwall()) {
                IronSourceWebView.this.mSavedState.setOfferwallReportInit(false);
                if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                    IronSourceWebView.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(IronSourceWebView.this.TAG, "onOfferWallInitSuccess()");
                            IronSourceWebView.this.mOnOfferWallListener.onOfferwallInitSuccess();
                        }
                    });
                }
            }
        }

        @JavascriptInterface
        public void onInitOfferWallFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onInitOfferWallFail(" + value + ")");
            IronSourceWebView.this.mSavedState.setOfferwallInitSuccess(false);
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            if (IronSourceWebView.this.mSavedState.reportInitOfferwall()) {
                IronSourceWebView.this.mSavedState.setOfferwallReportInit(false);
                if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                    IronSourceWebView.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            String toSend = message;
                            if (toSend == null) {
                                toSend = "We're sorry, some error occurred. we will investigate it";
                            }
                            Log.d(IronSourceWebView.this.TAG, "onOfferWallInitFail(message:" + toSend + ")");
                            IronSourceWebView.this.mOnOfferWallListener.onOfferwallInitFail(toSend);
                        }
                    });
                }
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_INIT_OFFERWALL_FAIL, value);
        }

        @JavascriptInterface
        public void onLoadInterstitialSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onLoadInterstitialSuccess(" + value + ")");
            setInterstitialAvailability(true);
            IronSourceWebView.this.responseBack(value, true, null, null);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialLoadSuccess();
                    }
                });
            }
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_LOAD_INTERSTITIAL_SUCCESS, "true");
        }

        @JavascriptInterface
        public void onLoadInterstitialFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onLoadInterstitialFail(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            IronSourceWebView.this.responseBack(value, true, null, null);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialLoadFailed(toSend);
                    }
                });
            }
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_LOAD_INTERSTITIAL_FAIL, "true");
        }

        @JavascriptInterface
        public void onShowInterstitialFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onShowInterstitialFail(" + value + ")");
            setInterstitialAvailability(false);
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            IronSourceWebView.this.responseBack(value, true, null, null);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialShowFailed(toSend);
                    }
                });
            }
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_SHOW_INTERSTITIAL_FAIL, value);
        }

        @JavascriptInterface
        public void onGenericFunctionSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGenericFunctionSuccess(" + value + ")");
            if (IronSourceWebView.this.mOnGenericFunctionListener == null) {
                Logger.d(IronSourceWebView.this.TAG, "genericFunctionListener was not found");
            } else {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        IronSourceWebView.this.mOnGenericFunctionListener.onGFSuccess();
                    }
                });
                IronSourceWebView.this.responseBack(value, true, null, null);
            }
        }

        @JavascriptInterface
        public void onGenericFunctionFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGenericFunctionFail(" + value + ")");
            if (IronSourceWebView.this.mOnGenericFunctionListener == null) {
                Logger.d(IronSourceWebView.this.TAG, "genericFunctionListener was not found");
                return;
            }
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            IronSourceWebView.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    IronSourceWebView.this.mOnGenericFunctionListener.onGFFail(message);
                }
            });
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GENERIC_FUNCTION_FAIL, value);
        }

        @JavascriptInterface
        public void createCalendarEvent(String value) {
            Logger.i(IronSourceWebView.this.TAG, "createCalendarEvent(" + value + ")");
            try {
                JSONObject jsObj = new JSONObject();
                JSONObject jsRecurrence = new JSONObject();
                jsRecurrence.put("frequency", "weekly");
                jsObj.put("id", "testevent723GDf84");
                jsObj.put(VKApiCommunityFull.DESCRIPTION, "Watch this crazy showInterstitial on cannel 5!");
                jsObj.put("start", "2014-02-01T20:00:00-8:00");
                jsObj.put("end", "2014-06-30T20:00:00-8:00");
                jsObj.put("status", "pending");
                jsObj.put("recurrence", jsRecurrence.toString());
                jsObj.put(NotificationCompat.CATEGORY_REMINDER, "2014-02-01T19:50:00-8:00");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @JavascriptInterface
        public void openUrl(String value) {
            Logger.i(IronSourceWebView.this.TAG, "openUrl(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String url = ssaObj.getString("url");
            String method = ssaObj.getString("method");
            Context context = IronSourceWebView.this.getCurrentActivityContext();
            try {
                if (method.equalsIgnoreCase(Constants.ParametersKeys.EXTERNAL_BROWSER)) {
                    UrlHandler.openUrl(context, url);
                } else if (method.equalsIgnoreCase(Constants.ParametersKeys.WEB_VIEW)) {
                    Intent intent = new Intent(context, (Class<?>) OpenUrlActivity.class);
                    intent.putExtra(IronSourceWebView.EXTERNAL_URL, url);
                    intent.putExtra(IronSourceWebView.SECONDARY_WEB_VIEW, true);
                    intent.putExtra(Constants.ParametersKeys.IMMERSIVE, IronSourceWebView.this.mIsImmersive);
                    context.startActivity(intent);
                } else if (method.equalsIgnoreCase("store")) {
                    Intent intent2 = new Intent(context, (Class<?>) OpenUrlActivity.class);
                    intent2.putExtra(IronSourceWebView.EXTERNAL_URL, url);
                    intent2.putExtra(IronSourceWebView.IS_STORE, true);
                    intent2.putExtra(IronSourceWebView.SECONDARY_WEB_VIEW, true);
                    context.startActivity(intent2);
                }
            } catch (Exception ex) {
                IronSourceWebView.this.responseBack(value, false, ex.getMessage(), null);
                ex.printStackTrace();
            }
        }

        @JavascriptInterface
        public void setForceClose(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setForceClose(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String width = ssaObj.getString("width");
            String hight = ssaObj.getString("height");
            IronSourceWebView.this.mHiddenForceCloseWidth = Integer.parseInt(width);
            IronSourceWebView.this.mHiddenForceCloseHeight = Integer.parseInt(hight);
            IronSourceWebView.this.mHiddenForceCloseLocation = ssaObj.getString("position");
        }

        @JavascriptInterface
        public void setBackButtonState(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setBackButtonState(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String state = ssaObj.getString("state");
            IronSourceSharedPrefHelper.getSupersonicPrefHelper().setBackButtonState(state);
        }

        @JavascriptInterface
        public void setStoreSearchKeys(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setStoreSearchKeys(" + value + ")");
            IronSourceSharedPrefHelper.getSupersonicPrefHelper().setSearchKeys(value);
        }

        @JavascriptInterface
        public void setWebviewBackgroundColor(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setWebviewBackgroundColor(" + value + ")");
            IronSourceWebView.this.setWebviewBackground(value);
        }

        @JavascriptInterface
        public void toggleUDIA(String value) {
            Logger.i(IronSourceWebView.this.TAG, "toggleUDIA(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.TOGGLE)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.TOGGLE_KEY_DOES_NOT_EXIST, null);
                return;
            }
            String toggleStr = ssaObj.getString(Constants.ParametersKeys.TOGGLE);
            int toggle = Integer.parseInt(toggleStr);
            if (toggle != 0) {
                String binaryToggle = Integer.toBinaryString(toggle);
                if (TextUtils.isEmpty(binaryToggle)) {
                    IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.FIALED_TO_CONVERT_TOGGLE, null);
                    return;
                }
                char[] binaryToggleArr = binaryToggle.toCharArray();
                if (binaryToggleArr[3] == '0') {
                    IronSourceSharedPrefHelper.getSupersonicPrefHelper().setShouldRegisterSessions(true);
                } else {
                    IronSourceSharedPrefHelper.getSupersonicPrefHelper().setShouldRegisterSessions(false);
                }
            }
        }

        @JavascriptInterface
        public void getUDIA(String value) {
            this.udiaResults = 0;
            Logger.i(IronSourceWebView.this.TAG, "getUDIA(" + value + ")");
            String funToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.GET_BY_FLAG)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.GET_BY_FLAG_KEY_DOES_NOT_EXIST, null);
                return;
            }
            String getByFlagStr = ssaObj.getString(Constants.ParametersKeys.GET_BY_FLAG);
            int getByFlag = Integer.parseInt(getByFlagStr);
            if (getByFlag != 0) {
                String binaryToggle = Integer.toBinaryString(getByFlag);
                if (TextUtils.isEmpty(binaryToggle)) {
                    IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.FIALED_TO_CONVERT_GET_BY_FLAG, null);
                    return;
                }
                StringBuilder strBld = new StringBuilder(binaryToggle).reverse();
                char[] binaryToggleArr = strBld.toString().toCharArray();
                JSONArray jsArr = new JSONArray();
                if (binaryToggleArr[3] == '0') {
                    JSONObject jsObj = new JSONObject();
                    try {
                        jsObj.put("sessions", IronSourceSharedPrefHelper.getSupersonicPrefHelper().getSessions());
                        IronSourceSharedPrefHelper.getSupersonicPrefHelper().deleteSessions();
                        jsArr.put(jsObj);
                    } catch (JSONException e) {
                    }
                }
                if (binaryToggleArr[2] == '1') {
                    this.udiaResults++;
                    Location location = LocationService.getLastLocation(IronSourceWebView.this.getContext());
                    if (location != null) {
                        JSONObject jsObj2 = new JSONObject();
                        try {
                            jsObj2.put("latitude", location.getLatitude());
                            jsObj2.put("longitude", location.getLongitude());
                            jsArr.put(jsObj2);
                            this.udiaResults--;
                            sendResults(funToCall, jsArr);
                            Logger.i(IronSourceWebView.this.TAG, "done location");
                            return;
                        } catch (JSONException e2) {
                            return;
                        }
                    }
                    this.udiaResults--;
                }
            }
        }

        private void sendResults(String funToCall, JSONArray jsArr) {
            Logger.i(IronSourceWebView.this.TAG, "sendResults: " + this.udiaResults);
            if (this.udiaResults <= 0) {
                injectGetUDIA(funToCall, jsArr);
            }
        }

        @JavascriptInterface
        public void onUDIASuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onUDIASuccess(" + value + ")");
        }

        @JavascriptInterface
        public void onUDIAFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onUDIAFail(" + value + ")");
        }

        @JavascriptInterface
        public void onGetUDIASuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetUDIASuccess(" + value + ")");
        }

        @JavascriptInterface
        public void onGetUDIAFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetUDIAFail(" + value + ")");
        }

        @JavascriptInterface
        public void setUserUniqueId(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setUserUniqueId(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.USER_UNIQUE_ID) || !ssaObj.containsKey(Constants.ParametersKeys.PRODUCT_TYPE)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.UNIQUE_ID_OR_PRODUCT_TYPE_DOES_NOT_EXIST, null);
                return;
            }
            String uniqueId = ssaObj.getString(Constants.ParametersKeys.USER_UNIQUE_ID);
            String productType = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            boolean result = IronSourceSharedPrefHelper.getSupersonicPrefHelper().setUniqueId(uniqueId, productType);
            if (result) {
                IronSourceWebView.this.responseBack(value, true, null, null);
            } else {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.SET_USER_UNIQUE_ID_FAILED, null);
            }
        }

        @JavascriptInterface
        public void getUserUniqueId(String value) {
            Logger.i(IronSourceWebView.this.TAG, "getUserUniqueId(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.PRODUCT_TYPE)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.PRODUCT_TYPE_DOES_NOT_EXIST, null);
                return;
            }
            String funToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            if (!TextUtils.isEmpty(funToCall)) {
                String productType = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
                String id = IronSourceSharedPrefHelper.getSupersonicPrefHelper().getUniqueId(productType);
                String params = IronSourceWebView.this.parseToJson(Constants.ParametersKeys.USER_UNIQUE_ID, id, Constants.ParametersKeys.PRODUCT_TYPE, productType, null, null, null, null, null, false);
                String script = IronSourceWebView.this.generateJSToInject(funToCall, params, Constants.JSMethods.ON_GET_USER_UNIQUE_ID_SUCCESS, Constants.JSMethods.ON_GET_USER_UNIQUE_ID_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void getAppsInstallTime(String value) {
            String dataToSend;
            SSAObj ssaObj = new SSAObj(value);
            boolean failed = true;
            String funToCall = null;
            try {
                String includeSystemApps = ssaObj.getString(Constants.ParametersKeys.INCLUDE_SYSTEM_APPS);
                JSONObject appsInstallTime = DeviceStatus.getAppsInstallTime(IronSourceWebView.this.getContext(), Boolean.parseBoolean(includeSystemApps));
                dataToSend = appsInstallTime.toString();
                failed = false;
            } catch (Exception e) {
                Logger.i(IronSourceWebView.this.TAG, "getAppsInstallTime failed(" + e.getLocalizedMessage() + ")");
                dataToSend = e.getLocalizedMessage();
            }
            if (failed) {
                String failFunToCall = IronSourceWebView.this.extractFailFunctionToCall(value);
                if (!TextUtils.isEmpty(failFunToCall)) {
                    funToCall = failFunToCall;
                }
            } else {
                String successFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
                if (!TextUtils.isEmpty(successFunToCall)) {
                    funToCall = successFunToCall;
                }
            }
            if (!TextUtils.isEmpty(funToCall)) {
                try {
                    dataToSend = URLDecoder.decode(dataToSend, Charset.defaultCharset().name());
                } catch (UnsupportedEncodingException e2) {
                    e2.printStackTrace();
                }
                String script = IronSourceWebView.this.generateJSToInject(funToCall, dataToSend);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void onGetUserUniqueIdSuccess(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetUserUniqueIdSuccess(" + value + ")");
        }

        @JavascriptInterface
        public void onGetUserUniqueIdFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetUserUniqueIdFail(" + value + ")");
        }

        private void injectGetUDIA(String funToCall, JSONArray jsonArr) {
            if (!TextUtils.isEmpty(funToCall)) {
                String script = IronSourceWebView.this.generateJSToInject(funToCall, jsonArr.toString(), Constants.JSMethods.ON_GET_UDIA_SUCCESS, Constants.JSMethods.ON_GET_UDIA_FAIL);
                IronSourceWebView.this.injectJavascript(script);
            }
        }

        @JavascriptInterface
        public void onOfferWallGeneric(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onOfferWallGeneric(" + value + ")");
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                IronSourceWebView.this.mOnOfferWallListener.onOWGeneric("", "");
            }
        }

        @JavascriptInterface
        public void setUserData(String value) {
            Logger.i(IronSourceWebView.this.TAG, "setUserData(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.KEY)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.KEY_DOES_NOT_EXIST, null);
                return;
            }
            if (!ssaObj.containsKey(Constants.ParametersKeys.VALUE)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.VALUE_DOES_NOT_EXIST, null);
                return;
            }
            String mKey = ssaObj.getString(Constants.ParametersKeys.KEY);
            String mValue = ssaObj.getString(Constants.ParametersKeys.VALUE);
            boolean result = IronSourceSharedPrefHelper.getSupersonicPrefHelper().setUserData(mKey, mValue);
            if (result) {
                String successFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
                String params = IronSourceWebView.this.parseToJson(mKey, mValue, null, null, null, null, null, null, null, false);
                String script = IronSourceWebView.this.generateJSToInject(successFunToCall, params);
                IronSourceWebView.this.injectJavascript(script);
                return;
            }
            IronSourceWebView.this.responseBack(value, false, "SetUserData failed writing to shared preferences", null);
        }

        @JavascriptInterface
        public void getUserData(String value) {
            Logger.i(IronSourceWebView.this.TAG, "getUserData(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            if (!ssaObj.containsKey(Constants.ParametersKeys.KEY)) {
                IronSourceWebView.this.responseBack(value, false, Constants.ErrorCodes.KEY_DOES_NOT_EXIST, null);
                return;
            }
            String failFunToCall = IronSourceWebView.this.extractSuccessFunctionToCall(value);
            String mKey = ssaObj.getString(Constants.ParametersKeys.KEY);
            String mValue = IronSourceSharedPrefHelper.getSupersonicPrefHelper().getUserData(mKey);
            String params = IronSourceWebView.this.parseToJson(mKey, mValue, null, null, null, null, null, null, null, false);
            String script = IronSourceWebView.this.generateJSToInject(failFunToCall, params);
            IronSourceWebView.this.injectJavascript(script);
        }

        @JavascriptInterface
        public void onGetUserCreditsFail(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onGetUserCreditsFail(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
            if (IronSourceWebView.this.shouldNotifyDeveloper(SSAEnums.ProductType.OfferWall.toString())) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String toSend = message;
                        if (toSend == null) {
                            toSend = "We're sorry, some error occurred. we will investigate it";
                        }
                        IronSourceWebView.this.mOnOfferWallListener.onGetOWCreditsFailed(toSend);
                    }
                });
            }
            IronSourceWebView.this.responseBack(value, true, null, null);
            IronSourceWebView.this.toastingErrMsg(Constants.JSMethods.ON_GET_USER_CREDITS_FAILED, value);
        }

        @JavascriptInterface
        public void onAdWindowsClosed(String value) {
            Logger.i(IronSourceWebView.this.TAG, "onAdWindowsClosed(" + value + ")");
            IronSourceWebView.this.mSavedState.adClosed();
            IronSourceWebView.this.mSavedState.setDisplayedDemandSourceName(null);
            SSAObj ssaObj = new SSAObj(value);
            final String product = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            final String demandSourceName = ssaObj.getString("demandSourceName");
            if (product.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
                Log.d(IronSourceWebView.this.PUB_TAG, "onRVAdClosed()");
            } else if (product.equalsIgnoreCase(SSAEnums.ProductType.Interstitial.toString())) {
                Log.d(IronSourceWebView.this.PUB_TAG, "onISAdClosed()");
            } else if (product.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString())) {
                Log.d(IronSourceWebView.this.PUB_TAG, "onOWAdClosed()");
            }
            if (IronSourceWebView.this.shouldNotifyDeveloper(product) && product != null) {
                IronSourceWebView.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (product.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
                            IronSourceWebView.this.mOnRewardedVideoListener.onRVAdClosed(demandSourceName);
                        } else if (product.equalsIgnoreCase(SSAEnums.ProductType.Interstitial.toString())) {
                            IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialClose();
                        } else if (product.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString())) {
                            IronSourceWebView.this.mOnOfferWallListener.onOWAdClosed();
                        }
                    }
                });
            }
        }

        @JavascriptInterface
        public void onVideoStatusChanged(String value) {
            Log.d(IronSourceWebView.this.TAG, "onVideoStatusChanged(" + value + ")");
            SSAObj ssaObj = new SSAObj(value);
            String product = ssaObj.getString(Constants.ParametersKeys.PRODUCT_TYPE);
            if (IronSourceWebView.this.mVideoEventsListener != null && !TextUtils.isEmpty(product) && SSAEnums.ProductType.RewardedVideo.toString().equalsIgnoreCase(product)) {
                String status = ssaObj.getString("status");
                if (Constants.ParametersKeys.VIDEO_STATUS_STARTED.equalsIgnoreCase(status)) {
                    IronSourceWebView.this.mVideoEventsListener.onVideoStarted();
                    return;
                }
                if ("paused".equalsIgnoreCase(status)) {
                    IronSourceWebView.this.mVideoEventsListener.onVideoPaused();
                    return;
                }
                if ("playing".equalsIgnoreCase(status)) {
                    IronSourceWebView.this.mVideoEventsListener.onVideoResumed();
                    return;
                }
                if (Constants.ParametersKeys.VIDEO_STATUS_ENDED.equalsIgnoreCase(status)) {
                    IronSourceWebView.this.mVideoEventsListener.onVideoEnded();
                } else if ("stopped".equalsIgnoreCase(status)) {
                    IronSourceWebView.this.mVideoEventsListener.onVideoStopped();
                } else {
                    Logger.i(IronSourceWebView.this.TAG, "onVideoStatusChanged: unknown status: " + status);
                }
            }
        }
    }

    public static void setEXTERNAL_URL(String EXTERNAL_URL2) {
        EXTERNAL_URL = EXTERNAL_URL2;
    }

    public void setVideoEventsListener(VideoEventsListener listener) {
        this.mVideoEventsListener = listener;
    }

    public void removeVideoEventsListener() {
        this.mVideoEventsListener = null;
    }

    public void setWebviewBackground(String value) {
        SSAObj ssaObj = new SSAObj(value);
        String keyColor = ssaObj.getString(Constants.ParametersKeys.COLOR);
        int bgColor = 0;
        if (!"transparent".equalsIgnoreCase(keyColor)) {
            bgColor = Color.parseColor(keyColor);
        }
        setBackgroundColor(bgColor);
    }

    public void load(final int loadAttemp) {
        try {
            loadUrl("about:blank");
        } catch (Throwable e) {
            Logger.e(this.TAG, "WebViewController:: load: " + e.toString());
            new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=webviewLoadBlank");
        }
        String controllerPath = "file://" + this.mCacheDirectory + File.separator + Constants.MOBILE_CONTROLLER_HTML;
        File file = new File(this.mCacheDirectory + File.separator + Constants.MOBILE_CONTROLLER_HTML);
        if (file.exists()) {
            this.mRequestParameters = getRequestParameters();
            String controllerPathWithParams = controllerPath + "?" + this.mRequestParameters;
            this.mLoadControllerTimer = new CountDownTimer(50000L, 1000L) {
                @Override
                public void onTick(long millisUntilFinished) {
                    Logger.i(IronSourceWebView.this.TAG, "Loading Controller Timer Tick " + millisUntilFinished);
                }

                @Override
                public void onFinish() {
                    Logger.i(IronSourceWebView.this.TAG, "Loading Controller Timer Finish");
                    if (loadAttemp == 3) {
                        IronSourceWebView.this.mGlobalControllerTimer.cancel();
                        Collection<DemandSource> demandSources = IronSourceAdsPublisherAgent.getInstance((Activity) IronSourceWebView.this.getCurrentActivityContext()).getDemandSources();
                        for (DemandSource demandSource : demandSources) {
                            if (demandSource.getDemandSourceInitState() == 1) {
                                IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.RewardedVideo, demandSource.getDemandSourceName());
                            }
                        }
                        if (IronSourceWebView.this.mISmiss) {
                            IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.Interstitial, null);
                        }
                        if (IronSourceWebView.this.mOWmiss) {
                            IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.OfferWall, null);
                        }
                        if (IronSourceWebView.this.mOWCreditsMiss) {
                            IronSourceWebView.this.sendProductErrorMessage(SSAEnums.ProductType.OfferWallCredits, null);
                            return;
                        }
                        return;
                    }
                    IronSourceWebView.this.load(2);
                }
            }.start();
            try {
                loadUrl(controllerPathWithParams);
            } catch (Throwable e2) {
                Logger.e(this.TAG, "WebViewController:: load: " + e2.toString());
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=webviewLoadWithPath");
            }
            Logger.i(this.TAG, "load(): " + controllerPathWithParams);
            return;
        }
        Logger.i(this.TAG, "load(): Mobile Controller HTML Does not exist");
        new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=htmlControllerDoesNotExistOnFileSystem");
    }

    private void initProduct(String applicationKey, String userId, SSAEnums.ProductType type, String action, String demandSourceName) {
        if (TextUtils.isEmpty(userId) || TextUtils.isEmpty(applicationKey)) {
            triggerOnControllerInitProductFail("User id or Application key are missing", type, demandSourceName);
            return;
        }
        if (this.mControllerState == SSAEnums.ControllerState.Ready) {
            IronSourceSharedPrefHelper.getSupersonicPrefHelper().setApplicationKey(applicationKey, type);
            IronSourceSharedPrefHelper.getSupersonicPrefHelper().setUserID(userId, type);
            createInitProductJSMethod(type, demandSourceName);
            return;
        }
        setMissProduct(type, demandSourceName);
        if (this.mControllerState == SSAEnums.ControllerState.Failed) {
            triggerOnControllerInitProductFail(SDKUtils.createErrorMessage(action, Constants.ErrorCodes.InitiatingController), type, demandSourceName);
        } else if (this.mGlobalControllerTimeFinish) {
            downloadController();
        }
    }

    public void initRewardedVideo(String applicationKey, String userId, String demandSourceName, DSRewardedVideoListener listener) {
        this.mRVAppKey = applicationKey;
        this.mRVUserId = userId;
        this.mOnRewardedVideoListener = listener;
        this.mSavedState.setRVAppKey(applicationKey);
        this.mSavedState.setRVUserId(userId);
        initProduct(applicationKey, userId, SSAEnums.ProductType.RewardedVideo, Constants.ErrorCodes.InitRV, demandSourceName);
    }

    public void initInterstitial(String applicationKey, String userId, Map<String, String> extraParameters, OnInterstitialListener listener) {
        this.mISAppKey = applicationKey;
        this.mISUserId = userId;
        this.mISExtraParameters = extraParameters;
        this.mOnInitInterstitialListener = listener;
        this.mSavedState.setInterstitialAppKey(this.mISAppKey);
        this.mSavedState.setInterstitialUserId(this.mISUserId);
        this.mSavedState.setInterstitialExtraParams(this.mISExtraParameters);
        this.mSavedState.setReportInitInterstitial(true);
        initProduct(this.mISAppKey, this.mISUserId, SSAEnums.ProductType.Interstitial, Constants.ErrorCodes.InitIS, null);
    }

    public void loadInterstitial() {
        if (!isInterstitialAdAvailable()) {
            this.mSavedState.setReportLoadInterstitial(true);
            String script = generateJSToInject(Constants.JSMethods.LOAD_INTERSTITIAL, Constants.JSMethods.ON_LOAD_INTERSTITIAL_SUCCESS, Constants.JSMethods.ON_LOAD_INTERSTITIAL_FAIL);
            injectJavascript(script);
        } else if (shouldNotifyDeveloper(SSAEnums.ProductType.Interstitial.toString())) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialLoadSuccess();
                }
            });
        }
    }

    public boolean isInterstitialAdAvailable() {
        if (this.mIsInterstitialAvailable == null) {
            return false;
        }
        return this.mIsInterstitialAvailable.booleanValue();
    }

    public void showInterstitial() {
        String script = generateJSToInject(Constants.JSMethods.SHOW_INTERSTITIAL, Constants.JSMethods.ON_SHOW_INTERSTITIAL_SUCCESS, Constants.JSMethods.ON_SHOW_INTERSTITIAL_FAIL);
        injectJavascript(script);
    }

    public void forceShowInterstitial() {
        String script = generateJSToInject(Constants.JSMethods.FORCE_SHOW_INTERSTITIAL, Constants.JSMethods.ON_SHOW_INTERSTITIAL_SUCCESS, Constants.JSMethods.ON_SHOW_INTERSTITIAL_FAIL);
        injectJavascript(script);
    }

    public void initOfferWall(String applicationKey, String userId, Map<String, String> extraParameters, OnOfferWallListener listener) {
        this.mOWAppKey = applicationKey;
        this.mOWUserId = userId;
        this.mOWExtraParameters = extraParameters;
        this.mOnOfferWallListener = listener;
        this.mSavedState.setOfferWallExtraParams(this.mOWExtraParameters);
        this.mSavedState.setOfferwallReportInit(true);
        initProduct(this.mOWAppKey, this.mOWUserId, SSAEnums.ProductType.OfferWall, Constants.ErrorCodes.InitOW, null);
    }

    public void showOfferWall(Map<String, String> extraParameters) {
        this.mOWExtraParameters = extraParameters;
        String script = generateJSToInject(Constants.JSMethods.SHOW_OFFER_WALL, Constants.JSMethods.ON_SHOW_OFFER_WALL_SUCCESS, Constants.JSMethods.ON_SHOW_OFFER_WALL_FAIL);
        injectJavascript(script);
    }

    public void getOfferWallCredits(String applicationKey, String userId, OnOfferWallListener listener) {
        this.mOWCreditsAppKey = applicationKey;
        this.mOWCreditsUserId = userId;
        this.mOnOfferWallListener = listener;
        initProduct(this.mOWCreditsAppKey, this.mOWCreditsUserId, SSAEnums.ProductType.OfferWallCredits, Constants.ErrorCodes.ShowOWCredits, null);
    }

    private void createInitProductJSMethod(SSAEnums.ProductType type, String demandSourceName) {
        String script = null;
        if (type == SSAEnums.ProductType.RewardedVideo) {
            DemandSource demandSource = IronSourceAdsPublisherAgent.getInstance((Activity) getCurrentActivityContext()).getDemandSourceByName(demandSourceName);
            Map<String, String> rvParamsMap = new HashMap<>();
            rvParamsMap.put(Constants.RequestParameters.APPLICATION_KEY, this.mRVAppKey);
            rvParamsMap.put(Constants.RequestParameters.APPLICATION_USER_ID, this.mRVUserId);
            if (demandSource != null) {
                if (demandSource.getExtraParams() != null) {
                    rvParamsMap.putAll(demandSource.getExtraParams());
                }
                if (!TextUtils.isEmpty(demandSourceName)) {
                    rvParamsMap.put("demandSourceName", demandSourceName);
                }
            }
            String params = flatMapToJsonAsString(rvParamsMap);
            script = generateJSToInject(Constants.JSMethods.INIT_REWARDED_VIDEO, params, Constants.JSMethods.ON_INIT_REWARDED_VIDEO_SUCCESS, Constants.JSMethods.ON_INIT_REWARDED_VIDEO_FAIL);
        } else if (type == SSAEnums.ProductType.Interstitial) {
            Map<String, String> interstitialParamsMap = new HashMap<>();
            interstitialParamsMap.put(Constants.RequestParameters.APPLICATION_KEY, this.mISAppKey);
            interstitialParamsMap.put(Constants.RequestParameters.APPLICATION_USER_ID, this.mISUserId);
            if (this.mISExtraParameters != null) {
                interstitialParamsMap.putAll(this.mISExtraParameters);
            }
            String params2 = flatMapToJsonAsString(interstitialParamsMap);
            script = generateJSToInject(Constants.JSMethods.INIT_INTERSTITIAL, params2, Constants.JSMethods.ON_INIT_INTERSTITIAL_SUCCESS, Constants.JSMethods.ON_INIT_INTERSTITIAL_FAIL);
        } else if (type == SSAEnums.ProductType.OfferWall) {
            Map<String, String> offerwallParamsMap = new HashMap<>();
            offerwallParamsMap.put(Constants.RequestParameters.APPLICATION_KEY, this.mOWAppKey);
            offerwallParamsMap.put(Constants.RequestParameters.APPLICATION_USER_ID, this.mOWUserId);
            if (this.mOWExtraParameters != null) {
                offerwallParamsMap.putAll(this.mOWExtraParameters);
            }
            String params3 = flatMapToJsonAsString(offerwallParamsMap);
            script = generateJSToInject(Constants.JSMethods.INIT_OFFERWALL, params3, Constants.JSMethods.ON_INIT_OFFERWALL_SUCCESS, Constants.JSMethods.ON_INIT_OFFERWALL_FAIL);
        } else if (type == SSAEnums.ProductType.OfferWallCredits) {
            String params4 = parseToJson(Constants.ParametersKeys.PRODUCT_TYPE, Constants.ParametersKeys.OFFER_WALL, Constants.RequestParameters.APPLICATION_KEY, this.mOWCreditsAppKey, Constants.RequestParameters.APPLICATION_USER_ID, this.mOWCreditsUserId, null, null, null, false);
            script = generateJSToInject(Constants.JSMethods.GET_USER_CREDITS, params4, "null", Constants.JSMethods.ON_GET_USER_CREDITS_FAILED);
        }
        if (script != null) {
            injectJavascript(script);
        }
    }

    private String flatMapToJsonAsString(Map<String, String> params) {
        JSONObject jsObj = new JSONObject();
        if (params != null) {
            Iterator<Map.Entry<String, String>> it = params.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                try {
                    jsObj.putOpt(pairs.getKey(), SDKUtils.encodeString(pairs.getValue()));
                } catch (JSONException e) {
                    Logger.i(this.TAG, "flatMapToJsonAsStringfailed " + e.toString());
                }
                it.remove();
            }
        }
        return jsObj.toString();
    }

    void setMissProduct(SSAEnums.ProductType type, String demandSourceName) {
        if (type == SSAEnums.ProductType.RewardedVideo) {
            DemandSource demandSource = IronSourceAdsPublisherAgent.getInstance((Activity) getCurrentActivityContext()).getDemandSourceByName(demandSourceName);
            if (demandSource != null) {
                demandSource.setDemandSourceInitState(1);
            }
        } else if (type == SSAEnums.ProductType.Interstitial) {
            this.mISmiss = true;
        } else if (type == SSAEnums.ProductType.OfferWall) {
            this.mOWmiss = true;
        } else if (type == SSAEnums.ProductType.OfferWallCredits) {
            this.mOWCreditsMiss = true;
        }
        Logger.i(this.TAG, "setMissProduct(" + type + ")");
    }

    private void triggerOnControllerInitProductFail(final String message, final SSAEnums.ProductType type, final String demandSourceName) {
        if (shouldNotifyDeveloper(type.toString())) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (SSAEnums.ProductType.RewardedVideo == type) {
                        Log.d(IronSourceWebView.this.TAG, "onRVInitFail(message:" + message + ")");
                        IronSourceWebView.this.mOnRewardedVideoListener.onRVInitFail(message, demandSourceName);
                        return;
                    }
                    if (SSAEnums.ProductType.Interstitial == type) {
                        IronSourceWebView.this.mSavedState.setInterstitialInitSuccess(false);
                        if (IronSourceWebView.this.mSavedState.reportInitInterstitial()) {
                            Log.d(IronSourceWebView.this.TAG, "onInterstitialInitFail(message:" + message + ")");
                            IronSourceWebView.this.mOnInitInterstitialListener.onInterstitialInitFailed(message);
                            IronSourceWebView.this.mSavedState.setReportInitInterstitial(false);
                            return;
                        }
                        return;
                    }
                    if (SSAEnums.ProductType.OfferWall == type) {
                        IronSourceWebView.this.mOnOfferWallListener.onOfferwallInitFail(message);
                    } else if (SSAEnums.ProductType.OfferWallCredits == type) {
                        IronSourceWebView.this.mOnOfferWallListener.onGetOWCreditsFailed(message);
                    }
                }
            });
        }
    }

    public void showRewardedVideo(String demandSourceName) {
        Map<String, String> rvParamsMap = new HashMap<>();
        if (!TextUtils.isEmpty(demandSourceName)) {
            rvParamsMap.put("demandSourceName", demandSourceName);
        }
        String params = flatMapToJsonAsString(rvParamsMap);
        String script = generateJSToInject(Constants.JSMethods.SHOW_REWARDED_VIDEO, params, Constants.JSMethods.ON_SHOW_REWARDED_VIDEO_SUCCESS, Constants.JSMethods.ON_SHOW_REWARDED_VIDEO_FAIL);
        injectJavascript(script);
    }

    public void assetCached(String file, String path) {
        String params = parseToJson(Constants.ParametersKeys.FILE, file, "path", path, null, null, null, null, null, false);
        String script = generateJSToInject(Constants.JSMethods.ASSET_CACHED, params);
        injectJavascript(script);
    }

    public void assetCachedFailed(String file, String path, String errorMsg) {
        String params = parseToJson(Constants.ParametersKeys.FILE, file, "path", path, Constants.ParametersKeys.ERR_MSG, errorMsg, null, null, null, false);
        String script = generateJSToInject(Constants.JSMethods.ASSET_CACHED_FAILED, params);
        injectJavascript(script);
    }

    public void enterBackground() {
        if (this.mControllerState == SSAEnums.ControllerState.Ready) {
            String script = generateJSToInject(Constants.JSMethods.ENTER_BACKGROUND);
            injectJavascript(script);
        }
    }

    public void enterForeground() {
        if (this.mControllerState == SSAEnums.ControllerState.Ready) {
            String script = generateJSToInject(Constants.JSMethods.ENTER_FOREGROUND);
            injectJavascript(script);
        }
    }

    public void viewableChange(boolean visibility, String webview) {
        String params = parseToJson(Constants.ParametersKeys.WEB_VIEW, webview, null, null, null, null, null, null, Constants.ParametersKeys.IS_VIEWABLE, visibility);
        String script = generateJSToInject(Constants.JSMethods.VIEWABLE_CHANGE, params);
        injectJavascript(script);
    }

    public void nativeNavigationPressed(String action) {
        String params = parseToJson("action", action, null, null, null, null, null, null, null, false);
        String script = generateJSToInject(Constants.JSMethods.NATIVE_NAVIGATION_PRESSED, params);
        injectJavascript(script);
    }

    public void pageFinished() {
        String script = generateJSToInject(Constants.JSMethods.PAGE_FINISHED);
        injectJavascript(script);
    }

    public void interceptedUrlToStore() {
        String script = generateJSToInject(Constants.JSMethods.INTERCEPTED_URL_TO_STORE);
        injectJavascript(script);
    }

    public void injectJavascript(String script) {
        String catchClosure = "empty";
        if (getDebugMode() == SSAEnums.DebugMode.MODE_0.getValue()) {
            catchClosure = "console.log(\"JS exeption: \" + JSON.stringify(e));";
        } else if (getDebugMode() >= SSAEnums.DebugMode.MODE_1.getValue() && getDebugMode() <= SSAEnums.DebugMode.MODE_3.getValue()) {
            catchClosure = "console.log(\"JS exeption: \" + JSON.stringify(e));";
        }
        final StringBuilder scriptBuilder = new StringBuilder();
        scriptBuilder.append("try{").append(script).append("}catch(e){").append(catchClosure).append("}");
        final String url = "javascript:" + scriptBuilder.toString();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Logger.i(IronSourceWebView.this.TAG, url);
                try {
                    if (IronSourceWebView.this.isKitkatAndAbove != null) {
                        if (IronSourceWebView.this.isKitkatAndAbove.booleanValue()) {
                            IronSourceWebView.this.evaluateJavascriptKitKat(scriptBuilder.toString());
                        } else {
                            IronSourceWebView.this.loadUrl(url);
                        }
                    } else if (Build.VERSION.SDK_INT >= 19) {
                        try {
                            IronSourceWebView.this.evaluateJavascriptKitKat(scriptBuilder.toString());
                            IronSourceWebView.this.isKitkatAndAbove = true;
                        } catch (NoSuchMethodError e) {
                            Logger.e(IronSourceWebView.this.TAG, "evaluateJavascrip NoSuchMethodError: SDK version=" + Build.VERSION.SDK_INT + " " + e);
                            IronSourceWebView.this.loadUrl(url);
                            IronSourceWebView.this.isKitkatAndAbove = false;
                        } catch (Throwable e2) {
                            Logger.e(IronSourceWebView.this.TAG, "evaluateJavascrip Exception: SDK version=" + Build.VERSION.SDK_INT + " " + e2);
                            IronSourceWebView.this.loadUrl(url);
                            IronSourceWebView.this.isKitkatAndAbove = false;
                        }
                    } else {
                        IronSourceWebView.this.loadUrl(url);
                        IronSourceWebView.this.isKitkatAndAbove = false;
                    }
                } catch (Throwable t) {
                    Logger.e(IronSourceWebView.this.TAG, "injectJavascript: " + t.toString());
                    new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=injectJavaScript");
                }
            }
        });
    }

    @SuppressLint({"NewApi"})
    public void evaluateJavascriptKitKat(String script) {
        evaluateJavascript(script, null);
    }

    public Context getCurrentActivityContext() {
        MutableContextWrapper mctx = (MutableContextWrapper) this.mCurrentActivityContext;
        return mctx.getBaseContext();
    }

    private String getRequestParameters() {
        DeviceProperties properties = DeviceProperties.getInstance(getContext());
        StringBuilder builder = new StringBuilder();
        String sdkVer = DeviceProperties.getSupersonicSdkVersion();
        if (!TextUtils.isEmpty(sdkVer)) {
            builder.append(Constants.RequestParameters.SDK_VERSION).append(Constants.RequestParameters.EQUAL).append(sdkVer).append(Constants.RequestParameters.AMPERSAND);
        }
        String osType = properties.getDeviceOsType();
        if (!TextUtils.isEmpty(osType)) {
            builder.append(Constants.RequestParameters.DEVICE_OS).append(Constants.RequestParameters.EQUAL).append(osType);
        }
        String serverControllerUrl = SDKUtils.getControllerUrl();
        Uri downloadUri = Uri.parse(serverControllerUrl);
        if (downloadUri != null) {
            String scheme = downloadUri.getScheme() + ":";
            String host = downloadUri.getHost();
            int port = downloadUri.getPort();
            if (port != -1) {
                host = host + ":" + port;
            }
            builder.append(Constants.RequestParameters.AMPERSAND).append(Constants.RequestParameters.PROTOCOL).append(Constants.RequestParameters.EQUAL).append(scheme);
            builder.append(Constants.RequestParameters.AMPERSAND).append(Constants.RequestParameters.DOMAIN).append(Constants.RequestParameters.EQUAL).append(host);
            String config = SDKUtils.getControllerConfig();
            if (!TextUtils.isEmpty(config)) {
                builder.append(Constants.RequestParameters.AMPERSAND).append(Constants.RequestParameters.CONTROLLER_CONFIG).append(Constants.RequestParameters.EQUAL).append(config);
            }
            builder.append(Constants.RequestParameters.AMPERSAND).append("debug").append(Constants.RequestParameters.EQUAL).append(getDebugMode());
        }
        return builder.toString();
    }

    public void closeWebView() {
        if (this.mChangeListener != null) {
            this.mChangeListener.onCloseRequested();
        }
    }

    public void responseBack(String value, boolean result, String errorMessage, String errorCode) {
        SSAObj ssaObj = new SSAObj(value);
        String success = ssaObj.getString(JSON_KEY_SUCCESS);
        String fail = ssaObj.getString(JSON_KEY_FAIL);
        String funToCall = null;
        if (result) {
            if (!TextUtils.isEmpty(success)) {
                funToCall = success;
            }
        } else if (!TextUtils.isEmpty(fail)) {
            funToCall = fail;
        }
        if (!TextUtils.isEmpty(funToCall)) {
            if (!TextUtils.isEmpty(errorMessage)) {
                try {
                    JSONObject jsObj = new JSONObject(value);
                    value = jsObj.put(Constants.ParametersKeys.ERR_MSG, errorMessage).toString();
                } catch (JSONException e) {
                }
            }
            if (!TextUtils.isEmpty(errorCode)) {
                try {
                    JSONObject jsObj2 = new JSONObject(value);
                    value = jsObj2.put(Constants.ParametersKeys.ERR_CODE, errorCode).toString();
                } catch (JSONException e2) {
                }
            }
            String script = generateJSToInject(funToCall, value);
            injectJavascript(script);
        }
    }

    public String extractSuccessFunctionToCall(String jsonStr) {
        SSAObj ssaObj = new SSAObj(jsonStr);
        String funToCall = ssaObj.getString(JSON_KEY_SUCCESS);
        return funToCall;
    }

    public String extractFailFunctionToCall(String jsonStr) {
        SSAObj ssaObj = new SSAObj(jsonStr);
        String funToCall = ssaObj.getString(JSON_KEY_FAIL);
        return funToCall;
    }

    public String parseToJson(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4, String key5, boolean value5) {
        JSONObject jsObj = new JSONObject();
        try {
            if (!TextUtils.isEmpty(key1) && !TextUtils.isEmpty(value1)) {
                jsObj.put(key1, SDKUtils.encodeString(value1));
            }
            if (!TextUtils.isEmpty(key2) && !TextUtils.isEmpty(value2)) {
                jsObj.put(key2, SDKUtils.encodeString(value2));
            }
            if (!TextUtils.isEmpty(key3) && !TextUtils.isEmpty(value3)) {
                jsObj.put(key3, SDKUtils.encodeString(value3));
            }
            if (!TextUtils.isEmpty(key4) && !TextUtils.isEmpty(value4)) {
                jsObj.put(key4, SDKUtils.encodeString(value4));
            }
            if (!TextUtils.isEmpty(key5)) {
                jsObj.put(key5, value5);
            }
        } catch (JSONException e) {
            e.printStackTrace();
            new IronSourceAsyncHttpRequestTask().execute(Constants.NATIVE_EXCEPTION_BASE_URL + e.getStackTrace()[0].getMethodName());
        }
        return jsObj.toString();
    }

    private String mapToJson(Map<String, String> map) {
        JSONObject jsObj = new JSONObject();
        if (map != null && !map.isEmpty()) {
            for (String key : map.keySet()) {
                String value = map.get(key);
                try {
                    jsObj.put(key, SDKUtils.encodeString(value));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return jsObj.toString();
    }

    public Object[] getDeviceParams(Context context) {
        boolean fail = false;
        DeviceProperties deviceProperties = DeviceProperties.getInstance(context);
        JSONObject jsObj = new JSONObject();
        try {
            jsObj.put(Constants.RequestParameters.APP_ORIENTATION, SDKUtils.translateRequestedOrientation(DeviceStatus.getActivityRequestedOrientation(getCurrentActivityContext())));
            String deviceOem = deviceProperties.getDeviceOem();
            if (deviceOem != null) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_OEM), SDKUtils.encodeString(deviceOem));
            }
            String deviceModel = deviceProperties.getDeviceModel();
            if (deviceModel != null) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_MODEL), SDKUtils.encodeString(deviceModel));
            } else {
                fail = true;
            }
            SDKUtils.loadGoogleAdvertiserInfo(context);
            String advertiserId = SDKUtils.getAdvertiserId();
            Boolean isLAT = Boolean.valueOf(SDKUtils.isLimitAdTrackingEnabled());
            if (!TextUtils.isEmpty(advertiserId)) {
                Logger.i(this.TAG, "add AID and LAT");
                jsObj.put("isLimitAdTrackingEnabled", isLAT);
                StringBuilder aid = new StringBuilder().append(Constants.RequestParameters.DEVICE_IDS).append(Constants.RequestParameters.LEFT_BRACKETS).append(Constants.RequestParameters.AID).append(Constants.RequestParameters.RIGHT_BRACKETS);
                jsObj.put(aid.toString(), SDKUtils.encodeString(advertiserId));
            }
            String deviceOSType = deviceProperties.getDeviceOsType();
            if (deviceOSType != null) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_OS), SDKUtils.encodeString(deviceOSType));
            } else {
                fail = true;
            }
            String deviceOSVersion = Integer.toString(deviceProperties.getDeviceOsVersion());
            if (deviceOSVersion != null) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_OS_VERSION), deviceOSVersion);
            } else {
                fail = true;
            }
            String ssaSDKVersion = DeviceProperties.getSupersonicSdkVersion();
            if (ssaSDKVersion != null) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.SDK_VERSION), SDKUtils.encodeString(ssaSDKVersion));
            }
            if (deviceProperties.getDeviceCarrier() != null && deviceProperties.getDeviceCarrier().length() > 0) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.MOBILE_CARRIER), SDKUtils.encodeString(deviceProperties.getDeviceCarrier()));
            }
            String connectionType = ConnectivityService.getConnectionType(context);
            if (!TextUtils.isEmpty(connectionType)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.CONNECTION_TYPE), SDKUtils.encodeString(connectionType));
            } else {
                fail = true;
            }
            String deviceLanguage = context.getResources().getConfiguration().locale.getLanguage();
            if (!TextUtils.isEmpty(deviceLanguage)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_LANGUAGE), SDKUtils.encodeString(deviceLanguage.toUpperCase()));
            }
            if (SDKUtils.isExternalStorageAvailable()) {
                long freeDiskSize = DeviceStatus.getAvailableMemorySizeInMegaBytes(this.mCacheDirectory);
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DISK_FREE_SIZE), SDKUtils.encodeString(String.valueOf(freeDiskSize)));
            } else {
                fail = true;
            }
            int deviceWidth = DeviceStatus.getDeviceWidth();
            String width = String.valueOf(deviceWidth);
            if (!TextUtils.isEmpty(width)) {
                StringBuilder key = new StringBuilder();
                key.append(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_SCREEN_SIZE)).append(Constants.RequestParameters.LEFT_BRACKETS).append(SDKUtils.encodeString("width")).append(Constants.RequestParameters.RIGHT_BRACKETS);
                jsObj.put(key.toString(), SDKUtils.encodeString(width));
            } else {
                fail = true;
            }
            int deviceHeigh = DeviceStatus.getDeviceHeight();
            String height = String.valueOf(deviceHeigh);
            StringBuilder key2 = new StringBuilder();
            key2.append(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_SCREEN_SIZE)).append(Constants.RequestParameters.LEFT_BRACKETS).append(SDKUtils.encodeString("height")).append(Constants.RequestParameters.RIGHT_BRACKETS);
            jsObj.put(key2.toString(), SDKUtils.encodeString(height));
            String packageName = ApplicationContext.getPackageName(getContext());
            if (!TextUtils.isEmpty(packageName)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.PACKAGE_NAME), SDKUtils.encodeString(packageName));
            }
            float deviceScale = DeviceStatus.getDeviceDensity();
            String scaleStr = String.valueOf(deviceScale);
            if (!TextUtils.isEmpty(scaleStr)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_SCREEN_SCALE), SDKUtils.encodeString(scaleStr));
            }
            boolean isRoot = DeviceStatus.isRootedDevice();
            String rootStr = String.valueOf(isRoot);
            if (!TextUtils.isEmpty(rootStr)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.IS_ROOT_DEVICE), SDKUtils.encodeString(rootStr));
            }
            float deviceVolume = DeviceProperties.getInstance(context).getDeviceVolume(context);
            if (!TextUtils.isEmpty(rootStr)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.DEVICE_VOLUME), deviceVolume);
            }
            Context ctx = getCurrentActivityContext();
            if (Build.VERSION.SDK_INT >= 19 && (ctx instanceof Activity)) {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.IMMERSIVE), DeviceStatus.isImmersiveSupported((Activity) ctx));
            }
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.BATTERY_LEVEL), DeviceStatus.getBatteryLevel(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.NETWORK_MCC), ConnectivityService.getNetworkMCC(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.NETWORK_MNC), ConnectivityService.getNetworkMNC(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.PHONE_TYPE), ConnectivityService.getPhoneType(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.SIM_OPERATOR), SDKUtils.encodeString(ConnectivityService.getSimOperator(ctx)));
            jsObj.put(SDKUtils.encodeString("lastUpdateTime"), ApplicationContext.getLastUpdateTime(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.FIRST_INSTALL_TIME), ApplicationContext.getFirstInstallTime(ctx));
            jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.APPLICATION_VERSION_NAME), SDKUtils.encodeString(ApplicationContext.getApplicationVersionName(ctx)));
        } catch (JSONException e) {
            e.printStackTrace();
            new IronSourceAsyncHttpRequestTask().execute(Constants.NATIVE_EXCEPTION_BASE_URL + e.getStackTrace()[0].getMethodName());
        }
        Object[] result = {jsObj.toString(), Boolean.valueOf(fail)};
        return result;
    }

    public Object[] getApplicationParams(String productType, String demandSourceName) {
        boolean fail = false;
        JSONObject jsObj = new JSONObject();
        String appKey = "";
        String userId = "";
        Map<String, String> productExtraParams = null;
        if (!TextUtils.isEmpty(productType)) {
            if (productType.equalsIgnoreCase(SSAEnums.ProductType.RewardedVideo.toString())) {
                appKey = this.mRVAppKey;
                userId = this.mRVUserId;
                DemandSource demandSource = IronSourceAdsPublisherAgent.getInstance((Activity) getCurrentActivityContext()).getDemandSourceByName(demandSourceName);
                if (demandSource != null) {
                    productExtraParams = demandSource.getExtraParams();
                }
            } else if (productType.equalsIgnoreCase(SSAEnums.ProductType.Interstitial.toString())) {
                appKey = this.mISAppKey;
                userId = this.mISUserId;
                productExtraParams = this.mISExtraParameters;
            } else if (productType.equalsIgnoreCase(SSAEnums.ProductType.OfferWall.toString())) {
                appKey = this.mOWAppKey;
                userId = this.mOWUserId;
                productExtraParams = this.mOWExtraParameters;
            }
            try {
                jsObj.put(Constants.ParametersKeys.PRODUCT_TYPE, productType);
            } catch (JSONException e) {
                e.printStackTrace();
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=noProductType");
            }
        } else {
            fail = true;
        }
        if (!TextUtils.isEmpty(userId)) {
            try {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.APPLICATION_USER_ID), SDKUtils.encodeString(userId));
            } catch (JSONException e2) {
                e2.printStackTrace();
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=encodeAppUserId");
            }
        } else {
            fail = true;
        }
        if (!TextUtils.isEmpty(appKey)) {
            try {
                jsObj.put(SDKUtils.encodeString(Constants.RequestParameters.APPLICATION_KEY), SDKUtils.encodeString(appKey));
            } catch (JSONException e3) {
                e3.printStackTrace();
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=encodeAppKey");
            }
        } else {
            fail = true;
        }
        if (productExtraParams != null && !productExtraParams.isEmpty()) {
            for (Map.Entry<String, String> entry : productExtraParams.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("sdkWebViewCache")) {
                    setWebviewCache(entry.getValue());
                }
                try {
                    jsObj.put(SDKUtils.encodeString(entry.getKey()), SDKUtils.encodeString(entry.getValue()));
                } catch (JSONException e4) {
                    e4.printStackTrace();
                    new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=extraParametersToJson");
                }
            }
        }
        Object[] result = {jsObj.toString(), Boolean.valueOf(fail)};
        return result;
    }

    public Object[] getAppsStatus(String appIds, String requestId) {
        boolean fail = false;
        JSONObject jSONObject = new JSONObject();
        try {
            if (!TextUtils.isEmpty(appIds) && !appIds.equalsIgnoreCase("null")) {
                if (!TextUtils.isEmpty(requestId) && !requestId.equalsIgnoreCase("null")) {
                    Context ctx = getContext();
                    List<ApplicationInfo> packages = DeviceStatus.getInstalledApplications(ctx);
                    JSONArray appIdsArray = new JSONArray(appIds);
                    JSONObject bundleIds = new JSONObject();
                    for (int i = 0; i < appIdsArray.length(); i++) {
                        String appId = appIdsArray.getString(i).trim();
                        if (!TextUtils.isEmpty(appId)) {
                            JSONObject isInstalled = new JSONObject();
                            boolean found = false;
                            Iterator<ApplicationInfo> it = packages.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    break;
                                }
                                ApplicationInfo packageInfo = it.next();
                                if (appId.equalsIgnoreCase(packageInfo.packageName)) {
                                    isInstalled.put(IS_INSTALLED, true);
                                    bundleIds.put(appId, isInstalled);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                isInstalled.put(IS_INSTALLED, false);
                                bundleIds.put(appId, isInstalled);
                            }
                        }
                    }
                    jSONObject.put(RESULT, bundleIds);
                    jSONObject.put(REQUEST_ID, requestId);
                } else {
                    fail = true;
                    jSONObject.put(TJAdUnitConstants.String.VIDEO_ERROR, "requestId is null or empty");
                }
            } else {
                fail = true;
                jSONObject.put(TJAdUnitConstants.String.VIDEO_ERROR, "appIds is null or empty");
            }
        } catch (Exception e) {
            fail = true;
        }
        Object[] finalResult = {jSONObject.toString(), Boolean.valueOf(fail)};
        return finalResult;
    }

    @Override
    public void onFileDownloadSuccess(SSAFile file) {
        if (file.getFile().contains(Constants.MOBILE_CONTROLLER_HTML)) {
            load(1);
        } else {
            assetCached(file.getFile(), file.getPath());
        }
    }

    @Override
    public void onFileDownloadFail(SSAFile file) {
        if (file.getFile().contains(Constants.MOBILE_CONTROLLER_HTML)) {
            this.mGlobalControllerTimer.cancel();
            Collection<DemandSource> demandSources = IronSourceAdsPublisherAgent.getInstance((Activity) getCurrentActivityContext()).getDemandSources();
            for (DemandSource demandSource : demandSources) {
                if (demandSource.getDemandSourceInitState() == 1) {
                    sendProductErrorMessage(SSAEnums.ProductType.RewardedVideo, demandSource.getDemandSourceName());
                }
            }
            if (this.mISmiss) {
                sendProductErrorMessage(SSAEnums.ProductType.Interstitial, null);
            }
            if (this.mOWmiss) {
                sendProductErrorMessage(SSAEnums.ProductType.OfferWall, null);
            }
            if (this.mOWCreditsMiss) {
                sendProductErrorMessage(SSAEnums.ProductType.OfferWallCredits, null);
                return;
            }
            return;
        }
        assetCachedFailed(file.getFile(), file.getPath(), file.getErrMsg());
    }

    @Override
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        Logger.i(this.TAG, url + " " + mimetype);
    }

    public void toastingErrMsg(final String methodName, String value) {
        SSAObj ssaObj = new SSAObj(value);
        final String message = ssaObj.getString(Constants.ParametersKeys.ERR_MSG);
        if (!TextUtils.isEmpty(message)) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (IronSourceWebView.this.getDebugMode() == SSAEnums.DebugMode.MODE_3.getValue()) {
                        Toast.makeText(IronSourceWebView.this.getCurrentActivityContext(), methodName + " : " + message, 1).show();
                    }
                }
            });
        }
    }

    public void setControllerKeyPressed(String value) {
        this.mControllerKeyPressed = value;
    }

    public String getControllerKeyPressed() {
        String keyPressed = this.mControllerKeyPressed;
        setControllerKeyPressed("interrupt");
        return keyPressed;
    }

    public void runGenericFunction(String method, Map<String, String> keyValPairs, OnGenericFunctionListener listener) {
        this.mOnGenericFunctionListener = listener;
        if (Constants.JSMethods.INIT_REWARDED_VIDEO.equalsIgnoreCase(method)) {
            String demandSourceName = keyValPairs.get("demandSourceName");
            initRewardedVideo(keyValPairs.get(Constants.RequestParameters.APPLICATION_USER_ID), keyValPairs.get(Constants.RequestParameters.APPLICATION_KEY), demandSourceName, this.mOnRewardedVideoListener);
        } else if (Constants.JSMethods.SHOW_REWARDED_VIDEO.equalsIgnoreCase(method)) {
            showRewardedVideo(keyValPairs.get("demandSourceName"));
        } else {
            String script = generateJSToInject(method, mapToJson(keyValPairs), Constants.JSMethods.ON_GENERIC_FUNCTION_SUCCESS, Constants.JSMethods.ON_GENERIC_FUNCTION_FAIL);
            injectJavascript(script);
        }
    }

    public void deviceStatusChanged(String networkType) {
        String params = parseToJson(Constants.RequestParameters.CONNECTION_TYPE, networkType, null, null, null, null, null, null, null, false);
        String script = generateJSToInject(Constants.JSMethods.DEVICE_STATUS_CHANGED, params);
        injectJavascript(script);
    }

    public void engageEnd(String action) {
        if (action.equals("forceClose")) {
            closeWebView();
        }
        String params = parseToJson("action", action, null, null, null, null, null, null, null, false);
        String script = generateJSToInject(Constants.JSMethods.ENGAGE_END, params);
        injectJavascript(script);
    }

    public void registerConnectionReceiver(Context context) {
        context.registerReceiver(this.mConnectionReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }

    public void unregisterConnectionReceiver(Context context) {
        try {
            context.unregisterReceiver(this.mConnectionReceiver);
        } catch (IllegalArgumentException e) {
        } catch (Exception e1) {
            Log.e(this.TAG, "unregisterConnectionReceiver - " + e1);
            new IronSourceAsyncHttpRequestTask().execute(Constants.NATIVE_EXCEPTION_BASE_URL + e1.getStackTrace()[0].getMethodName());
        }
    }

    public void pause() {
        if (Build.VERSION.SDK_INT > 10) {
            try {
                onPause();
            } catch (Throwable e) {
                Logger.i(this.TAG, "WebViewController: pause() - " + e);
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=webviewPause");
            }
        }
    }

    public void resume() {
        if (Build.VERSION.SDK_INT > 10) {
            try {
                onResume();
            } catch (Throwable e) {
                Logger.i(this.TAG, "WebViewController: onResume() - " + e);
                new IronSourceAsyncHttpRequestTask().execute("https://www.supersonicads.com/mobile/sdk5/log?method=webviewResume");
            }
        }
    }

    public void setOnWebViewControllerChangeListener(OnWebViewChangeListener listener) {
        this.mChangeListener = listener;
    }

    public FrameLayout getLayout() {
        return this.mControllerLayout;
    }

    public boolean inCustomView() {
        return this.mCustomView != null;
    }

    public void hideCustomView() {
        this.mWebChromeClient.onHideCustomView();
    }

    private void setWebviewCache(String value) {
        if (value.equalsIgnoreCase("0")) {
            getSettings().setCacheMode(2);
        } else {
            getSettings().setCacheMode(-1);
        }
    }

    public boolean handleSearchKeysURLs(String url) throws Exception {
        List<String> searchKeys = IronSourceSharedPrefHelper.getSupersonicPrefHelper().getSearchKeys();
        if (searchKeys != null) {
            try {
                if (!searchKeys.isEmpty()) {
                    for (String key : searchKeys) {
                        if (url.contains(key)) {
                            UrlHandler.openUrl(getCurrentActivityContext(), url);
                            return true;
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return false;
    }

    public void setState(State state) {
        this.mState = state;
    }

    public State getState() {
        return this.mState;
    }

    public void sendProductErrorMessage(SSAEnums.ProductType type, String demnadSourceName) {
        String action = "";
        switch (type) {
            case RewardedVideo:
                action = Constants.ErrorCodes.InitRV;
                break;
            case Interstitial:
                action = Constants.ErrorCodes.InitIS;
                break;
            case OfferWall:
                action = Constants.ErrorCodes.InitOW;
                break;
            case OfferWallCredits:
                action = Constants.ErrorCodes.ShowOWCredits;
                break;
        }
        triggerOnControllerInitProductFail(SDKUtils.createErrorMessage(action, Constants.ErrorCodes.InitiatingController), type, demnadSourceName);
    }

    @Override
    public void destroy() {
        super.destroy();
        if (this.downloadManager != null) {
            this.downloadManager.release();
        }
        if (this.mConnectionReceiver != null) {
            this.mConnectionReceiver = null;
        }
        this.mUiHandler = null;
        this.mCurrentActivityContext = null;
    }

    private String generateJSToInject(String funToCall) {
        StringBuilder script = new StringBuilder();
        script.append("SSA_CORE.SDKController.runFunction('").append(funToCall).append("');");
        return script.toString();
    }

    public String generateJSToInject(String funToCall, String parameters) {
        StringBuilder script = new StringBuilder();
        script.append("SSA_CORE.SDKController.runFunction('").append(funToCall).append("?parameters=").append(parameters).append("');");
        return script.toString();
    }

    private String generateJSToInject(String funToCall, String successFunc, String failFunc) {
        StringBuilder script = new StringBuilder();
        script.append("SSA_CORE.SDKController.runFunction('").append(funToCall).append("','").append(successFunc).append("','").append(failFunc).append("');");
        return script.toString();
    }

    public String generateJSToInject(String funToCall, String parameters, String successFunc, String failFunc) {
        StringBuilder script = new StringBuilder();
        script.append("SSA_CORE.SDKController.runFunction('").append(funToCall).append("?parameters=").append(parameters).append("','").append(successFunc).append("','").append(failFunc).append("');");
        return script.toString();
    }

    public AdUnitsState getSavedState() {
        return this.mSavedState;
    }

    public void restoreState(AdUnitsState state) {
        synchronized (this.mSavedStateLocker) {
            if (state.shouldRestore() && this.mControllerState.equals(SSAEnums.ControllerState.Ready)) {
                Log.d(this.TAG, "restoreState(state:" + state + ")");
                int lastAd = state.getDisplayedProduct();
                if (lastAd != -1) {
                    if (lastAd == SSAEnums.ProductType.RewardedVideo.ordinal()) {
                        Log.d(this.TAG, "onRVAdClosed()");
                        String demandSourceName = state.getDisplayedDemandSourceName();
                        if (this.mOnRewardedVideoListener != null && !TextUtils.isEmpty(demandSourceName)) {
                            this.mOnRewardedVideoListener.onRVAdClosed(demandSourceName);
                        }
                    } else if (lastAd == SSAEnums.ProductType.Interstitial.ordinal()) {
                        Log.d(this.TAG, "onInterstitialAdClosed()");
                        if (this.mOnInitInterstitialListener != null) {
                            this.mOnInitInterstitialListener.onInterstitialClose();
                        }
                    } else if (lastAd == SSAEnums.ProductType.OfferWall.ordinal()) {
                        Log.d(this.TAG, "onOWAdClosed()");
                        if (this.mOnOfferWallListener != null) {
                            this.mOnOfferWallListener.onOWAdClosed();
                        }
                    }
                    state.adOpened(-1);
                    state.setDisplayedDemandSourceName(null);
                } else {
                    Log.d(this.TAG, "No ad was opened");
                }
                if (state.isInterstitialInitSuccess()) {
                    Log.d(this.TAG, "onInterstitialAvailability(false)");
                    if (this.mOnInitInterstitialListener != null) {
                    }
                    String appKey = state.getInterstitialAppKey();
                    String userId = state.getInterstitialUserId();
                    Map<String, String> extraParams = state.getInterstitialExtraParams();
                    Log.d(this.TAG, "initInterstitial(appKey:" + appKey + ", userId:" + userId + ", extraParam:" + extraParams + ")");
                    initInterstitial(appKey, userId, extraParams, this.mOnInitInterstitialListener);
                }
                String appKey2 = state.getRVAppKey();
                String userId2 = state.getRVUserId();
                Collection<DemandSource> demandSources = IronSourceAdsPublisherAgent.getInstance((Activity) getCurrentActivityContext()).getDemandSources();
                for (DemandSource demandSource : demandSources) {
                    if (demandSource.getDemandSourceInitState() == 2) {
                        String demandSourceName2 = demandSource.getDemandSourceName();
                        Log.d(this.TAG, "onRVNoMoreOffers()");
                        this.mOnRewardedVideoListener.onRVNoMoreOffers(demandSourceName2);
                        initRewardedVideo(appKey2, userId2, demandSourceName2, this.mOnRewardedVideoListener);
                    }
                }
                state.setShouldRestore(false);
            }
            this.mSavedState = state;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == 4) {
            if (!this.mChangeListener.onBackButtonPressed()) {
                return super.onKeyDown(keyCode, event);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    void runOnUiThread(Runnable task) {
        this.mUiHandler.post(task);
    }
}