Mad Aces v1.2.2.3版本的 MD5 值为:f29ebd7c5808053d9f3f3722a5db1688

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


package com.unity3d.ads.android;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Build;
import com.google.android.gms.drive.DriveFile;
import com.unity3d.ads.android.UnityAdsDeviceLog;
import com.unity3d.ads.android.cache.UnityAdsCache;
import com.unity3d.ads.android.campaign.UnityAdsCampaign;
import com.unity3d.ads.android.data.UnityAdsDevice;
import com.unity3d.ads.android.item.UnityAdsRewardItem;
import com.unity3d.ads.android.item.UnityAdsRewardItemManager;
import com.unity3d.ads.android.properties.UnityAdsConstants;
import com.unity3d.ads.android.properties.UnityAdsProperties;
import com.unity3d.ads.android.view.UnityAdsFullscreenActivity;
import com.unity3d.ads.android.webapp.IUnityAdsWebDataListener;
import com.unity3d.ads.android.webapp.UnityAdsWebData;
import com.unity3d.ads.android.zone.UnityAdsIncentivizedZone;
import com.unity3d.ads.android.zone.UnityAdsZone;
import com.unity3d.ads.android.zone.UnityAdsZoneManager;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONObject;

@TargetApi(9)
public class UnityAds implements 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";
    private static boolean a = false;
    private static IUnityAdsListener b = null;
    private static UnityAds c = null;

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

    private UnityAds() {
    }

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

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

    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) {
        b = iUnityAdsListener;
    }

    public static IUnityAdsListener getListener() {
        return b;
    }

    public static void changeActivity(Activity activity) {
        if (activity == null) {
            UnityAdsDeviceLog.debug("changeActivity: null, ignoring");
            return;
        }
        UnityAdsDeviceLog.debug("changeActivity: " + activity.getClass().getName());
        UnityAdsProperties.CURRENT_ACTIVITY = new WeakReference(activity);
        if (!(activity instanceof UnityAdsFullscreenActivity)) {
            UnityAdsProperties.BASE_ACTIVITY = new WeakReference(activity);
        }
    }

    public static boolean hide() {
        if (!(UnityAdsProperties.CURRENT_ACTIVITY.get() instanceof UnityAdsFullscreenActivity)) {
            return false;
        }
        ((Activity) UnityAdsProperties.CURRENT_ACTIVITY.get()).finish();
        return true;
    }

    public static boolean setZone(String str) {
        if (UnityAdsProperties.isShowingAds()) {
            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 (!UnityAdsProperties.isShowingAds() && 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) {
                UnityAdsCache.stopAllDownloads();
                currentZone.mergeOptions(map);
                if (currentZone.noOfferScreen()) {
                    ArrayList viewableVideoPlanCampaigns = UnityAdsWebData.getViewableVideoPlanCampaigns();
                    if (viewableVideoPlanCampaigns.size() > 0) {
                        UnityAdsProperties.SELECTED_CAMPAIGN = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(0);
                    }
                }
                UnityAdsDeviceLog.info("Launching ad from \"" + currentZone.getZoneName() + "\", options: " + currentZone.getZoneOptions().toString());
                UnityAdsProperties.SELECTED_CAMPAIGN_CACHED = false;
                Intent intent = new Intent(UnityAdsProperties.getCurrentActivity(), (Class<?>) UnityAdsFullscreenActivity.class);
                intent.addFlags(UnityAdsWebData.getZoneManager().getCurrentZone().openAnimated() ? DriveFile.MODE_READ_ONLY : 268500992);
                Activity baseActivity = UnityAdsProperties.getBaseActivity();
                if (baseActivity != null) {
                    try {
                        baseActivity.startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        UnityAdsDeviceLog.error("Could not find UnityAdsFullScreenActivity (failed Android manifest merging?): " + e.getMessage());
                    } catch (Exception e2) {
                        UnityAdsDeviceLog.error("Weird error: " + e2.getMessage());
                    }
                }
                return true;
            }
            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);
    }

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

    public static boolean canShow() {
        if (!UnityAdsProperties.isAdsReadySent()) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.WEBAPP_NOT_INITIALIZED);
            return false;
        }
        if (UnityAdsProperties.isShowingAds()) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.SHOWING_ADS);
            return false;
        }
        if (!UnityAdsDevice.isActiveNetworkConnected()) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.NO_INTERNET);
            return false;
        }
        if (UnityAdsWebData.initInProgress()) {
            return false;
        }
        ArrayList viewableVideoPlanCampaigns = UnityAdsWebData.getViewableVideoPlanCampaigns();
        if (viewableVideoPlanCampaigns == null) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.NO_ADS);
            return false;
        }
        if (viewableVideoPlanCampaigns.size() == 0) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.ZERO_ADS);
            return false;
        }
        UnityAdsCampaign unityAdsCampaign = (UnityAdsCampaign) viewableVideoPlanCampaigns.get(0);
        if (!unityAdsCampaign.allowStreamingVideo().booleanValue() && !UnityAdsCache.isCampaignCached(unityAdsCampaign)) {
            UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.VIDEO_NOT_CACHED);
            return false;
        }
        UnityAdsDeviceLog.logShowStatus(UnityAdsDeviceLog.UnityAdsShowMsg.READY);
        return true;
    }

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

    @Deprecated
    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;
    }

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

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

    @Deprecated
    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;
    }

    @Deprecated
    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());
        }
    }

    @Deprecated
    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 onWebDataCompleted() {
        boolean z = true;
        UnityAdsDeviceLog.entered();
        JSONObject jSONObject = null;
        boolean z2 = false;
        if (UnityAdsWebData.getData() != null && UnityAdsWebData.getData().has(UnityAdsConstants.UNITY_ADS_JSON_DATA_ROOTKEY)) {
            try {
                jSONObject = UnityAdsWebData.getData().getJSONObject(UnityAdsConstants.UNITY_ADS_JSON_DATA_ROOTKEY);
            } catch (Exception e) {
                z2 = true;
            }
            if (!z2) {
                UnityAdsWebData.setupCampaignRefreshTimer();
                if (jSONObject.has(UnityAdsConstants.UNITY_ADS_WEBVIEW_DATAPARAM_SDK_IS_CURRENT_KEY)) {
                    try {
                        z = jSONObject.getBoolean(UnityAdsConstants.UNITY_ADS_WEBVIEW_DATAPARAM_SDK_IS_CURRENT_KEY);
                    } catch (Exception e2) {
                        z2 = true;
                    }
                }
            }
        }
        if (!z2 && !z && UnityAdsProperties.getCurrentActivity() != null && UnityAdsUtils.isDebuggable()) {
            AlertDialog create = new AlertDialog.Builder(UnityAdsProperties.getCurrentActivity()).create();
            create.setTitle("Unity Ads");
            create.setMessage("You are not running the latest version of Unity Ads android. Please update your version (this dialog won't appear in release builds).");
            create.setButton("OK", new a(this, create));
            create.show();
        }
        UnityAdsDeviceLog.entered();
        if (a) {
            UnityAdsCache.initialize(UnityAdsWebData.getVideoPlanCampaigns());
        }
        UnityAdsUtils.runOnUiThread(new c());
    }

    @Override
    public void onWebDataFailed() {
        if (getListener() != null && !UnityAdsProperties.UNITY_ADS_READY_SENT.booleanValue()) {
            getListener().onFetchFailed();
            UnityAdsProperties.UNITY_ADS_READY_SENT = true;
        }
    }

    public static void init(Activity activity, String str, IUnityAdsListener iUnityAdsListener) {
        if (c == 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 1502 (Unity + " + UnityAdsProperties.UNITY_VERSION + ") with gameId " + str);
                } else {
                    UnityAdsDeviceLog.info("Initializing Unity Ads version 1502 with gameId " + str);
                }
                try {
                    Class.forName("com.unity3d.ads.android.webapp.UnityAdsWebBridge").getMethod("handleWebEvent", String.class, String.class);
                    UnityAdsDeviceLog.debug("UnityAds ProGuard check OK");
                } catch (ClassNotFoundException e) {
                    UnityAdsDeviceLog.error("UnityAds ProGuard check fail: com.unity3d.ads.android.webapp.UnityAdsWebBridge class not found, check ProGuard settings");
                    return;
                } catch (NoSuchMethodException e2) {
                    UnityAdsDeviceLog.error("UnityAds ProGuard check fail: com.unity3d.ads.android.webapp.handleWebEvent method not found, check ProGuard settings");
                    return;
                } catch (Exception e3) {
                    UnityAdsDeviceLog.debug("UnityAds ProGuard check: Unknown exception: " + e3);
                }
                if (c == null) {
                    c = new UnityAds();
                }
                setListener(iUnityAdsListener);
                UnityAdsProperties.UNITY_ADS_GAME_ID = str;
                UnityAdsProperties.BASE_ACTIVITY = new WeakReference(activity);
                UnityAdsProperties.APPLICATION_CONTEXT = activity.getApplicationContext();
                UnityAdsProperties.CURRENT_ACTIVITY = new WeakReference(activity);
                UnityAdsDeviceLog.debug("Is debuggable=" + UnityAdsUtils.isDebuggable());
                UnityAdsWebData.setWebDataListener(c);
                new Thread(new b(activity)).start();
            } catch (NumberFormatException e4) {
                throw new IllegalArgumentException("gameId does not parse as an integer");
            }
        }
    }
}