Stick Squad 3 v1.2.5.9版本的 MD5 值为:375cf7f77a7075270cd68d1397368279

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


package com.fusepowered.u1;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import com.fusepowered.u1.cache.IUnityAdsCacheListener;
import com.fusepowered.u1.cache.UnityAdsCacheManager;
import com.fusepowered.u1.cache.UnityAdsDownloader;
import com.fusepowered.u1.campaign.UnityAdsCampaign;
import com.fusepowered.u1.campaign.UnityAdsCampaignHandler;
import com.fusepowered.u1.item.UnityAdsRewardItem;
import com.fusepowered.u1.item.UnityAdsRewardItemManager;
import com.fusepowered.u1.properties.UnityAdsConstants;
import com.fusepowered.u1.properties.UnityAdsProperties;
import com.fusepowered.u1.video.UnityAdsVideoPausedView;
import com.fusepowered.u1.view.IUnityAdsMainViewListener;
import com.fusepowered.u1.view.UnityAdsMainView;
import com.fusepowered.u1.webapp.IUnityAdsWebBridgeListener;
import com.fusepowered.u1.webapp.IUnityAdsWebDataListener;
import com.fusepowered.u1.webapp.UnityAdsWebData;
import com.fusepowered.u1.zone.UnityAdsIncentivizedZone;
import com.fusepowered.u1.zone.UnityAdsZone;
import com.fusepowered.u1.zone.UnityAdsZoneManager;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@TargetApi(9)
public class UnityAds implements IUnityAdsCacheListener, IUnityAdsMainViewListener, IUnityAdsWebBridgeListener, IUnityAdsWebDataListener {
    public static final String UNITY_ADS_OPTION_GAMERSID_KEY = "sid";
    public static final String UNITY_ADS_OPTION_MUTE_VIDEO_SOUNDS = "muteVideoSounds";
    public static final String UNITY_ADS_OPTION_NOOFFERSCREEN_KEY = "noOfferScreen";
    public static final String UNITY_ADS_OPTION_OPENANIMATED_KEY = "openAnimated";
    public static final String UNITY_ADS_OPTION_VIDEO_USES_DEVICE_ORIENTATION = "useDeviceOrientationForVideo";
    public static final String UNITY_ADS_REWARDITEM_NAME_KEY = "name";
    public static final String UNITY_ADS_REWARDITEM_PICTURE_KEY = "picture";
    public static UnityAdsCacheManager cachemanager = null;
    public static UnityAdsWebData webdata = null;
    public static UnityAdsMainView mainview = null;
    private static boolean a = false;
    private static boolean b = false;

    private static boolean f395c = false;
    private static boolean d = false;
    private static boolean e = false;
    private static boolean f = false;
    private static boolean g = false;
    private static boolean h = false;
    private static boolean i = false;
    private static boolean j = false;
    private static AlertDialog k = null;
    private static TimerTask l = null;
    private static Timer m = null;
    private static TimerTask n = null;
    private static Timer o = null;
    private static long p = 0;
    private static UnityAds q = null;
    private static IUnityAdsListener r = null;
    private static int s = -1;
    private static final String[] t = {"Unity Ads is ready to show ads", "Unity Ads not ready to show ads: not initialized", "Unity Ads not ready to show ads: webapp not initialized", "Unity Ads not ready to show ads: already showing ads", "Unity Ads not ready to show ads: no internet connection available", "Unity Ads not ready to show ads: no ads are available", "Unity Ads not ready to show ads: zero ads available", "Unity Ads not ready to show ads: video not cached"};

    public static boolean b() {
        a = true;
        return true;
    }

    public static boolean g() {
        f395c = true;
        return true;
    }

    public static boolean j() {
        f = true;
        return true;
    }

    public static boolean m() {
        j = true;
        return true;
    }

    public static boolean n() {
        b = false;
        return false;
    }

    public static void o() {
        ArrayList viewableVideoPlanCampaigns;
        boolean z = true;
        if (f) {
            f = false;
            UnityAdsDeviceLog.debug("Starting delayed ad plan refresh");
        } else if (p > 0 && SystemClock.elapsedRealtime() > p) {
            s();
            UnityAdsDeviceLog.debug("Refreshing ad plan from server due to timer deadline");
        } else if (UnityAdsProperties.CAMPAIGN_REFRESH_VIEWS_MAX > 0 && UnityAdsProperties.CAMPAIGN_REFRESH_VIEWS_COUNT >= UnityAdsProperties.CAMPAIGN_REFRESH_VIEWS_MAX) {
            UnityAdsDeviceLog.debug("Refreshing ad plan from server due to endscreen limit");
        } else if (webdata == null || webdata.getVideoPlanCampaigns() == null || webdata.getViewableVideoPlanCampaigns().size() != 0) {
            z = false;
        } else {
            UnityAdsDeviceLog.debug("All available videos watched, refreshing ad plan from server");
        }
        if (z) {
            new Thread(new g()).start();
            return;
        }
        if (webdata == null || (viewableVideoPlanCampaigns = webdata.getViewableVideoPlanCampaigns()) == null || viewableVideoPlanCampaigns.size() <= 0) {
            return;
        }
        UnityAdsCampaign unityAdsCampaign = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(0);
        if (cachemanager.isCampaignCached(unityAdsCampaign, false) || !unityAdsCampaign.allowCacheVideo().booleanValue()) {
            return;
        }
        cachemanager.cacheNextVideo(unityAdsCampaign);
    }

    public static void p() {
        l = new f();
        Timer timer = new Timer();
        m = timer;
        timer.scheduleAtFixedRate(l, 0L, 50L);
    }

    private UnityAds() {
    }

    public static boolean isSupported() {
        return Build.VERSION.SDK_INT >= 9;
    }

    public static void setDebugMode(boolean z) {
        if (z) {
            UnityAdsDeviceLog.setLogLevel(UnityAdsDeviceLog.LOGLEVEL_DEBUG);
        } else {
            UnityAdsDeviceLog.setLogLevel(UnityAdsDeviceLog.LOGLEVEL_INFO);
        }
    }

    public static void setTestMode(boolean z) {
        UnityAdsProperties.TESTMODE_ENABLED = Boolean.valueOf(z);
    }

    public static void setTestDeveloperId(String str) {
        UnityAdsProperties.TEST_DEVELOPER_ID = str;
    }

    public static void setTestOptionsId(String str) {
        UnityAdsProperties.TEST_OPTIONS_ID = str;
    }

    public static String getSDKVersion() {
        return UnityAdsConstants.UNITY_ADS_VERSION;
    }

    public static void setCampaignDataURL(String str) {
        UnityAdsProperties.CAMPAIGN_DATA_URL = str;
    }

    public static void enableUnityDeveloperInternalTestMode() {
        UnityAdsProperties.CAMPAIGN_DATA_URL = "https://impact.staging.applifier.com/mobile/campaigns";
        UnityAdsProperties.UNITY_DEVELOPER_INTERNAL_TEST = true;
    }

    public static void setListener(IUnityAdsListener iUnityAdsListener) {
        r = iUnityAdsListener;
    }

    public static void changeActivity(Activity activity) {
        String str;
        Boolean bool;
        if (activity == null) {
            UnityAdsDeviceLog.debug("changeActivity: null, ignoring");
            return;
        }
        UnityAdsDeviceLog.debug("changeActivity: " + activity.getClass().getName());
        if (activity != null && !activity.equals(UnityAdsProperties.getCurrentActivity())) {
            UnityAdsProperties.CURRENT_ACTIVITY = new WeakReference(activity);
            if (activity != null && (activity instanceof U1InterstitialActivity)) {
                if (!e) {
                    str = null;
                } else {
                    UnityAdsDeviceLog.debug("This open request is from the developer, setting start view");
                    str = "start";
                }
                if (str != null) {
                    JSONObject jSONObject = new JSONObject();
                    try {
                        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
                        jSONObject.put("action", UnityAdsConstants.UNITY_ADS_WEBVIEW_API_OPEN);
                        jSONObject.put("zone", currentZone.getZoneId());
                        if (currentZone.isIncentivized()) {
                            jSONObject.put(UnityAdsConstants.UNITY_ADS_WEBVIEW_API_REWARD_ITEM_KEY, ((UnityAdsIncentivizedZone) currentZone).itemManager().getCurrentItem().getKey());
                        }
                        bool = true;
                    } catch (Exception e2) {
                        bool = false;
                    }
                    UnityAdsDeviceLog.debug("DataOk: " + bool);
                    if (bool.booleanValue()) {
                        UnityAdsDeviceLog.debug("Opening with view:" + str + " and data:" + jSONObject.toString());
                        if (mainview != null) {
                            new Thread(new c(str, jSONObject)).start();
                        }
                    }
                }
                e = false;
                return;
            }
            UnityAdsProperties.BASE_ACTIVITY = new WeakReference(activity);
        }
    }

    public static boolean hide() {
        if (!b) {
            return false;
        }
        q();
        return true;
    }

    public static boolean setZone(String str) {
        if (b) {
            return false;
        }
        if (UnityAdsWebData.getZoneManager() == null) {
            throw new IllegalStateException("Unable to set zone before campaigns are available");
        }
        return UnityAdsWebData.getZoneManager().setCurrentZone(str);
    }

    public static boolean setZone(String str, String str2) {
        if (!b && setZone(str)) {
            UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
            if (currentZone.isIncentivized()) {
                return ((UnityAdsIncentivizedZone) currentZone).itemManager().setCurrentItem(str2);
            }
        }
        return false;
    }

    public static String getZone() {
        UnityAdsZone currentZone;
        UnityAdsZoneManager zoneManager = UnityAdsWebData.getZoneManager();
        if (zoneManager == null || (currentZone = zoneManager.getCurrentZone()) == null) {
            return null;
        }
        return currentZone.getZoneId();
    }

    public static boolean show(Map map) {
        if (canShow()) {
            UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
            if (currentZone != null) {
                UnityAdsDownloader.stopAllDownloads();
                currentZone.mergeOptions(map);
                if (currentZone.noOfferScreen()) {
                    ArrayList viewableVideoPlanCampaigns = webdata.getViewableVideoPlanCampaigns();
                    if (viewableVideoPlanCampaigns.size() > 0) {
                        UnityAdsProperties.SELECTED_CAMPAIGN = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(0);
                    }
                }
                UnityAdsDeviceLog.info("Launching ad from \"" + currentZone.getZoneName() + "\", options: " + currentZone.getZoneOptions().toString());
                e = true;
                b = true;
                h = false;
                j = false;
                UnityAdsProperties.SELECTED_CAMPAIGN_CACHED = false;
                Intent intent = new Intent(UnityAdsProperties.getCurrentActivity(), (Class<?>) U1InterstitialActivity.class);
                intent.addFlags(UnityAdsWebData.getZoneManager().getCurrentZone().openAnimated() ? 268435456 : 268500992);
                try {
                    UnityAdsProperties.getBaseActivity().startActivity(intent);
                } catch (ActivityNotFoundException e2) {
                    UnityAdsDeviceLog.error("Could not find UnityAdsFullScreenActivity (failed Android manifest merging?): " + e2.getStackTrace());
                } catch (Exception e3) {
                    UnityAdsDeviceLog.error("Weird error: " + e3.getStackTrace());
                }
                return b;
            }
            UnityAdsDeviceLog.error("Unity Ads current zone is null");
        } else {
            UnityAdsDeviceLog.error("Unity Ads not ready to show ads");
        }
        return false;
    }

    public static boolean show() {
        return show(null);
    }

    public static boolean canShowAds() {
        return canShow();
    }

    public static boolean canShow() {
        ConnectivityManager connectivityManager;
        if (webdata == null) {
            a(1);
            return false;
        }
        if (!d) {
            a(2);
            return false;
        }
        if (b) {
            a(3);
            return false;
        }
        Activity currentActivity = UnityAdsProperties.getCurrentActivity();
        if (currentActivity != null && (connectivityManager = (ConnectivityManager) currentActivity.getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE)) != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (!(activeNetworkInfo != null && activeNetworkInfo.isConnected())) {
                a(4);
                return false;
            }
        }
        if (webdata.initInProgress()) {
            return false;
        }
        ArrayList viewableVideoPlanCampaigns = webdata.getViewableVideoPlanCampaigns();
        if (viewableVideoPlanCampaigns == null) {
            a(5);
            return false;
        }
        if (viewableVideoPlanCampaigns.size() == 0) {
            a(6);
            return false;
        }
        UnityAdsCampaign unityAdsCampaign = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(0);
        if (!unityAdsCampaign.allowStreamingVideo().booleanValue() && !cachemanager.isCampaignCached(unityAdsCampaign, true)) {
            a(7);
            return false;
        }
        a(0);
        return true;
    }

    private static void a(int i2) {
        if (i2 != s) {
            s = i2;
            UnityAdsDeviceLog.info(t[i2]);
        }
    }

    public static boolean hasMultipleRewardItems() {
        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
        if (currentZone == null || !currentZone.isIncentivized()) {
            return false;
        }
        return ((UnityAdsIncentivizedZone) currentZone).itemManager().itemCount() > 1;
    }

    public static ArrayList getRewardItemKeys() {
        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
        if (currentZone == null || !currentZone.isIncentivized()) {
            return null;
        }
        ArrayList allItems = ((UnityAdsIncentivizedZone) currentZone).itemManager().allItems();
        ArrayList arrayList = new ArrayList();
        Iterator it = allItems.iterator();
        while (it.hasNext()) {
            arrayList.add(((UnityAdsRewardItem) it.next()).getKey());
        }
        return arrayList;
    }

    public static String getDefaultRewardItemKey() {
        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
        if (currentZone == null || !currentZone.isIncentivized()) {
            return null;
        }
        return ((UnityAdsIncentivizedZone) currentZone).itemManager().getDefaultItem().getKey();
    }

    public static String getCurrentRewardItemKey() {
        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
        if (currentZone == null || !currentZone.isIncentivized()) {
            return null;
        }
        return ((UnityAdsIncentivizedZone) currentZone).itemManager().getCurrentItem().getKey();
    }

    public static boolean setRewardItemKey(String str) {
        UnityAdsZone currentZone;
        if (canShow() && (currentZone = UnityAdsWebData.getZoneManager().getCurrentZone()) != null && currentZone.isIncentivized()) {
            return ((UnityAdsIncentivizedZone) currentZone).itemManager().setCurrentItem(str);
        }
        return false;
    }

    public static void setDefaultRewardItemAsRewardItem() {
        UnityAdsZone currentZone;
        if (canShow() && (currentZone = UnityAdsWebData.getZoneManager().getCurrentZone()) != null && currentZone.isIncentivized()) {
            UnityAdsRewardItemManager itemManager = ((UnityAdsIncentivizedZone) currentZone).itemManager();
            itemManager.setCurrentItem(itemManager.getDefaultItem().getKey());
        }
    }

    public static Map getRewardItemDetailsWithKey(String str) {
        UnityAdsZone currentZone = UnityAdsWebData.getZoneManager().getCurrentZone();
        if (currentZone != null && currentZone.isIncentivized()) {
            UnityAdsRewardItem item = ((UnityAdsIncentivizedZone) currentZone).itemManager().getItem(str);
            if (item != null) {
                return item.getDetails();
            }
            UnityAdsDeviceLog.info("Could not fetch reward item: " + str);
        }
        return null;
    }

    @Override
    public void onMainViewAction(UnityAdsMainView.UnityAdsMainViewAction unityAdsMainViewAction) {
        switch (j.a[unityAdsMainViewAction.ordinal()]) {
            case 1:
                if (b) {
                    q();
                    return;
                }
                return;
            case 2:
                if (r != null) {
                    r.onVideoStarted();
                }
                ArrayList viewableVideoPlanCampaigns = webdata.getViewableVideoPlanCampaigns();
                if (UnityAdsProperties.SELECTED_CAMPAIGN != null && viewableVideoPlanCampaigns.size() > 1) {
                    UnityAdsCampaign unityAdsCampaign = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(1);
                    if (cachemanager.isCampaignCached(UnityAdsProperties.SELECTED_CAMPAIGN, true) && !cachemanager.isCampaignCached(unityAdsCampaign, true) && unityAdsCampaign.allowCacheVideo().booleanValue()) {
                        cachemanager.cacheNextVideo(unityAdsCampaign);
                    }
                }
                r();
                return;
            case 3:
                UnityAdsProperties.CAMPAIGN_REFRESH_VIEWS_COUNT++;
                if (r != null && UnityAdsProperties.SELECTED_CAMPAIGN != null && !UnityAdsProperties.SELECTED_CAMPAIGN.isViewed().booleanValue()) {
                    UnityAdsDeviceLog.info("Unity Ads video completed");
                    UnityAdsProperties.SELECTED_CAMPAIGN.setCampaignStatus(UnityAdsCampaign.UnityAdsCampaignStatus.VIEWED);
                    r.onVideoCompleted(getCurrentRewardItemKey(), false);
                    return;
                }
                return;
            case 4:
                UnityAdsProperties.CAMPAIGN_REFRESH_VIEWS_COUNT++;
                if (r != null && UnityAdsProperties.SELECTED_CAMPAIGN != null && !UnityAdsProperties.SELECTED_CAMPAIGN.isViewed().booleanValue()) {
                    UnityAdsDeviceLog.info("Unity Ads video skipped");
                    UnityAdsProperties.SELECTED_CAMPAIGN.setCampaignStatus(UnityAdsCampaign.UnityAdsCampaignStatus.VIEWED);
                    r.onVideoCompleted(getCurrentRewardItemKey(), true);
                    return;
                }
                return;
            case 5:
                UnityAdsDeviceLog.debug("Retrying video play, because something went wrong.");
                h = false;
                a(300L);
                return;
            default:
                return;
        }
    }

    @Override
    public void onCampaignUpdateStarted() {
        UnityAdsDeviceLog.debug("Campaign updates started.");
    }

    @Override
    public void onCampaignReady(UnityAdsCampaignHandler unityAdsCampaignHandler) {
        if (unityAdsCampaignHandler != null && unityAdsCampaignHandler.getCampaign() != null) {
            UnityAdsDeviceLog.debug(unityAdsCampaignHandler.getCampaign().toString());
        }
    }

    @Override
    public void onAllCampaignsReady() {
        UnityAdsDeviceLog.entered();
    }

    @Override
    public void onWebDataCompleted() {
        boolean z;
        JSONObject jSONObject;
        boolean z2 = true;
        UnityAdsDeviceLog.entered();
        if (webdata.getData() == null || !webdata.getData().has("data")) {
            z = false;
        } else {
            try {
                jSONObject = webdata.getData().getJSONObject("data");
                z = false;
            } catch (Exception e2) {
                z = true;
                jSONObject = null;
            }
            if (!z) {
                s();
                if (UnityAdsProperties.CAMPAIGN_REFRESH_SECONDS > 0) {
                    n = new h();
                    p = SystemClock.elapsedRealtime() + (UnityAdsProperties.CAMPAIGN_REFRESH_SECONDS * 1000);
                    Timer timer = new Timer();
                    o = timer;
                    timer.schedule(n, UnityAdsProperties.CAMPAIGN_REFRESH_SECONDS * 1000);
                }
                if (jSONObject.has(UnityAdsConstants.UNITY_ADS_WEBVIEW_DATAPARAM_SDK_IS_CURRENT_KEY)) {
                    try {
                        z2 = jSONObject.getBoolean(UnityAdsConstants.UNITY_ADS_WEBVIEW_DATAPARAM_SDK_IS_CURRENT_KEY);
                    } catch (Exception e3) {
                        z = true;
                    }
                }
            }
        }
        if (!z && !z2 && UnityAdsProperties.getCurrentActivity() != null && UnityAdsUtils.isDebuggable(UnityAdsProperties.getCurrentActivity())) {
            AlertDialog create = new AlertDialog.Builder(UnityAdsProperties.getCurrentActivity()).create();
            k = create;
            create.setTitle("Unity Ads");
            k.setMessage("You are not running the latest version of Unity Ads android. Please update your version (this dialog won't appear in release builds).");
            k.setButton("OK", new a(this));
            k.show();
        }
        UnityAdsDeviceLog.entered();
        if (a) {
            cachemanager.updateCache(webdata.getVideoPlanCampaigns());
        }
        d = false;
        if (mainview != null) {
            UnityAdsDeviceLog.debug("Destroying views");
            mainview.webview.destroy();
            mainview = null;
        }
        if (UnityAdsProperties.getCurrentActivity() != null) {
            try {
                mainview = new UnityAdsMainView(UnityAdsProperties.getCurrentActivity(), q, q);
                return;
            } catch (OutOfMemoryError e4) {
                UnityAdsDeviceLog.error("Out of memory error when allocating Unity Ads views, halting Unity Ads init: " + e4.getMessage());
                e4.printStackTrace();
                q.onWebDataFailed();
                return;
            }
        }
        UnityAdsDeviceLog.error("Current activity is null when initializing mainview, halting Unity Ads init");
        q.onWebDataFailed();
    }

    @Override
    public void onWebDataFailed() {
        if (r != null && !f395c) {
            r.onFetchFailed();
            f395c = true;
        }
    }

    @Override
    public void onPlayVideo(JSONObject jSONObject) {
        UnityAdsDeviceLog.entered();
        if (jSONObject.has("campaignId")) {
            String str = null;
            try {
                str = jSONObject.getString("campaignId");
            } catch (Exception e2) {
                UnityAdsDeviceLog.error("Could not get campaignId");
            }
            if (str != null) {
                if (webdata != null && webdata.getCampaignById(str) != null) {
                    UnityAdsProperties.SELECTED_CAMPAIGN = webdata.getCampaignById(str);
                }
                if (UnityAdsProperties.SELECTED_CAMPAIGN != null && UnityAdsProperties.SELECTED_CAMPAIGN.getCampaignId() != null && UnityAdsProperties.SELECTED_CAMPAIGN.getCampaignId().equals(str)) {
                    Boolean bool = false;
                    try {
                        bool = Boolean.valueOf(jSONObject.getBoolean(UnityAdsConstants.UNITY_ADS_WEBVIEW_EVENTDATA_REWATCH_KEY));
                    } catch (Exception e3) {
                    }
                    UnityAdsDeviceLog.debug("Selected campaign=" + UnityAdsProperties.SELECTED_CAMPAIGN.getCampaignId() + " isViewed: " + UnityAdsProperties.SELECTED_CAMPAIGN.isViewed());
                    if (UnityAdsProperties.SELECTED_CAMPAIGN != null) {
                        if (bool.booleanValue() || !UnityAdsProperties.SELECTED_CAMPAIGN.isViewed().booleanValue()) {
                            if (bool.booleanValue()) {
                                h = false;
                            }
                            a(0L);
                        }
                    }
                }
            }
        }
    }

    @Override
    public void onPauseVideo(JSONObject jSONObject) {
    }

    @Override
    public void onCloseAdsView(JSONObject jSONObject) {
        hide();
    }

    @Override
    public void onWebAppLoadComplete(JSONObject jSONObject) {
        UnityAdsDeviceLog.entered();
    }

    @Override
    public void onWebAppInitComplete(JSONObject jSONObject) {
        UnityAdsDeviceLog.entered();
        d = true;
        Boolean bool = true;
        if ((webdata == null || webdata.getViewableVideoPlanCampaigns() == null || webdata.getViewableVideoPlanCampaigns().size() <= 0) ? false : true) {
            JSONObject jSONObject2 = new JSONObject();
            try {
                jSONObject2.put("action", UnityAdsConstants.UNITY_ADS_WEBVIEW_API_INITCOMPLETE);
            } catch (Exception e2) {
                bool = false;
            }
            if (bool.booleanValue()) {
                mainview.webview.setWebViewCurrentView("start", jSONObject2);
                if (f395c || r == null) {
                    return;
                }
                UnityAdsUtils.runOnUiThread(new e());
            }
        }
    }

    @Override
    public void onOrientationRequest(JSONObject jSONObject) {
        ((Activity) UnityAdsProperties.CURRENT_ACTIVITY.get()).setRequestedOrientation(jSONObject.optInt("orientation", -1));
    }

    @Override
    public void onOpenPlayStore(JSONObject jSONObject) {
        String string;
        String str = null;
        UnityAdsDeviceLog.entered();
        if (jSONObject != null) {
            UnityAdsDeviceLog.debug(jSONObject.toString());
            Boolean bool = false;
            if (jSONObject.has("iTunesId")) {
                try {
                    string = jSONObject.getString("iTunesId");
                } catch (Exception e2) {
                    UnityAdsDeviceLog.error("Could not fetch playStoreId");
                }
                if (jSONObject.has("clickUrl")) {
                    try {
                        str = jSONObject.getString("clickUrl");
                    } catch (Exception e3) {
                        UnityAdsDeviceLog.error("Could not fetch clickUrl");
                    }
                }
                if (jSONObject.has("bypassAppSheet")) {
                    try {
                        bool = Boolean.valueOf(jSONObject.getBoolean("bypassAppSheet"));
                    } catch (Exception e4) {
                        UnityAdsDeviceLog.error("Could not fetch bypassAppSheet");
                    }
                }
                if (string == null && !bool.booleanValue()) {
                    UnityAdsDeviceLog.debug("Opening playstore activity with storeId: " + string);
                    if (UnityAdsProperties.getCurrentActivity() != null) {
                        try {
                            UnityAdsProperties.getCurrentActivity().startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + string)));
                            return;
                        } catch (Exception e5) {
                            UnityAdsDeviceLog.error("Couldn't start PlayStore intent!");
                            return;
                        }
                    }
                    return;
                }
                if (str == null) {
                    UnityAdsDeviceLog.debug("Opening playStore in browser: " + str);
                    if (UnityAdsProperties.getCurrentActivity() != null) {
                        try {
                            UnityAdsProperties.getCurrentActivity().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
                            return;
                        } catch (Exception e6) {
                            UnityAdsDeviceLog.error("Couldn't start browser intent!");
                            return;
                        }
                    }
                    return;
                }
                return;
            }
            string = null;
            if (jSONObject.has("clickUrl")) {
            }
            if (jSONObject.has("bypassAppSheet")) {
            }
            if (string == null) {
            }
            if (str == null) {
            }
        }
    }

    @Override
    public void onLaunchIntent(JSONObject jSONObject) {
        try {
            Intent a2 = a(jSONObject);
            if (a2 == null) {
                UnityAdsDeviceLog.error("No suitable intent to launch");
                UnityAdsDeviceLog.debug("Intent JSON: " + jSONObject.toString());
            } else {
                Activity currentActivity = UnityAdsProperties.getCurrentActivity();
                if (currentActivity == null) {
                    UnityAdsDeviceLog.error("Unable to launch intent: current activity is null");
                } else {
                    currentActivity.startActivity(a2);
                }
            }
        } catch (Exception e2) {
            UnityAdsDeviceLog.error("Failed to launch intent: " + e2.getMessage());
        }
    }

    private static Intent a(JSONObject jSONObject) {
        try {
            if (jSONObject.has("packageName") && !jSONObject.has("className") && !jSONObject.has("action") && !jSONObject.has("mimeType")) {
                Activity currentActivity = UnityAdsProperties.getCurrentActivity();
                if (currentActivity == null) {
                    UnityAdsDeviceLog.error("Unable to parse data to generate intent: current activity is null");
                    return null;
                }
                Intent launchIntentForPackage = currentActivity.getPackageManager().getLaunchIntentForPackage(jSONObject.getString("packageName"));
                if (launchIntentForPackage != null && jSONObject.has("flags")) {
                    launchIntentForPackage.addFlags(jSONObject.getInt("flags"));
                    return launchIntentForPackage;
                }
                return launchIntentForPackage;
            }
            Intent intent = new Intent();
            if (jSONObject.has("className") && jSONObject.has("packageName")) {
                intent.setClassName(jSONObject.getString("packageName"), jSONObject.getString("className"));
            }
            if (jSONObject.has("action")) {
                intent.setAction(jSONObject.getString("action"));
            }
            if (jSONObject.has("uri")) {
                intent.setData(Uri.parse(jSONObject.getString("uri")));
            }
            if (jSONObject.has("mimeType")) {
                intent.setType(jSONObject.getString("mimeType"));
            }
            if (jSONObject.has("categories")) {
                JSONArray jSONArray = jSONObject.getJSONArray("categories");
                if (jSONArray.length() > 0) {
                    for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                        intent.addCategory(jSONArray.getString(i2));
                    }
                }
            }
            if (jSONObject.has("flags")) {
                intent.setFlags(jSONObject.getInt("flags"));
            }
            if (jSONObject.has("extras")) {
                JSONArray jSONArray2 = jSONObject.getJSONArray("extras");
                for (int i3 = 0; i3 < jSONArray2.length(); i3++) {
                    JSONObject jSONObject2 = jSONArray2.getJSONObject(i3);
                    String string = jSONObject2.getString("key");
                    Object obj = jSONObject2.get("value");
                    if (obj instanceof String) {
                        intent.putExtra(string, (String) obj);
                    } else if (obj instanceof Integer) {
                        intent.putExtra(string, ((Integer) obj).intValue());
                    } else if (obj instanceof Double) {
                        intent.putExtra(string, ((Double) obj).doubleValue());
                    } else if (obj instanceof Boolean) {
                        intent.putExtra(string, ((Boolean) obj).booleanValue());
                    } else {
                        UnityAdsDeviceLog.error("Unable to parse launch intent extra " + string);
                    }
                }
            }
            return intent;
        } catch (JSONException e2) {
            UnityAdsDeviceLog.error("Exception while parsing intent json: " + e2.getMessage());
            return null;
        }
    }

    public static void init(Activity activity, String str, IUnityAdsListener iUnityAdsListener) {
        if (q == null && !a) {
            if (str == null || str.length() == 0) {
                throw new IllegalArgumentException("gameId is empty");
            }
            try {
                if (Integer.parseInt(str) <= 0) {
                    throw new IllegalArgumentException("gameId is invalid");
                }
                if (UnityAdsProperties.UNITY_VERSION != null && UnityAdsProperties.UNITY_VERSION.length() > 0) {
                    UnityAdsDeviceLog.info("Initializing Unity Ads version 1407 (Unity + " + UnityAdsProperties.UNITY_VERSION + ") with gameId " + str);
                } else {
                    UnityAdsDeviceLog.info("Initializing Unity Ads version 1407 with gameId " + str);
                }
                try {
                    Class.forName("com.fusepowered.u1.webapp.UnityAdsWebBridge").getMethod("handleWebEvent", String.class, String.class);
                    UnityAdsDeviceLog.debug("UnityAds ProGuard check OK");
                } catch (ClassNotFoundException e2) {
                    UnityAdsDeviceLog.error("UnityAds ProGuard check fail: com.unity3d.ads.android.webapp.UnityAdsWebBridge class not found, check ProGuard settings");
                    return;
                } catch (NoSuchMethodException e3) {
                    UnityAdsDeviceLog.error("UnityAds ProGuard check fail: com.unity3d.ads.android.webapp.handleWebEvent method not found, check ProGuard settings");
                    return;
                } catch (Exception e4) {
                    UnityAdsDeviceLog.debug("UnityAds ProGuard check: Unknown exception: " + e4);
                }
                String packageName = activity.getPackageName();
                PackageManager packageManager = activity.getPackageManager();
                if (packageName != null && packageManager != null) {
                    try {
                        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 1);
                        for (int i2 = 0; i2 < packageInfo.activities.length; i2++) {
                            if (packageInfo.activities[i2].launchMode == 2) {
                                i = true;
                                UnityAdsDeviceLog.debug("Running in singleTask application mode");
                            }
                        }
                    } catch (Exception e5) {
                        UnityAdsDeviceLog.debug("Error while checking singleTask activities");
                    }
                }
                if (q == null) {
                    q = new UnityAds();
                }
                setListener(iUnityAdsListener);
                UnityAdsProperties.UNITY_ADS_GAME_ID = str;
                UnityAdsProperties.BASE_ACTIVITY = new WeakReference(activity);
                UnityAdsProperties.CURRENT_ACTIVITY = new WeakReference(activity);
                UnityAdsVideoPausedView.initScreenMetrics(activity);
                UnityAdsDeviceLog.debug("Is debuggable=" + UnityAdsUtils.isDebuggable(activity));
                UnityAdsCacheManager unityAdsCacheManager = new UnityAdsCacheManager(activity);
                cachemanager = unityAdsCacheManager;
                unityAdsCacheManager.setDownloadListener(q);
                UnityAdsWebData unityAdsWebData = new UnityAdsWebData();
                webdata = unityAdsWebData;
                unityAdsWebData.setWebDataListener(q);
                new Thread(new b(activity)).start();
            } catch (NumberFormatException e6) {
                throw new IllegalArgumentException("gameId does not parse as an integer");
            }
        }
    }

    public static void q() {
        r();
        if (UnityAdsProperties.getCurrentActivity() != null && (UnityAdsProperties.getCurrentActivity() instanceof U1InterstitialActivity)) {
            new Handler(Looper.getMainLooper()).postDelayed(new k((byte) 0), 1L);
        } else {
            UnityAdsDeviceLog.debug("Did not close");
        }
    }

    public static void a(long j2) {
        if (h) {
            UnityAdsDeviceLog.debug("Prevent double start of video playback");
            return;
        }
        h = true;
        UnityAdsDeviceLog.debug("Running threaded");
        UnityAdsUtils.runOnUiThread(new l((byte) 0), j2);
    }

    public static void checkMainview() {
        if (g) {
            g = false;
            if (mainview != null) {
                mainview.fixActivityAttachment();
            }
        }
    }

    public static void handleFullscreenDestroy() {
        if (i) {
            t();
        } else if (b) {
            g = true;
        }
    }

    public static void r() {
        if (l != null) {
            l.cancel();
        }
        if (m != null) {
            m.cancel();
            m.purge();
        }
        l = null;
        m = null;
    }

    private static void s() {
        p = 0L;
        if (o != null) {
            o.cancel();
        }
    }

    public static void t() {
        if (!j) {
            int i2 = 30;
            if (i) {
                i2 = 250;
            }
            new Handler(Looper.getMainLooper()).postDelayed(new i(), i2);
        }
    }
}